]> O.S.I.I.S - jp/crow.git/commitdiff
cumulative styling
authorjpbruyere <jp.bruyere@hotmail.com>
Sat, 30 Jul 2016 15:01:40 +0000 (17:01 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sat, 30 Jul 2016 15:01:40 +0000 (17:01 +0200)
Styles/Slider.style
Tests/OpenTKGameWindow.cs
src/GraphicObjects/GraphicObject.cs
src/Interface.cs
src/StyleReader.cs

index 7e4f60684e152fe87cf646f3eec7ebd81f526ee9..5b60e6af995aa65d75fc73471ab5ea3c4aab4939 100644 (file)
@@ -1,4 +1,4 @@
-Background = vgradient|0:Black|0,1:Gray|0,9:Gray|1:LightGray;
+Background = vgradient|0:Black|0.1:Gray|0.9:Gray|1:LightGray;
 Foreground = Gray;
 Focusable = true;
 Fit = true;
index 379f89f1b45e4e62bdcfb42e920f449ca34fb170..2b3bdb245937f995c553ddc0cdd26e9f34ce7e7a 100644 (file)
@@ -316,12 +316,12 @@ namespace Crow
                #region keyboard Handling
                void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs otk_e)
                {
-                       //if (!CrowInterface.ProcessKeyDown((int)otk_e.Key))
+                       if (!CrowInterface.ProcessKeyDown((int)otk_e.Key))
                                KeyboardKeyDown.Raise (this, otk_e);
         }
                void Keyboard_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs otk_e)
                {
-                       //if (!CrowInterface.ProcessKeyUp((int)otk_e.Key))
+                       if (!CrowInterface.ProcessKeyUp((int)otk_e.Key))
                                KeyboardKeyUp.Raise (this, otk_e);
                }
                void OpenTKGameWindow_KeyPress (object sender, OpenTK.KeyPressEventArgs e)
index 26a7a59dab9564d1cf6293c713ca6ad7639350f8..b8291783f289d83401c5407e1756326aba87d3d4 100644 (file)
@@ -492,7 +492,7 @@ namespace Crow
                string getDefaultStyleResId (Type t) {
                        string [] tmp = t.FullName.Split ('.');
                        string res = tmp [0] + ".Styles";
-                       for (int i = 1; i < tmp.Length; i++)                    
+                       for (int i = 1; i < tmp.Length; i++)
                                res += "." + tmp [i];
                        return res;
                }
@@ -509,7 +509,7 @@ namespace Crow
                                return;
                        }
 
-                       Dictionary<string, string> styling = null;
+                       List<Dictionary<string, string>> styling = new List<Dictionary<string, string>>();
 
                        //Search for a style mathing :
                        //1: Full class name, with full namespace
@@ -518,15 +518,14 @@ namespace Crow
                        //   those files being placed in a Styles folder
 
                        if (Interface.CurrentInterface.Styling.ContainsKey (thisType.FullName))
-                               styling = Interface.CurrentInterface.Styling [thisType.FullName];
-                       else if (Interface.CurrentInterface.Styling.ContainsKey (thisType.Name))
-                               styling = Interface.CurrentInterface.Styling [thisType.Name];
-                       else {
-                               string styleFullName = getDefaultStyleResId (thisType);
-                               if (Interface.CurrentInterface.Styling.ContainsKey (styleFullName)) 
-                                       styling = Interface.CurrentInterface.Styling [styleFullName];
-                       }
-                                                                            
+                               styling.Add (Interface.CurrentInterface.Styling [thisType.FullName]);
+                       if (Interface.CurrentInterface.Styling.ContainsKey (thisType.Name))
+                               styling.Add (Interface.CurrentInterface.Styling [thisType.Name]);
+                       
+                       string styleFullName = getDefaultStyleResId (thisType);
+                       if (Interface.CurrentInterface.Styling.ContainsKey (styleFullName))
+                               styling.Add (Interface.CurrentInterface.Styling [styleFullName]);
+                       
                        //Reflexion being very slow compared to dyn method or delegates,
                        //I compile the initial values coded in the CustomAttribs of the class,
                        //all other instance of this type would not longer use reflexion to init properly
@@ -564,13 +563,17 @@ namespace Crow
                                                name = xaa.AttributeName;
                                }
 
