diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-12 17:47:36 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-12 17:47:36 +0100 |
| commit | 970a3f7239d5e57eb011295cda9eee015bbe97f4 (patch) | |
| tree | 7d09918825c72a7e0f58b5d8b174f27805cdfcc5 /src/GraphicObjects/GraphicObject.cs | |
| parent | 44caf51048bde7e9daf78acc779278642c798748 (diff) | |
| parent | d1e33e2f2212e2f9a60caebd3eb839b36357b2c6 (diff) | |
Merge branch 'NewClipping'
Diffstat (limited to 'src/GraphicObjects/GraphicObject.cs')
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 14516dba..24fd852a 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -31,6 +31,9 @@ namespace Crow internal List<Binding> Bindings = new List<Binding> (); internal int layoutingTries = 0; + Rectangles clipping = new Rectangles(); + public Rectangles Clipping { get { return clipping; }} + #region IValueChange implementation public event EventHandler<ValueChangeEventArgs> ValueChanged; public virtual void NotifyValueChanged(string MemberName, object _value) @@ -121,15 +124,7 @@ namespace Crow [XmlIgnore]public ILayoutable Parent { get { return _parent; } set { -// if (_parent == value) -// return; -// if (_parent != null) -// ClearBinding (); -// _parent = value; -// -// if (DataSource != null) -// ResolveBindings (); } } @@ -149,21 +144,19 @@ namespace Crow get { return Parent == null ? null : Parent.HostContainer; } } public virtual Rectangle ContextCoordinates(Rectangle r){ - return - Parent.ContextCoordinates (r);// + ClientRectangle.Position; + 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){ return Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position; } - public virtual Rectangle getSlot() - { - return Slot; - } - public virtual Rectangle getBounds() - { - return Bounds; - } + public virtual Rectangle getSlot() => Slot; + public virtual Rectangle getBounds() => Bounds; #endregion #region EVENT HANDLERS @@ -478,14 +471,21 @@ namespace Crow public virtual bool Contains(GraphicObject goToFind){ return false; } - - public virtual void registerClipRect() - { - HostContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot)); + public virtual void RegisterClip(Rectangle clip){ + if (CacheEnabled && bmp != null) + Clipping.AddRectangle (clip + ClientRectangle.Position); + Parent.RegisterClip (clip + Slot.Position + ClientRectangle.Position); + } +// public virtual void registerClipRect(Rectangle clip) +// { +// Rectangle tmp = ContextCoordinates (clip); +// if (CacheEnabled) { +// } + //HostContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot)); //this clipping should take only last painted slots on each level in ancestor tree which //is not the case for now. - HostContainer.redrawClip.AddRectangle (ScreenCoordinates(LastPaintedSlot)); - } + //HostContainer.redrawClip.AddRectangle (ScreenCoordinates(LastPaintedSlot)); + //} /// <summary> /// Clear chached object and add clipping region in redraw list of interface /// </summary> @@ -502,12 +502,6 @@ namespace Crow { if (IsQueuedForRedraw) return; - //test if this speed up a lot to cancel clipping for an uncached group - Group p = Parent as Group; - if (p != null) { - if (p.bmp == null) - return; - } if (HostContainer == null) return; HostContainer.gobjsToRedraw.Add (this); @@ -734,9 +728,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; @@ -752,17 +746,34 @@ 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 (); + } + //Clipping.clearAndClip (ctx); + Clipping.Reset(); + } /// <summary> Chained painting routine on the parent context of the actual cached version /// of the widget </summary> - public virtual void Paint (ref Context ctx, Rectangles clip = null) + public virtual void Paint (ref Context ctx) { if (!Visible) return; LastPaintedSlot = Slot; - Rectangle rb = Parent.ContextCoordinates (Slot); - if (cacheEnabled) { if (Slot.Width > Interface.MaxCacheSize || Slot.Height > Interface.MaxCacheSize) cacheEnabled = false; @@ -770,28 +781,19 @@ namespace Crow if (cacheEnabled) { if (bmp == null) - UpdateGraphic (); + RecreateCache (); - 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; + UpdateCache (ctx); + } else { + Rectangle rb = Slot + Parent.ClientRectangle.Position; + ctx.Save (); + + ctx.Translate (rb.X, rb.Y); + + onDraw (ctx); + + ctx.Restore (); } - ctx.Save (); - ctx.Translate (rb.X, rb.Y); - onDraw (ctx); - ctx.Restore (); } #endregion |