From: jpbruyere Date: Sat, 30 Jul 2016 15:01:40 +0000 (+0200) Subject: cumulative styling X-Git-Tag: v0.4~24^2~5 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=d690d2f5f862af5766e4496f9a92671d490ad806;p=jp%2Fcrow.git cumulative styling --- diff --git a/Styles/Slider.style b/Styles/Slider.style index 7e4f6068..5b60e6af 100644 --- a/Styles/Slider.style +++ b/Styles/Slider.style @@ -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; diff --git a/Tests/OpenTKGameWindow.cs b/Tests/OpenTKGameWindow.cs index 379f89f1..2b3bdb24 100644 --- a/Tests/OpenTKGameWindow.cs +++ b/Tests/OpenTKGameWindow.cs @@ -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) diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 26a7a59d..b8291783 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -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 styling = null; + List> styling = new List>(); //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; /// return size of content + margins protected virtual int measureRawSize (LayoutingType lt) { - return lt == LayoutingType.Width ? + return lt == LayoutingType.Width ? contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin; } /// By default in groups, LayoutingType.ArrangeChildren is reset @@ -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; } diff --git a/src/Interface.cs b/src/Interface.cs index 2636b60a..b8b06918 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -34,7 +34,7 @@ namespace Crow /// /// 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(); Interface.CurrentInterface = this; LoadStyling (); } @@ -89,11 +88,9 @@ namespace Crow public static FontOptions FontRenderingOptions; #endregion - /// - /// The layouting queue contains layouting commands - /// - public Queue LayoutingQueue; + public Queue LayoutingQueue = new Queue (); public Queue GraphicUpdateQueue = new Queue(); + public Dictionary> Styling; public string Clipboard; public static void RegisterForGraphicUpdate(GraphicObject g) { @@ -267,7 +264,6 @@ namespace Crow return tmp; } } - public Dictionary> Styling; public void LoadStyling() { System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture; @@ -276,44 +272,22 @@ namespace Crow Styling = new Dictionary> (); //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); diff --git a/src/StyleReader.cs b/src/StyleReader.cs index c1cc28bf..5060b3d9 100644 --- a/src/StyleReader.cs +++ b/src/StyleReader.cs @@ -40,6 +40,8 @@ namespace Crow List targetsClasses = new List (); 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 (); - 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 (); + 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"); } } }