Example #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="game">The currently running Game object.</param>
        public GUIManager(Game game)
            : base(game)
        {
            this.controls = new List<UIComponent>();
            this.focusedControl = null;
            this.modalControl = null;

            // Ensure this and mouse are always drawn on top, mouse is MaxValue
            this.DrawOrder = int.MaxValue - 1;

            // Get input event system, and register event handlers
            this.inputEvents = (IInputEventsService)this.Game.Services.GetService(typeof(IInputEventsService));
            if (this.inputEvents != null)
            {
                this.inputEvents.RequestingFocus += new MouseDownHandler(RequestingFocus);
                this.inputEvents.MouseMove += new MouseMoveHandler(CheckMouseStatus);
            }

            // Create graphical mouse cursor
            this.mouseCursor = new MouseCursor(game, this);
            this.mouseCursor.Initialize();
        }
Example #2
0
 /// <summary>
 /// Refresh menu items positions when any of them change size.
 /// </summary>
 /// <param name="sender">Resized control.</param>
 protected void OnMenuItemResize(UIComponent sender)
 {
     RefreshMenuItems();
 }
Example #3
0
 /// <summary>
 /// Overridden to prevent any control except MenuItem from being added.
 /// </summary>
 /// <param name="control">Control to add.</param>
 public override void Add(UIComponent control)
 {
     Debug.Assert(false);
 }
Example #4
0
        /// <summary>
        /// Update locations of child control.
        /// </summary>
        /// <param name="sender"></param>
        protected override void OnResize(UIComponent sender)
        {
            base.OnResize(sender);

            // Update child sizes
            button.Width = Height;
            button.Height = Height;
            label.Height = Height;

            RefreshMargins();
        }
Example #5
0
        /// <summary>
        /// Update child controls.
        /// </summary>
        /// <param name="sender">Resized control.</param>
        protected override void OnResize(UIComponent sender)
        {
            base.OnResize(sender);

            this.box.Width = Width;
            this.box.Height = Height;

            RefreshMargins();
        }
Example #6
0
        /// <summary>
        /// Close listbox and update textbox, and invoke SelectionChanged
        /// event.
        /// </summary>
        /// <param name="sender">Selected control.</param>
        protected void OnSelectionChanged(UIComponent sender)
        {
            // Update text
            string text = this.listBox.GetSelectedText();
            if (text != null)
                this.textBox.Text = text;

            CloseListBox();

            if (SelectionChanged != null)
                SelectionChanged.Invoke(this);
        }
Example #7
0
 /// <summary>
 /// Refresh the skins whenever control is resized.
 /// </summary>
 /// <param name="sender">Resized control.</param>
 protected override void OnResize(UIComponent sender)
 {
     base.OnResize(sender);
     RefreshSkins();
 }
Example #8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="game">The currently running Game object.</param>
        /// <param name="guiManager">GUIManager that this control is part of.</param>
        public ListBox(Game game, GUIManager guiManager)
            : base(game, guiManager)
        {
            this.entries = new List<Label>();
            this.selectedIndex = -1;
            this.resizeToFit = false;

            #region Create Child Controls
            this.box = new Box(game, guiManager);
            this.surface = new UIComponent(game, guiManager);
            this.viewPort = new UIComponent(game, guiManager);
            this.scrollBar = new ScrollBar(game, guiManager);
            #endregion

            #region Add Child Controls
            Add(this.box);
            this.viewPort.Add(this.surface);
            Add(this.viewPort);
            #endregion

            #region Set Properties
            this.surface.CanHaveFocus = false;
            this.viewPort.CanHaveFocus = false;
            //this.scrollBar.Y = 1;
            #endregion

            #region Set Default Properties
            Width = defaultWidth;
            Height = defaultHeight;
            HMargin = defaultHMargin;
            VMargin = defaultVMargin;
            Skin = defaultSkin;
            Font = defaultFont;
            #endregion

            #region Event Handlers
            this.scrollBar.Scroll += new ScrollHandler(OnScroll);
            // Scrollbar doesn't need keyboard, so hand control over to this
            this.scrollBar.KeyDown += new KeyDownHandler(OnKeyDown);
            #endregion
        }
Example #9
0
 /// <summary>
 /// Add child controls to viewport, so user doesn't have to worry about
 /// title bars etc.
 /// </summary>
 /// <param name="control">Control to add.</param>
 public override void Add(UIComponent control)
 {
     // Add to viewport
     this.viewPort.Add(control);
 }
