public virtual void update(GameTime gameTime, InputHelper inputHelper) { if (inputHelper.MouseLeftButtonPressed()) { // 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.MousePosition)) { // Handle the click element.onClick(new Events.ClickEvent(inputHelper.MousePosition)); // Make this element active activeElement = i; } } } // Check if there is an active element and if it's visible GuiElement active = ActiveElement; if (active != null && active.Visible) { active.handleKeyboardInput(inputHelper); } }
protected GuiElement(Rectangle bounds) { this.bounds = bounds; visible = true; parent = null; }
public void removeElement(GuiElement element) { elements.Remove(element); }
public void addElement(GuiElement element) { elements.Add(element); }