コード例 #1
0
        // # MARGIN #
        // ##########

        // ###########
        // # PADDING #
        private void PaddingWork(StyleKey key, object val)
        {
            string padding = (key == StyleKey.padding) ? (string)val : (string)GetVal(StyleKey.padding);

            float top, right, bot, left;

            hglConverter.GetMarginStyle(padding, out top, out right, out bot, out left);

            float f;

            if (float.TryParse(hglEtc.DropAlphabet((string)val), out f))
            {
                switch (key)
                {
                case StyleKey.padding_top:     top = f; break;

                case StyleKey.padding_right:   right = f; break;

                case StyleKey.padding_bottom:  bot = f; break;

                case StyleKey.padding_left:    left = f; break;
                }
            }
            m_hash[StyleKey.padding]        = top + " " + right + " " + bot + " " + left;
            m_hash[StyleKey.padding_top]    = top.ToString();
            m_hash[StyleKey.padding_right]  = right.ToString();
            m_hash[StyleKey.padding_bottom] = bot.ToString();
            m_hash[StyleKey.padding_left]   = left.ToString();
        }
コード例 #2
0
        // ##########
        // # MARGIN #
        private void MaginWork(StyleKey key, object ival)
        {
            m_hash[key] = (string)ival;
            if (key == StyleKey.margin)
            {
                float top, right, bot, left;
                if (hglConverter.GetMarginStyle((string)ival, out top, out right, out bot, out left))
                {
                    m_hash[StyleKey.margin_top]    = (top == -0xa ? "auto" : top.ToString());
                    m_hash[StyleKey.margin_right]  = (right == -0xa ? "auto" : right.ToString());
                    m_hash[StyleKey.margin_bottom] = (bot == -0xa ? "auto" : bot.ToString());
                    m_hash[StyleKey.margin_left]   = (left == -0xa ? "auto" : left.ToString());
                }
                return;
            }

            var top1   = GetFloat_allowAuto(StyleKey.margin_top, 0);
            var left1  = GetFloat_allowAuto(StyleKey.margin_left, 0);
            var bot1   = GetFloat_allowAuto(StyleKey.margin_bottom, 0);
            var right1 = GetFloat_allowAuto(StyleKey.margin_right, 0);

            m_hash[StyleKey.margin_top]    = (top1 == -0xa ? "auto" : top1.ToString());
            m_hash[StyleKey.margin_right]  = (right1 == -0xa ? "auto" : right1.ToString());
            m_hash[StyleKey.margin_bottom] = (bot1 == -0xa ? "auto" : bot1.ToString());
            m_hash[StyleKey.margin_left]   = (left1 == -0xa ? "auto" : left1.ToString());

            m_hash[StyleKey.margin] = m_hash[StyleKey.margin_top].ToString() + " "
                                      + m_hash[StyleKey.margin_right].ToString() + " "
                                      + m_hash[StyleKey.margin_bottom].ToString() + " "
                                      + m_hash[StyleKey.margin_left].ToString();
        }
コード例 #3
0
 /// <inheritdoc/>
 public Boolean Equals(StyleKey other)
 {
     return
         (name == other.name &&
          navigationExpression.HasValue == other.navigationExpression.HasValue &&
          navigationExpression.GetValueOrDefault().Equals(other.navigationExpression.GetValueOrDefault()));
 }
コード例 #4
0
        /// <summary>
        /// Adds a trigger to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="trigger">The trigger to add to the prioritizer.</param>
        /// <param name="index">The index of the trigger's rule set within the style sheet.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression?navigationExpression, UvssTrigger trigger, Int32 index)
        {
            Contract.Require(uv, nameof(uv));

            var key      = new StyleKey(trigger.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, false);

            PrioritizedTrigger existing;

            if (!triggers.TryGetValue(key, out existing))
            {
                triggers[key] = new PrioritizedTrigger(trigger, selector, priority, index);
            }
            else
            {
                var comparison = selector.ComparePriority(existing.Selector);
                if (comparison == 0 && index > existing.Index)
                {
                    comparison = 1;
                }

                if (comparison > 0 && (trigger.IsImportant || !existing.Trigger.IsImportant))
                {
                    triggers[key] = new PrioritizedTrigger(trigger, selector, priority, index);
                }
            }
        }
