//////////////////////////////////////////////////////////////////////////// private void SetValue(MouseEventArgs e) { Point p = new Point(e.Position.X, e.Position.Y); Value = (int)(100-((((float)Width - (float)p.X) / (float)Width) * (float)100)); ; Value = (int)MathHelper.Clamp(Value, 0.0f, 100.0f); }
void btn_MouseOver(object sender, MouseEventArgs e) { txt.Items.Add((sender == btn ? "Button" : "List") + ": Over"); txt.ItemIndex = txt.Items.Count - 1; }
void btn_MouseUp(object sender, MouseEventArgs e) { txt.Items.Add((sender == btn ? "Button" : "List") + ": Up " + e.Button.ToString()); txt.ItemIndex = txt.Items.Count - 1; }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMousePress(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button == MouseButton.Left) { int pos = e.Position.X; if (pos < btnSlider.Left) { Value -= pageSize; } else if (pos >= btnSlider.Left + btnSlider.Width) { Value += pageSize; } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); int i = lastIndex; TrackItem((int)e.State.X - Root.AbsoluteLeft, (int)e.State.Y - Root.AbsoluteTop); if (ItemIndex >= 0 && (i == -1 || i != ItemIndex) && Items[ItemIndex].Items != null && Items[ItemIndex].Items.Count > 0 && ChildMenu != null) { HideSubMenu(); lastIndex = ItemIndex; OnClick(e); } else if (ChildMenu != null && i != ItemIndex) { HideSubMenu(); Focused = true; } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// void Input_MouseDown(object sender, MouseEventArgs e) { if (ReadOnly && (e.Position.X >= AbsoluteLeft && e.Position.X <= AbsoluteLeft + Width && e.Position.Y >= AbsoluteTop && e.Position.Y <= AbsoluteTop + Height)) return; if (lstCombo.Visible && (e.Position.X < lstCombo.AbsoluteLeft || e.Position.X > lstCombo.AbsoluteLeft + lstCombo.Width || e.Position.Y < lstCombo.AbsoluteTop || e.Position.Y > lstCombo.AbsoluteTop + lstCombo.Height) && (e.Position.X < btnDown.AbsoluteLeft || e.Position.X > btnDown.AbsoluteLeft + btnDown.Width || e.Position.Y < btnDown.AbsoluteTop || e.Position.Y > btnDown.AbsoluteTop + btnDown.Height)) { //lstCombo.Visible = false; btnDown_Click(sender, e); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (tabPages.Count > 1) { Point p = new Point(e.State.X - Root.AbsoluteLeft, e.State.Y - Root.AbsoluteTop); for (int i = 0; i < tabPages.Count; i++) { Rectangle r = tabPages[i].HeaderRect; if (p.X >= r.Left && p.X <= r.Right && p.Y >= r.Top && p.Y <= r.Bottom) { SelectedIndex = i; break; } } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void AdjustPosition(ref MouseEventArgs e) { Rectangle screen = manager.Game.Window.ClientBounds; if (e.Position.X < 0) e.Position.X = 0; if (e.Position.Y < 0) e.Position.Y = 0; if (e.Position.X >= screen.Width) e.Position.X = screen.Width - 1; if (e.Position.Y >= screen.Height) e.Position.Y = screen.Height - 1; }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void BuildMouseEvent(MouseState state, MouseButton button, ref MouseEventArgs e) { e.State = state; e.Button = button; e.Position = new Point((int)(mouseState.X * manager.ScreenWidth), (int)(mouseState.Y * manager.ScreenHeight)); AdjustPosition(ref e); e.Position = RecalcPosition(e.Position); e.State = new MouseState(e.State.LeftButton, e.State.MiddleButton, e.State.RightButton, e.State.XButton1, e.State.XButton2, e.Position.X, e.Position.Y, e.State.WheelDelta); Point pos = RecalcPosition(new Point((int)(mouseState.X * manager.ScreenWidth), (int)(mouseState.Y * manager.ScreenHeight))); e.Difference = new Point(e.Position.X - pos.X, e.Position.Y - pos.Y); }
/// <summary> /// Handles mouse down events for the tab control. /// </summary> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); // More than one tab page? if (tabPages.Count > 1) { // Convert mouse position to relative offset. Point p = new Point(e.State.X - Root.AbsoluteLeft, e.State.Y - Root.AbsoluteTop); // See if any of the tab page headers were clicked. for (int i = 0; i < tabPages.Count; i++) { Rectangle r = tabPages[i].HeaderRect; // Select page if mouse position is within header. if (p.X >= r.Left && p.X <= r.Right && p.Y >= r.Top && p.Y <= r.Bottom) { SelectedIndex = i; break; } } } }
/// <summary> /// Handles mouse move events for the tab control. /// </summary> /// <param name="e"></param> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // More than one tab page control created? if (tabPages.Count > 1) { int index = hoveredIndex; // Get mouse position as a relative offset from the tab control. Point p = new Point(e.State.X - Root.AbsoluteLeft, e.State.Y - Root.AbsoluteTop); // Determine if the mouse is hovering any of the tab page headers. for (int i = 0; i < tabPages.Count; i++) { Rectangle r = tabPages[i].HeaderRect; // Mouse is within the current header region? if (p.X >= r.Left && p.X <= r.Right && p.Y >= r.Top && p.Y <= r.Bottom && tabPages[i].Enabled) { index = i; break; } else { index = -1; } } // Update the hovered tab page header index? if (index != hoveredIndex) { hoveredIndex = index; Invalidate(); } } }
void slider_MouseUp(object sender, MouseEventArgs e) { bSliderDown = false; }
void slider_MouseMove(object sender, MouseEventArgs e) { if (bSliderDown) { delta = p.X - e.Position.X; Value -= (int)(delta / 1.5); } }
void slider_MouseDown(object sender, MouseEventArgs e) { bSliderDown = true; p = new Point(e.Position.X, e.Position.Y); }
//////////////////////////////////////////////////////////////////////////// protected override void OnMouseScroll(MouseEventArgs e) { if (!ClientArea.Enabled) return; // If current control doesn't scroll, scroll the parent control if (sbVert.Range - sbVert.PageSize < 1) { Control c = this; while (c != null) { var p = c.Parent as Container; if (p != null && p.Enabled) { p.OnMouseScroll(e); break; } c = c.Parent; } return; } if (e.ScrollDirection == MouseScrollDirection.Down) sbVert.ScrollDown(ScrollAlot); else sbVert.ScrollUp(ScrollAlot); base.OnMouseScroll(e); }
//////////////////////////////////////////////////////////////////////////// private void BuildMouseEvent(MouseState state, MouseButton button, MouseScrollDirection direction, ref MouseEventArgs e) { BuildMouseEvent(state, button, ref e); e.ScrollDirection = direction; }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (ReadOnly && e.Button == MouseButton.Left) { btnDown_Click(this, new MouseEventArgs()); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void UpdateButtons(MouseState state, GameTime gameTime) { #if (!XBOX && !XBOX_FAKE) MouseEventArgs e = new MouseEventArgs(); foreach (InputMouseButton btn in mouseButtons) { ButtonState bs; // = ButtonState.Released; if (btn.Button == MouseButton.Left) bs = state.LeftButton; else if (btn.Button == MouseButton.Right) bs = state.RightButton; else if (btn.Button == MouseButton.Middle) bs = state.MiddleButton; else if (btn.Button == MouseButton.XButton1) bs = state.XButton1; else if (btn.Button == MouseButton.XButton2) bs = state.XButton2; else continue; bool pressed = (bs.Down); if (pressed) { double ms = gameTime.ElapsedGameTime.TotalMilliseconds; if (pressed) btn.Countdown -= ms; } if ((pressed) && (!btn.Pressed)) { btn.Pressed = true; BuildMouseEvent(state, btn.Button, ref e); if (MouseDown != null) MouseDown.Invoke(this, e); if (MousePress != null) MousePress.Invoke(this, e); } else if ((!pressed) && (btn.Pressed)) { btn.Pressed = false; btn.Countdown = RepeatDelay; BuildMouseEvent(state, btn.Button, ref e); if (MouseUp != null) MouseUp.Invoke(this, e); } else if (btn.Pressed && btn.Countdown < 0) { e.Button = btn.Button; btn.Countdown = RepeatRate; BuildMouseEvent(state, btn.Button, ref e); if (MousePress != null) MousePress.Invoke(this, e); } } #endif }
//////////////////////////////////////////////////////////////////////////// protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (HotTrack) { TrackItem(e.Position.X, e.Position.Y); } }
//////////////////////////////////////////////////////////////////////////// private void UpdateMouse(MouseState state, GameTime gameTime) { #if (!XBOX && !XBOX_FAKE) if ((state.X != mouseState.X) || (state.Y != mouseState.Y)) { MouseEventArgs e = new MouseEventArgs(); MouseButton btn = MouseButton.None; if (state.LeftButton.Down) btn = MouseButton.Left; else if (state.RightButton.Down) btn = MouseButton.Right; else if (state.MiddleButton.Down) btn = MouseButton.Middle; else if (state.XButton1.Down) btn = MouseButton.XButton1; else if (state.XButton2.Down) btn = MouseButton.XButton2; BuildMouseEvent(state, btn, ref e); if (MouseMove != null) { MouseMove.Invoke(this, e); } } // Mouse wheel position changed if (state.WheelDelta != mouseState.WheelDelta) { MouseEventArgs e = new MouseEventArgs(); MouseScrollDirection direction = state.WheelDelta < mouseState.WheelDelta ? MouseScrollDirection.Down : MouseScrollDirection.Up; BuildMouseEvent(state, MouseButton.None, direction, ref e); if (MouseScroll != null) { MouseScroll.Invoke(this, e); } } UpdateButtons(state, gameTime); mouseState = state; #endif }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (tabPages.Count > 1) { int index = hoveredIndex; Point p = new Point(e.State.X - Root.AbsoluteLeft, e.State.Y - Root.AbsoluteTop); for (int i = 0; i < tabPages.Count; i++) { Rectangle r = tabPages[i].HeaderRect; if (p.X >= r.Left && p.X <= r.Right && p.Y >= r.Top && p.Y <= r.Bottom && tabPages[i].Enabled) { index = i; break; } else { index = -1; } } if (index != hoveredIndex) { hoveredIndex = index; Invalidate(); } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// void ArrowPress(object sender, MouseEventArgs e) { if (e.Button == MouseButton.Left) { if (sender == btnMinus) { ScrollUp(); } else if (sender == btnPlus) { ScrollDown(); } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseUp(MouseEventArgs e) { btnSlider.Passive = false; base.OnMouseUp(e); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseOut(MouseEventArgs e) { base.OnMouseOut(e); OnMouseMove(e); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); btnSlider.Passive = true; if (e.Button == MouseButton.Left) { if (orientation == Orientation.Horizontal) { int pos = e.Position.X; if (pos < btnSlider.Left) { ScrollUp(true); } else if (pos >= btnSlider.Left + btnSlider.Width) { ScrollDown(true); } } else { int pos = e.Position.Y; if (pos < btnSlider.Top) { ScrollUp(true); } else if (pos >= btnSlider.Top + btnSlider.Height) { ScrollDown(true); } } } }
void btn_MousePress(object sender, MouseEventArgs e) { // txt.Items.Add((sender == btn ? "Button" : "List") + ": Press"); // txt.ItemIndex = txt.Items.Count - 1; }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void btn_MousePress(object sender, MouseEventArgs e) { Focused = true; if (sender == btnUp) ShiftIndex(true); else if (sender == btnDown) ShiftIndex(false); }
void lst_MouseScroll(object sender, MouseEventArgs e) { txt.Items.Add((sender == btn ? "Button" : "List") + ": Scroll"); txt.ItemIndex = txt.Items.Count - 1; }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); bMouseDown = false; }