]> O.S.I.I.S - jp/crow.git/commitdiff
MaxLayoutingTries; CachingEnabled in GraphicObject + MaxCacheSize
authorjpbruyere <jp.bruyere@hotmail.com>
Mon, 8 Feb 2016 16:22:23 +0000 (17:22 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Mon, 8 Feb 2016 16:22:23 +0000 (17:22 +0100)
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/ILayoutable.cs
src/Interface.cs
src/LayoutingQueueItem.cs
src/OpenTKGameWindow.cs

index 43b9a7251f8fca89f48513805a17a107eaaa0425..27f1fe5dd3f28bdfe46b548a5753f6787ac01864 100644 (file)
@@ -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);
 
-                       Rectangle rb = Parent.ContextCoordinates(Slot);
+                       if (cacheEnabled) {
+                               if (Slot.Width > Interface.MaxCacheSize || Slot.Height > Interface.MaxCacheSize)
+                                       cacheEnabled = false;
+                       }
 
-                       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 ();
+                       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 ();
                                }
-                               ctx.SetSourceSurface (source, rb.X, rb.Y);
-                               ctx.Paint ();
+                               return;
                        }
+                       ctx.Save ();
+                       ctx.Translate (rb.X, rb.Y);
+                       onDraw (ctx);
+                       ctx.Restore ();
                }
                #endregion
 
index b9a97b0ec3e8c223d4e914359186df47d96278e2..edddedd7033ebf30e5577466a727d2f18dc5cca6 100644 (file)
@@ -5,6 +5,7 @@ namespace Crow
 {
        public interface ILayoutable
        {
+               int LayoutingTries { get; set; }
                ILayoutable Parent { get; set; }
 
                Rectangle ClientRectangle { get; }
index 5ecd7a88d0801b555f273dc56bf656e5c2f0c977..5a67751d87bc26c7b4d96ba6e8e80c5c71bc6a99 100644 (file)
@@ -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>();
 
index a558efd2ef07cff6055d8c98be8c5f471b4b7d00..03a39c5c3fd1a6db24642a4177c83454249e08bc 100644 (file)
@@ -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
index 2083346ca2a255b9ae3ed8160cb0579c505fb878..0892ec475b4b83773276ee48d87d7bd6e2817ee9 100644 (file)
@@ -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 (); }