/// <summary> /// Registers event handlers with the input events system, and /// refreshes the control position. /// </summary> public override void Initialize() { foreach (UIComponent control in this.controls) { control.Initialize(); } if (!this.isInitialized) { // Get input event system, and register event handlers this.inputEvents = (IInputEventsService)Game.Services.GetService(typeof(IInputEventsService)); if (this.inputEvents != null) { this.inputEvents.KeyDown += new KeyDownHandler(KeyDownIntercept); this.inputEvents.KeyUp += new KeyUpHandler(KeyUpIntercept); this.inputEvents.MouseDown += new MouseDownHandler(MouseDownIntercept); this.inputEvents.MouseUp += new MouseUpHandler(MouseUpIntercept); this.inputEvents.MouseMove += new MouseMoveHandler(MouseMoveIntercept); } // Refreshing here allows controls to sort themselves out Refresh(); base.Initialize(); this.isInitialized = true; } }
/// <summary> /// Constructor adds game component, and sets up initial cursor. /// </summary> /// <param name="game">The currently running Game object.</param> /// <param name="guiManager">Associated GUIManager object.</param> public MouseCursor(Game game, GUIManager guiManager) : base(game) { this.guiManager = guiManager; // Get input event system this.inputEvents = (IInputEventsService)Game.Services.GetService(typeof(IInputEventsService)); #region Set Default Cursors SetSkinLocation(MouseState.Normal, defaultNormalLocation, defaultNormalOffset); SetSkinLocation(MouseState.Moving, defaultMovingLocation, defaultMovingOffset); SetSkinLocation(MouseState.ResizingNS, defaultResizingNSLocation, defaultResizingNSOffset); SetSkinLocation(MouseState.ResizingWE, defaultResizingWELocation, defaultResizingWEOffset); SetSkinLocation(MouseState.ResizingNWSE, defaultResizingNWSELocation, defaultResizingNWSEOffset); SetSkinLocation(MouseState.ResizingNESW, defaultResizingNESWLocation, defaultResizingNESWOffset); #endregion SetMouseState(MouseState.Normal); }
/// <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; // 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(); }
/// <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.isRedrawRequired = 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.RequiresRedraw += new RequiresRedrawHandler(OnRequiresRedraw); this.GetFocus += new GetFocusHandler(OnGetFocus); this.LoseFocus += new LoseFocusHandler(OnLoseFocus); #endregion instanceCount++; }
/// <summary> /// Constructor adds game component, and sets up initial cursor. /// </summary> /// <param name="game">The currently running Game object.</param> /// <param name="guiManager">Associated GUIManager object.</param> public MouseCursor(Game game, GUIManager guiManager) : base(game) { this.guiManager = guiManager; // Get input event system this.inputEvents = (IInputEventsService)Game.Services.GetService(typeof(IInputEventsService)); // Ensure mouse is ALWAYS drawn on top DrawOrder = int.MaxValue; #region Set Default Cursors SetSkinLocation(MouseState.Normal, defaultNormalLocation, defaultNormalOffset); SetSkinLocation(MouseState.Moving, defaultMovingLocation, defaultMovingOffset); SetSkinLocation(MouseState.ResizingNS, defaultResizingNSLocation, defaultResizingNSOffset); SetSkinLocation(MouseState.ResizingWE, defaultResizingWELocation, defaultResizingWEOffset); SetSkinLocation(MouseState.ResizingNWSE, defaultResizingNWSELocation, defaultResizingNWSEOffset); SetSkinLocation(MouseState.ResizingNESW, defaultResizingNESWLocation, defaultResizingNESWOffset); #endregion SetMouseState(MouseState.Normal); }
/// <summary> /// Registers event handlers with the input events system, and /// refreshes the control position. /// </summary> public override void Initialize() { foreach (UIComponent control in this.controls) control.Initialize(); if (!this.isInitialized) { // Get input event system, and register event handlers this.inputEvents = (IInputEventsService)Game.Services.GetService(typeof(IInputEventsService)); if (this.inputEvents != null) { this.inputEvents.KeyDown += new KeyDownHandler(KeyDownIntercept); this.inputEvents.KeyUp += new KeyUpHandler(KeyUpIntercept); this.inputEvents.MouseDown += new MouseDownHandler(MouseDownIntercept); this.inputEvents.MouseUp += new MouseUpHandler(MouseUpIntercept); this.inputEvents.MouseMove += new MouseMoveHandler(MouseMoveIntercept); } // Refreshing here allows controls to sort themselves out Refresh(); base.Initialize(); this.isInitialized = true; } }
/// <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++; }
/// <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(); }