aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-02-12 11:26:52 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-02-12 11:26:52 +0100
commit83c588a624723742e77db3914259ee37c530bca2 (patch)
treea3a0cf98cfcb4860b430693df01d84fdb4a2bdd3 /src/GraphicObjects
parent0f813f1c3d1bc3e4deeee089d771eb0443949e3f (diff)
progressing, not using contextCoord anymore
Diffstat (limited to 'src/GraphicObjects')
-rw-r--r--src/GraphicObjects/GraphicObject.cs64
-rw-r--r--src/GraphicObjects/PrivateContainer.cs59
2 files changed, 80 insertions, 43 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 699d39a9..763d1277 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -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
diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs
index 63f4f02a..f3a512d0 100644
--- a/src/GraphicObjects/PrivateContainer.cs
+++ b/src/GraphicObjects/PrivateContainer.cs
@@ -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