示例#1
0
 /// <summary>
 /// Create a new Widget.
 /// </summary>
 /// <param name="screen">The Widget's screen.</param>
 /// <param name="parent">The Widget's parent.</param>
 private Widget(WidgetScreen screen, Widget parent)
 {
     if (screen == null)
         throw new ArgumentNullException("screen");
     Screen = screen;
     Parent = parent;
     StateChanged("");
 }
示例#2
0
 /// <summary>
 /// Create a new Widget.
 /// </summary>
 /// <param name="parent">The Widget's parent.</param>
 public Widget(Widget parent)
     : this(parent.Screen, parent)
 {
 }
示例#3
0
        /// <summary>
        /// Check if a Widget is an ancestor of this one.
        /// </summary>
        /// <param name="potentialAncestor">The widget to check.</param>
        /// <returns>True if potentialAncestor was in the parent hierarchy of the current Widget.</returns>
        public bool isAncestor(Widget potentialAncestor)
        {
            if (potentialAncestor == null)
                return false;

            if (potentialAncestor == this)
                return true;

            return parent == null ? false : parent.isAncestor(potentialAncestor);
        }
示例#4
0
 /// <summary>
 /// Create a new Control with a given parent.
 /// </summary>
 /// <param name="parent">The Control's parent.</param>
 public Control(Widget parent)
     : base(parent)
 {
 }
示例#5
0
        protected void RegisterCSSClass(String cssClassName, Widget widget)
        {
            if (cssClassName == null || cssClassName.Length == 0 || widget == null)
                return;

            List<Widget> explicitWidgets = null;
            if (!cssStyleLinks.TryGetValue(cssClassName, out explicitWidgets))
                cssStyleLinks[cssClassName] = (explicitWidgets = new List<Widget>());

            if (!explicitWidgets.Contains(widget))
                explicitWidgets.Add(widget);
        }
示例#6
0
        /// <summary>
        /// Handles the input provided by the ScreenManager's InputControl. You should not need to override this - use the specialized input methods instead!
        /// </summary>
        /// <param name="input">The InputControl object passed in from the ScreenManager.</param>
        public override void HandleInput(InputControl input)
        {
            base.HandleInput(input);

            //store mouse pos
            Point mousePos = input.CurrentMouse;

            //check for a  widget at mouse point
            Widget widgetAtPoint = baseWidget.ChildAtPoint(mousePos, HitFlags.Mouse);

            //handle mouse movement
            bool cascade = true;
            if (input.MouseMoved())
            {
                //check for mouse enter/leave events
                if (widgetAtPoint != mouseHoverWidget)
                {
                    if (mouseHoverWidget != null)
                        cascade = !mouseHoverWidget.MouseLeave(mousePos);

                    mouseHoverWidget = widgetAtPoint;

                    if (mouseHoverWidget != null)
                        cascade &= !mouseHoverWidget.MouseEnter(mousePos);
                }

                if (cascade)
                    MouseMove(mousePos,input.PreviousMouse);
            }

            //handle mouse clicks
            for (int i = 1; i <= 5; i++)
            {
                ButtonState current;
                if (input.MouseChanged(i,out current))
                {
                    cascade = true;
                    if (current == ButtonState.Pressed)
                    {
                        mouseDownWidgets[i-1] = widgetAtPoint;
                        if (widgetAtPoint != null)
                            cascade = !widgetAtPoint.MouseDown(mousePos, i);

                        if (cascade)
                            MouseDown(mousePos, i);
                    }
                    else
                    {
                        if (mouseDownWidgets[i-1] != null)
                            cascade = !mouseDownWidgets[i - 1].MouseUp(mousePos, i);
                        mouseDownWidgets[i-1] = null;

                        if (cascade)
                            MouseUp(mousePos, i);
                    }
                }
            }

            //check keyboard events
            for (int i = 0; i < watchedKeys.Length; i++)
            {
                if (input.KeyReleased(watchedKeys[i]))
                {
                    cascade = true;
                    if (selectedWidget != null)
                        cascade = !selectedWidget.KeyUp(watchedKeys[i]);
                    if (cascade)
                        KeyUp(watchedKeys[i]);
                }

                if (input.KeyPressed(watchedKeys[i]))
                {
                    cascade = true;
                    if (selectedWidget != null)
                        cascade = !selectedWidget.KeyDown(watchedKeys[i]);
                    if (cascade)
                        KeyDown(watchedKeys[i]);
                }
            }
        }
