diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-08 17:22:23 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-08 17:22:23 +0100 |
| commit | a5eec67305d20d7112743f649e2a327ba717ceec (patch) | |
| tree | 6f2c6402e64e0d9d5cae161a5ac08b63be56ad9f /src | |
| parent | d810ad18dc2a1908211b6967d666c915140f24c9 (diff) | |
MaxLayoutingTries; CachingEnabled in GraphicObject + MaxCacheSize
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 57 | ||||
| -rw-r--r-- | src/GraphicObjects/ILayoutable.cs | 1 | ||||
| -rw-r--r-- | src/Interface.cs | 2 | ||||
| -rw-r--r-- | src/LayoutingQueueItem.cs | 5 | ||||
| -rw-r--r-- | src/OpenTKGameWindow.cs | 4 |
5 files changed, 54 insertions, 15 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 43b9a725..27f1fe5d 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -29,6 +29,7 @@ namespace Crow #endif internal List<Binding> Bindings = new List<Binding> (); + internal int layoutingTries = 0; #region IValueChange implementation public event EventHandler<ValueChangeEventArgs> ValueChanged; @@ -80,6 +81,7 @@ namespace Crow HorizontalAlignment _horizontalAlignment = HorizontalAlignment.Center; Size _maximumSize = "0;0"; Size _minimumSize = "0;0"; + bool cacheEnabled = false; #endregion #region public fields @@ -178,6 +180,16 @@ namespace Crow #endregion #region public properties + [XmlAttributeAttribute()][DefaultValue(true)] + public virtual bool CacheEnabled { + get { return cacheEnabled; } + set { + if (cacheEnabled == value) + return; + cacheEnabled = value; + NotifyValueChanged ("CacheEnabled", cacheEnabled); + } + } [XmlAttributeAttribute()][DefaultValue("unamed")] public virtual string Name { get { return _name; } @@ -499,6 +511,11 @@ namespace Crow } #region Layouting + public int LayoutingTries { + get { return layoutingTries; } + set { layoutingTries = value; } + } + /// <summary> return size of content + margins </summary> protected virtual Size measureRawSize () { return Bounds.Size; @@ -740,25 +757,37 @@ namespace Crow if (!Visible) return; - if (bmp == null) - UpdateGraphic (); + Rectangle rb = Parent.ContextCoordinates (Slot); + + if (cacheEnabled) { + if (Slot.Width > Interface.MaxCacheSize || Slot.Height > Interface.MaxCacheSize) + cacheEnabled = false; + } - Rectangle rb = Parent.ContextCoordinates(Slot); + 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 (); + 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 (); } - ctx.SetSourceSurface (source, rb.X, rb.Y); - ctx.Paint (); + return; } + ctx.Save (); + ctx.Translate (rb.X, rb.Y); + onDraw (ctx); + ctx.Restore (); } #endregion diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index b9a97b0e..edddedd7 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -5,6 +5,7 @@ namespace Crow { public interface ILayoutable { + int LayoutingTries { get; set; } ILayoutable Parent { get; set; } Rectangle ClientRectangle { get; } diff --git a/src/Interface.cs b/src/Interface.cs index 5ecd7a88..5a67751d 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -52,6 +52,8 @@ namespace Crow public static bool DesignerMode = false; /// <summary> Threshold to catch borders for sizing </summary> public static int BorderThreshold = 5; + public const int MaxCacheSize = 2048; + public const int MaxLayoutingTries = 50; public static Queue<LayoutingQueueItem> LayoutingQueue = new Queue<LayoutingQueueItem>(); diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index a558efd2..03a39c5c 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -61,8 +61,11 @@ namespace Crow #if DEBUG_LAYOUTING Debug.WriteLine ("Requeuing => " + this.ToString ()); #endif - Interface.LayoutingQueue.Enqueue (this); + GraphicObject.LayoutingTries ++; + if (GraphicObject.LayoutingTries < Interface.MaxLayoutingTries) + Interface.LayoutingQueue.Enqueue (this); } else { + GraphicObject.LayoutingTries = 0; #if DEBUG_LAYOUTING Debug.WriteLine ("Layouting => " + this.ToString ()); #endif diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 2083346c..0892ec47 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -544,6 +544,10 @@ namespace Crow #endregion #region ILayoutable implementation + public int LayoutingTries { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + } public LayoutingType RegisteredLayoutings { get { return LayoutingType.None; } set { throw new NotImplementedException (); } |