The engine now uses the SDL2.0 scroll events properly.

Scroll speed is now a user preference.
This commit is contained in:
Saticmotion
2014-05-12 22:04:18 +02:00
parent bad6a99caf
commit 1bf3f3e03e
14 changed files with 69 additions and 57 deletions

View File

@@ -66,6 +66,7 @@ Also thanks to:
* Riderr3 * Riderr3
* Sascha Biedermann (bidifx) * Sascha Biedermann (bidifx)
* Sebastien Kerguen (xanax) * Sebastien Kerguen (xanax)
* Simon Verbeke (Saticmotion)
* Taryn Hill (Phrohdoh) * Taryn Hill (Phrohdoh)
* Teemu Nieminen (Temeez) * Teemu Nieminen (Temeez)
* Tim Mylemans (gecko) * Tim Mylemans (gecko)

View File

@@ -20,19 +20,21 @@ namespace OpenRA
void OnTextInput(string text); void OnTextInput(string text);
} }
public enum MouseInputEvent { Down, Move, Up } public enum MouseInputEvent { Down, Move, Up, Scroll }
public struct MouseInput public struct MouseInput
{ {
public MouseInputEvent Event; public MouseInputEvent Event;
public MouseButton Button; public MouseButton Button;
public int ScrollDelta;
public int2 Location; public int2 Location;
public Modifiers Modifiers; public Modifiers Modifiers;
public int MultiTapCount; public int MultiTapCount;
public MouseInput(MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods, int multiTapCount) public MouseInput(MouseInputEvent ev, MouseButton button, int scrollDelta, int2 location, Modifiers mods, int multiTapCount)
{ {
Event = ev; Event = ev;
Button = button; Button = button;
ScrollDelta = scrollDelta;
Location = location; Location = location;
Modifiers = mods; Modifiers = mods;
MultiTapCount = multiTapCount; MultiTapCount = multiTapCount;
@@ -45,9 +47,7 @@ namespace OpenRA
None = 0, None = 0,
Left = 1, Left = 1,
Right = 2, Right = 2,
Middle = 4, Middle = 4
WheelDown = 8,
WheelUp = 16
} }
[Flags] [Flags]

View File

@@ -131,6 +131,7 @@ namespace OpenRA
public bool ViewportEdgeScroll = true; public bool ViewportEdgeScroll = true;
public MouseScrollType MouseScroll = MouseScrollType.Standard; public MouseScrollType MouseScroll = MouseScrollType.Standard;
public float ViewportEdgeScrollStep = 10f; public float ViewportEdgeScrollStep = 10f;
public float UIScrollSpeed = 50f;
public bool UseClassicMouseStyle = false; public bool UseClassicMouseStyle = false;
public bool AlwaysShowStatusBars = false; public bool AlwaysShowStatusBars = false;

View File

@@ -23,7 +23,6 @@ namespace OpenRA.Widgets
public class ScrollPanelWidget : Widget public class ScrollPanelWidget : Widget
{ {
public int ScrollbarWidth = 24; public int ScrollbarWidth = 24;
public float ScrollVelocity = 4f;
public int ItemSpacing = 2; public int ItemSpacing = 2;
public int ButtonDepth = ChromeMetrics.Get<int>("ButtonDepth"); public int ButtonDepth = ChromeMetrics.Get<int>("ButtonDepth");
public string Background = "scrollpanel-bg"; public string Background = "scrollpanel-bg";
@@ -130,9 +129,9 @@ namespace OpenRA.Widgets
return EventBounds; return EventBounds;
} }
void Scroll(int direction) void Scroll(int amount)
{ {
ListOffset += direction*ScrollVelocity; ListOffset += amount * Game.Settings.Game.UIScrollSpeed;
ListOffset = Math.Min(0,Math.Max(Bounds.Height - ContentHeight, ListOffset)); ListOffset = Math.Min(0,Math.Max(Bounds.Height - ContentHeight, ListOffset));
} }
@@ -188,15 +187,9 @@ namespace OpenRA.Widgets
int2 lastMouseLocation; int2 lastMouseLocation;
public override bool HandleMouseInput(MouseInput mi) public override bool HandleMouseInput(MouseInput mi)
{ {
if (mi.Button == MouseButton.WheelDown) if (mi.Event == MouseInputEvent.Scroll)
{ {
Scroll(-1); Scroll(mi.ScrollDelta);
return true;
}
if (mi.Button == MouseButton.WheelUp)
{
Scroll(1);
return true; return true;
} }

View File

@@ -63,7 +63,6 @@ namespace OpenRA.Mods.Cnc.Widgets
public readonly string PaletteWidget = null; public readonly string PaletteWidget = null;
public readonly string TypesContainer = null; public readonly string TypesContainer = null;
public readonly float ScrollVelocity = 4f;
public readonly int TabWidth = 30; public readonly int TabWidth = 30;
public readonly int ArrowWidth = 20; public readonly int ArrowWidth = 20;
public Dictionary<string, ProductionTabGroup> Groups; public Dictionary<string, ProductionTabGroup> Groups;
@@ -182,9 +181,9 @@ namespace OpenRA.Mods.Cnc.Widgets
Game.Renderer.DisableScissor(); Game.Renderer.DisableScissor();
} }
void Scroll(int direction) void Scroll(int amount)
{ {
listOffset += direction * ScrollVelocity; listOffset += amount * Game.Settings.Game.UIScrollSpeed;
listOffset = Math.Min(0, Math.Max(Bounds.Width - rightButtonRect.Width - leftButtonRect.Width - contentWidth, listOffset)); listOffset = Math.Min(0, Math.Max(Bounds.Width - rightButtonRect.Width - leftButtonRect.Width - contentWidth, listOffset));
} }
@@ -228,15 +227,9 @@ namespace OpenRA.Mods.Cnc.Widgets
public override bool HandleMouseInput(MouseInput mi) public override bool HandleMouseInput(MouseInput mi)
{ {
if (mi.Button == MouseButton.WheelDown) if (mi.Event == MouseInputEvent.Scroll)
{ {
Scroll(-1); Scroll(mi.ScrollDelta);
return true;
}
if (mi.Button == MouseButton.WheelUp)
{
Scroll(1);
return true; return true;
} }

View File

@@ -164,14 +164,13 @@ namespace OpenRA.Mods.RA.Widgets
public override bool HandleMouseInput(MouseInput mi) public override bool HandleMouseInput(MouseInput mi)
{ {
// Eat mouse-up events if (mi.Event != MouseInputEvent.Scroll && mi.Event != MouseInputEvent.Down)
if (mi.Event != MouseInputEvent.Down)
return true; return true;
if (mi.Button == MouseButton.WheelDown) if (mi.Event == MouseInputEvent.Scroll && mi.ScrollDelta < 0)
return ChangeTab(false); return ChangeTab(false);
if (mi.Button == MouseButton.WheelUp) if (mi.Event == MouseInputEvent.Scroll && mi.ScrollDelta > 0)
return ChangeTab(true); return ChangeTab(true);
var action = tabs.Where(a => a.First.Contains(mi.Location)) var action = tabs.Where(a => a.First.Contains(mi.Location))

View File

@@ -290,6 +290,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
BindCheckboxPref(panel, "CLASSICORDERS_CHECKBOX", gs, "UseClassicMouseStyle"); BindCheckboxPref(panel, "CLASSICORDERS_CHECKBOX", gs, "UseClassicMouseStyle");
BindCheckboxPref(panel, "EDGESCROLL_CHECKBOX", gs, "ViewportEdgeScroll"); BindCheckboxPref(panel, "EDGESCROLL_CHECKBOX", gs, "ViewportEdgeScroll");
BindSliderPref(panel, "SCROLLSPEED_SLIDER", gs, "ViewportEdgeScrollStep"); BindSliderPref(panel, "SCROLLSPEED_SLIDER", gs, "ViewportEdgeScrollStep");
BindSliderPref(panel, "UI_SCROLLSPEED_SLIDER", gs, "UIScrollSpeed");
var mouseScrollDropdown = panel.Get<DropDownButtonWidget>("MOUSE_SCROLL"); var mouseScrollDropdown = panel.Get<DropDownButtonWidget>("MOUSE_SCROLL");
mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gs); mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gs);
@@ -348,6 +349,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
gs.MouseScroll = dgs.MouseScroll; gs.MouseScroll = dgs.MouseScroll;
gs.ViewportEdgeScroll = dgs.ViewportEdgeScroll; gs.ViewportEdgeScroll = dgs.ViewportEdgeScroll;
gs.ViewportEdgeScrollStep = dgs.ViewportEdgeScrollStep; gs.ViewportEdgeScrollStep = dgs.ViewportEdgeScrollStep;
gs.UIScrollSpeed = dgs.UIScrollSpeed;
foreach (var f in ks.GetType().GetFields()) foreach (var f in ks.GetType().GetFields())
{ {
@@ -357,6 +359,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
} }
panel.Get<SliderWidget>("SCROLLSPEED_SLIDER").Value = gs.ViewportEdgeScrollStep; panel.Get<SliderWidget>("SCROLLSPEED_SLIDER").Value = gs.ViewportEdgeScrollStep;
panel.Get<SliderWidget>("UI_SCROLLSPEED_SLIDER").Value = gs.UIScrollSpeed;
}; };
} }

