示例#1
0
            public object GetParameter(string name)
            {
                string result;

                if (DictionaryParameters.TryGetValue(name, out result))
                {
                    return(result); // returns string, not object!
                }
                WidgetParameterIndex index = WidgetManager.GetParameterIndexByName(name);

                if (index != WidgetParameterIndex.None)
                {
                    object objectResult;

                    if (ObjectParameters.TryGetValue((int)index, out objectResult))
                    {
                        return(objectResult);
                    }
                }

                if (Parent != null)
                {
                    return(Parent.GetParameter(name));
                }

                return(null);
            }
示例#2
0
        public WidgetButton(WidgetStyleSheet style, string text = "")
            : base(style)
        {
            m_needLayout = true;

            m_label          = new WidgetLabel();
            m_label.Color    = style.GetParameterColor("text_color", 0x0);
            m_label.FontSize = style.FontSize;
            m_label.Font     = style.Font;
            m_label.Text     = text;
            m_label.Parent   = this;
            m_layout         = ButtonLayout.Center;
            m_textPadding    = style.Padding;

            m_image        = new WidgetImage(WidgetBackgroundStyle.None, string.Empty);
            m_image.Parent = this;
            m_image.Color  = style.GetParameterColor("image_color", 0xffffff);
            m_imagePadding = style.GetParameter <Margin>("image_padding");

            m_hoveredStyle  = WidgetManager.GetStyle(style.GetParameter("hovered_style"));
            m_disabledStyle = WidgetManager.GetStyle(style.GetParameter("disabled_style"));

            m_clickSound = "click";

            Size = style.Size;
        }
示例#3
0
        protected override void ApplyStyle(WidgetStyleSheet style)
        {
            m_label.Color = style.GetParameterColor("text_color", 0x0);

            string hoveredStyle = style.GetParameter("hovered_style");

            if (hoveredStyle != null)
            {
                m_hoveredStyle = WidgetManager.GetStyle(hoveredStyle);
            }

            string disabledStyle = style.GetParameter("disabled_style");

            if (disabledStyle != null)
            {
                m_disabledStyle = WidgetManager.GetStyle(disabledStyle);
            }

            int color = style.GetParameterColor("image_color", -1);

            if (color != -1)
            {
                m_image.Color = color;
            }


            //TextAlign = style.Align;

            base.ApplyStyle(style);
        }
示例#4
0
        public override bool Touch(float x, float y, bool press, bool unpress, int pointer)
        {
            if ((!string.IsNullOrEmpty(m_tooltip) || OnTooltip != null) && ((pointer == 0 && !unpress && !press) || (press && WindowController.Instance.IsTouchScreen)))
            {
                return(WidgetManager.HandleTooltip(this, m_tooltip, new Vector2(x, y), OnTooltip));
            }

            return(base.Touch(x, y, press, unpress, pointer));
        }
示例#5
0
        public WidgetContextMenu(WidgetStyleSheet style)
            : base(style)
        {
            Visible     = false;
            m_itemStyle = WidgetManager.GetStyle(style.GetParameter("item_style"));
            if (m_itemStyle == null)
            {
                m_itemStyle = WidgetManager.DefaultButtonStyle;
            }

            m_itemSize = m_itemStyle.Size;
            m_padding  = style.Padding;
        }
示例#6
0
        public static void Show(WidgetTooltip tooltip, Vector2 position, RectangleF region)
        {
            Hide();

            tooltip.ZIndex = int.MaxValue;
            WidgetManager.GetTopmostWindow().AddChild(tooltip);
            tooltip.Update(); // make sure all sizes are settled up

            tooltip.Region = region;
            tooltip.UpdatePosition(position);

            WindowController.Instance.OnTouch += tooltip.UnHoverTouch;

            s_currentTooltip = tooltip;
        }
示例#7
0
        public void SetFocused(bool value)
        {
            if (IsFocused == value)
            {
                return;
            }

            IsFocused = value;

            //UpdateColor();
            m_cursorPosition = m_text.Length;
            UpdateCursor(0, 0);

            WidgetManager.UpdateFocus(this, value);
            //WidgetManager.UpdateFocus(this, true);
        }
