]> O.S.I.I.S - jp/crow.git/commitdiff
testing clipping rect registration, clear and clip, not working
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 12 Feb 2016 12:05:32 +0000 (13:05 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 12 Feb 2016 12:05:32 +0000 (13:05 +0100)
Tests/GOLIBTest_4.cs
Tests/GOLIBTests.cs
Tests/Interfaces/clip0.crow
Tests/Interfaces/clip2.crow
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/IGOLibHost.cs
src/GraphicObjects/PrivateContainer.cs
src/OpenTKGameWindow.cs

index 8fbfe4ec2309414d61e65c88dba5e6cc8c395dab..9c8fe3858bce5160e35911b777bb311eae2b0668 100644 (file)
@@ -171,7 +171,7 @@ namespace test
                {
                        if (!e.Mouse.IsButtonDown (MouseButton.Left)||sender!=c)
                                return;
-                       redrawClip.AddRectangle (c.ScreenCoordinates(c.Slot));
+                       clipping.AddRectangle (c.ScreenCoordinates(c.Slot));
                        c.Left += e.XDelta;
                        c.Top += e.YDelta;
                        c.registerForGraphicUpdate ();
index 622d1ce70ad36b8a002ea391fa74747d7305cf43..c14277f427c5f03744a1816b1dbcc278511c6bb5 100644 (file)
@@ -37,9 +37,9 @@ namespace test
                int frameCpt = 0;
                int idx = 0;
                string[] testFiles = {
-                       "clip2.crow",
                        "clip0.crow",
                        "clip1.crow",
+                       "clip2.crow",
                        "0.crow",
                        "5.crow",
                        "testCombobox.goml",
index 2ebea9ff56447288b0b67f4e9eb1b93c0613f382..dbe6eb341718e426a8b9fa24f5700a1ef133d9f3 100755 (executable)
@@ -1,9 +1,9 @@
 <?xml version="1.0"?>
-<Container Fit="true" Margin="50" Background="LimeGreen" CacheEnabled="false"
+<Container Fit="true" Margin="50" Background="LimeGreen" CacheEnabled="true"
                HorizontalAlignment="Right" VerticalAlignment="Bottom"
                MouseEnter="{Background=Gray}"
                MouseLeave="{Background=LimeGreen}">
-       <Label HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="false"
+       <Label HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="true"
                MouseEnter="{Background=DimGray}" Width="100"
                MouseLeave="{Background=BlueCrayola}"
                Margin="10" Text="{drawing}" Background="BlueCrayola"/>
index 622951001d806c86eed7daf2a45422b56ae11751..8f6b4656260a50015f5bafe8ea9cdf96e2cfb941 100755 (executable)
@@ -1,10 +1,15 @@
 <?xml version="1.0"?>
-<Group Fit="true" Margin="50" Background="LimeGreen" CacheEnabled="true"
+<Group Fit="true" Margin="50" Background="Yellow" CacheEnabled="true"
+               HorizontalAlignment="Right" VerticalAlignment="Bottom"
+               MouseEnter="{Background=DimGray}"
+               MouseLeave="{Background=Yellow}">
+<Group Fit="true" Margin="50" Background="LimeGreen" CacheEnabled="false"
                HorizontalAlignment="Right" VerticalAlignment="Bottom"
                MouseEnter="{Background=Gray}"
                MouseLeave="{Background=LimeGreen}">
-       <Label HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="true"
+       <Label HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="false"
                MouseEnter="{Background=DimGray}" Width="100"
                MouseLeave="{Background=BlueCrayola}"
                Margin="10" Text="{drawing}" Background="BlueCrayola"/>
+ </Group>
  </Group>
\ No newline at end of file
index 87ac0eeffbdbbd7015e7628d35b47c9a9249a5df..97e4eccf010f8b8ae409efb3dd5fd28af5d764e4 100644 (file)
@@ -31,8 +31,8 @@ namespace Crow
                internal List<Binding> Bindings = new List<Binding> ();
                internal int layoutingTries = 0;
 
-               Rectangles _clipping = new Rectangles();
-               public Rectangles Clipping { get { return _clipping; }}
+               Rectangles clipping = new Rectangles();
+               public Rectangles Clipping { get { return clipping; }}
 
                #region IValueChange implementation
                public event EventHandler<ValueChangeEventArgs> ValueChanged;
@@ -471,11 +471,10 @@ namespace Crow
                public virtual bool Contains(GraphicObject goToFind){
                        return false;
                }
-               public void RegisterClip(Rectangle clip){
-                       Rectangle r = Slot + Parent.ClientRectangle;
+               public void RegisterClip(Rectangle clip){                       
                        if (CacheEnabled && bmp != null)
-                               Clipping.AddRectangle (r);                              
-                       Parent.RegisterClip (r);
+                               Clipping.AddRectangle (clip);                           
+                       Parent.RegisterClip (clip + Slot.Position + Parent.ClientRectangle.Position);
                }
 //             public virtual void registerClipRect(Rectangle clip)
 //             {
@@ -768,7 +767,9 @@ namespace Crow
                                //                                      }
                                ctx.SetSourceSurface (cache, rb.X, rb.Y);
                                ctx.Paint ();
-                       }                                               
+                       }
+                       //Clipping.clearAndClip (ctx);
+                       Clipping.Reset();
                }
                /// <summary> Chained painting routine on the parent context of the actual cached version
                /// of the widget </summary>
@@ -793,7 +794,6 @@ namespace Crow
                                Rectangle rb = Slot + Parent.ClientRectangle.Position;
                                ctx.Save ();
 
-                               //Clipping.clearAndClip (ctx);
                                ctx.Translate (rb.X, rb.Y);
 
                                onDraw (ctx);
index 4305a6658e9bbd0de4e8080967740c4eddba4f6e..efc5240befad957183e20edc4fb8f8d413d2fd64 100644 (file)
@@ -238,6 +238,7 @@ namespace Crow
                                ctx.SetSourceSurface (cache, rb.X, rb.Y);
                                ctx.Paint ();
                        }