View File

@@ -37,6 +37,7 @@ namespace OpenRA.Renderer.Sdl2
public void PumpInput(IInputHandler inputHandler) public void PumpInput(IInputHandler inputHandler)
{ {
var mods = MakeModifiers((int)SDL.SDL_GetModState()); var mods = MakeModifiers((int)SDL.SDL_GetModState());
var scrollDelta = 0;
inputHandler.ModifierKeys(mods); inputHandler.ModifierKeys(mods);
MouseInput? pendingMotion = null; MouseInput? pendingMotion = null;
@@ -79,7 +80,7 @@ namespace OpenRA.Renderer.Sdl2
var pos = new int2(e.button.x, e.button.y); var pos = new int2(e.button.x, e.button.y);
inputHandler.OnMouseInput(new MouseInput( inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Down, button, pos, mods, MouseInputEvent.Down, button, scrollDelta, pos, mods,
MultiTapDetection.DetectFromMouse(e.button.button, pos))); MultiTapDetection.DetectFromMouse(e.button.button, pos)));
break; break;
@@ -98,7 +99,7 @@ namespace OpenRA.Renderer.Sdl2
var pos = new int2(e.button.x, e.button.y); var pos = new int2(e.button.x, e.button.y);
inputHandler.OnMouseInput(new MouseInput( inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Up, button, pos, mods, MouseInputEvent.Up, button, scrollDelta, pos, mods,
MultiTapDetection.InfoFromMouse(e.button.button))); MultiTapDetection.InfoFromMouse(e.button.button)));
break; break;
@@ -107,7 +108,7 @@ namespace OpenRA.Renderer.Sdl2
case SDL.SDL_EventType.SDL_MOUSEMOTION: case SDL.SDL_EventType.SDL_MOUSEMOTION:
{ {
pendingMotion = new MouseInput( pendingMotion = new MouseInput(
MouseInputEvent.Move, lastButtonBits, MouseInputEvent.Move, lastButtonBits, scrollDelta,
new int2(e.motion.x, e.motion.y), mods, 0); new int2(e.motion.x, e.motion.y), mods, 0);
break; break;
@@ -115,15 +116,10 @@ namespace OpenRA.Renderer.Sdl2
case SDL.SDL_EventType.SDL_MOUSEWHEEL: case SDL.SDL_EventType.SDL_MOUSEWHEEL:
{ {
// Retain compatibility with existing bogus behavior
// TODO: Implement real scroll behavior. We've dropped SDL 1.2 support!
if (e.wheel.y == 0)
break;
int x, y; int x, y;
SDL.SDL_GetMouseState(out x, out y); SDL.SDL_GetMouseState(out x, out y);
var button = e.wheel.y < 0 ? MouseButton.WheelDown : MouseButton.WheelUp; scrollDelta = e.wheel.y;
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Down, button, new int2(x, y), Modifiers.None, 0)); inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, scrollDelta, new int2(x, y), Modifiers.None, 0));
break; break;
} }