示例#8
0
        private void Hide(WidgetButton caller)
        {
            if (!Visible)
            {
                return;
            }

            Visible = false;

            if (m_autohide)
            {
                WidgetManager.RemoveExclusive(this);
            }


//                WidgetManager.WindowController.OnTouch -= UnHoverTouch;
        }
示例#9
0
        public WidgetCheckBox(WidgetStyleSheet style, bool isChecked)
            : base(style)
        {
            m_image        = new WidgetImage(WidgetBackgroundStyle.ImageFit, style.GetParameter("check_image"));
            m_image.Parent = this;
            m_image.Color  = style.GetParameterColor("image_color", 0xffffff);
            m_imagePadding = style.GetParameter <Margin>("image_padding");

            m_imageAlign = WidgetAlign.VerticalCenter | WidgetAlign.HorizontalCenter;

            Size = style.Size;

            m_checked = isChecked;

            m_hoveredStyle  = WidgetManager.GetStyle(style.GetParameter("hovered_style"));
            m_disabledStyle = WidgetManager.GetStyle(style.GetParameter("disabled_style"));
        }
示例#10
0
        public void SetFocused(bool value)
        {
            if (IsFocused == value)
            {
                return;
            }

            if (!Enabled)
            {
                return;
            }

            IsFocused = value;

            m_cursorPosition = m_text.Length;
            UpdateCursor(0);

            WidgetManager.UpdateFocus(this, value);
        }
示例#11
0
        public void Show(Vector2 position, bool autohide = true)
        {
            Hide();

            WidgetManager.GetTopmostWindow().AddChild(this);

            this.Position = position - m_padding.TopLeft;

            Visible = true;

            if (autohide)
            {
                WidgetManager.SetExclusive(this);
            }

//                WidgetManager.WindowController.OnTouch += UnHoverTouch;

            m_autohide = autohide;
        }
示例#12
0
        public WidgetScrollView(WidgetStyleSheet style)
            : base(style)
        {
            m_contentView        = new WidgetPanel(WidgetManager.DefaultWidgetStyle);
            m_contentView.Parent = this;
            ClipContents         = true;
            m_horizontalScroll   = WidgetScrollType.Normal | WidgetScrollType.Visible | WidgetScrollType.AutoHide;
            m_verticalScroll     = WidgetScrollType.Normal | WidgetScrollType.Visible | WidgetScrollType.AutoHide;

            m_horizontalScrollBar                 = new Widget(WidgetManager.GetStyle("scroll_horizontal"));
            m_horizontalScrollBar.Parent          = this;
            m_horizontalScrollBarIndicator        = new Widget(WidgetManager.GetStyle("scroll_indicator_horizontal"));
            m_horizontalScrollBarIndicator.Parent = this;

            m_verticalScrollBar                 = new Widget(WidgetManager.GetStyle("scroll_vertical"));
            m_verticalScrollBar.Parent          = this;
            m_verticalScrollBarIndicator        = new Widget(WidgetManager.GetStyle("scroll_indicator_vertical"));
            m_verticalScrollBarIndicator.Parent = this;

            m_needLayout = true;
        }
示例#13
0
        public void SetFocused(bool value)
        {
            if (m_focused == value)
            {
                return;
            }

            m_focused = value;

            if (!string.IsNullOrEmpty(m_focusImage))
            {
                BackgroundTexture = value ? m_focusImage : Style.BackgroundTexture;
            }

            //UpdateColor();
            m_cursorPosition = m_text.Length;
            UpdateCursor(0);

            UpdateColor();

            WidgetManager.UpdateFocus(this, value);
            //WidgetManager.UpdateFocus(this, true);
        }
