Exemple #1
0
 protected bool UpdateWidgets(GameTime gameTime, List<GuiWidget> widgets, Boolean update) {
     bool cursorOnWidget = false;
     for (int i = widgets.Count - 1; i >= 0; i--) {
         GuiWidget widget = widgets[i];
         widget.GuiHandler = this;
         if (update) {
             widget.PreUpdate();
             widget.Update(gameTime);
         }
         if (widget == TooltipWidget) {
             continue;
         }
         bool cursorOnChild = cursorOnWidget;
         if (widget.ShowChildren) {
             cursorOnChild = cursorOnWidget || UpdateWidgets(gameTime, widget.Widgets, false);
         }
         if (widget.InView && (widget.Position.X + widget.Offset.X <= MouseState.Position.X && MouseState.Position.X <= widget.Position.X + widget.Offset.X + widget.Size.X &&
             widget.Position.Y + widget.Offset.Y <= MouseState.Position.Y && MouseState.Position.Y <= widget.Position.Y + widget.Offset.Y + widget.Size.Y)) {
             cursorOnWidget = true;
             widget.Hover(gameTime);
             if (!cursorOnChild && MouseState.LeftButton.State == MouseButtonStates.Clicked) {
                 widget.Click(gameTime, 1);
                 if (FocusedWidget != null) {
                     FocusedWidget.Unfocus(gameTime);
                 }
                 FocusedWidget = widget;
             }
             if (!cursorOnChild && MouseState.RightButton.State == MouseButtonStates.Clicked) {
                 widget.Click(gameTime, 3);
             }
             if (!cursorOnChild && MouseState.LeftButton.State == MouseButtonStates.DragStarted) {
                 if (DraggingWidget != null) {
                     DraggingWidget.Dragging(gameTime, MouseButtonStates.DragEnded);
                 }
                 DraggingWidget = widget;
                 DraggingWidget.Dragging(gameTime, MouseButtonStates.DragStarted);
             }
             widget.Scroll(gameTime, MouseState.WheelTurns);
         }
         cursorOnWidget = cursorOnWidget || cursorOnChild;
     }
     return cursorOnWidget;
 }