コード例 #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
ファイル: GlobalStyle.cs プロジェクト: groov0v/edriven-gui
        /// <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"));
        }
コード例 #3
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);
         }
     }
 }
コード例 #4
0
ファイル: StyleManager.cs プロジェクト: onamoni/edriven-gui
        internal StyleDeclaration GetMergedStyleDeclaration(string selector)
        {
            StyleDeclaration style = GetStyleDeclaration(selector);

            //StyleDeclaration parentStyle = null;

            // If we have a parent, get its style and merge them with our style.
            //if (parent)
            //    parentStyle = parent.getMergedStyleDeclaration(selector);

            if (null != style)             // || null != parentStyle)
            {
                style = new CSSMergedStyleDeclaration(style, /*parentStyle*/ null,
                                                      /*style ? */ style.SelectorString /* : parentStyle.SelectorString*/, false);
            }

            return(style);
        }
コード例 #5
0
// ReSharper restore UnassignedField.Global
#endif

        internal static void Load()
        {
            //Debug.Log("##### Loading default styles #####");

            var styleManager = StyleManager.Instance;

            if (null == _styleableClasses)
            {
                _styleableClasses = StyleReflector.GetAllStyleableClasses();
            }

#if DEBUG
            if (DebugMode)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Type type in _styleableClasses)
                {
                    sb.AppendLine(type.FullName);
                }
                Debug.Log(string.Format(@"Default style declarations from styleable types ({0}):
{1}", _styleableClasses.Count, sb));
            }
#endif

#if DEBUG
            if (DebugMode)
            {
                _time = DateTime.Now;
            }
#endif

            foreach (Type type in _styleableClasses)
            {
                //var selector = StyleSelector.FormatType(type.FullName);
                var    fullName    = type.FullName; // string.Format("[{0}]", type.FullName);
                object selector    = new Selector(fullName, null);
                var    mergedStyle = styleManager.GetMergedStyleDeclaration(fullName);

                /*if (null != mergedStyle)
                 *  Debug.Log("mergedStyle for " + type.FullName + " is:" + mergedStyle);*/

                /**
                 * Creating style declaration
                 * */
                var declaration = new StyleDeclaration(selector, mergedStyle == null); // {IsReflected = true};

                if (declaration.Set1 == null)
                {
                    declaration.Set1 = new DefaultValuesFactory(type);
                }

                if (mergedStyle != null &&
                    (null == mergedStyle.Set1 ||
                     //ObjectUtil.compare(new style.defaultFactory(), new mergedStyle.defaultFactory())))
                     declaration.Set1.Produce().Equals(mergedStyle.Set1.Produce())))
                {
                    //Debug.Log("*** Setting for " + style.SelectorString);
                    styleManager.SetStyleDeclaration(declaration.SelectorString, declaration, false);
                }
                //Debug.Log("   -> " + StyleManager.Instance.GetStyleDeclaration(selector));
            }

#if DEBUG
            if (DebugMode)
            {
                var diff = DateTime.Now.Subtract(_time);
                Debug.Log("It took " + diff.TotalMilliseconds + " ms.");
            }
#endif
        }
コード例 #6
0
// ReSharper restore UnassignedField.Global
#endif

        internal static void Load()
        {
            //Debug.Log("##### Loading default styles #####");

            var styleManager = StyleManager.Instance;

            if (null == _styleableClasses)
                _styleableClasses = StyleReflector.GetAllStyleableClasses();
            
#if DEBUG
            if (DebugMode)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Type type in _styleableClasses)
                {
                    sb.AppendLine(type.FullName);
                }
                Debug.Log(string.Format(@"Default style declarations from styleable types ({0}):
{1}", _styleableClasses.Count, sb));
            }
#endif

#if DEBUG
            if (DebugMode)
            {
                _time = DateTime.Now;
            }
#endif

            foreach (Type type in _styleableClasses)
            {
                //var selector = StyleSelector.FormatType(type.FullName);
                var fullName = type.FullName; // string.Format("[{0}]", type.FullName);
                object selector = new Selector(fullName, null);
                var mergedStyle = styleManager.GetMergedStyleDeclaration(fullName);
                /*if (null != mergedStyle)
                    Debug.Log("mergedStyle for " + type.FullName + " is:" + mergedStyle);*/

                /**
                 * Creating style declaration
                 * */
                var declaration = new StyleDeclaration(selector, mergedStyle == null); // {IsReflected = true};

                if (declaration.Set1 == null)
                {
                    declaration.Set1 = new DefaultValuesFactory(type);
                }

                if (mergedStyle != null &&
                    (null == mergedStyle.Set1 ||
                    //ObjectUtil.compare(new style.defaultFactory(), new mergedStyle.defaultFactory())))
                    declaration.Set1.Produce().Equals(mergedStyle.Set1.Produce())))
                {
                    //Debug.Log("*** Setting for " + style.SelectorString);
                    styleManager.SetStyleDeclaration(declaration.SelectorString, declaration, false);
                }
                //Debug.Log("   -> " + StyleManager.Instance.GetStyleDeclaration(selector));
            }

#if DEBUG
            if (DebugMode)
            {
                var diff = DateTime.Now.Subtract(_time);
                Debug.Log("It took " + diff.TotalMilliseconds + " ms.");
            }
#endif
        }
コード例 #7
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
        }
コード例 #8
0
ファイル: StyleManager.cs プロジェクト: onamoni/edriven-gui
// ReSharper disable UnusedMember.Global
        ///<summary>
        ///</summary>
        ///<param name="selector"></param>
        ///<param name="update"></param>
        public void ClearStyleDeclaration(string selector, bool update)