示例#14
0
        public override bool Key(SpecialKey key, bool up, string keyString)
        {
            if (!IsFocused)
            {
                return(false);
            }

            if (!Enabled)
            {
                return(false);
            }

            if (OnKeyPressed != null && OnKeyPressed(this, key, keyString))
            {
                return(true);
            }

            if (up && key == SpecialKey.Back)
            {
                if (OnTextEntered != null)
                {
                    OnTextEntered(this, string.Empty);
                }
                return(true);
            }

            if (up && (key == SpecialKey.Enter || key == SpecialKey.Joystick_Start))
            {
                if (OnTextEntered != null)
                {
                    OnTextEntered(this, m_text);
                }
                return(true);
            }

            if (up && key == SpecialKey.Tab)
            {
                if (TabToValidate && OnTextEntered != null)
                {
                    OnTextEntered(this, m_text);
                }

                if (WidgetManager.FocusNext(this) && OnFocusLost != null)
                {
                    OnFocusLost(this, m_text);
                }

                return(true);
            }

            if ((key == SpecialKey.Letter || key == SpecialKey.Paste) /* && Font.HaveSymbol(character)*/)
            {
                // filter non-printable chars

                StringBuilder stringToAdd = new StringBuilder(keyString.Length);

                for (int i = 0; i < keyString.Length; i++)
                {
                    if (Font.HaveSymbol(keyString[i]))
                    {
                        stringToAdd.Append(keyString[i]);
                    }
                }

                if (stringToAdd.Length > 0)
                {
                    string toAdd = stringToAdd.ToString();

                    // Input string validation. Only called on paste and input
                    if (OnValidateInput != null && !OnValidateInput(m_text, toAdd))
                    {
                        return(true);
                    }

                    if (m_cursorPosition == m_text.Length)
                    {
                        m_text += toAdd;
                    }
                    else
                    {
                        m_text = m_text.Insert(m_cursorPosition, toAdd);
                    }

                    if (OnTextChanged != null)
                    {
                        OnTextChanged(this, m_text);
                    }

                    m_cursorPosition += toAdd.Length;
                    Relayout();
                    return(true);
                }
            }

            if (!up)
            {
                switch (key)
                {
                case SpecialKey.Backspace:
                    if (m_cursorPosition > m_preffix.Length)
                    {
                        m_text = m_text.Substring(0, m_cursorPosition - 1) + m_text.Substring(m_cursorPosition);

                        if (OnTextChanged != null)
                        {
                            OnTextChanged(this, m_text);
                        }

                        m_cursorPosition--;
                        Relayout();
                    }
                    break;

                case SpecialKey.Delete:
                    if (m_cursorPosition <= m_text.Length - 1)
                    {
                        m_text = m_text.Substring(0, m_cursorPosition) + m_text.Substring(m_cursorPosition + 1);

                        if (OnTextChanged != null)
                        {
                            OnTextChanged(this, m_text);
                        }

                        Relayout();
                    }
                    break;

                case SpecialKey.Left:
                    if (m_cursorPosition > m_preffix.Length)
                    {
                        UpdateCursor(-1);
                    }
                    break;

                case SpecialKey.Right:
                    if (m_cursorPosition <= m_text.Length - 1)
                    {
                        UpdateCursor(1);
                    }
                    break;
                }
            }

            switch (key)
            {
            case SpecialKey.Up:
            case SpecialKey.Down:
                return(false);
            }



            return(true);
        }
示例#15
0
 public WidgetContextMenu()
     : this(WidgetManager.GetStyle("default_context_menu"))
 {
 }
