コード例 #1
0
        /// <summary>
        /// Initializes the Singleton instance
        /// </summary>
        internal void Initialize()
        {
            //StyleDeclaration style = StyleManager.Instance.GetStyleDeclaration("global");
            //if (null == style)
            //{
            //    style = new StyleDeclaration();

            //    var dict = new Dictionary<string, object> { { "foo", "bar" } };
            //    style.Factory = new StyleTableValuesFactory(dict); // ?? DefaultValues ???????

            //    StyleManager.Instance.SetStyleDeclaration("global", style, false);
            //}

            var styleManager = StyleManager.Instance;
            var selector     = new Selector("global", null, null);
            var mergedStyle  = styleManager.GetMergedStyleDeclaration("global");
            var style        = new StyleDeclaration(selector, mergedStyle == null);

            if (style.Set1 == null)
            {
                //Debug.Log("Creating DefaultValues for " + selector);
                var dict = new StyleTable(); // { { "foo", "bar" } };
                style.Set1 = new StyleTableValuesFactory(dict);
            }

            if (null != mergedStyle &&
                (null == mergedStyle.Set1 ||
                 style.Set1.Produce().Equals(mergedStyle.Set1.Produce())))
            {
                styleManager.SetStyleDeclaration(style.SelectorString, style, false);
            }

            //Debug.Log("Global style initialized: " + styleManager.GetStyleDeclaration("global"));
        }
コード例 #2
0
        /**
         *
         */
        internal StyleTable CreateProtoChainRoot(bool registerClone = true)
        {
            StyleTable root = new StyleTable();

            // If there's a defaultFactory for this style sheet,
            // then add the object it produces to the root.
            if (null != Set1)
            {
                root = root.CloneAndOverrideWith(Set1.Produce());
            }

            // If there's a factory for this style sheet,
            // then add the object it produces to the root.
            if (null != Set2)
            {
                root = root.CloneAndOverrideWith(Set2.Produce());
            }

            if (registerClone)
            {
                _clones.Add(root);
            }

            return(root);
        }
コード例 #3
0
ファイル: StyleTable.cs プロジェクト: onamoni/edriven-gui
 /// <summary>
 /// Adds the new values to the table and overrides the duplicates
 /// </summary>
 /// <param name="table"></param>
 public void OverrideWith(StyleTable table)
 {
     foreach (KeyValuePair <string, object> pair in table)
     {
         this[pair.Key] = pair.Value;
     }
 }
コード例 #4
0
        /// <summary>
        /// Reads the serialized declaration and extracts key/value pairs
        /// </summary>
        /// <returns></returns>
        public StyleTable Produce()
        {
            StyleTable table = new StyleTable();

            foreach (KeyValuePair <string, object> pair in _table)
            {
                table.Add(pair.Key, pair.Value);
            }
            return(table);
        }
コード例 #5
0
ファイル: StyleTable.cs プロジェクト: onamoni/edriven-gui
        /// <summary>
        /// Adds the new values to the table and overrides the duplicates
        /// </summary>
        /// <param name="table"></param>
        public StyleTable CloneAndOverrideWith(StyleTable table)
        {
            StyleTable clone = (StyleTable)Clone();

            foreach (KeyValuePair <string, object> pair in table)
            {
                clone[pair.Key] = pair.Value;
            }
            return(clone);
        }
コード例 #6
0
ファイル: StyleTable.cs プロジェクト: onamoni/edriven-gui
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public object Clone()
        {
            StyleTable table = new StyleTable();

            foreach (KeyValuePair <string, object> pair in this)
            {
                table.Add(pair.Key, pair.Value);
            }
            return(table);
        }
コード例 #7
0
        /// <summary>
        /// Gets the style
        /// </summary>
        /// <param name="styleProp"></param>
        /// <returns></returns>
// ReSharper disable MemberCanBePrivate.Global
        public object GetStyle(string styleProp)