コード例 #5
0
        public void Set <T>(StyleKey key, T val)
        {
            if (val == null)
            {
                return;
            }
            if (key.ToString().Contains("margin"))
            {
                MaginWork(key, val);
            }
            else if (key.ToString().Contains("padding"))
            {
                PaddingWork(key, val);
            }
            else if (key.ToString().Contains("border"))
            {
                BorderWork(key, val);
            }
            else if (key.ToString().Contains("background"))
            {
                BackgroundWork(key, val);
            }
            else if (key == StyleKey.font_size)
            {
                float f  = 1;
                var   v1 = val.ToString().Replace("pt", "");
                if (float.TryParse(v1.ToString(), out f))
                {
                    m_hash[key] = v1.ToString();
                }
                else
                {
                    //Debug.LogError("val=" + val);
                    string v2 = "1";
                    switch (val.ToString())
                    {
                    case "xx-small":
                    case "x-small":
                    case "small": v2 = "16"; break;

                    case "medium": v2 = "20"; break;

                    case "large": v2 = "30"; break;

                    case "x-large":
                    case "xx-large": v2 = "50"; break;

                    default: v2 = "16"; break;
                    }

                    m_hash[key] = v2;
                }
            }
            else
            {
                m_hash[key] = val.ToString();
            }
        }
コード例 #6
0
        public Color?GetColorErrorNull(StyleKey key) // if Error return Color(-1,-1,-1);
        {
            Color x;

            if (hglConverter.GetColorString((string)GetVal(key), out x))
            {
                return(x);
            }

            return(null);
        }