-                               bool memberHasStyle = false;
-                               if (styling != null){
-                                       if (styling.ContainsKey (name))
-                                               memberHasStyle = true;
-                               } 
-                               if (memberHasStyle){
-                                       defaultValue = styling [name];
+                               int styleIndex = -1;
+                               if (styling.Count > 0){
+                                       for (int i = 0; i < styling.Count; i++) {
+                                               if (styling[i].ContainsKey (name)){
+                                                       styleIndex = i;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               if (styleIndex >= 0){
+                                       defaultValue = styling[styleIndex] [name];
                                }else {
                                        if (name == "Style") {
                                                //retrieve default value from class attribute
@@ -662,7 +665,7 @@ namespace Crow
                                        if (pi.PropertyType == typeof (string))
                                                il.Emit (OpCodes.Ldstr, Convert.ToString (defaultValue));
                                        else {
-                                               MethodInfo miParse = pi.PropertyType.GetMethod 
+                                               MethodInfo miParse = pi.PropertyType.GetMethod
                                                                       ("Parse", BindingFlags.Static | BindingFlags.Public,
                                                                        Type.DefaultBinder, new Type [] {typeof (string)},null);
                                                if (miParse == null)
@@ -722,7 +725,7 @@ namespace Crow
                protected Size contentSize;
                /// <summary> return size of content + margins </summary>
                protected virtual int measureRawSize (LayoutingType lt) {
-                       return lt == LayoutingType.Width ? 
+                       return lt == LayoutingType.Width ?
                                contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin;
                }
                /// <summary> By default in groups, LayoutingType.ArrangeChildren is reset </summary>
@@ -848,7 +851,7 @@ namespace Crow
                                        }
                                } else
                                        Slot.Y = Top;
-                               
+
                                if (LastSlots.Y == Slot.Y)
                                        break;
 
@@ -920,7 +923,7 @@ namespace Crow
                                        }
                                } else
                                        Slot.Height = 0;
-                               
+
                                if (LastSlots.Height == Slot.Height)
                                        break;
 
@@ -928,7 +931,7 @@ namespace Crow
 
                                OnLayoutChanges (layoutType);
 
-                               LastSlots.Height = Slot.Height; 
+                               LastSlots.Height = Slot.Height;
                                break;
                        }
 
index 2636b60abd76dafe4a288e3b2a1f98fc518efd04..b8b06918cc03093823260da7866655a0007d7191 100644 (file)
@@ -34,7 +34,7 @@ namespace Crow
        /// <summary>
        /// The Interface Class is the top container of the application.
        /// It provides the Dirty bitmap and zone of the interface to be drawn on screen
-       /// 
+       ///
        /// The Interface contains :
        ///     - rendering and layouting queues and logic.
        ///     - helpers to load XML interfaces files
@@ -53,7 +53,6 @@ namespace Crow
                        FontRenderingOptions.SubpixelOrder = SubpixelOrder.Rgb;
                }
                public Interface(){
-                       LayoutingQueue = new Queue<LayoutingQueueItem>();
                        Interface.CurrentInterface = this;
                        LoadStyling ();
                }
@@ -89,11 +88,9 @@ namespace Crow
                public static FontOptions FontRenderingOptions;
                #endregion
 
-               /// <summary>
-               /// The layouting queue contains layouting commands
-               /// </summary>
-               public Queue<LayoutingQueueItem> LayoutingQueue;
+               public Queue<LayoutingQueueItem> LayoutingQueue = new Queue<LayoutingQueueItem> ();
                public Queue<GraphicObject> GraphicUpdateQueue = new Queue<GraphicObject>();
+               public Dictionary<string, Dictionary<string, string>> Styling;
                public string Clipboard;
                public static void RegisterForGraphicUpdate(GraphicObject g)
                {
@@ -267,7 +264,6 @@ namespace Crow
                                return tmp;
                        }
                }
-               public Dictionary<string, Dictionary<string, string>> Styling;
 
                public void LoadStyling() {
                        System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
@@ -276,44 +272,22 @@ namespace Crow
                        Styling = new Dictionary<string, Dictionary<string, string>> ();
 
                        //fetch styling info in this order, if member styling is alreadey referenced in previous
-                       //assembly, it's ignored
+                       //assembly, it's ignored.
                        loadStylingFromAssembly (Assembly.GetEntryAssembly ());
                        loadStylingFromAssembly (Assembly.GetExecutingAssembly ());
 
                        Thread.CurrentThread.CurrentCulture = savedCulture;
                }
 