示例#7
0
 /// <summary>
 /// Create a new Button with a given parent.
 /// </summary>
 /// <param name="parent">The Widget's parent.</param>
 public Button(Widget parent)
     : base(parent)
 {
     HitFlags = HitFlags.Mouse;
 }
示例#8
0
        public override void Draw(SpriteBatch spriteBatch, Widget widget, Color col)
        {
            if (Texture == null
                || col.A == 0
                || BorderStyle == Styles.BorderStyle.None
                || BorderStyle == Styles.BorderStyle.Hidden
                || BorderWidth <= 0)
                return;

            int left = (int)((float)widget.CalculatedBoundsI.X * Width);
            int top = (int)((float)widget.CalculatedBoundsI.Y * Height);
            int width = (int)((float)widget.CalculatedBoundsI.Width * Width);
            int height = (int)((float)widget.CalculatedBoundsI.Height * Height);

            if (BorderStyle == Styles.BorderStyle.Solid || BorderStyle == Styles.BorderStyle.Double)
            {
                //top and bottom
                spriteBatch.Draw(Texture, new Rectangle(left, top, width, BorderWidth), col);
                spriteBatch.Draw(Texture, new Rectangle(left, top + height - BorderWidth, width, BorderWidth), col);

                //left and right
                spriteBatch.Draw(Texture, new Rectangle(left, top + BorderWidth, BorderWidth, height - 2 * BorderWidth), col);
                spriteBatch.Draw(Texture, new Rectangle(left + width - BorderWidth, top + BorderWidth, BorderWidth, height - 2 * BorderWidth), col);

                if (BorderStyle == Styles.BorderStyle.Double)
                {
                    left += BorderWidth * 2;
                    top += BorderWidth * 2;
                    width -= BorderWidth * 4;
                    height -= BorderWidth * 4;

                    //top and bottom
                    spriteBatch.Draw(Texture, new Rectangle(left, top, width, BorderWidth), col);
                    spriteBatch.Draw(Texture, new Rectangle(left, top + height - BorderWidth, width, BorderWidth), col);

                    //left and right
                    spriteBatch.Draw(Texture, new Rectangle(left, top + BorderWidth, BorderWidth, height - 2 * BorderWidth), col);
                    spriteBatch.Draw(Texture, new Rectangle(left + width - BorderWidth, top + BorderWidth, BorderWidth, height - 2 * BorderWidth), col);
                }
            }
            else if (BorderStyle == Styles.BorderStyle.Dotted || BorderStyle == Styles.BorderStyle.Dashed)
            {
                int len = BorderWidth * (BorderStyle == Styles.BorderStyle.Dotted ? 1 : 4);

                //top and bottom
                int pos = 0;
                while (pos < width)
                {
                    spriteBatch.Draw(Texture, new Rectangle(left + pos, top, len, BorderWidth), col);
                    spriteBatch.Draw(Texture, new Rectangle(left + pos, top + height - BorderWidth, len, BorderWidth), col);
                    pos += len * 2;
                }

                //left and right
                height -= BorderWidth * 2;
                pos = 0;
                while (pos < height)
                {
                    spriteBatch.Draw(Texture, new Rectangle(left, top + BorderWidth + pos, BorderWidth, len), col);
                    spriteBatch.Draw(Texture, new Rectangle(left + width - BorderWidth, top + BorderWidth + pos, BorderWidth, len), col);
                    pos += len * 2;
                }
            }
        }