Example #10
0
        /// <summary>
        /// Is the specified control contained in this part of the GUI tree.
        /// </summary>
        /// <param name="control">Control to search for.</param>
        /// <returns>TRUE if control was found, otherwise FALSE.</returns>
        protected internal bool IsChild(UIComponent key)
        {
            if (key == this)
                return true;
            else
            {
                foreach (UIComponent control in this.controls)
                {
                    if (control.IsChild(key))
                        return true;
                }
            }

            return false;
        }
Example #11
0
        /// <summary>
        /// Removes the child control.
        /// </summary>
        /// <param name="control">Control to remove.</param>
        /// <returns>TRUE if control existed, otherwise FALSE.</returns>
        public virtual bool Remove(UIComponent control)
        {
            bool result = false;

            if (this.controls.Remove(control))
            {
                control.CleanUp();
                result = true;
            }

            return result;
        }
Example #12
0
 /// <summary>
 /// Adds a control as a child, if it has not already been added. Also
 /// initializes control.
 /// </summary>
 /// <param name="control">Control to add.</param>
 public virtual void Add(UIComponent control)
 {
     if (!this.controls.Contains(control))
     {
         control.Parent = this;
         control.Initialize();
         this.controls.Add(control);
     }
 }
Example #13
0
        /// <summary>
        /// Constructor sets up data and event handlers.
        /// </summary>
        /// <param name="game">The currently running Game object.</param>
        /// <param name="guiManager">GUIManager that this control is part of.</param>
        public UIComponent(Game game, GUIManager guiManager)
            : base(game)
        {
            this.guiManager = guiManager;
            this.inputEvents = null;
            this.absolutePosition = Point.Zero;
            this.controls = new List<UIComponent>();
            this.parent = null;

            // Minimum size of 1
            this.location = new Rectangle(0, 0, 1, 1);
            this.minWidth = 1;
            this.minHeight = 1;

            this.zOrder = 0.0f;
            this.canHaveFocus = true;
            this.isInitialized = false;
            this.isAnimating = false;
            this.isMouseOver = false;
            this.isPressed = false;

            #region Event Handlers
            this.MouseDown += new MouseDownHandler(OnMouseDown);
            this.MouseUp += new MouseUpHandler(OnMouseUp);
            this.MouseMove += new MouseMoveHandler(OnMouseMove);
            this.MouseOver += new MouseOverHandler(OnMouseOver);
            this.MouseOut += new MouseOutHandler(OnMouseOut);
            this.KeyDown += new KeyDownHandler(OnKeyDown);
            this.KeyUp += new KeyUpHandler(OnKeyUp);
            this.Move += new MoveHandler(OnMove);
            this.Resize += new ResizeHandler(OnResize);
            this.GetFocus += new GetFocusHandler(OnGetFocus);
            this.LoseFocus += new LoseFocusHandler(OnLoseFocus);
            #endregion

            instanceCount++;
        }
Example #14
0
 /// <summary>
 /// Simply refreshes, override to handle event.
 /// </summary>
 /// <param name="args">Resized control.</param>
 protected virtual void OnResize(UIComponent sender)
 {
     Refresh();
 }
Example #15
0
 /// <summary>
 /// Called when a parent controls is resized.
 /// </summary>
 /// <param name="sender">Resized control.</param>
 protected virtual void OnParentResized(UIComponent sender)
 {
 }
Example #16
0
 /// <summary>
 /// Overridden to prevent any control except RadioButton from being
 /// added.
 /// </summary>
 /// <param name="control">Control to add.</param>
 public override void Add(UIComponent control)
 {
     Debug.Assert(false);
 }
 /// <summary>
 /// Overridden to prevent controls from being added.
 /// </summary>
 /// <param name="control">Control to add.</param>
 public override void Add(UIComponent control)
 {
     Debug.Assert(false, "No controls can be added to this component.");
 }
Example #18
0
 /// <summary>
 /// Remove child controls from viewport, so user doesn't have to worry
 /// about title bars etc.
 /// </summary>
 /// <param name="control">Control to remove.</param>
 /// <returns>Removal result.</returns>
 public override bool Remove(UIComponent control)
 {
     return this.viewPort.Remove(control);
 }
Example #19
0
        /// <summary>
        /// Resize child controls.
        /// </summary>
        /// <param name="sender">Resizing control.</param>
        protected override void OnResize(UIComponent sender)
        {
            base.OnResize(sender);

            this.box.Width = Width;
            this.scrollBar.X = Width - this.scrollBar.Width;

            this.box.Height = Height;
            this.scrollBar.Height = Height;

            RefreshMargins();
            RefreshEntries();
        }