示例#16
0
        public override bool Key(SpecialKey key, bool up, char character)
        {
            if (!m_focused)
            {
                return(false);
            }

            if (up && key == SpecialKey.Back)
            {
                //SetFocused(false);
                if (OnTextEntered != null)
                {
                    OnTextEntered(this, string.Empty);
                }
                return(true);
            }

            if (up && (key == SpecialKey.Enter))
            {
                //SetFocused(false);
                if (OnTextEntered != null)
                {
                    OnTextEntered(this, m_text);
                }
                return(true);
            }

            if (up && key == SpecialKey.Tab)
            {
                if (WidgetManager.FocusNext(this) && OnFocusLost != null)
                {
                    OnFocusLost(this, m_text);
                }

                return(true);
            }

            if ((key == SpecialKey.Letter || key == SpecialKey.Paste) && m_font.HaveSymbol(character))
            {
                m_text = m_text.Insert(m_cursorPosition, character.ToString());

                if (OnTextChanged != null)
                {
                    OnTextChanged(this, m_text);
                }

                UpdateCursor(1);
                return(true);
            }

            if (!up)
            {
                switch (key)
                {
                case SpecialKey.Backspace:
                    if (m_cursorPosition > m_preffix.Length)
                    {
                        m_text = m_text.Substring(0, m_cursorPosition - 1) + m_text.Substring(m_cursorPosition);

                        if (OnTextChanged != null)
                        {
                            OnTextChanged(this, m_text);
                        }

                        UpdateCursor(-1);
                    }
                    break;

                case SpecialKey.Delete:
                    if (m_cursorPosition <= m_text.Length - 1)
                    {
                        m_text = m_text.Substring(0, m_cursorPosition) + m_text.Substring(m_cursorPosition + 1);

                        if (OnTextChanged != null)
                        {
                            OnTextChanged(this, m_text);
                        }

                        UpdateCursor(0);
                    }
                    break;

                case SpecialKey.Left:
                    if (m_cursorPosition > m_preffix.Length)
                    {
                        UpdateCursor(-1);
                    }
                    break;

                case SpecialKey.Right:
                    if (m_cursorPosition <= m_text.Length - 1)
                    {
                        UpdateCursor(1);
                    }
                    break;
                }
            }

            switch (key)
            {
            case SpecialKey.Up:
            case SpecialKey.Down:
                return(false);
            }



            return(true);
        }
示例#17
0
 public override void Remove()
 {
     WidgetManager.UpdateFocus(this, false);
     base.Remove();
 }
示例#18
0
        public override bool Key(SpecialKey key, bool up, string keyString)
        {
            if (!IsFocused)
            {
                return(false);
            }

            if (up && key == SpecialKey.Back)
            {
                //SetFocused(false);
                if (OnTextEntered != null)
                {
                    OnTextEntered(this, string.Empty);
                }
                return(true);
            }

            if (up && (key == SpecialKey.Enter || key == SpecialKey.Joystick_Start))
            {
                //SetFocused(false);
                if (OnTextEntered != null)
                {
                    OnTextEntered(this, m_text);
                }
                return(true);
            }

            if (up && key == SpecialKey.Tab)
            {
                if (WidgetManager.FocusNext(this) && OnFocusLost != null)
                {
                    OnFocusLost(this, m_text);
                }

                return(true);
            }

            if ((key == SpecialKey.Letter || key == SpecialKey.Paste) /* && Font.HaveSymbol(character)*/)
            {
                StringBuilder stringToAdd = new StringBuilder(keyString.Length);

                for (int i = 0; i < keyString.Length; i++)
                {
                    if (Font.HaveSymbol(keyString[i]))
                    {
                        stringToAdd.Append(keyString[i]);
                    }
                }

                if (stringToAdd.Length > 0)
                {
                    string toAdd = stringToAdd.ToString();

                    if (m_cursorPosition == m_text.Length)
                    {
                        m_text += toAdd;
                    }
                    else
                    {
                        m_text = m_text.Insert(m_cursorPosition, toAdd);
                    }

                    if (OnTextChanged != null)
                    {
                        OnTextChanged(this, m_text);
                    }

                    m_cursorPosition     += toAdd.Length;
                    m_cursorLinePosition += toAdd.Length;
                    Relayout();
                    return(true);
                }
            }

            if (!up)
            {
                switch (key)
                {
                case SpecialKey.Backspace:
                    if (m_cursorPosition > 0)
                    {
                        m_text = m_text.Substring(0, m_cursorPosition - 1) + m_text.Substring(m_cursorPosition);

                        if (OnTextChanged != null)
                        {
                            OnTextChanged(this, m_text);
                        }

                        m_cursorPosition--;
                        m_cursorLinePosition--;
                        Relayout();
                    }
                    break;

                case SpecialKey.Delete:
                    if (m_cursorPosition <= m_text.Length - 1)
                    {
                        m_text = m_text.Substring(0, m_cursorPosition) + m_text.Substring(m_cursorPosition + 1);

                        if (OnTextChanged != null)
                        {
                            OnTextChanged(this, m_text);
                        }

                        Relayout();
                    }
                    break;

                case SpecialKey.Enter:
                {
                    if (m_cursorPosition == m_text.Length)
                    {
                        m_text += "\n";
                    }
                    else
                    {
                        m_text = m_text.Insert(m_cursorPosition, "\n");
                    }

                    if (OnTextChanged != null)
                    {
                        OnTextChanged(this, m_text);
                    }

                    m_cursorPosition++;
                    m_cursorLine++;
                    m_cursorLinePosition = 0;

                    Relayout();
                }
                break;

                case SpecialKey.Left:
                    if (m_cursorPosition > 0)
                    {
                        UpdateCursor(-1, 0);
                    }
                    break;

                case SpecialKey.Right:
                    if (m_cursorPosition <= m_text.Length - 1)
                    {
                        UpdateCursor(1, 0);
                    }
                    break;

                case SpecialKey.Home:
                    if (m_cursorLinePosition > 0)
                    {
                        UpdateCursor(-m_cursorLinePosition, 0);
                    }
                    break;

                case SpecialKey.End:
                    UpdateCursor(int.MaxValue, 0);
                    break;

                case SpecialKey.Up:
                    if (m_cursorLine > 0)
                    {
                        UpdateCursor(0, -1);
                    }
                    break;

                case SpecialKey.Down:
                    if (m_cursorLine < m_lines.Length - 1)
                    {
                        UpdateCursor(0, 1);
                    }
                    break;
                }
            }

            return(true);
        }