コード例 #7
0
 private bool isInherit(StyleKey key)
 {
     foreach (var k in m_inherit)
     {
         if (k == key)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #8
0
        public float GetFloat(StyleKey key, float def /*= float.NaN*/)
        {
            float  x;
            string val = (string)GetVal(key);

            val = hglEtc.DropAlphabet(val);
            if (float.TryParse(val, out x))
            {
                return(x);
            }
            return(def);
        }
コード例 #9
0
 public bool Equals(StyleKey <T> other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(string.Equals(this.Name, other.Name) && this.ValueType == other.ValueType);
 }
コード例 #10
0
 private object GetVal(StyleKey key)
 {
     if (m_hash.ContainsKey(key))
     {
         return(m_hash[key]);
     }
     if (m_xe != null && m_xe.parent != null && isInherit(key))
     {
         return(m_xe.parent.thisStyle.GetVal(key));
     }
     return(null);
 }
コード例 #11
0
        public IStyleKey <T> CreateKey <T>(string name, bool inherit)
        {
            if (this.registeredKeys.ContainsKey(name))
            {
                throw new ArgumentException();
            }

            var styleKey = new StyleKey <T>(this, this.registeredKeys.Count, name, typeof(T), inherit);

            this.registeredKeys.Add(name, styleKey);
            return(styleKey);
        }
コード例 #12
0
 /// <summary>
 /// Get or set a style parameter.
 /// </summary>
 public string this[StyleKey key] {
     get {
         string value;
         if (_properties.TryGetValue(key, out value))
         {
             return(value);
         }
         return(null);
     }
     set {
         _properties[key] = value;
     }
 }
コード例 #13
0
        /// <summary>
        /// Adds a trigger to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="trigger">The trigger to add to the prioritizer.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, Trigger trigger)
        {
            Contract.Require(uv, "uv");

            var key = new StyleKey(trigger.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, false);

            PrioritizedTrigger existing;
            if (!triggers.TryGetValue(key, out existing) || selector.IsHigherPriorityThan(existing.Selector))
            {
                triggers[key] = new PrioritizedTrigger(trigger, selector, priority);
            }
        }
コード例 #14
0
        public StyleKey GetKey(string keystr)
        {
            StyleKey key = StyleKey.NONE;

            try {
                key = (StyleKey)System.Enum.Parse(typeof(StyleKey), keystr.Replace('-', '_'));
            }
            catch
            {
                key = StyleKey.NONE;
            }
            return(key);
        }
コード例 #15
0
ファイル: Style.cs プロジェクト: MasterQ32/Solid
        public State GetState(StyleKey key)
        {
            switch (key)
            {
            case StyleKey.Default: return(this.Default ?? this.fallbackState);

            case StyleKey.Hovered: return(this.Hovered ?? this.Default ?? this.fallbackState);

            case StyleKey.Active: return(this.Active ?? this.Hovered ?? this.Default ?? this.fallbackState);

            case StyleKey.Disabled: return(this.Disabled ?? this.Default ?? this.fallbackState);

            default: throw new NotSupportedException();
            }
        }
コード例 #16
0
        // # BORDER WORK #
        // ###############

        // ###################
        // # BACKGROUND WORK #
        private void BackgroundWork(StyleKey key, object val)
        {
            string background = (key == StyleKey.background) ? (string)val : (string)GetVal(StyleKey.background);

            Color  color    = new Color(float.NaN, float.NaN, float.NaN);
            string imgUrl   = "";
            string imgAtlas = "";

            hglConverter.GetBackgroundStyle(background, out color, out imgUrl, out imgAtlas);

            switch (key)
            {
            case StyleKey.background_color:
            {
                Color tcolor;
                if (hglConverter.GetColorString((string)val, out tcolor))
                {
                    color = tcolor;
                }
            }
            break;

            case StyleKey.background_image:
            {
                string url;
                if (hglConverter.GetUrlStyle((string)val, out url))
                {
                    imgUrl = url;
                }
            }
            break;

            case StyleKey.background_atlas:
            {
                string atlas;
                if (hglConverter.GetAtlasStyle((string)val, out atlas))
                {
                    imgAtlas = atlas;
                }
            }
            break;
            }

            m_hash[StyleKey.background]       = "#" + hglUtil.Color2String_RRGGBB(color) + " url(" + imgUrl + ") atlas(" + imgAtlas + ")";
            m_hash[StyleKey.background_color] = "#" + hglUtil.Color2String_RRGGBB(color);
            m_hash[StyleKey.background_image] = imgUrl;
            m_hash[StyleKey.background_atlas] = imgAtlas;
        }
コード例 #17
0
        public float GetFloat_allowAuto(StyleKey key, float def /*= float.NaN*/)
        {
            float  x;
            string val = (string)GetVal(key);

            if (val == "auto")
            {
                return((float)-0xa);
            }
            val = hglEtc.DropAlphabet(val);
            if (float.TryParse(val, out x))
            {
                return(x);
            }
            return(def);
        }
コード例 #18
0
        // # PADDING #
        // ###########

        // ###############
        // # BORDER WORK #
        private void BorderWork(StyleKey key, object val)
        {
            float  width;
            Color? color = null;
            string style;

            if (key == StyleKey.border)
            {
                string border = (string)val;
                if (!hglConverter.GetBorder(border, out width, out color, out style))
                {
                    return;
                }
                if (width >= 0)
                {
                    m_hash[StyleKey.border_width] = width.ToString();
                }
                if (color != null)
                {
                    m_hash[StyleKey.border_color] = "#" + hglUtil.Color2String_RRGGBB((Color)color);
                }
                if (style != null)
                {
                    m_hash[StyleKey.border_style] = style;
                }
                return;
            }

            m_hash[key] = val.ToString();

            string borderstr = "";

            if (m_hash[StyleKey.border_width] != null)
            {
                borderstr += (string)m_hash[StyleKey.border_width] + " ";
            }
            if (m_hash[StyleKey.border_color] != null)
            {
                borderstr += (string)m_hash[StyleKey.border_color] + " ";
            }
            if (m_hash[StyleKey.border_style] != null)
            {
                borderstr += (string)m_hash[StyleKey.border_style];
            }

            m_hash[StyleKey.border] = borderstr;
        }
コード例 #19
0
ファイル: Style.cs プロジェクト: MasterQ32/Solid
        /// <summary>
        /// Gets the brush for the given style key. If no brush is available for this key, the default brush will be returned.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="foreground"></param>
        /// <returns></returns>
        public IBrush GetBrush(StyleKey key, bool foreground)
        {
            var state = this.GetState(key);

            if (state == null)
            {
                return(null);
            }

            if (foreground)
            {
                return(state.Foreground);
            }
            else
            {
                return(state.Background);
            }
        }
コード例 #20
0
        /// <summary>
        /// Adds a style to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="style">The style to add to the prioritizer.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, UvssStyle style)
        {
            Contract.Require(uv, "uv");

            var key = new StyleKey(style.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, style.IsImportant);

            PrioritizedStyle existing;
            if (!styles.TryGetValue(key, out existing))
            {
                styles[key] = new PrioritizedStyle(style, selector, priority);
            }
            else
            {
                if (selector.IsHigherPriorityThan(existing.Selector) && (style.IsImportant || !existing.Style.IsImportant))
                {
                    styles[key] = new PrioritizedStyle(style, selector, priority);
                }
            }
        }
コード例 #21
0
        public float GetFloat_allowPercent(StyleKey key, float def /*= float.NaN*/)
        {
            bool   isPercent = false;
            float  x;
            string val = (string)GetVal(key);

            if (hglEtc.check_tail(val, "%"))
            {
                isPercent = true;
            }
            val = hglEtc.DropAlphabet(val);
            if (float.TryParse(val, out x))
            {
                if (isPercent)
                {
                    return(-(x / 100f)); // give negative digit
                }
                return(x);
            }
            return(def);
        }
コード例 #22
0
        public Configuration(Ini ini)
        {
            BaseUrl = ini.ReadString("Config", "BaseUrl");
            if (!BaseUrl.EndsWith("/"))
            {
                BaseUrl += "/";
            }
            if (!BaseUrl.EndsWith("api/v1/"))
            {
                BaseUrl += "api/v1/";
            }
            ApiSecretHash  = Sha1(ini.ReadString("Config", "APISecret"));
            UpdateInterval = ini.ReadInt("Config", "UpdateInterval");
            High           = ini.ReadFloat("Config", "High");
            Low            = ini.ReadFloat("Config", "Low");
            try
            {
                Unit = ini.ReadEnum <Unit>("Config", "Unit");
            }
            catch
            {
                // backward compatibility
                Unit = Unit.mgdl;
            }
            UseColor      = ini.ReadBool("Config", "UseColor");
            UseAlarm      = ini.ReadBool("Config", "UseAlarm");
            AlarmInterval = ini.ReadInt("Config", "AlarmInterval");
            TimeRange     = Math.Min(ini.ReadInt("Config", "TimeRange"), 6);
            StyleKey styleKey = ini.ReadEnum <StyleKey>("Config", "Style");

            Style      = (BaseStyle)Activator.CreateInstance(_styles[styleKey]);
            Width      = ini.ReadInt("Config", "Width");
            Height     = ini.ReadInt("Config", "Height");
            FontFamily = ini.ReadString("Config", "FontFamily");
            FontSize   = ini.ReadInt("Config", "FontSize");
        }
コード例 #23
0
        /// <summary>
        /// Adds a trigger to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="trigger">The trigger to add to the prioritizer.</param>
        /// <param name="index">The index of the trigger's rule set within the style sheet.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, UvssTrigger trigger, Int32 index)
        {
            Contract.Require(uv, nameof(uv));

            var key = new StyleKey(trigger.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, false);

            PrioritizedTrigger existing;
            if (!triggers.TryGetValue(key, out existing))
            {
                triggers[key] = new PrioritizedTrigger(trigger, selector, priority, index);
            }
            else
            {
                var comparison = selector.ComparePriority(existing.Selector);
                if (comparison == 0 && index > existing.Index)
                    comparison = 1;

                if (comparison > 0 && (trigger.IsImportant || !existing.Trigger.IsImportant))
                {
                    triggers[key] = new PrioritizedTrigger(trigger, selector, priority, index);
                }
            }
        }
コード例 #24
0
 /// <summary>
 /// Get or set a style parameter.
 /// </summary>
 public string this[string key] {
     get {
         string value;
         if (StyleKeys.KeySet.Contains(key.ToLowercase().GetHashCode()))
         {
             StyleKey styleKey = StyleKeys.GetKey(key);
             if (styleKey != StyleKey.None)
             {
                 _properties.TryGetValue(styleKey, out value);
                 return(value);
             }
         }
         if (_params == null)
         {
             return(null);
         }
         _params.TryGetValue(key, out value);
         return(value);
     }
     set {
         if (StyleKeys.KeySet.Contains(key.ToLowercase().GetHashCode()))
         {
             StyleKey styleKey = StyleKeys.GetKey(key);
             if (styleKey != StyleKey.None)
             {
                 _properties[styleKey] = value;
                 return;
             }
         }
         if (_params == null)
         {
             _params = new Dictionary <string, string>();
         }
         _params[key] = value;
     }
 }
コード例 #25
0
ファイル: StyleSheet.cs プロジェクト: Fedorm/core-master
        private void AssignControl(ILayoutable control)
        {
            if (control == null)
            {
                throw new ArgumentException("Cannot assign this control");
            }

            IStyleKey key = new StyleKey(control);

            Dictionary <Type, IStyle> styles;

            if (!_stylesByKey.TryGetValue(key, out styles))
            {
                styles = new Dictionary <Type, IStyle>();
                foreach (var item in _styles)
                {
                    StyleSelector selector   = item.Key;
                    uint[]        styleParts = selector.Parts;
                    int           j          = styleParts.Length - 1;
                    if (j >= 0)
                    {
                        bool allowed = false;
                        for (int i = key.Parts.Length - 1; i >= 0; i--)
                        {
                            IStyleKeyPart keyPart   = key.Parts[i];
                            uint          styleItem = styleParts[j];
                            if (styleItem == keyPart.Type || styleItem == keyPart.CssClass)
                            {
                                allowed = true;
                                j--;
                                if (j < 0)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                allowed = false;
                                break;
                            }
                        }

                        if (allowed)
                        {
                            foreach (IStyle style in item.Value)
                            {
                                styles.Remove(style.GetType());
                                styles.Add(style.GetType(), style);
                            }
                        }
                    }
                }

                _stylesByKey.Add(key, styles);
            }

            control.StyleKey = key;
            control.Styles   = styles;

            var container = control as IContainer;

            if (container != null)
            {
                foreach (object child in container.Controls)
                {
                    AssignControl(child as ILayoutable);
                }
            }
        }
コード例 #26
0
 public string Get(StyleKey key)
 {
     return((string)GetVal(key));//  m_hash[key];
 }
コード例 #27
0
 public bool HasKey(StyleKey key)
 {
     return(m_hash.ContainsKey(key));
 }
コード例 #28
0
 bool CheckStyle(StyleKey styleKey)
 {
     return ((styles & (int) styleKey) != 0);
 }
コード例 #29
0
 void SetStyle(StyleKey styleKey)
 {
     styles |= (int)styleKey;
 }
コード例 #30
0
 bool CheckStyle(StyleKey styleKey)
 {
     return((styles & (int)styleKey) != 0);
 }
コード例 #31
0
 void SetStyle(StyleKey styleKey)
 {
     styles |= (int) styleKey;
 }
コード例 #32
0
        public void SetColor(StyleKey key, Color val)
        {
            string s = "#" + hglUtil.Color2String_RRGGBB(val);

            m_hash[key] = s;
        }