Example #20
0
 /// <summary>
 /// Closes window, starting animation if necessary. Also invokes the
 /// window Close event.
 /// </summary>
 /// <param name="sender">Control invoking close.</param>
 protected void OnClose(UIComponent sender)
 {
     CloseWindow();
 }
Example #21
0
        /// <summary>
        /// Resize child controls.
        /// </summary>
        /// <param name="sender">Resizing control.</param>
        protected override void OnResize(UIComponent sender)
        {
            base.OnResize(sender);

            this.button.Width = Height;
            this.button.Height = Height;
            this.button.X = Width - this.button.Width;
            this.textBox.Width = Width - this.button.Width;
            this.textBox.Height = Height;
        }
Example #22
0
        protected override void OnMove(UIComponent sender)
        {
            base.OnMove(sender);

            // If moving, change transparency
            if (IsAnimating && this.transparency == -1)
            {
                //this.transparency = Transparency;
                //Transparency *= defaultAnimationTransparency;
            }
        }
Example #23
0
        /// <summary>
        /// Close the message box when button is clicked.
        /// </summary>
        /// <param name="sender">Clicked control.</param>
        private void OnClick(UIComponent sender)
        {
            // Go through button list, check what result to return.
            // Note that cancel is the default result, so no need to look for
            // that.
            for (int i = 0; i < this.buttonList.Count; i++)
            {
                if (sender == this.buttonList[i])
                {
                    if (i == 0)
                    {
                        if (this.buttons == MessageBoxButtons.OK || this.buttons == MessageBoxButtons.OK_Cancel)
                            SetDialogResult(DialogResult.OK);
                        else
                            SetDialogResult(DialogResult.Yes);
                    }
                    else if (i == 1)
                    {
                        if (this.buttons != MessageBoxButtons.OK_Cancel)
                            SetDialogResult(DialogResult.No);
                    }

                    break;
                }
            }

            CloseWindow();
        }
Example #24
0
        /// <summary>
        /// Update child controls.
        /// </summary>
        /// <param name="sender">Resizing control.</param>
        protected override void OnResize(UIComponent sender)
        {
            base.OnResize(sender);

            // Width
            this.box.Width = Width;
            this.titleBar.Width = Width;
            this.movableArea.Width = Width;
            this.closeButton.X = Width - this.closeButton.Width - this.closeButton.Y;

            // Resize label
            if (this.hasCloseButton)
                this.label.Width = Width - this.closeButton.Width - this.closeButton.Y - (this.margin * 2);
            else
                this.label.Width = Width - (this.margin * 2);

            this.viewPort.Width = Width - (this.margin * 2);
            this.backgroundMovableArea.Width = this.viewPort.Width;

            // Height
            this.box.Height = Height;
            this.viewPort.Height = Height - TitleBarHeight - this.margin;
            this.backgroundMovableArea.Height = this.viewPort.Height;

            RefreshResizableAreas();

            // If resizing, change transparency
            if (IsAnimating && this.transparency == -1)
            {
                //this.transparency = Transparency;
                //Transparency *= defaultAnimationTransparency;
            }
        }
Example #25
0
 /// <summary>
 /// This event handler is called when the button is clicked. It simply
 /// relays the event to the event handler of this control.
 /// </summary>
 /// <param name="sender">Clicked control.</param>
 public void OnClick(UIComponent sender)
 {
     if (Click != null)
         Click.Invoke(this);
 }
Example #26
0
 /// <summary>
 /// Don't check mouse status during animation.
 /// </summary>
 /// <param name="sender">Animating control.</param>
 private void OnEndAnimating(UIComponent sender)
 {
     IsAnimating = false;
     // Reset transparency
     if (this.transparency != -1)
     {
         //Transparency = this.transparency;
         //this.transparency = -1;
     }
 }
Example #27
0
        /// <summary>
        /// Update highlight size.
        /// </summary>
        /// <param name="sender">Resized control</param>
        protected override void OnResize(UIComponent sender)
        {
            base.OnResize(sender);

            this.highlightBox.Width = Width;
            this.highlightBox.Height = Height;

            this.arrow.X = Width - this.arrow.Width - this.hMargin;
            this.arrow.Y = (Height - this.arrow.Height) / 2;
        }
Example #28
0
 /// <summary>
 /// Don't check mouse status during animation.
 /// </summary>
 /// <param name="sender">Animating control.</param>
 private void OnStartAnimating(UIComponent sender)
 {
     IsAnimating = true;
 }