示例#19
0
        internal WidgetStyleSheet(string name, WidgetStyleSheet parent, XmlNode node)
            : this(parent)
        {
            foreach (XmlNode element in node.ChildNodes)
            {
                try
                {
                    string value = element.InnerText;
                    if (string.IsNullOrEmpty(value) && element.Attributes.GetNamedItem("value") != null)
                    {
                        value = element.Attributes.GetNamedItem("value").Value;
                    }

                    if (value == null)
                    {
                        value = string.Empty;
                    }
                    else
                    {
                        value = value.Trim('\r', '\n', '\t', ' ');
                    }

                    switch (element.Name)
                    {
                    case "back_style":
                        m_backgroundStyle = (WidgetBackgroundStyle)Enum.Parse(typeof(WidgetBackgroundStyle), value);
                        break;

                    case "back_depth":
                        m_backgroundDepth = (WidgetBackgroundDepth)Enum.Parse(typeof(WidgetBackgroundDepth), value);
                        break;

                    case "back_image":
                        m_backgroundTexture = value;
                        break;

                    case "back_scale":
                        m_backgroundScale = FloatParse(value);
                        break;

                    case "back_pivot":
                    {
                        string[] values = value.Split(';');
                        float    x      = FloatParse(values[0]);
                        float    y      = FloatParse(values[1]);
                        m_backgroundPivot = new Vector2(x, y);
                        break;
                    }

                    case "font":
                        m_font = WidgetManager.GetFont(value);
                        break;

                    case "font_size":
                        m_fontSize = FloatParse(value);
                        break;

                    case "clip":
                        m_clip = bool.Parse(value);
                        break;

                    case "color":
                        m_color = ColorParse(value);
                        break;

                    case "opacity":
                        m_opacity = FloatParse(value);
                        break;

                    case "size":
                        m_size = Vector2Parse(value);
                        break;

                    case "clip_margin":
                        m_clipMargin = MarginParse(value);
                        break;

                    case "padding":
                        m_padding = MarginParse(value);
                        break;

                    case "back_padding":
                        m_backgroundPadding = MarginParse(value);
                        break;

                    default:
                        m_parameters[element.Name] = value;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    WindowController.Instance.LogError("Error parsing style {0}, element {1}: {2}", name, element.Name, ex);
                    throw;
                }
            }
        }