Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
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
        }