+                       Clipping.Reset();
                }
                #endregion
 
index 1c50d55834d10b775f1919d003c5855ffd9ec7aa..1cf6978ce2d7aa5055055c6189249868f96a7f3d 100644 (file)
@@ -5,7 +5,6 @@ namespace Crow
 {
        public interface IGOLibHost
        {
-               Rectangles redrawClip { get; set; }
                List<GraphicObject> gobjsToRedraw { get; }
                GraphicObject activeWidget { get; set; }
                GraphicObject hoverWidget { get; set; }
index 0a87d03cc22d699d48ef6422bbf54c13ce1c48ef..4012a7afb9ab0693e380f8e7acea7ca4bf536469 100644 (file)
@@ -146,11 +146,13 @@ namespace Crow
                        using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {
                                Context gr = new Context (cache);
 
-                               //Clipping.clearAndClip (gr);
-                               base.onDraw (gr);
+                               //Clipping.clearAndClip (ctx);
 
                                if (Clipping.count > 0) {
                                        if (child != null) {
+                                               
+                                               base.onDraw (gr);
+
                                                child.Paint (ref gr);
                                        }
                                }
@@ -160,6 +162,7 @@ namespace Crow
                                ctx.SetSourceSurface (cache, rb.X, rb.Y);
                                ctx.Paint ();
                        }
+                       Clipping.Reset();
                }
 //             public override Rectangle ContextCoordinates (Rectangle r)
 //             {
index 007556bccd018d815f2617ad2000e7c372371a12..5a2dc7fe1d19d3ce6c19a71c210409b73f1a6618 100644 (file)
@@ -54,7 +54,7 @@ namespace Crow
                List<GraphicObject> _gobjsToRedraw = new List<GraphicObject>();
 
                #region IGOLibHost implementation
-               public Rectangles redrawClip {
+               public Rectangles clipping {
                        get {
                                return _redrawClip;
                        }
@@ -181,7 +181,7 @@ namespace Crow
                        shader.ProjectionMatrix = Matrix4.CreateOrthographicOffCenter 
                                (0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1);                    
 
-                       redrawClip.AddRectangle (ClientRectangle);
+                       clipping.AddRectangle (ClientRectangle);
                }
                void createOpenGLSurface()
                {
@@ -253,55 +253,65 @@ namespace Crow
                        updateTime.Restart ();                  
                        #endif
 
-                       using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
-                               using (ctx = new Context (surf)){
+                       GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count];
+                       GraphicObjects.CopyTo (invGOList, 0);
+                       invGOList = invGOList.Reverse ().ToArray ();
 
-                                       GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count];
-                                       GraphicObjects.CopyTo (invGOList, 0);
-                                       invGOList = invGOList.Reverse ().ToArray ();
+                       #if MEASURE_TIME
+                       layoutTime.Start ();
+                       #endif
+                       //Debug.WriteLine ("======= Layouting queue start =======");
 
-                                       #if MEASURE_TIME
-                                       layoutTime.Start ();
-                                       #endif
-                                       //Debug.WriteLine ("======= Layouting queue start =======");
+                       while (Interface.LayoutingQueue.Count > 0) {
+                               LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
+                               lqi.ProcessLayouting ();
+                       }
 
-                                       while (Interface.LayoutingQueue.Count > 0) {
-                                               LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
-                                               lqi.ProcessLayouting ();
-                                       }
+                       #if MEASURE_TIME
+                       layoutTime.Stop ();
+                       #endif
 
-                                       #if MEASURE_TIME
-                                       layoutTime.Stop ();
-                                       #endif
+                       //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");
+                       //final redraw clips should be added only when layout is completed among parents,
+                       //that's why it take place in a second pass
+                       GraphicObject[] gotr = new GraphicObject[gobjsToRedraw.Count];
+                       gobjsToRedraw.CopyTo (gotr);
+                       gobjsToRedraw.Clear ();
+                       foreach (GraphicObject p in gotr) {
+                               p.IsQueuedForRedraw = false;
+                               p.RegisterClip (p.LastPaintedSlot);
+                               p.RegisterClip (p.getSlot());
+                       }
 
-                                       //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");
-                                       //final redraw clips should be added only when layout is completed among parents,
-                                       //that's why it take place in a second pass
-                                       GraphicObject[] gotr = new GraphicObject[gobjsToRedraw.Count];
-                                       gobjsToRedraw.CopyTo (gotr);
-                                       gobjsToRedraw.Clear ();
-                                       foreach (GraphicObject p in gotr) {
-                                               p.IsQueuedForRedraw = false;
-                                               p.RegisterClip (p.LastPaintedSlot);
-                                               p.RegisterClip (p.getSlot());
-                                       }
+                       #if MEASURE_TIME
+                       updateTime.Stop ();
+                       drawingTime.Start ();
+                       #endif
+
+                       using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
+                               using (ctx = new Context (surf)){
 
-                                       #if MEASURE_TIME
-                                       updateTime.Stop ();
-                                       drawingTime.Start ();
-                                       #endif
 
+                                       if (clipping.count > 0) {
+                                               //Link.draw (ctx);
+                                               clipping.clearAndClip(ctx);
 
-                                                       //Link.draw (ctx);
-                                       foreach (GraphicObject p in invGOList) {
-                                               if (!p.Visible)
-                                                       continue;
+                                               foreach (GraphicObject p in invGOList) {
+                                                       if (!p.Visible)
+                                                               continue;
 
-                                               ctx.Save ();
+                                                       ctx.Save ();
 
-                                               p.Paint (ref ctx);
+                                                       p.Paint (ref ctx);
                                                
-                                               ctx.Restore ();
+                                                       ctx.Restore ();
+                                               }
+
+                                               #if DEBUG_CLIP_RECTANGLE
+                                               clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
+                                               #endif
+
+                                               clipping.Reset ();
                                        }
 
                                        #if MEASURE_TIME
@@ -536,7 +546,7 @@ namespace Crow
 
                #region ILayoutable implementation
                public void RegisterClip(Rectangle r){
-                       redrawClip.AddRectangle (r);
+                       clipping.AddRectangle (r);
                }
                public int LayoutingTries {
                        get { throw new NotImplementedException (); }