View File

@@ -35,7 +35,6 @@ Container@MAPCHOOSER_PANEL:
Y: 45 Y: 45
Width: PARENT_RIGHT - 30 Width: PARENT_RIGHT - 30
Height: 440 Height: 440
ScrollVelocity: 40
Children: Children:
ScrollItem@MAP_TEMPLATE: ScrollItem@MAP_TEMPLATE:
Width: 168 Width: 168

View File

@@ -59,7 +59,6 @@ Container@SERVERBROWSER_PANEL:
Y: 15 Y: 15
Width: 700 Width: 700
Height: 440 Height: 440
ScrollVelocity: 20
Children: Children:
ScrollItem@SERVER_TEMPLATE: ScrollItem@SERVER_TEMPLATE:
Width: PARENT_RIGHT-27 Width: PARENT_RIGHT-27

View File

@@ -3,7 +3,7 @@ Container@SETTINGS_PANEL:
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 590 Width: 590
Height: 310+68 Height: 378
Children: Children:
Label@TITLE: Label@TITLE:
Width: 590 Width: 590
@@ -36,7 +36,7 @@ Container@SETTINGS_PANEL:
Background@bg: Background@bg:
Y: 34 Y: 34
Width: 590 Width: 590
Height: 310 Height: 360
Background: panel-black Background: panel-black
Children: Children:
Container@DISPLAY_PANEL: Container@DISPLAY_PANEL:
@@ -326,18 +326,33 @@ Container@SETTINGS_PANEL:
Ticks: 5 Ticks: 5
MinimumValue: 10 MinimumValue: 10
MaximumValue: 50 MaximumValue: 50
Label@UI_SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 97
Width: 95
Height: 25
Text: UI Scroll Speed:
Align: Right
Slider@UI_SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 103
Width: 250
Height: 20
Ticks: 5
MinimumValue: 1
MaximumValue: 100
Label@HOTKEYS_TITLE: Label@HOTKEYS_TITLE:
Y: 115 Y: 135
Width: PARENT_RIGHT Width: PARENT_RIGHT
Font: Bold Font: Bold
Text: Hotkeys Text: Hotkeys
Align: Center Align: Center
ScrollPanel@HOTKEY_LIST: ScrollPanel@HOTKEY_LIST:
X: 15 X: 15
Y: 135 Y: 155
Width: 560 Width: 560
ItemSpacing: 4 ItemSpacing: 4
Height: 160 Height: 180
Children: Children:
ScrollItem@HEADER: ScrollItem@HEADER:
Width: 528 Width: 528
@@ -451,13 +466,13 @@ Container@SETTINGS_PANEL:
Text: Check Sync around Unsynced Code Text: Check Sync around Unsynced Code
Button@BACK_BUTTON: Button@BACK_BUTTON:
Key: escape Key: escape
Y: 343 Y: 393
Width: 140 Width: 140
Height: 35 Height: 35
Text: Back Text: Back
Button@RESET_BUTTON: Button@RESET_BUTTON:
X: 150 X: 150
Y: 343 Y: 393
Width: 140 Width: 140
Height: 35 Height: 35
Text: Reset Text: Reset

