]> O.S.I.I.S - jp/crow.git/commitdiff
separate RecreateCache and UpdateCache
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 12 Feb 2016 10:52:50 +0000 (11:52 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 12 Feb 2016 10:52:50 +0000 (11:52 +0100)
Tests/GOLIBTests.cs
Tests/Interfaces/clip1.crow
Tests/Interfaces/clip2.crow [new file with mode: 0755]
Tests/Tests.csproj
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/PrivateContainer.cs
src/OpenTKGameWindow.cs

index adc61818524254a9ae612d765d6a9fd5d38ed4b8..622d1ce70ad36b8a002ea391fa74747d7305cf43 100644 (file)
@@ -37,6 +37,7 @@ namespace test
                int frameCpt = 0;
                int idx = 0;
                string[] testFiles = {
+                       "clip2.crow",
                        "clip0.crow",
                        "clip1.crow",
                        "0.crow",
index 957080b9dea27a649df0b11bd24a6111aafc4959..d5fcf79b2bd1a5d273d2eafe19059726a7146ee9 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<Container Fit="true" Margin="20" Background="SkyBlue" CacheEnabled="false"
+<Container Fit="true" Margin="20" Background="SkyBlue" CacheEnabled="true"
                HorizontalAlignment="Right" VerticalAlignment="Bottom"
                MouseEnter="{Background=LightGray}"
                MouseLeave="{Background=SkyBlue}">
                                HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                MouseEnter="{Background=Blue}"
                                MouseLeave="{Background=Yellow}">
-                               <Container Width="200" Height="200" Margin="0" Background="LimeGreen" CacheEnabled="false"
+                               <Container Margin="50" Background="LimeGreen" CacheEnabled="true"
                                                HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                                MouseEnter="{Background=Gray}"
                                                MouseLeave="{Background=LimeGreen}">
-                                       <Label Left="30"  HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="false"
+                                       <Label HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="true"
                                                MouseEnter="{Background=DimGray}"
                                                MouseLeave="{Background=BlueCrayola}" 
                                                Margin="1" Text="{drawing}" Background="BlueCrayola"/>
diff --git a/Tests/Interfaces/clip2.crow b/Tests/Interfaces/clip2.crow
new file mode 100755 (executable)
index 0000000..6229510
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<Group Fit="true" Margin="50" Background="LimeGreen" CacheEnabled="true"
+               HorizontalAlignment="Right" VerticalAlignment="Bottom"
+               MouseEnter="{Background=Gray}"
+               MouseLeave="{Background=LimeGreen}">
+       <Label HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="true"
+               MouseEnter="{Background=DimGray}" Width="100"
+               MouseLeave="{Background=BlueCrayola}"
+               Margin="10" Text="{drawing}" Background="BlueCrayola"/>
+ </Group>
\ No newline at end of file
index 0fe3ffa14b25a9810a37a207cf4bb4e6538bcc20..d1e171091f0e9da3c130f4ff75a53de55be27e79 100644 (file)
     <None Include="Interfaces\clip1.crow">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="Interfaces\clip2.crow">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
index 763d1277cc0e6ce1a48e73efafd2c81995d65ab6..87ac0eeffbdbbd7015e7628d35b47c9a9249a5df 100644 (file)
@@ -793,7 +793,7 @@ namespace Crow
                                Rectangle rb = Slot + Parent.ClientRectangle.Position;
                                ctx.Save ();
 
-                               Clipping.clearAndClip (ctx);
+                               //Clipping.clearAndClip (ctx);
                                ctx.Translate (rb.X, rb.Y);
 
                                onDraw (ctx);
index 33fe006dd581e5006d8e5ceea8c5504ddd756de1..4305a6658e9bbd0de4e8080967740c4eddba4f6e 100644 (file)
@@ -204,9 +204,6 @@ namespace Crow
                                break;
                        }
                }
-               public override Rectangle ContextCoordinates(Rectangle r){
-                       return r + ClientRectangle.Position;
-               }       
 
                protected override void onDraw (Context gr)
                {
@@ -216,43 +213,31 @@ namespace Crow
                                g.Paint (ref gr);
                        }
                }
