예제 #1
0
        public virtual void update(InputHelper inputHelper)
        {
            if (inputHelper.MouseLeftButtonPressed)
            {
                // Output a message showing where we clicked :)
                Console.WriteLine("Mouse position on click: " + inputHelper.GetMousePosition(false));

                // Set no element active if none has been pressed
                activeElement = -1;

                // Check if an element has been clicked.
                for (int i = 0; i < elements.Count; ++i)
                {
                    GuiElement element = elements[i];

                    // Only visible elements have events associated with them
                    if (!element.Visible)
                    {
                        continue;
                    }

                    // Check if this is a clicked element
                    if (element.Bounds.Contains(inputHelper.GetMousePosition(false)))
                    {
                        // Handle the click
                        element.onClick(new Events.ClickEvent(inputHelper.GetMousePosition(false)));

                        // Make this element active
                        activeElement = i;

                        // An element has been clicked, check no more
                        break;
                    }
                }

                if (activeElement == -1)
                {
                    onMisclick();
                }
            }

            // Check if there is an active element and if it's visible
            GuiElement active = ActiveElement;

            if (active != null && active.Visible)
            {
                active.handleKeyboardInput(inputHelper);
            }
        }
예제 #2
0
 protected GuiElement(Rectangle bounds)
 {
     this.bounds = bounds;
     visible     = true;
     parent      = null;
 }
예제 #3
0
 public void removeElement(GuiElement element)
 {
     elements.Remove(element);
 }
예제 #4
0
 public void addElement(GuiElement element)
 {
     elements.Add(element);
 }