mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-23 04:34:58 -04:00
Use precise mouse wheel delta everywhere.
This commit is contained in:
parent
985f76fd6b
commit
99ca17407d
@ -42,7 +42,7 @@ namespace ClassicalSharp.Gui {
|
||||
|
||||
public virtual bool HandlesMouseMove(int mouseX, int mouseY) { return false; }
|
||||
|
||||
public virtual bool HandlesMouseScroll(int delta) { return false; }
|
||||
public virtual bool HandlesMouseScroll(float delta) { return false; }
|
||||
|
||||
public virtual bool HandlesMouseUp(int mouseX, int mouseY, MouseButton button) { return false; }
|
||||
|
||||
|
@ -388,9 +388,11 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandlesMouseScroll(int delta) {
|
||||
float chatAcc;
|
||||
public override bool HandlesMouseScroll(float delta) {
|
||||
if (!HandlesAllInput) return false;
|
||||
chatIndex -= delta;
|
||||
int steps = Utils.AccumulateWheelDelta(ref chatAcc, delta);
|
||||
chatIndex -= steps;
|
||||
ScrollHistory();
|
||||
return true;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
return HandleMouseMove(widgets, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public override bool HandlesMouseScroll(int delta) { return true; }
|
||||
public override bool HandlesMouseScroll(float delta) { return true; }
|
||||
|
||||
public override bool HandlesMouseUp(int mouseX, int mouseY, MouseButton button) { return true; }
|
||||
|
||||
|
@ -173,7 +173,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
chat.OpenTextInputBar(text);
|
||||
}
|
||||
|
||||
public override bool HandlesMouseScroll(int delta) {
|
||||
public override bool HandlesMouseScroll(float delta) {
|
||||
return chat.HandlesMouseScroll(delta);
|
||||
}
|
||||
|
||||
|
@ -40,14 +40,16 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
height = Math.Min(y + height, TableHeight - scrollBorder) - y;
|
||||
}
|
||||
|
||||
public override bool HandlesMouseScroll(int delta) {
|
||||
float invAcc;
|
||||
public override bool HandlesMouseScroll(float delta) {
|
||||
bool bounds = Contains(TableX - scrollWidth, TableY, TableWidth + scrollWidth,
|
||||
TableHeight, game.Mouse.X, game.Mouse.Y);
|
||||
bool hotbar = game.Input.AltDown || game.Input.ControlDown || game.Input.ShiftDown;
|
||||
if (!bounds || hotbar) return false;
|
||||
|
||||
int rowY = (selIndex / blocksPerRow) - scrollY;
|
||||
scrollY -= delta;
|
||||
int steps = Utils.AccumulateWheelDelta(ref invAcc, delta);
|
||||
scrollY -= steps;
|
||||
ClampScrollY();
|
||||
if (selIndex == - 1) return true;
|
||||
|
||||
|
@ -107,7 +107,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override bool HandlesMouseMove(int mouseX, int mouseY) { return true; }
|
||||
|
||||
public override bool HandlesMouseScroll(int delta) { return true; }
|
||||
public override bool HandlesMouseScroll(float delta) { return true; }
|
||||
|
||||
public override bool HandlesMouseUp(int mouseX, int mouseY, MouseButton button) { return true; }
|
||||
|
||||
|
@ -71,7 +71,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
return HandleMouseMove(widgets, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public override bool HandlesMouseScroll(int delta) { return true; }
|
||||
public override bool HandlesMouseScroll(float delta) { return true; }
|
||||
|
||||
public override bool HandlesKeyPress(char key) { return true; }
|
||||
|
||||
|
@ -131,36 +131,32 @@ namespace ClassicalSharp {
|
||||
}
|
||||
}
|
||||
|
||||
float deltaAcc = 0;
|
||||
float deltaAcc;
|
||||
void MouseWheelChanged(object sender, MouseWheelEventArgs e) {
|
||||
if (game.Gui.ActiveScreen.HandlesMouseScroll(e.Delta)) return;
|
||||
|
||||
Inventory inv = game.Inventory;
|
||||
bool hotbar = AltDown || ControlDown || ShiftDown;
|
||||
if ((!hotbar && game.Camera.Zoom(e.DeltaPrecise)) || DoFovZoom(e.DeltaPrecise) || !inv.CanChangeHeldBlock)
|
||||
if ((!hotbar && game.Camera.Zoom(e.Delta)) || DoFovZoom(e.Delta) || !inv.CanChangeHeldBlock)
|
||||
return;
|
||||
ScrollHotbar(e.DeltaPrecise);
|
||||
ScrollHotbar(e.Delta);
|
||||
}
|
||||
|
||||
void ScrollHotbar(float deltaPrecise) {
|
||||
void ScrollHotbar(float delta) {
|
||||
Inventory inv = game.Inventory;
|
||||
if (AltDown) {
|
||||
int index = inv.Offset / Inventory.BlocksPerRow;
|
||||
inv.Offset = ScrolledIndex(deltaPrecise, index) * Inventory.BlocksPerRow;
|
||||
inv.Offset = ScrolledIndex(delta, index) * Inventory.BlocksPerRow;
|
||||
} else {
|
||||
inv.SelectedIndex = ScrolledIndex(deltaPrecise, inv.SelectedIndex);
|
||||
inv.SelectedIndex = ScrolledIndex(delta, inv.SelectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
int ScrolledIndex(float deltaPrecise, int currentIndex) {
|
||||
// Some mice may use deltas of say (0.2, 0.2, 0.2, 0.2, 0.2)
|
||||
// We must use rounding at final step, not at every intermediate step.
|
||||
deltaAcc += deltaPrecise;
|
||||
int delta = (int)deltaAcc;
|
||||
deltaAcc -= delta;
|
||||
int ScrolledIndex(float delta, int currentIndex) {
|
||||
int steps = Utils.AccumulateWheelDelta(ref deltaAcc, delta);
|
||||
|
||||
const int blocksPerRow = Inventory.BlocksPerRow;
|
||||
int diff = -delta % blocksPerRow;
|
||||
int diff = -steps % blocksPerRow;
|
||||
int index = currentIndex + diff;
|
||||
|
||||
if (index < 0) index += blocksPerRow;
|
||||
|
@ -110,6 +110,15 @@ namespace ClassicalSharp {
|
||||
public static void LogDebug(string text, params object[] args) {
|
||||
Console.WriteLine(String.Format(text, args));
|
||||
}
|
||||
|
||||
public static int AccumulateWheelDelta(ref float accmulator, float delta) {
|
||||
// Some mice may use deltas of say (0.2, 0.2, 0.2, 0.2, 0.2)
|
||||
// We must use rounding at final step, not at every intermediate step.
|
||||
accmulator += delta;
|
||||
int steps = (int)accmulator;
|
||||
accmulator -= steps;
|
||||
return steps;
|
||||
}
|
||||
|
||||
#if !LAUNCHER
|
||||
/// <summary> Attempts to caselessly parse the given string as a Key enum member,
|
||||
|
@ -61,8 +61,10 @@ namespace Launcher.Gui.Screens {
|
||||
}
|
||||
}
|
||||
|
||||
float colourAcc;
|
||||
protected override void MouseWheelChanged(object sender, MouseWheelEventArgs e) {
|
||||
AdjustSelectedColour(e.Delta);
|
||||
int steps = Utils.AccumulateWheelDelta(ref colourAcc, e.Delta);
|
||||
AdjustSelectedColour(steps);
|
||||
}
|
||||
|
||||
protected override void KeyDown(object sender, KeyboardKeyEventArgs e) {
|
||||
|
@ -143,9 +143,11 @@ namespace Launcher.Gui.Screens {
|
||||
Resize();
|
||||
}
|
||||
|
||||
float tableAcc;
|
||||
protected override void MouseWheelChanged(object sender, MouseWheelEventArgs e) {
|
||||
TableWidget table = (TableWidget)widgets[view.tableIndex];
|
||||
table.CurrentIndex -= e.Delta;
|
||||
int steps = Utils.AccumulateWheelDelta(ref tableAcc, e.Delta);
|
||||
table.CurrentIndex -= steps;
|
||||
MarkPendingRedraw();
|
||||
}
|
||||
|
||||
|
@ -40,23 +40,16 @@ namespace OpenTK.Input {
|
||||
MouseButtonEventArgs button_args = new MouseButtonEventArgs();
|
||||
MouseWheelEventArgs wheel_args = new MouseWheelEventArgs();
|
||||
|
||||
/// <summary> Gets the absolute wheel position in integer units.
|
||||
/// To support high-precision mice, it is recommended to use <see cref="WheelPrecise"/> instead. </summary>
|
||||
public int Wheel {
|
||||
get { return (int)Math.Round(wheel, MidpointRounding.AwayFromZero); }
|
||||
internal set { WheelPrecise = value; }
|
||||
}
|
||||
|
||||
/// <summary> Gets the absolute wheel position in floating-point units. </summary>
|
||||
public float WheelPrecise {
|
||||
public float Wheel {
|
||||
get { return wheel; }
|
||||
internal set {
|
||||
wheel = value;
|
||||
|
||||
wheel_args.X = pos.X;
|
||||
wheel_args.Y = pos.Y;
|
||||
wheel_args.ValuePrecise = wheel;
|
||||
wheel_args.DeltaPrecise = wheel - last_wheel;
|
||||
wheel_args.Value = wheel;
|
||||
wheel_args.Delta = wheel - last_wheel;
|
||||
|
||||
WheelChanged(this, wheel_args);
|
||||
|
||||
@ -65,14 +58,10 @@ namespace OpenTK.Input {
|
||||
}
|
||||
|
||||
/// <summary> Gets an integer representing the absolute x position of the pointer, in window pixel coordinates. </summary>
|
||||
public int X {
|
||||
get { return pos.X; }
|
||||
}
|
||||
public int X { get { return pos.X; } }
|
||||
|
||||
/// <summary> Gets an integer representing the absolute y position of the pointer, in window pixel coordinates. </summary>
|
||||
public int Y {
|
||||
get { return pos.Y; }
|
||||
}
|
||||
public int Y { get { return pos.Y; } }
|
||||
|
||||
/// <summary> Gets a System.Boolean indicating the state of the specified MouseButton. </summary>
|
||||
/// <param name="button">The MouseButton to check.</param>
|
||||
@ -149,18 +138,10 @@ namespace OpenTK.Input {
|
||||
|
||||
public class MouseWheelEventArgs : MouseEventArgs {
|
||||
|
||||
/// <summary> Gets the value of the wheel in integer units.
|
||||
/// To support high-precision mice, it is recommended to use <see cref="ValuePrecise"/> instead. </summary>
|
||||
public int Value { get { return (int)Math.Round(ValuePrecise, MidpointRounding.AwayFromZero); } }
|
||||
|
||||
/// <summary> Gets the change in value of the wheel for this event in integer units.
|
||||
/// To support high-precision mice, it is recommended to use <see cref="DeltaPrecise"/> instead. </summary>
|
||||
public int Delta { get { return (int)Math.Round(DeltaPrecise, MidpointRounding.AwayFromZero); } }
|
||||
|
||||
/// <summary> Gets the precise value of the wheel in floating-point units. </summary>
|
||||
public float ValuePrecise;
|
||||
public float Value;
|
||||
|
||||
/// <summary> Gets the precise change in value of the wheel for this event in floating-point units. </summary>
|
||||
public float DeltaPrecise;
|
||||
public float Delta;
|
||||
}
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ namespace OpenTK.Platform.MacOS
|
||||
return OSStatus.NoError;
|
||||
|
||||
case MouseEventKind.WheelMoved:
|
||||
mouse.WheelPrecise += API.GetEventMouseWheelDelta(inEvent);
|
||||
mouse.Wheel += API.GetEventMouseWheelDelta(inEvent);
|
||||
return OSStatus.NoError;
|
||||
|
||||
case MouseEventKind.MouseMoved:
|
||||
|
@ -206,7 +206,7 @@ namespace OpenTK.Platform.Windows
|
||||
case WindowMessage.MOUSEWHEEL:
|
||||
// This is due to inconsistent behavior of the WParam value on 64bit arch, whese
|
||||
// wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000
|
||||
mouse.WheelPrecise += ((long)wParam << 32 >> 48) / 120.0f;
|
||||
mouse.Wheel += ((long)wParam << 32 >> 48) / 120.0f;
|
||||
return IntPtr.Zero;
|
||||
|
||||
case WindowMessage.LBUTTONDOWN:
|
||||
|
@ -34,7 +34,6 @@ namespace OpenTK.Platform.Windows {
|
||||
/// <summary>Describes a win32 window.</summary>
|
||||
public sealed class WinWindowInfo : IWindowInfo {
|
||||
internal IntPtr handle, dc;
|
||||
WinWindowInfo parent;
|
||||
bool disposed;
|
||||
|
||||
/// <summary> Constructs a new instance. </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user