예제 #1
0
        public void Add(params GUIArea[] areas)
        {
            for (int i = 0; i < areas.Length; i++)
            {
                GUIArea area = areas[i];
                this.areas.Add(area);
                area.Resize(ScreenWidth, ScreenHeight);
            }

            requireReSort = true;
        }
예제 #2
0
 public void Draw()
 {
     for (int i = 0; i < areas.Count; i++)
     {
         GUIArea area = areas[i];
         if (area.Visible)
         {
             area.Draw(sb);
         }
     }
 }
예제 #3
0
        public void Update(float deltaTime)
        {
            // Check for the need to resort areas by zindex
            for (int i = 0; i < areas.Count; i++)
            {
                GUIArea area = areas[i];

                if (area.ZIndexChanged)
                {
                    requireReSort      = true;
                    area.ZIndexChanged = false;
                }
            }

            // Sort if needed
            if (requireReSort)
            {
                areas.Sort(CompareZ);
            }

            // Process mouse input in order by z
            bool clickHandled = false, mouseOverHandled = false;

            for (int i = areas.Count - 1; i >= 0; i--)
            {
                GUIArea area = areas[i];
                area.Update(deltaTime);

                if (area.Visible)
                {
                    area.ProcessMouse(clickHandled, mouseOverHandled,
                                      out clickHandled, out mouseOverHandled);
                }
            }

            HandledMouseInput = clickHandled;
            HandledMouseOver  = mouseOverHandled;
        }
예제 #4
0
 int CompareZ(GUIArea a, GUIArea b)
 {
     return(a.ZIndex.CompareTo(b.ZIndex));
 }
        public override void Update(float deltaTime)
        {
            if (!CanDraw() || Input.GetMouseButtonUp(MouseButton.Left))
            {
                HasFocus = false;
            }

            if (HasFocus)
            {
                int   spacesMoved;
                Key[] controlKeys;

                string text = Text;

                cursorPos = MathHelper.Clamp(cursorPos, 0, text.Length);

                DashKeyboard.ProcessTextKeyInput(Input.CurrentKeyboardState, deltaTime, cursorPos,
                                                 ref text, out spacesMoved, out controlKeys, new Key[0], MaxLength);

                Label.Text = text;
                cursorPos += spacesMoved;

                if (spacesMoved > 0)
                {
                    blinkTime = blinkDelay;
                    showPipe  = true;
                    GUIArea.ElementUsedKeyboard();
                }

                for (int i = 0; i < controlKeys.Length; i++)
                {
                    Key key = controlKeys[i];

                    if (key == Key.Backspace && Text.Length > 0)
                    {
                        Text = Text.Remove(Text.Length - 1);
                        cursorPos--;
                    }
                }

                if (Input.GetKeyDown(Key.Enter) || Input.GetKeyDown(Key.KeypadEnter))
                {
                    enterHeld = true;
                }

                if (enterHeld && (Input.GetKeyUp(Key.Enter) || Input.GetKeyUp(Key.KeypadEnter)))
                {
                    HasFocus  = false;
                    enterHeld = false;

                    if (OnEnterPressed != null)
                    {
                        OnEnterPressed(this, Text);
                    }
                }

                if (blinkTime > 0)
                {
                    blinkTime -= deltaTime;
                }
                else
                {
                    blinkTime = blinkDelay;
                    showPipe  = !showPipe;
                }
            }

            Label.TextExtension = showPipe && HasFocus ? "|" : " ";

            if (!HasFocus && hadFocus && OnTextChanged != null)
            {
                OnTextChanged(this, Text);
            }


            hadFocus = HasFocus;
            base.Update(deltaTime);
        }