// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called when the mouse has left a hover state. Override to add /// mouse hover handling code. /// </summary> internal protected virtual void OnMouseHoverEnd(MouseData mouseData) { if (MouseHoverEnd != null) { MouseHoverEnd(this, new MouseEventArgs(mouseData)); } }
// ///////////////////////////////////////////////////////////////////////////////// #endregion #region Mouse Input // ///////////////////////////////////////////////////////////////////////////////// private void PollMouse(uint totalElapsed) { MouseData mouse = new MouseData(TCODMouse.getStatus()); CheckMouseButtons(mouse); // check for mouse move //if (mouse.Position != lastMousePosition) //{ // DoMouseMove(mouse); // lastMousePosition = mouse.Position; // lastMouseMoveTime = totalElapsed; //} if (mouse.PixelPosition != lastMousePixelPosition) { DoMouseMove(mouse); lastMousePosition = mouse.Position; lastMousePixelPosition = mouse.PixelPosition; lastMouseMoveTime = totalElapsed; } // check for hover if ((totalElapsed - lastMouseMoveTime) > hoverMSTol && isHovering == false) { StartHover(mouse); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// private void StartDrag(MouseData mouse) { isDragging = true; // TODO fix this, it does not pass origin of drag as intended attachedComponent.OnMouseDragBegin(mouse.Position); }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> internal protected override void OnMouseMoved(MouseData mouseData) { base.OnMouseMoved(mouseData); foreach (Manager m in managerList) { m.OnMouseMoved(mouseData); } Control checkUnderMouse = GetTopControlAt(mouseData.Position); if (checkUnderMouse != CurrentUnderMouse) { // check for Leave and Enter actions if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseLeave(); } if (checkUnderMouse != null && checkUnderMouse.IsActive) { checkUnderMouse.OnMouseEnter(); } CurrentUnderMouse = checkUnderMouse; } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseMoved(mouseData); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called when a previously pressed mouse button has been released. Override to /// add mouse button handling code. /// </summary> internal protected virtual void OnMouseButtonUp(MouseData mouseData) { if (MouseButtonUp != null) { MouseButtonUp(this, new MouseEventArgs(mouseData)); } }
/// <summary> /// Construct a MouseEventArgs given the MouseData /// </summary> /// <param name="mouseData"></param> public MouseEventArgs(MouseData mouseData) { if (mouseData == null) { throw new ArgumentNullException("mouseData"); } this.mouseData = mouseData; }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// private void DoMouseButtonUp(MouseData mouse) { if (isDragging) { StopDrag(mouse); } attachedComponent.OnMouseButtonUp(mouse); }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method sets the IsBeingPushed state if applicable. Override to add /// custom handling code after calling this base method. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseButtonUp(MouseData mouseData) { base.OnMouseButtonUp(mouseData); if (mouseData.MouseButton == MouseButton.LeftButton) { IsBeingPushed = false; } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method detects if a menu item was selected, and calls OnItemSelected if this /// is the case. Override to add custom handling. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); if (mouseOverIndex != -1) { OnItemSelected(mouseOverIndex); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called when the mouse has moved to a new cell position. Override to add /// mouse move handling code. /// </summary> internal protected virtual void OnMouseMoved(MouseData mouseData) { CurrentMousePos = mouseData.Position; if (MouseMoved != null) { MouseMoved(this, new MouseEventArgs(mouseData)); } }
// ///////////////////////////////////////////////////////////////////////////////// #endregion #region Message Handlers // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called when a mouse button is released while over this button. Triggers proper /// events. Override to add custom handling. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseButtonUp(MouseData mouseData) { bool wasBeingPushed = IsBeingPushed; // store, since base call will reset this to false base.OnMouseButtonUp(mouseData); if (mouseData.MouseButton == MouseButton.LeftButton && wasBeingPushed) { OnButtonPushed(); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Detects which, if any, item has been selected by a left mouse button. Override /// to add custom handling. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); if (mouseOverIndex != -1) { if (CurrentSelected != mouseOverIndex) { CurrentSelected = mouseOverIndex; OnItemSelected(CurrentSelected); } } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> internal protected override void OnMouseHoverBegin(MouseData mouseData) { base.OnMouseHoverBegin(mouseData); foreach (Manager m in managerList) { m.OnMouseHoverBegin(mouseData); } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseHoverBegin(mouseData); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// private void DoMouseButtonDown(MouseData mouse) { if (isDragging) { StopDrag(mouse); } if (mouse.MouseButton == MouseButton.LeftButton) { startLBDown = mouse.PixelPosition; } attachedComponent.OnMouseButtonDown(mouse); }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> internal protected override void OnMouseButtonUp(MouseData mouseData) { base.OnMouseButtonUp(mouseData); foreach (Manager m in managerList) { m.OnMouseButtonUp(mouseData); } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseButtonUp(mouseData); } LastLBDown = null; }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// private void CheckMouseButtons(MouseData mouse) { if (mouse.MouseButton != lastMouseButton) { if (lastMouseButton == MouseButton.None) { DoMouseButtonDown(mouse); } else { DoMouseButtonUp(new MouseData(lastMouseButton, mouse.Position, mouse.PixelPosition)); } lastMouseButton = mouse.MouseButton; } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method detects if the mouse pointer is currently over a menu items and /// sets the state accordingly. Override to add custom handling. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseMoved(MouseData mouseData) { base.OnMouseMoved(mouseData); Point lPos = ScreenToLocal(mouseData.Position); mouseOverIndex = GetItemAt(lPos); if (mouseOverIndex != -1) { TooltipText = Items[mouseOverIndex].TooltipText; } else { TooltipText = null; } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// private void DoMouseMove(MouseData mouse) { StopHover(mouse); attachedComponent.OnMouseMoved(mouse); // check for BeginDrag if (mouse.MouseButton == MouseButton.LeftButton) { int delta = Math.Abs(mouse.PixelPosition.X - startLBDown.X) + Math.Abs(mouse.PixelPosition.Y - startLBDown.Y); if (delta > dragPixelTol && isDragging == false) { StartDrag(mouse); } } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> internal protected override void OnMouseHoverEnd(MouseData mouseData) { if (CurrentTooltip != null) { CurrentTooltip.Dispose(); CurrentTooltip = null; } base.OnMouseHoverEnd(mouseData); foreach (Manager m in managerList) { m.OnMouseHoverEnd(mouseData); } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseHoverEnd(mouseData); } }
// ///////////////////////////////////////////////////////////////////////////////// #endregion #region Message Handlers // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Triggers appropriate events based on a mouse button down action. Override to /// add custom mouse button handling code. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); if (mouseData.MouseButton == MouseButton.LeftButton) { if (IsChecked) { IsChecked = false; } else { IsChecked = true; } if (CheckBoxToggled != null) { CheckBoxToggled(this, EventArgs.Empty); } } }
// ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> internal protected override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); foreach (Manager m in managerList) { m.OnMouseButtonDown(mouseData); } // If applicable, forward MouseDown and Select to child control if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseButtonDown(mouseData); LastLBDown = CurrentUnderMouse; } // Check to see if a control looses KBFocus if user hit any mouse button outside current focused control if (CurrentKeyboardFocus != null) { if (CurrentKeyboardFocus != CurrentUnderMouse) { CurrentKeyboardFocus.OnReleaseKeyboardFocus(); CurrentKeyboardFocus = null; } } // Give KBFocus to child on left button down, if applicable if (CurrentUnderMouse != null && CurrentUnderMouse.CanHaveKeyboardFocus && CurrentUnderMouse.HasKeyboardFocus == false && mouseData.MouseButton == MouseButton.LeftButton && CurrentUnderMouse.IsActive) { CurrentKeyboardFocus = CurrentUnderMouse; CurrentKeyboardFocus.OnTakeKeyboardFocus(); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called when a previously pressed mouse button has been released. Override to /// add mouse button handling code. /// </summary> protected internal virtual void OnMouseButtonUp(MouseData mouseData) { if (MouseButtonUp != null) { MouseButtonUp(this, new MouseEventArgs(mouseData)); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method requests that a tooltip be displayed, calling this.DetermineTooltipText() /// to get the displayed text. Override to add custom handling code after calling /// this base method. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseHoverBegin(MouseData mouseData) { base.OnMouseHoverBegin(mouseData); ParentWindow.ShowTooltip(DetermineTooltipText(), mouseData.Position); }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method detects if the mouse is over one of the items, and changes state /// accordingly. Override to add custom handling. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseMoved(MouseData mouseData) { base.OnMouseMoved(mouseData); Point lPos = ScreenToLocal(mouseData.Position); mouseOverIndex = GetItemAt(lPos); if (mouseOverIndex != -1) { TooltipText = Items[mouseOverIndex].TooltipText; } else { TooltipText = null; } }
protected override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); if (mouseData.MouseButton == MouseButton.RightButton) { Menu menu = new Menu(new MenuTemplate() { Items = new System.Collections.Generic.List<MenuItemData>() { new MenuItemData("Menu Item 1","Selected Menu Item 1"), new MenuItemData("Menu Item 2","Selected Menu Item 2"), new MenuItemData("Menu Item 3","Selected Menu Item 3"), new MenuItemData("Menu Item 4","Selected Menu Item 4") }, UpperLeftPos = mouseData.Position, }); ParentWindow.AddControl(menu); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> protected internal override void OnMouseMoved(MouseData mouseData) { base.OnMouseMoved(mouseData); foreach (Manager m in managerList) { m.OnMouseMoved(mouseData); } Control checkUnderMouse = GetTopControlAt(mouseData.Position); if (checkUnderMouse != CurrentUnderMouse) { // check for Leave and Enter actions if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseLeave(); } if (checkUnderMouse != null && checkUnderMouse.IsActive) { checkUnderMouse.OnMouseEnter(); } CurrentUnderMouse = checkUnderMouse; } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseMoved(mouseData); } }
// ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> protected internal override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); foreach (Manager m in managerList) { m.OnMouseButtonDown(mouseData); } // If applicable, forward MouseDown and Select to child control if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseButtonDown(mouseData); LastLBDown = CurrentUnderMouse; } // Check to see if a control looses KBFocus if user hit any mouse button outside current focused control if (CurrentKeyboardFocus != null) { if (CurrentKeyboardFocus != CurrentUnderMouse) { CurrentKeyboardFocus.OnReleaseKeyboardFocus(); CurrentKeyboardFocus = null; } } // Give KBFocus to child on left button down, if applicable if (CurrentUnderMouse != null && CurrentUnderMouse.CanHaveKeyboardFocus && CurrentUnderMouse.HasKeyboardFocus == false && mouseData.MouseButton == MouseButton.LeftButton && CurrentUnderMouse.IsActive) { CurrentKeyboardFocus = CurrentUnderMouse; CurrentKeyboardFocus.OnTakeKeyboardFocus(); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> protected internal override void OnMouseHoverBegin(MouseData mouseData) { base.OnMouseHoverBegin(mouseData); foreach (Manager m in managerList) { m.OnMouseHoverBegin(mouseData); } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseHoverBegin(mouseData); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called when the mouse has left a hover state. Override to add /// mouse hover handling code. /// </summary> protected internal virtual void OnMouseHoverEnd(MouseData mouseData) { if (MouseHoverEnd != null) { MouseHoverEnd(this, new MouseEventArgs(mouseData)); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called when the mouse has moved to a new cell position. Override to add /// mouse move handling code. /// </summary> protected internal virtual void OnMouseMoved(MouseData mouseData) { CurrentMousePos = mouseData.Position; if (MouseMoved != null) { MouseMoved(this, new MouseEventArgs(mouseData)); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called by the framework when a mouse button is released while over this control. /// Base method removes the schedules for the emit cycle. /// </summary> /// <param name="mouseData"></param> protected override void OnMouseButtonUp(MouseData mouseData) { base.OnMouseButtonUp(mouseData); if (mouseData.MouseButton == MouseButton.LeftButton) { RemoveSchedule(EmitSchedule); RemoveSchedule(CountdownSchedule); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// private void StartHover(MouseData mouse) { attachedComponent.OnMouseHoverBegin(mouse); isHovering = true; }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// private void StopDrag(MouseData mouse) { isDragging = false; attachedComponent.OnMouseDragEnd(mouse.Position); }
/// Usually, to add a tooltip, we would set a Control's TooltTipText property to the desired text. However, /// here we are adding a tooltip to the entire window, so this won't work. Window's do not provide automatic /// tooltip support (probably because it is usually a bad idea). Fortunately, adding tooltips /// to a window is fairly easy. We just override OnMouseHoverBegin, and call ShowTooltip(). The framework /// handles closing the tooltip automatically when the mouse moves. protected override void OnMouseHoverBegin(MouseData mouseData) { base.OnMouseHoverBegin(mouseData); /// We only show the tooltip when the mouse pointer is at the same position as the player position. if(mouseData.Position == currentPos) ShowTooltip("It's you!", mouseData.Position); }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> protected internal override void OnMouseButtonUp(MouseData mouseData) { base.OnMouseButtonUp(mouseData); foreach (Manager m in managerList) { m.OnMouseButtonUp(mouseData); } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseButtonUp(mouseData); } LastLBDown = null; }
// ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called by the framework when a mouse button is pressed while over this button. /// Base method creates and starts the schedules for the emit cycle. /// </summary> /// <param name="mouseData"></param> protected override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); if (mouseData.MouseButton == MouseButton.LeftButton) { DoStartEmitting(); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> protected internal override void OnMouseHoverEnd(MouseData mouseData) { if (CurrentTooltip != null) { CurrentTooltip.Dispose(); CurrentTooltip = null; } base.OnMouseHoverEnd(mouseData); foreach (Manager m in managerList) { m.OnMouseHoverEnd(mouseData); } if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseHoverEnd(mouseData); } }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// private void StopHover(MouseData mouse) { attachedComponent.OnMouseHoverEnd(mouse); isHovering = false; }
// ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Triggers appropriate events based on a mouse button down action. Override to /// add custom mouse button handling code. /// </summary> /// <param name="mouseData"></param> protected internal override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); if (mouseData.MouseButton == MouseButton.LeftButton) { if (IsChecked) { IsChecked = false; } else { IsChecked = true; } if (CheckBoxToggled != null) { CheckBoxToggled(this, EventArgs.Empty); } } }