Example #29
0
        /// <summary>
        /// Overloaded to refresh control positions after menu items are
        /// removed.
        /// </summary>
        /// <param name="control">Control to remove.</param>
        /// <returns>TRUE if control exists, otherwise FALSE.</returns>
        public override bool Remove(UIComponent control)
        {
            bool result = false;

            if (base.Remove(control))
            {
                this.menuItems.Remove((MenuItem)control);
                RefreshMenuItems();
                result = true;
            }

            return result;
        }
Example #30
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="game">The currently running Game object.</param>
        /// <param name="guiManager">GUIManager that this control is part of.</param>
        public Window(Game game, GUIManager guiManager)
            : base(game, guiManager)
        {
            this.isResizable = true;
            this.transparency = -1;

            #region Create Child Controls
            this.box = new Box(game, guiManager);
            this.viewPort = new UIComponent(game, guiManager);
            this.titleBar = new Bar(game, guiManager);
            this.movableArea = new MovableArea(game, guiManager);
            this.backgroundMovableArea = new MovableArea(game, guiManager);
            this.label = new Label(game, guiManager);
            this.closeButton = new ImageButton(game, guiManager);
            #endregion

            #region Add Child Controls
            base.Add(this.box);
            base.Add(this.viewPort);
            base.Add(this.titleBar);
            base.Add(this.label);
            base.Add(this.movableArea);
            #endregion

            #region Add Resizable Areas
            this.resizableAreas = new ResizableArea[8];

            for (int i = 0; i < 8; i++)
            {
                this.resizableAreas[i] = new ResizableArea(game, guiManager);
                this.resizableAreas[i].ZOrder = 0.3f;
                this.resizableAreas[i].StartResizing += new StartResizingHandler(OnStartAnimating);
                this.resizableAreas[i].EndResizing += new EndResizingHandler(OnEndAnimating);
                base.Add(this.resizableAreas[i]);
            }

            this.resizableAreas[0].ResizeArea = ResizeAreas.TopLeft;
            this.resizableAreas[1].ResizeArea = ResizeAreas.Top;
            this.resizableAreas[2].ResizeArea = ResizeAreas.TopRight;
            this.resizableAreas[3].ResizeArea = ResizeAreas.Left;
            this.resizableAreas[4].ResizeArea = ResizeAreas.Right;
            this.resizableAreas[5].ResizeArea = ResizeAreas.BottomLeft;
            this.resizableAreas[6].ResizeArea = ResizeAreas.Bottom;
            this.resizableAreas[7].ResizeArea = ResizeAreas.BottomRight;
            #endregion

            #region Set Non-Default Properties
            this.movableArea.ZOrder = 0.1f;
            this.closeButton.ZOrder = 0.4f;
            this.viewPort.ZOrder = 0.2f;
            this.viewPort.CanHaveFocus = true;
            MinWidth = 150;
            #endregion

            #region Set Default Properties
            Margin = defaultMargin;
            HasCloseButton = defaultHasCloseButton;
            HasFullWindowMovableArea = defaultFullWindowMovableArea;
            TitleBarHeight = defaultTitleBarHeight;
            Width = MinWidth;
            Height = MinHeight;
            ButtonSize = defaultButtonSize;
            Skin = defaultSkin;
            TitleBarSkin = defaultTitleBarSkin;
            CloseButtonSkin = defaultCloseButtonSkin;
            CloseButtonHoverSkin = defaultCloseButtonHoverSkin;
            CloseButtonPressedSkin = defaultCloseButtonPressedSkin;
            #endregion

            #region Event Handlers
            this.closeButton.Click += new ClickHandler(OnClose);
            this.movableArea.StartMoving += new StartMovingHandler(OnStartAnimating);
            this.movableArea.EndMoving += new EndMovingHandler(OnEndAnimating);
            this.backgroundMovableArea.StartMoving += new StartMovingHandler(OnStartAnimating);
            this.backgroundMovableArea.EndMoving += new EndMovingHandler(OnEndAnimating);
            #endregion

            Refresh();
        }
Example #31
0
 /// <summary>
 /// When the parent control is resized, fill the entire width.
 /// </summary>
 /// <param name="sender">Resized control.</param>
 protected override void OnParentResized(UIComponent sender)
 {
     base.OnParentResized(sender);
     Width = sender.Width;
 }
Example #32
0
        /// <summary>
        /// Refresh child controls when control is resized.
        /// </summary>
        /// <param name="sender">Resized control.</param>
        protected override void OnResize(UIComponent sender)
        {
            base.OnResize(sender);

            if (this.buttonBar != null)
            {
                this.buttonBar.Width = Width;
                this.buttonBar.Height = Height;
            }

            if (this.label != null)
                RefreshLabelPosition();
        }