]> O.S.I.I.S - jp/crow.git/commitdiff
progressing, not using contextCoord anymore
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 12 Feb 2016 10:26:52 +0000 (11:26 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 12 Feb 2016 10:26:52 +0000 (11:26 +0100)
Tests/GOLIBTests.cs
Tests/Interfaces/clip1.crow
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/PrivateContainer.cs

index 45bf6392410649230cd2b8dace4d1d21854ba652..adc61818524254a9ae612d765d6a9fd5d38ed4b8 100644 (file)
@@ -37,8 +37,8 @@ namespace test
                int frameCpt = 0;
                int idx = 0;
                string[] testFiles = {
-                       "clip1.crow",
                        "clip0.crow",
+                       "clip1.crow",
                        "0.crow",
                        "5.crow",
                        "testCombobox.goml",
index a4f42b107854e9e9e785bbc2c6172dc046f97bd1..957080b9dea27a649df0b11bd24a6111aafc4959 100755 (executable)
@@ -1,21 +1,21 @@
 <?xml version="1.0"?>
-<Container Fit="true" Margin="20" Background="SkyBlue" CacheEnabled="true"
+<Container Fit="true" Margin="20" Background="SkyBlue" CacheEnabled="false"
                HorizontalAlignment="Right" VerticalAlignment="Bottom"
                MouseEnter="{Background=LightGray}"
                MouseLeave="{Background=SkyBlue}">
-               <Container Fit="true" Margin="20" Background="Red" CacheEnabled="true"
+               <Container Fit="true" Margin="20" Background="Red" CacheEnabled="false"
                        HorizontalAlignment="Right" VerticalAlignment="Bottom"
                        MouseEnter="{Background=White}"
                        MouseLeave="{Background=Red}">
-                       <Container Fit="true" Margin="20" Background="Yellow" CacheEnabled="true"
+                       <Container Fit="true" Margin="20" Background="Yellow" CacheEnabled="false"
                                HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                MouseEnter="{Background=Blue}"
                                MouseLeave="{Background=Yellow}">
-                               <Container Margin="50" Background="LimeGreen" CacheEnabled="false"
+                               <Container Width="200" Height="200" Margin="0" Background="LimeGreen" CacheEnabled="false"
                                                HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                                MouseEnter="{Background=Gray}"
                                                MouseLeave="{Background=LimeGreen}">
-                                       <Label  HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="true"
+                                       <Label Left="30"  HorizontalAlignment="Center" VerticalAlignment="Center" CacheEnabled="false"
                                                MouseEnter="{Background=DimGray}"
                                                MouseLeave="{Background=BlueCrayola}" 
                                                Margin="1" Text="{drawing}" Background="BlueCrayola"/>
index 699d39a9c5d9b8e870d40c529b497e4c4622a589..763d1277cc0e6ce1a48e73efafd2c81995d65ab6 100644 (file)
@@ -144,7 +144,11 @@ namespace Crow
                        get { return Parent == null ? null : Parent.HostContainer; }
                }
                public virtual Rectangle ContextCoordinates(Rectangle r){
-                       return
+                       GraphicObject go = Parent as GraphicObject;
+                       if (go == null)
+                               return r + Parent.ClientRectangle.Position;
+                       return go.CacheEnabled ?
+                               r + Parent.ClientRectangle.Position : 
                                Parent.ContextCoordinates (r);
                }                       
                public virtual Rectangle ScreenCoordinates (Rectangle r){
@@ -731,9 +735,9 @@ namespace Crow
                }
 
                /// <summary>
-               /// Interfal drawing context creation on a cached surface limited to slot size
+               /// Internal drawing context creation on a cached surface limited to slot size
                /// this trigger the effective drawing routine </summary>
-               protected virtual void UpdateGraphic ()
+               protected virtual void RecreateCache ()
                {
                        int stride = 4 * Slot.Width;
 
@@ -749,6 +753,23 @@ namespace Crow
                                draw.Flush ();
                        }
                }
+               protected virtual void UpdateCache(Context ctx){
+                       Rectangle rb = Slot + Parent.ClientRectangle.Position;
+                       using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {
+                               //                                      //TODO:improve equality test for basic color and Fill
+                               //                                      if (this.Background is SolidColor) {
+                               //                                              if ((this.Background as SolidColor).Equals (Color.Clear)) {
+                               //                                                      ctx.Save ();
+                               //                                                      ctx.Operator = Operator.Clear;
+                               //                                                      ctx.Rectangle (rb);
+                               //                                                      ctx.Fill ();
+                               //                                                      ctx.Restore ();
+                               //                                              }
+                               //                                      }
+                               ctx.SetSourceSurface (cache, rb.X, rb.Y);
+                               ctx.Paint ();
+                       }                                               
+               }
                /// <summary> Chained painting routine on the parent context of the actual cached version
                /// of the widget </summary>
                public virtual void Paint (ref Context ctx)