-
-               public override void Paint(ref Context ctx)
+               protected override void UpdateCache (Context ctx)
                {
-                       if ( !Visible )
-                               return;
+                       Rectangle rb = Slot + Parent.ClientRectangle.Position;
 
-                       if (CacheEnabled) {
-                               if (bmp == null)
-                                       RecreateCache ();
-                       }
+                       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);
 
-                       if (Clipping.count > 0) {
-                               using (ImageSurface cache =
-                                              new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, Slot.Width * 4)) {
-                                       Context gr = new Context (cache);
+                               foreach (GraphicObject c in children) {
+                                       if (!c.Visible)
+                                               continue;
+                                       c.Paint (ref gr);                                               
+                               }
 
-                                       Clipping.clearAndClip (gr);
-                                       Rectangle rBack = Slot.Size;
-                                       Background.SetAsSource (gr, rBack);
-                                       CairoHelpers.CairoRectangle (gr, rBack, CornerRadius);
-                                       gr.Fill ();
+                               #if DEBUG_CLIP_RECTANGLE
+                               Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8));
+                               #endif
 
-                                       foreach (GraphicObject c in children) {
-                                               if (!c.Visible)
-                                                       continue;
-                                               Rectangles childClip = Clipping.intersectingRects (ContextCoordinates (c.Slot));
-                                               if (childClip.count > 0)
-                                                       c.Paint (ref ctx);                                              
-                                       }
-                                       #if DEBUG_CLIP_RECTANGLE
-                                       Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8));
-                                       #endif
+                               gr.Dispose ();
 
-                                       gr.Dispose ();
-                               }
-                       }                               
-                       base.Paint (ref ctx);
+                               ctx.SetSourceSurface (cache, rb.X, rb.Y);
+                               ctx.Paint ();
+                       }
                }
                #endregion
 
index f3a512d0fdabe5cec320c13921fa8ffb8cd81289..0a87d03cc22d699d48ef6422bbf54c13ce1c48ef 100644 (file)
@@ -146,7 +146,7 @@ namespace Crow
                        using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {
                                Context gr = new Context (cache);
 
-                               child.Clipping.clearAndClip (gr);
+                               //Clipping.clearAndClip (gr);
                                base.onDraw (gr);
 
                                if (Clipping.count > 0) {
index e6fc9681800e0b51e7a582e0c747270067a4e762..007556bccd018d815f2617ad2000e7c372371a12 100644 (file)
@@ -290,36 +290,20 @@ namespace Crow
                                        updateTime.Stop ();
                                        drawingTime.Start ();
                                        #endif
-                                       Debug.WriteLine (redrawClip.ToString ());
-                                       lock (redrawClip) {
-                                               if (redrawClip.count > 0) {
-                                                       #if DEBUG_CLIP_RECTANGLE
-                                               redrawClip.stroke (ctx, new Color(1.0,0,0,0.3));
-                                                       #endif
-                                                       redrawClip.clearAndClip (ctx);
 
-                                                       //Link.draw (ctx);
-                                                       foreach (GraphicObject p in invGOList) {
-                                                               if (!p.Visible)
-                                                                       continue;
-
-                                                               ctx.Save ();
 
-                                                               Rectangles clip = redrawClip.intersectingRects (p.Slot);
+                                                       //Link.draw (ctx);
+                                       foreach (GraphicObject p in invGOList) {
+                                               if (!p.Visible)
+                                                       continue;
 
-                                                               if (clip.count > 0)
-                                                                       p.Paint (ref ctx);
-                                                               
-                                                               ctx.Restore ();
+                                               ctx.Save ();
 
-                                                       }
-                                                       ctx.ResetClip ();
-                                                       #if DEBUG_CLIP_RECTANGLE
-                                               redrawClip.stroke (ctx, Color.Red.AdjustAlpha(0.1));
-                                                       #endif
-                                                       redrawClip.Reset ();
-                                               }
+                                               p.Paint (ref ctx);
+                                               
+                                               ctx.Restore ();
                                        }
+
                                        #if MEASURE_TIME
                                        drawingTime.Stop ();
                                        #endif