-               void loadStylingFromAssembly (Assembly assembly) { 
+               void loadStylingFromAssembly (Assembly assembly) {
                        foreach (string s in assembly
                                        .GetManifestResourceNames ()
                                         .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) {
 
                                StyleReader sr = new StyleReader (assembly, s);
-                                                                       
+                               sr.Dispose ();
                        }
                }
-
-               //public static bool TryGetStyle (Type crowType, out Stream stream) {                   
-               //      string styleId = crowType.Name + ".style";
-
-               //      if (tryGetStyle (Assembly.GetEntryAssembly (), styleId, out stream))
-               //              return true;
-               //      if (tryGetStyle (Assembly.GetExecutingAssembly (), styleId, out stream))
-               //              return true;                    
-               //      return false;
-               //}
-
-               //static bool tryGetStyle (Assembly assembly, string styleId, out Stream stream) { 
-               //      try {
-               //              stream = assembly.GetManifestResourceStream (
-               //                              assembly.GetManifestResourceNames ().FirstOrDefault (r => r.EndsWith
-               //                                                                                                                        (styleId, StringComparison.OrdinalIgnoreCase)));
-               //      } catch {
-               //              stream = null;
-               //              return false;
-               //      }
-               //      return true;
-               //}
                #endregion
 
                #if MEASURE_TIME
@@ -766,7 +740,7 @@ namespace Crow
                #endregion
 
                #region Keyboard
-               public bool ProcessKeyDown(int Key){                    
+               public bool ProcessKeyDown(int Key){
                        if (_focusedWidget == null)
                                return false;
                        KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard);
index c1cc28bf964adba928e78d312d90d0a82672bd45..5060b3d98c154d13eac81223ab68dcdd4f5f90a4 100644 (file)
@@ -40,6 +40,8 @@ namespace Crow
                        List<string> targetsClasses = new List<string> ();
                        string currentProperty = "";
 
+                       int curlyBracketCount = 0;
+
                        while (!EndOfStream) {
                                char c = (Char)Read ();
 
@@ -90,25 +92,43 @@ namespace Crow
                                                token += c;
                                        break;
                                case readerState.expression:
-                                       if (c == ';') {
-                                               if (!string.IsNullOrEmpty (token)) {
-                                                       string expression = token.Trim ();
+                                       if (curlyBracketCount == 0) {
+                                               if (c == '{'){
+                                                       if (string.IsNullOrEmpty(token))
+                                                               throw new Exception ("Unexpected token '{'");
+                                                       curlyBracketCount++;
+                                                       token = "{";
+                                               }else if (c == '}')
+                                                       throw new Exception ("Unexpected token '{'");
+                                               else if (c == ';') {
+                                                       if (!string.IsNullOrEmpty (token)) {
+                                                               string expression = token.Trim ();
 
-                                                       foreach (string tc in targetsClasses) {
-                                                               if (!iface.Styling.ContainsKey (tc))
-                                                                       iface.Styling [tc] = new Dictionary<string, string> ();
-                                                               else if (iface.Styling [tc].ContainsKey (currentProperty))
-                                                                       continue;
-                                                               iface.Styling [tc] [currentProperty] = expression;
+                                                               foreach (string tc in targetsClasses) {
+                                                                       if (!iface.Styling.ContainsKey (tc))
+                                                                               iface.Styling [tc] = new Dictionary<string, string> ();
+                                                                       else if (iface.Styling [tc].ContainsKey (currentProperty))
+                                                                               continue;
+                                                                       iface.Styling [tc] [currentProperty] = expression;
+                                                               }
+                                                               token = "";
                                                        }
-                                                       token = "";
-                                               }
-                                               state = readerState.propertyName;
-                                       } else
+                                                       state = readerState.propertyName;
+                                               } else
+                                                       token += c;
+                                       } else {
+                                               if (c == '{')
+                                                       curlyBracketCount++;
+                                               else if (c == '}')
+                                                       curlyBracketCount--;
                                                token += c;
+                                       }
                                        break;
                                }
-                       }                                       
+                       }
+
+                       if (curlyBracketCount > 0)
+                               throw new Exception ("Unexpected end of file");
                }
        }
 }