View File

@@ -18,7 +18,6 @@ Background@MAPCHOOSER_PANEL:
Y: 47 Y: 47
Width: PARENT_RIGHT - 40 Width: PARENT_RIGHT - 40
Height: 474 Height: 474
ScrollVelocity: 40
Children: Children:
ScrollItem@MAP_TEMPLATE: ScrollItem@MAP_TEMPLATE:
Width: 180 Width: 180

View File

@@ -49,7 +49,6 @@ Background@SERVERBROWSER_PANEL:
Y: 80 Y: 80
Width: 700 Width: 700
Height: 360 Height: 360
ScrollVelocity: 20
Children: Children:
ScrollItem@SERVER_TEMPLATE: ScrollItem@SERVER_TEMPLATE:
Width: PARENT_RIGHT-27 Width: PARENT_RIGHT-27

View File

@@ -3,7 +3,7 @@ Background@SETTINGS_PANEL:
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM- HEIGHT)/2 Y: (WINDOW_BOTTOM- HEIGHT)/2
Width: 600 Width: 600
Height: 400 Height: 450
Children: Children:
Label@SETTINGS_LABEL_TITLE: Label@SETTINGS_LABEL_TITLE:
Y: 20 Y: 20
@@ -330,18 +330,33 @@ Background@SETTINGS_PANEL:
Ticks: 5 Ticks: 5
MinimumValue: 10 MinimumValue: 10
MaximumValue: 50 MaximumValue: 50
Label@UI_SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 97
Width: 95
Height: 25
Text: UI Scroll Speed:
Align: Right
Slider@UI_SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 103
Width: 250
Height: 20
Ticks: 5
MinimumValue: 1
MaximumValue: 100
Label@HOTKEYS_TITLE: Label@HOTKEYS_TITLE:
Y: 115 Y: 135
Width: PARENT_RIGHT Width: PARENT_RIGHT
Font: Bold Font: Bold
Text: Hotkeys Text: Hotkeys
Align: Center Align: Center
ScrollPanel@HOTKEY_LIST: ScrollPanel@HOTKEY_LIST:
X: 15 X: 15
Y: 135 Y: 155
Width: 560 Width: 560
ItemSpacing: 4 ItemSpacing: 4
Height: 160 Height: 180
Children: Children:
ScrollItem@HEADER: ScrollItem@HEADER:
BaseName: scrollheader BaseName: scrollheader