// ReSharper restore MemberCanBePrivate.Global
        {
            // First look in the overrides, in case setStyle()
            // has been called on this StyleDeclaration.
            if (null != _overrides)
            {
                // If the property exists in our overrides, but
                // has 'undefined' as its value, it has been
                // cleared from this stylesheet so return
                // undefined.

                /*if (_overrides.ContainsKey(styleProp) && UNDEFINED.Equals(_overrides[styleProp]))
                 * {
                 *      return UNDEFINED;
                 * }*/

                if (_overrides.ContainsKey(styleProp))
                {
                    var v = _overrides[styleProp];
                    if (!UNDEFINED.Equals(v))                     // must use !==
                    {
                        return(v);
                    }
                }
            }
            // not found in overrides

            if (null != Set2)
            {
                StyleTable o = Set2.Produce();
                object     v = o.GetValue(styleProp);
                if (!UNDEFINED.Equals(v))
                {
                    return(v);
                }
            }
            // not found in stylesheet

            if (null != Set1)
            {
                StyleTable o = Set1.Produce();
                object     v = o.GetValue(styleProp);
                if (!UNDEFINED.Equals(v))
                {
                    return(v);
                }
            }
            // not faund in default values

            // so return null
            return(UNDEFINED);
        }
コード例 #8
0
        public override void InitStyles(Selector selector, StyleTable styles)
        {
            var components = GetComponentsMatchingSelector(selector);

            foreach (Component component in components)
            {
                // 2. for additions, set the style
                foreach (KeyValuePair <string, object> pair in styles)
                {
                    component.SetStyle(pair.Key, pair.Value);
                }
            }
        }
コード例 #9
0
ファイル: StyleManager.cs プロジェクト: onamoni/edriven-gui
 /**
  *
  *  This method is called by code autogenerated by the MXML compiler,
  *  after StyleManager.styles is popuplated with CSSStyleDeclarations.
  */
 ///<summary>
 ///</summary>
 internal void InitProtoChainRoots()
 {
     //Debug.Log("### InitProtoChainRoots ###");
     if (null == _stylesRoot)
     {
         //_stylesRoot = _selectors["global"].AddStyleToProtoChain(new StyleTable(), null);
         StyleDeclaration style = GetMergedStyleDeclaration("global");
         if (style != null)
         {
             //Debug.Log("Global:::::: " + style);
             _stylesRoot = style.AddStyleToProtoChain(new StyleTable(), null);
         }
     }
 }
コード例 #10
0
        public override void InitStyles(Selector selector, StyleTable styles)
        {
            var components = GetComponentsMatchingSelector(selector);

            foreach (Component component in components)
            {
                // 2. for additions, set the style
                foreach (KeyValuePair <string, object> pair in styles)
                {
                    MemberWrapper wrapper = new MemberWrapper(component.GetType(), pair.Key);
                    wrapper.SetValue(component, pair.Value);
                }
            }
        }
コード例 #11
0
        /**
         *
         */
        private void ClearStyleAttr(string styleProp)
        {
            // Put "undefined" into our overrides Array
            if (null == _overrides)
            {
                _overrides = new StyleTable();
            }

            _overrides[styleProp] = UNDEFINED;

            // Remove the property from all our clones
            foreach (var clone in _clones)
            {
                clone.Remove(styleProp);
            }
        }