@@ -758,8 +779,6 @@ namespace Crow
 
                        LastPaintedSlot = Slot;
 
-                       Rectangle rb = Parent.ContextCoordinates (Slot);
-
                        if (cacheEnabled) {
                                if (Slot.Width > Interface.MaxCacheSize || Slot.Height > Interface.MaxCacheSize)
                                        cacheEnabled = false;
@@ -767,29 +786,20 @@ namespace Crow
 
                        if (cacheEnabled) {
                                if (bmp == null)
-                                       UpdateGraphic ();
-                               using (ImageSurface source = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {
-//                                     //TODO:improve equality test for basic color and Fill
-//                                     if (this.Background is SolidColor) {
-//                                             if ((this.Background as SolidColor).Equals (Color.Clear)) {
-//                                                     ctx.Save ();
-//                                                     ctx.Operator = Operator.Clear;
-//                                                     ctx.Rectangle (rb);
-//                                                     ctx.Fill ();
-//                                                     ctx.Restore ();
-//                                             }
-//                                     }
-                                       ctx.SetSourceSurface (source, rb.X, rb.Y);
-                                       ctx.Paint ();
-                               }
-                               return;
-                       }
-                       ctx.Save ();
+                                       RecreateCache ();
 
-                       Clipping.clearAndClip (ctx);
-                       ctx.Translate (rb.X, rb.Y);
-                       onDraw (ctx);
-                       ctx.Restore ();
+                               UpdateCache (ctx);
+                       } else {
+                               Rectangle rb = Slot + Parent.ClientRectangle.Position;
+                               ctx.Save ();
+
+                               Clipping.clearAndClip (ctx);
+                               ctx.Translate (rb.X, rb.Y);
+
+                               onDraw (ctx);
+
+                               ctx.Restore ();
+                       }
                }
                #endregion
 
index 63f4f02ae513697d853479341354e188ee61ac5e..f3a512d0fdabe5cec320c13921fa8ffb8cd81289 100644 (file)
@@ -133,30 +133,57 @@ namespace Crow
                                break;
                        }
                }
-
-               public override Rectangle ContextCoordinates (Rectangle r)
+               protected override void onDraw (Context gr)
                {
-                       return
-                               Parent.ContextCoordinates(r) + Slot.Position + ClientRectangle.Position;
+                       base.onDraw (gr);
+                       if (child != null)
+                               child.Paint (ref gr);
                }
-               public override void Paint(ref Cairo.Context ctx)
+               protected override void UpdateCache (Context ctx)
                {
-                       if (!Visible)//check if necessary??
-                               return;
-
-                       ctx.Save();
+                       Rectangle rb = Slot + Parent.ClientRectangle.Position;
 
-                       base.Paint(ref ctx);
+                       using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {
+                               Context gr = new Context (cache);
 
-                       //clip to client zone
-                       CairoHelpers.CairoRectangle (ctx, Parent.ContextCoordinates(ClientRectangle + Slot.Position), CornerRadius);
-                       ctx.Clip();
+                               child.Clipping.clearAndClip (gr);
+                               base.onDraw (gr);
 
-                       if (child != null)
-                               child.Paint(ref ctx);
+                               if (Clipping.count > 0) {
+                                       if (child != null) {
+                                               child.Paint (ref gr);
+                                       }
+                               }
+                                       
+                               gr.Dispose ();
 
-                       ctx.Restore();            
+                               ctx.SetSourceSurface (cache, rb.X, rb.Y);
+                               ctx.Paint ();
+                       }
                }
+//             public override Rectangle ContextCoordinates (Rectangle r)
+//             {
+//                     return
+//                             Parent.ContextCoordinates(r) + Slot.Position + ClientRectangle.Position;
+//             }
+//             public override void Paint(ref Cairo.Context ctx)
+//             {
+//                     if (!Visible)//check if necessary??
+//                             return;
+//
+//                     ctx.Save();
+//
+//                     base.Paint(ref ctx);
+//
+//                     //clip to client zone
+//                     CairoHelpers.CairoRectangle (ctx, Parent.ContextCoordinates(ClientRectangle + Slot.Position), CornerRadius);
+//                     ctx.Clip();
+//
+//                     if (child != null)
+//                             child.Paint(ref ctx);
+//
+//                     ctx.Restore();            
+//             }
 
                #endregion