// ReSharper restore UnusedMember.Global
        {
            StyleDeclaration styleDeclaration = GetStyleDeclaration(selector);

            if (null != styleDeclaration && styleDeclaration.SelectorRefCount > 0)
            {
                styleDeclaration.SelectorRefCount--;
            }

            if (_selectors.ContainsKey(selector))
            {
                _selectors.Remove(selector);
            }

            // Clear out matching decls from our selectors stored by subject
            int i;
            StyleDeclaration decl;

            if (null != styleDeclaration && string.IsNullOrEmpty(styleDeclaration.Subject))
            {
                List <StyleDeclaration> decls = _subjects[styleDeclaration.Subject];
                if (null != decls)
                {
                    // Work from the back of the array so we can remove elements
                    // as we go.
                    for (i = decls.Count - 1; i >= 0; i--)
                    {
                        decl = decls[i];
                        if (null != decl && decl.SelectorString == selector)
                        {
                            if (decls.Count == 1)
                            {
                                _subjects.Remove(styleDeclaration.Subject);
                            }
                            else
                            {
                                decls.RemoveAt(i);
                            }
                        }
                    }
                }
            }
            else
            {
                // Without a subject, we start searching all declarations for this
                // selector, clear out matching selectors if found and then assume
                // this we can limit our search to this subject and stop looking.
                var matchingSubject = false;
                foreach (var decls2 in _subjects.Values)
                {
                    if (null != decls2)
                    {
                        // Work from the back of the array so we can remove elements
                        // as we go.
                        for (i = decls2.Count - 1; i >= 0; i--)
                        {
                            decl = decls2[i];
                            if (null != decl && decl.SelectorString == selector)
                            {
                                matchingSubject = true;
                                if (decls2.Count == 1)
                                {
                                    _subjects.Remove(decl.Subject);
                                }
                                else
                                {
                                    decls2.RemoveAt(i);
                                }
                            }
                        }

                        if (matchingSubject)
                        {
                            break;
                        }
                    }
                }
            }

            if (update)
            {
                StyleDeclarationsChanged();
            }
        }
コード例 #9
0
ファイル: StyleManager.cs プロジェクト: onamoni/edriven-gui
// ReSharper disable UnusedMember.Global
        ///<summary>
        ///</summary>
        ///<param name="selector"></param>
        ///<param name="styleDeclaration"></param>
        ///<param name="update"></param>
        internal void SetStyleDeclaration(string selector, StyleDeclaration styleDeclaration, bool update)
// ReSharper restore UnusedMember.Global
        {
            //Debug.Log("SetStyleDeclaration: " + selector);

            styleDeclaration.SelectorRefCount++;
            //Debug.Log("    styleDeclaration.SelectorRefCount: " + styleDeclaration.SelectorRefCount);

            _selectors[selector] = styleDeclaration;

            //// Flush cache and start over.
            //_typeSelectorCache = new Dictionary<string, List<StyleDeclaration>>();

            //if (update)
            //    StyleDeclarationsChanged();

            // We also index by subject to help match advanced selectors
            string subject = styleDeclaration.Subject;

            if (null != selector)
            {
                if (null == styleDeclaration.Subject)
                {
                    // If the styleDeclaration does not yet have a subject we
                    // update its selector to keep it in sync with the provided
                    // selector.
                    styleDeclaration.SelectorString = selector;
                    subject = styleDeclaration.Subject;
                }
                else if (selector != styleDeclaration.SelectorString)
                {
                    // The styleDeclaration does not match the provided selector, so
                    // we ignore the subject on the styleDeclaration and try to
                    // determine the subject from the selector
                    char firstChar = selector[0];
                    if (firstChar == '.' || firstChar == ':' || firstChar == '#')
                    {
                        subject = "*";
                    }
                    else
                    {
                        // TODO: Support parsing Advanced CSS selectors for a
                        // subject...
                        subject = selector;
                    }

                    // Finally, we update the styleDeclaration's selector to keep
                    // it in sync with the provided selector.
                    styleDeclaration.SelectorString = selector;
                }
            }

            //Debug.Log("subject: " + subject);

            if (subject != null)
            {
                List <StyleDeclaration> declarations = null;

                if (_subjects.ContainsKey(subject))
                {
                    declarations = _subjects[subject];
                }

                if (declarations == null)
                {
                    declarations = new List <StyleDeclaration> {
                        styleDeclaration
                    };
                    _subjects[subject] = declarations;
                }
                else
                {
                    declarations.Add(styleDeclaration);
                }
            }

            //Debug.Log(3);

            // Flush cache and start over.
            //_typeSelectorCache = new Dictionary<string, List<StyleDeclaration>>();

            if (update)
            {
                StyleDeclarationsChanged();
            }
        }
コード例 #10
0
ファイル: GuiInspector.cs プロジェクト: groov0v/edriven-gui
// ReSharper disable UnusedMember.Local
        void Update()
// ReSharper restore UnusedMember.Local
        {
            if (null == _declaration)
                _declaration = StyleManager.Instance.GetStyleDeclaration(typeof(InspectorOverlay).FullName);

            if (_borderColor != BorderColor || _textColor != TextColor || _font != Font)
            {
                if (_borderColor != BorderColor)
                {
                    _borderColor = BorderColor;
                    _declaration.SetStyle("borderColor", _borderColor);
                }
                if (_textColor != TextColor)
                {
                    _textColor = TextColor;
                    _declaration.SetStyle("textColor", _textColor);
                }
                if (_font != Font)
                {
                    _font = Font;
                    _declaration.SetStyle("font", _font);
                }
            }
        }