コード例 #12
0
        /// <summary>
        /// Reads the component metadata and extracts key/value pairs
        /// </summary>
        /// <returns></returns>
        public StyleTable Produce()
        {
            //Debug.Log(string.Format("DefaultValuesFactory->Produce [{0}]", _componentType));

            if (null == _cached)
            {
                _cached = new StyleTable();

                var attributes = StyleReflector.GetStyleAttributes(_componentType);

#if DEBUG
                if (null != StyleProtoChain.TYPE_TO_MONITOR)
                {
                    if (_componentType == StyleProtoChain.TYPE_TO_MONITOR)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (StyleAttribute attribute in attributes)
                        {
                            sb.AppendLine(string.Format("[{0}, {1}]", attribute.Name, attribute.GetDefault()));
                        }
                        Debug.Log(string.Format(@"DefaultValuesFactory->Produced [{0}]
{1}", _componentType, sb));
                    }
                }
#endif

                foreach (StyleAttribute attribute in attributes)
                {
                    /**
                     * 1. Validate proxy
                     * */
                    ValidateAttribute(attribute);

                    /**
                     * 2. Extract possible value
                     * */
                    var def = attribute.GetDefault(); // ovdje je bio bug kod boja - nije se koristilo GetDefault(), već samo Default
                    if (null != def)
                    {
                        _cached.Add(attribute.Name, def);
                    }
                }
            }

            return((StyleTable)_cached.Clone());
        }
コード例 #13
0
ファイル: StyleTable.cs プロジェクト: onamoni/edriven-gui
        ///<summary>
        /// Checks if the tables are equal
        ///</summary>
        ///<param name="other"></param>
        ///<returns></returns>
        public bool Equals(StyleTable other)
        {
            if (other.Keys.Count != Keys.Count)
            {
                return(false);
            }

            foreach (string key in other.Keys)
            {
                if (!ContainsKey(key))
                {
                    return(false);
                }
                if (other[key] != this[key])
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #14
0
        /// <summary>
        /// Reads the serialized declaration and extracts key/value pairs
        /// </summary>
        /// <returns></returns>
        public StyleTable Produce()
        {
            if (null == _cached)
            {
                _cached = new StyleTable();

//#if DEBUG
//                        StringBuilder sb = new StringBuilder();
//                        foreach (StyleProperty property in _styleSheetDeclaration.Properties)
//                        {
//                            sb.AppendLine(string.Format("[{0}, {1}]", property.Name, property.Value));
//                        }
//                        Debug.Log(string.Format(@"StyleSheetValuesFactory->Produced
//{0}", sb));
//#endif

                foreach (StyleProperty property in _styleSheetDeclaration.Properties)
                {
                    _cached.Add(property.Name, property.Value);
                }
            }

            return((StyleTable)_cached.Clone());
        }
コード例 #15
0
        internal static void InitProtoChain(IStyleClient client)
        {
            /*if (client.GetType().FullName == "Assets.eDriven.Skins.ImageButtonSkin")
             *      Debug.Log("Assets.eDriven.Skins.ImageButtonSkin: " + client);*/

            //Debug.Log("InitProtoChain: " + client);
            StyleManager styleManager = StyleManager.Instance;
            //StyleDeclaration classSelector = null;

            Component        uicObject = client as Component;
            StyleDeclaration styleDeclaration;

            List <StyleDeclaration> universalSelectors = new List <StyleDeclaration>();
            bool   hasStyleName = false;
            object styleName    = client.StyleName;

            //Debug.LogWarning("styleName: " + styleName);

            /**
             * prvo gledamo classname setiran na ovoj komponenti
             * ako je setiran, uzimamo style declaration za taj classname iz poola
             * */

            if (null != styleName)
            {
                /*if (client.StyleName is string && (string)client.StyleName == "test")
                 *      Debug.Log("client.StyleName");*/

                // Get the style sheet referenced by the styleName property
                //classSelector = StyleManager.Instance.GetStyleDeclaration("." + StyleName);
                if (styleName is StyleDeclaration)
                {
                    //Debug.LogWarning("Style name is StyleDeclaration: " + styleName);
                    // Get the styles referenced by the styleName property.
                    universalSelectors.Add((StyleDeclaration)styleName);
                }

                #region Still not used. This is normally used for parent-child style propagation (skins)
                //else if (/*styleName is IFlexDisplayObject || */styleName is IStyleClient) // TODO
                //{
                //    // If the styleName property is a Component, then there's a
                //    // special search path for that case.
                //    StyleProtoChain.InitProtoChainForUIComponentStyleName(client);
                //    return;
                //}
                #endregion

                else if (styleName is string)
                {
                    //Debug.LogWarning("Style name is istring: " + styleName);
                    hasStyleName = true;
                }
                else
                {
                    Debug.LogWarning("Error");
                }
            }

            /**
             * ovdje sada imamo style declaration za classname
             *
             * nakon toga moramo uzeti non-inherit chain (global root) i
             * inherit chain (inheriting styles od parenta)
             * oni su nam potrebni kako bi prenijeli stilove iz parenta ukoliko nisu deklarirani na ovoj komponenti
             * */

            // To build the proto chain, we start at the end and work forward.
            // Referring to the list at the top of this function, we'll start by
            // getting the tail of the proto chain, which is:
            //  - for non-inheriting styles, the global style sheet
            //  - for inheriting styles, my parent's style object
            StyleTable nonInheritChain = styleManager.StylesRoot;
            StyleTable inheritChain;

            //IStyleClient p = Parent as IStyleClient;
            IStyleClient p      = null;
            var          visual = client as IVisualElement;
            if (null != visual)
            {
                p = visual.Parent as IStyleClient;
            }

            if (null != p)
            {
                inheritChain = p.InheritingStyles;

                #region Monitor

//#if DEBUG
//                if (null != TYPE_TO_MONITOR)
//                {
//                    if (uicObject.GetType() == TYPE_TO_MONITOR)
//                    {
//                        StringBuilder sb = new StringBuilder();
//                        sb.AppendLine(client + " -> parent chains:");
//                        sb.AppendLine("p.InheritingStyles: " + p.InheritingStyles);
//                        sb.AppendLine("p.NonInheritingStyles: " + p.NonInheritingStyles);
//                        Debug.Log(sb);
//                    }
//                }
//#endif

                #endregion

                if (inheritChain == STYLE_UNINITIALIZED)
                {
                    // ako parent nema inicijaliziran inherit chain, znači da ništa ne nasljeđuje od svojih parenta
                    // te također ni on sam ne definira niti jedan inheriting style.
                    // u tom slučaju se možemo referencirati na non-inherit chain
                    inheritChain = nonInheritChain;
                }
            }
            else
            {
                inheritChain = styleManager.StylesRoot;
            }

            #region Monitor

//#if DEBUG
//            if (null != TYPE_TO_MONITOR)
//            {
//                if (uicObject.GetType() == TYPE_TO_MONITOR)
//                {
//                    StringBuilder sb = new StringBuilder();
//                    sb.AppendLine(client + " -> chains:");
//                    sb.AppendLine("inheritChain: " + inheritChain);
//                    sb.AppendLine("nonInheritChain: " + nonInheritChain);
//                    Debug.Log(sb);
//                }
//            }
//#endif

            #endregion

            /**
             * Sada moramo obraditi type deklaracije
             * Radi se o tome da stil Buttona nasljeđuje i stilove definirane na superklasama
             * Znači prvo potrebno je izbildati niz deklaracija (gleda se da li postoje definirane u stylesheetu)
             * i to redoslijedom od superklasa do ove klase
             * To odrađuje metoda "getClassStyleDeclarations()" koja vraća taj mini-niz
             * Redoslijed u nizu je bitan jer propertyji definirani na subklasi overrajdaju one na superklasi
             * */

            // Working backwards up the list, the next element in the
            // search path is the type selector

            List <StyleDeclaration> styleDeclarations = GetMatchingStyleDeclarations(client, universalSelectors);

            if (null != styleDeclarations)
            {
                #region Monitor

                if (StyleDebugging.DebugComponents.Contains(client.GetType()))
                {
                    StyleDebugging.DebugDeclarationApplication(client, styleDeclarations);
                }

                #endregion

                int n = styleDeclarations.Count;                 //typeSelectors.Count;
                for (int i = 0; i < n; i++)
                {
                    styleDeclaration = styleDeclarations[i];
                    inheritChain     = styleDeclaration.AddStyleToProtoChain(inheritChain, uicObject);
                    nonInheritChain  = styleDeclaration.AddStyleToProtoChain(nonInheritChain, uicObject);
                }
            }

            #region For simple (string) styles (like ".stile") - not used here

            //int n;

            //if (hasStyleName)
            //{
            //    var styleNames = Regex.Split((string) styleName, @"/\s+/");
            //    n = styleNames.Count();
            //    for (var i = 0; i < n; i++)
            //    {
            //        if (styleNames[i].Length > 0)
            //        {
            //            styleDeclaration = styleManager.GetMergedStyleDeclaration("." + styleNames[i]);
            //            if (null != styleDeclaration)
            //                universalSelectors.Add(styleDeclaration);
            //        }
            //    }
            //}

            //// Working backwards up the list, the next element in the
            //// search path is the type selector
            //var styleDeclarations = client.GetClassStyleDeclarations();
            ////Debug.Log("##### styleDeclarations: " + styleDeclarations.Count);

            ////if (client is Skin && ((Skin)client).Parent is Button)
            ///*if (client.GetType().FullName == "Assets.eDriven.Skins.ImageButtonSkin")
            //    Debug.Log("Skin: " + client);*/

            //if (null != styleDeclarations)
            //{
            //    n = styleDeclarations.Count; //typeSelectors.Count;
            //    for (int i = 0; i < n; i++)
            //    {
            //        styleDeclaration = styleDeclarations[i];
            //        inheritChain = styleDeclaration.AddStyleToProtoChain(inheritChain, uicObject);
            //        nonInheritChain = styleDeclaration.AddStyleToProtoChain(nonInheritChain, uicObject);
            //        /*if (styleDeclaration.effects)
            //            object.registerEffects(styleDeclaration.effects);*/
            //    }
            //}

            //// Next are the class selectors
            //n = universalSelectors.Count;
            //for (var i = 0; i < n; i++)
            //{
            //    styleDeclaration = universalSelectors[i];
            //    if (null != styleDeclaration)
            //    {
            //        inheritChain = styleDeclaration.AddStyleToProtoChain(inheritChain, uicObject);
            //        nonInheritChain = styleDeclaration.AddStyleToProtoChain(nonInheritChain, uicObject);
            //        /*if (styleDeclaration.effects)
            //            object.registerEffects(styleDeclaration.effects);*/
            //    }
            //}

            #endregion

            // Finally, we'll add the in-line styles
            // to the head of the proto chain.

            styleDeclaration = client.StyleDeclaration;

            client.InheritingStyles =
                null != styleDeclaration?
                styleDeclaration.AddStyleToProtoChain(inheritChain, uicObject) :
                    inheritChain;

            client.NonInheritingStyles =
                null != styleDeclaration?
                styleDeclaration.AddStyleToProtoChain(nonInheritChain, uicObject) :
                    nonInheritChain;

            #region Monitor

//#if DEBUG
//            if (null != TYPE_TO_MONITOR)
//            {
//                if (uicObject.GetType() == TYPE_TO_MONITOR || uicObject.GetType() == typeof(HGroup))
//                {
//                    StringBuilder sb = new StringBuilder();
//                    sb.AppendLine(@"### proto chain initialized ###
//" + ComponentUtil.PathToString(uicObject, "->"));
//                    sb.AppendLine();

//                    if (null != client.StyleDeclaration && null != client.StyleDeclaration.Overrides)
//                    {
//                        sb.AppendLine("Overrides: " + client.StyleDeclaration.Overrides);
//                    }
//                    sb.AppendLine();

//                    sb.AppendLine("InheritingStyles: " + client.InheritingStyles);
//                    sb.AppendLine();

//                    sb.AppendLine("NonInheritingStyles: " + client.NonInheritingStyles);

//                    Debug.Log(sb);
//                }
//            }
//#endif

            #endregion
        }
コード例 #16
0
        /// <summary>
        /// Private
        /// </summary>
        /// <param name="styleProp"></param>
        /// <param name="value"></param>
        internal void SetLocalStyle(string styleProp, object value)
        {
            //object oldValue = GetStyle(styleProp);

            if (UNDEFINED.Equals(value))
            {
                ClearStyleAttr(styleProp);
                return;
            }

            StyleTable o;

            if (null != Set1)
            {
                o = Set1.Produce();
                if (!o.ContainsKey(styleProp) || o[styleProp] != value)                 // Defaultni factory nema taj stil ili ga ima ali s različitom vrijednošću
                {
                    /**
                     * Defaultni factory ima različitu vrijednost ovog stila, znači radi se o overrideu
                     * Kreirajmo overrides tablicu i u njoj setirajmo stil
                     * */
                    if (null == _overrides)
                    {
                        _overrides = new StyleTable();
                    }

                    _overrides[styleProp] = value;
                }
                else if (null != _overrides && _overrides.ContainsKey(styleProp))                 // Defaultni factory ima taj stil i to sa istom vrijednošću
                {
                    /**
                     * Obrišimo ga u overrides tabeli
                     * */
                    _overrides.Remove(styleProp);
                }
            }

            if (null != Set2)
            {
                o = Set2.Produce();
                if (!o.ContainsKey(styleProp) || o[styleProp] != value)
                {
                    if (null == _overrides)
                    {
                        _overrides = new StyleTable();
                    }

                    _overrides[styleProp] = value;
                }
                else if (null != _overrides && _overrides.ContainsKey(styleProp))
                {
                    _overrides.Remove(styleProp);
                }
            }

            if (null == Set1 && null == Set2)             // Ne postoji niti jedan factory (ni metadata, ni stylesheet)
            {
                if (null == _overrides)
                {
                    _overrides = new StyleTable();
                }
                _overrides[styleProp] = value;
            }

            UpdateClones(styleProp, value);
        }
コード例 #17
0
// ReSharper restore UnassignedField.Global
#endif

        ///<summary>
        ///</summary>
        ///<param name="chain">Replikativni Dictionary</param>
        ///<param name="target"></param>
        ///<returns></returns>
        internal virtual StyleTable AddStyleToProtoChain(StyleTable chain, object target /*, object filterMap*/)
        {
            //Debug.Log("AddStyleToProtoChain: chain: " + chain + "; target: " + target);

            bool nodeAddedToChain = false;

            //var originalChain = chain;

            //if (filterMap)
            //{
            //    chain = {};
            //}

#if DEBUG
            if (!string.IsNullOrEmpty(DebugId))
            {
                Debug.Log(DebugId + " 0. " + chain);
            }
#endif

            // If there's a defaultFactory for this style sheet,
            // then add the object it produces to the chain.
            if (null != Set1)
            {
                chain            = chain.CloneAndOverrideWith(Set1.Produce());
                nodeAddedToChain = true;
            }

#if DEBUG
            if (!string.IsNullOrEmpty(DebugId))
            {
                Debug.Log(DebugId + " 1. " + chain);
            }
#endif

            // If there's a factory for this style sheet,
            // then add the object it produces to the chain.
            if (null != Set2)
            {
                chain            = chain.CloneAndOverrideWith(Set2.Produce());
                nodeAddedToChain = true;
            }

#if DEBUG
            if (!string.IsNullOrEmpty(DebugId))
            {
                Debug.Log(DebugId + " 2. " + chain);
            }
#endif

            //Debug.Log("-- chain: " + chain);

            // If someone has called setStyle() on this StyleDeclaration,
            // then some of the values returned from the factory are
            // out-of-date. Overwrite them with the up-to-date values.
            if (null != _overrides)
            {
                // Before we add our overrides to the object at the head of
                // the chain, make sure that we added an object at the head
                // of the chain.
                if (null == Set1 && null == Set2)
                {
                    chain            = (StyleTable)chain.Clone();
                    nodeAddedToChain = true;
                }

                foreach (string p in _overrides.Keys)
                {
                    if (!UNDEFINED.Equals(_overrides[p]))
                    {
                        chain[p] = _overrides[p];
                    }

                    /*if (UNDEFINED.Equals(_overrides[p]))
                     *      chain.Remove(p);
                     * else
                     *      chain[p] = _overrides[p];*/
                }
            }

#if DEBUG
            if (!string.IsNullOrEmpty(DebugId))
            {
                Debug.Log(DebugId + " 3. " + chain);
            }
#endif

            #region _complex

            ////if (filterMap)
            ////{
            //    if (nodeAddedToChain)
            //    {
            //        //Debug.Log("nodeAddedToChain");
            //        //var filteredChain = new Dictionary<string, object>();
            //        //for (string i in chain)
            //        //{
            //        //    if (filterMap[i] != null)
            //        //    {
            //        //        filteredChain[filterMap[i]] = chain[i];
            //        //    }
            //        //}

            //        //var f = new StyleTableValuesFactory(originalChain);

            //        chain = (StyleTable) originalChain.Clone();

            //        //chain = originalChain;

            //        //chain = filteredChain;
            //        //chain = f.Produce();

            //        //chain[FILTERMAP_PROP] = filterMap;
            //    }
            //    else
            //    {
            //        chain = originalChain;
            //    }
            ////}

            #endregion

            if (nodeAddedToChain)
            {
                _clones.Add(chain);
            }

            return(chain);
        }
コード例 #18
0
// ReSharper restore UnassignedField.Global
#endif
        /// <summary>
        /// Loads style declarations<br/>
        /// We are actually doing a full process from scratch on each screen resize<br/>
        /// The things that are cached are default styles (reflected) and eDriven stylesheet styles<br/>
        /// Each style declaration is being tested against its media queries<br/>
        /// Only declarations passing the media query are turned into actual CSSStyleDeclarations and are further processed<br/>
        /// </summary>
        internal static void Process()
        {
            var styleManager = StyleManager.Instance;

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("##### Loading style sheets #####");
            }
#endif

            /**
             * 1. Reloading the cache (the cache itself will do a full reload if needed)
             * */
            StyleDeclarationCache.Instance.Load();

            /**
             * 2. Getting ALL the style declarations from the cache
             * */
            List <Serialization.StyleDeclaration> declarations = StyleDeclarationCache.Instance.GetDeclarations();

            if (null == declarations)
            {
                return; // nothing to do here
            }
            int count = 0;
            var list  = new List <string>();

            /**
             * 4. Merging (A)
             * We need to group the same declarations together
             * That's because we need - at this stage - to merge declarations for the same component
             * In the StyleDeclaration system, there are no duplicated declarations
             * */
            Dictionary <string, List <Serialization.StyleDeclaration> > groups = new Dictionary <string, List <Serialization.StyleDeclaration> >();
            foreach (Serialization.StyleDeclaration declaration in declarations)
            {
                var mediaQueryPasses = true;
                if (null != declaration.MediaQueries)
                {
                    foreach (MediaQuery query in declaration.MediaQueries)
                    {
                        /* if a single query doesn't pass, do not process this style declaration */
                        try
                        {
#if DEBUG
                            if (DebugMode)
                            {
                                Debug.Log("Query: " + query);
                            }
#endif
                            mediaQueryPasses = MediaQueryManager.Instance.EvaluateQuery(query.Name, query.Value);
#if DEBUG
                            if (DebugMode)
                            {
                                if (!mediaQueryPasses)
                                {
                                    Debug.Log("    " + query + " doesn't pass");
                                }
                            }
#endif

                            /**
                             * When a single query doesn't pass, break the loop!
                             * (this is the AND operation!)
                             * */
                            if (!mediaQueryPasses)
                            {
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.LogError(ex.Message);
                        }
                    }
                }
                if (!mediaQueryPasses)
                {
                    continue; // skip
                }
                //declarationsPassingMediaQueries.Add(declaration);
                Selector selector  = Selector.BuildSelector(declaration.Type, declaration.Class, declaration.Id);
                var      selString = selector.ToString();
                if (!groups.ContainsKey(selString))
                {
                    groups[selString] = new List <Serialization.StyleDeclaration>();
                }
                groups[selString].Add(declaration);

                /**
                 * If we are here, it means the style declaration passes its own media queries
                 * */

                count++;
            }

            /**
             * 5. Merging (B)
             * Mearge declarations from each group together
             * */
            foreach (var key in groups.Keys)
            {
                // check if the group contains declarations (it should, at least one)
                var decls = groups[key];
                if (decls.Count == 0)
                {
                    continue;
                }

                // take the first declaration
                var declaration = decls[0];

                // create selector (same for all the declarations in the group)
                Selector selector = Selector.BuildSelector(declaration.Type, declaration.Class, declaration.Id);

                list.Add(selector.ToString());

                // get the existing or create new declaration
                //StyleDeclaration mergedStyle = styleManager.GetMergedStyleDeclaration(selector.ToString());

                StyleDeclaration style = styleManager.GetStyleDeclaration(selector.ToString());
                if (null == style)
                {
                    style = new StyleDeclaration(selector, true) // register
                    {
                        Module = declaration.Module
                    };
                }

                /*StyleDeclaration style = new StyleDeclaration(selector, mergedStyle == null)
                 * {
                 *  Module = declaration.Module
                 * };*/

                // create (blank) factory
                if (style.Set2 == null)
                {
                    StyleTable mainTable = new StyleTable();
                    style.Set2 = new StyleTableValuesFactory(mainTable);

                    // override the factory with each declaration
                    foreach (Serialization.StyleDeclaration styleDeclaration in decls)
                    {
                        StyleTable styleTable = new StyleTable();
                        foreach (StyleProperty property in styleDeclaration.Properties)
                        {
                            var value = property.Value;

                            /**
                             * Very important:
                             * null == value -> works only in build!
                             * For the editor we need a paralel check: value.GetType() != typeof(Object)
                             * That's because in editor the value isn't null!!!!!
                             * */
                            if (null == value || value.GetType() != typeof(Object))
                            {
                                styleTable.Add(property.Name, value);
                            }
                        }
                        mainTable.OverrideWith(styleTable);
                    }
                }

                //Debug.Log("style: " + style);
            }

            /*Debug.Log(@"!!!! declarationsPassingMediaQueries:
             * " + ListUtil<StyleDeclaration>.Format(declarationsPassingMediaQueries));*/

#if DEBUG
            if (DebugMode)
            {
                StringBuilder sb = new StringBuilder();
                list.Sort();
                foreach (string name in list)
                {
                    var line  = string.Format(@"============== {0} ==============
", name);
                    var decls = styleManager.GetStyleDeclarations(name);
                    if (null != decls)
                    {
                        line = string.Format(@"============== {0} [found {1}] ==============
{2}", name, decls.Count, ListUtil <StyleDeclaration> .Format(decls));
                    }
                    sb.AppendLine(line);
                }
                Debug.Log(string.Format(@"Style declarations loaded from stylesheet ({0}):
{1}", count, sb));
            }
#endif
        }
コード例 #19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="table"></param>
 public StyleTableValuesFactory(StyleTable table)
 {
     _table = table;
 }
コード例 #20
0
 /// <summary>
 /// Initialires styles
 /// </summary>
 /// <param name="selector"></param>
 /// <param name="styles"></param>
 public abstract void InitStyles(Selector selector, StyleTable styles);