From 1bf3f3e03e7bf23c9963354b8af51e2705b2b6fe Mon Sep 17 00:00:00 2001 From: Saticmotion Date: Mon, 12 May 2014 22:04:18 +0200 Subject: [PATCH] The engine now uses the SDL2.0 scroll events properly. Scroll speed is now a user preference. --- AUTHORS | 1 + OpenRA.Game/IInputHandler.cs | 10 +++---- OpenRA.Game/Settings.cs | 1 + OpenRA.Game/Widgets/ScrollPanelWidget.cs | 15 +++------- .../Widgets/ProductionTabsWidget.cs | 15 +++------- OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs | 7 ++--- OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs | 3 ++ OpenRA.Renderer.Sdl2/Sdl2Input.cs | 18 +++++------- mods/cnc/chrome/mapchooser.yaml | 1 - mods/cnc/chrome/serverbrowser.yaml | 1 - mods/cnc/chrome/settings.yaml | 29 ++++++++++++++----- mods/ra/chrome/map-chooser.yaml | 1 - mods/ra/chrome/serverbrowser.yaml | 1 - mods/ra/chrome/settings.yaml | 23 ++++++++++++--- 14 files changed, 69 insertions(+), 57 deletions(-) diff --git a/AUTHORS b/AUTHORS index e9b8950887..e405bda155 100644 --- a/AUTHORS +++ b/AUTHORS @@ -66,6 +66,7 @@ Also thanks to: * Riderr3 * Sascha Biedermann (bidifx) * Sebastien Kerguen (xanax) + * Simon Verbeke (Saticmotion) * Taryn Hill (Phrohdoh) * Teemu Nieminen (Temeez) * Tim Mylemans (gecko) diff --git a/OpenRA.Game/IInputHandler.cs b/OpenRA.Game/IInputHandler.cs index 1515283e52..3e97103479 100755 --- a/OpenRA.Game/IInputHandler.cs +++ b/OpenRA.Game/IInputHandler.cs @@ -20,19 +20,21 @@ namespace OpenRA void OnTextInput(string text); } - public enum MouseInputEvent { Down, Move, Up } + public enum MouseInputEvent { Down, Move, Up, Scroll } public struct MouseInput { public MouseInputEvent Event; public MouseButton Button; + public int ScrollDelta; public int2 Location; public Modifiers Modifiers; 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; Button = button; + ScrollDelta = scrollDelta; Location = location; Modifiers = mods; MultiTapCount = multiTapCount; @@ -45,9 +47,7 @@ namespace OpenRA None = 0, Left = 1, Right = 2, - Middle = 4, - WheelDown = 8, - WheelUp = 16 + Middle = 4 } [Flags] diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 650307bd75..74693a494d 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -131,6 +131,7 @@ namespace OpenRA public bool ViewportEdgeScroll = true; public MouseScrollType MouseScroll = MouseScrollType.Standard; public float ViewportEdgeScrollStep = 10f; + public float UIScrollSpeed = 50f; public bool UseClassicMouseStyle = false; public bool AlwaysShowStatusBars = false; diff --git a/OpenRA.Game/Widgets/ScrollPanelWidget.cs b/OpenRA.Game/Widgets/ScrollPanelWidget.cs index e0e04bac3f..c721cbab88 100644 --- a/OpenRA.Game/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Game/Widgets/ScrollPanelWidget.cs @@ -23,7 +23,6 @@ namespace OpenRA.Widgets public class ScrollPanelWidget : Widget { public int ScrollbarWidth = 24; - public float ScrollVelocity = 4f; public int ItemSpacing = 2; public int ButtonDepth = ChromeMetrics.Get("ButtonDepth"); public string Background = "scrollpanel-bg"; @@ -130,9 +129,9 @@ namespace OpenRA.Widgets 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)); } @@ -188,15 +187,9 @@ namespace OpenRA.Widgets int2 lastMouseLocation; public override bool HandleMouseInput(MouseInput mi) { - if (mi.Button == MouseButton.WheelDown) + if (mi.Event == MouseInputEvent.Scroll) { - Scroll(-1); - return true; - } - - if (mi.Button == MouseButton.WheelUp) - { - Scroll(1); + Scroll(mi.ScrollDelta); return true; } diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs index b927360740..6355c3bff5 100644 --- a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs @@ -63,7 +63,6 @@ namespace OpenRA.Mods.Cnc.Widgets public readonly string PaletteWidget = null; public readonly string TypesContainer = null; - public readonly float ScrollVelocity = 4f; public readonly int TabWidth = 30; public readonly int ArrowWidth = 20; public Dictionary Groups; @@ -182,9 +181,9 @@ namespace OpenRA.Mods.Cnc.Widgets 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)); } @@ -228,15 +227,9 @@ namespace OpenRA.Mods.Cnc.Widgets public override bool HandleMouseInput(MouseInput mi) { - if (mi.Button == MouseButton.WheelDown) + if (mi.Event == MouseInputEvent.Scroll) { - Scroll(-1); - return true; - } - - if (mi.Button == MouseButton.WheelUp) - { - Scroll(1); + Scroll(mi.ScrollDelta); return true; } diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs index 044719eff5..f2180833d2 100755 --- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs @@ -164,14 +164,13 @@ namespace OpenRA.Mods.RA.Widgets public override bool HandleMouseInput(MouseInput mi) { - // Eat mouse-up events - if (mi.Event != MouseInputEvent.Down) + if (mi.Event != MouseInputEvent.Scroll && mi.Event != MouseInputEvent.Down) return true; - if (mi.Button == MouseButton.WheelDown) + if (mi.Event == MouseInputEvent.Scroll && mi.ScrollDelta < 0) return ChangeTab(false); - if (mi.Button == MouseButton.WheelUp) + if (mi.Event == MouseInputEvent.Scroll && mi.ScrollDelta > 0) return ChangeTab(true); var action = tabs.Where(a => a.First.Contains(mi.Location)) diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs index e2aef9edaa..0e1b1365f8 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs @@ -290,6 +290,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic BindCheckboxPref(panel, "CLASSICORDERS_CHECKBOX", gs, "UseClassicMouseStyle"); BindCheckboxPref(panel, "EDGESCROLL_CHECKBOX", gs, "ViewportEdgeScroll"); BindSliderPref(panel, "SCROLLSPEED_SLIDER", gs, "ViewportEdgeScrollStep"); + BindSliderPref(panel, "UI_SCROLLSPEED_SLIDER", gs, "UIScrollSpeed"); var mouseScrollDropdown = panel.Get("MOUSE_SCROLL"); mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gs); @@ -348,6 +349,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic gs.MouseScroll = dgs.MouseScroll; gs.ViewportEdgeScroll = dgs.ViewportEdgeScroll; gs.ViewportEdgeScrollStep = dgs.ViewportEdgeScrollStep; + gs.UIScrollSpeed = dgs.UIScrollSpeed; foreach (var f in ks.GetType().GetFields()) { @@ -357,6 +359,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic } panel.Get("SCROLLSPEED_SLIDER").Value = gs.ViewportEdgeScrollStep; + panel.Get("UI_SCROLLSPEED_SLIDER").Value = gs.UIScrollSpeed; }; } diff --git a/OpenRA.Renderer.Sdl2/Sdl2Input.cs b/OpenRA.Renderer.Sdl2/Sdl2Input.cs index 7aed1c1747..b2e9ee3060 100644 --- a/OpenRA.Renderer.Sdl2/Sdl2Input.cs +++ b/OpenRA.Renderer.Sdl2/Sdl2Input.cs @@ -37,6 +37,7 @@ namespace OpenRA.Renderer.Sdl2 public void PumpInput(IInputHandler inputHandler) { var mods = MakeModifiers((int)SDL.SDL_GetModState()); + var scrollDelta = 0; inputHandler.ModifierKeys(mods); MouseInput? pendingMotion = null; @@ -79,7 +80,7 @@ namespace OpenRA.Renderer.Sdl2 var pos = new int2(e.button.x, e.button.y); inputHandler.OnMouseInput(new MouseInput( - MouseInputEvent.Down, button, pos, mods, + MouseInputEvent.Down, button, scrollDelta, pos, mods, MultiTapDetection.DetectFromMouse(e.button.button, pos))); break; @@ -98,7 +99,7 @@ namespace OpenRA.Renderer.Sdl2 var pos = new int2(e.button.x, e.button.y); inputHandler.OnMouseInput(new MouseInput( - MouseInputEvent.Up, button, pos, mods, + MouseInputEvent.Up, button, scrollDelta, pos, mods, MultiTapDetection.InfoFromMouse(e.button.button))); break; @@ -107,7 +108,7 @@ namespace OpenRA.Renderer.Sdl2 case SDL.SDL_EventType.SDL_MOUSEMOTION: { pendingMotion = new MouseInput( - MouseInputEvent.Move, lastButtonBits, + MouseInputEvent.Move, lastButtonBits, scrollDelta, new int2(e.motion.x, e.motion.y), mods, 0); break; @@ -115,15 +116,10 @@ namespace OpenRA.Renderer.Sdl2 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; SDL.SDL_GetMouseState(out x, out y); - var button = e.wheel.y < 0 ? MouseButton.WheelDown : MouseButton.WheelUp; - inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Down, button, new int2(x, y), Modifiers.None, 0)); + scrollDelta = e.wheel.y; + inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, scrollDelta, new int2(x, y), Modifiers.None, 0)); break; } @@ -173,7 +169,7 @@ namespace OpenRA.Renderer.Sdl2 // Special case workaround for windows users if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_F4 && mods.HasModifier(Modifiers.Alt) && - Platform.CurrentPlatform == PlatformType.Windows) + Platform.CurrentPlatform == PlatformType.Windows) { Game.Exit(); } diff --git a/mods/cnc/chrome/mapchooser.yaml b/mods/cnc/chrome/mapchooser.yaml index 95885e4125..16e204c5db 100644 --- a/mods/cnc/chrome/mapchooser.yaml +++ b/mods/cnc/chrome/mapchooser.yaml @@ -35,7 +35,6 @@ Container@MAPCHOOSER_PANEL: Y: 45 Width: PARENT_RIGHT - 30 Height: 440 - ScrollVelocity: 40 Children: ScrollItem@MAP_TEMPLATE: Width: 168 diff --git a/mods/cnc/chrome/serverbrowser.yaml b/mods/cnc/chrome/serverbrowser.yaml index 57eb5b100a..3c4ddb3a3a 100644 --- a/mods/cnc/chrome/serverbrowser.yaml +++ b/mods/cnc/chrome/serverbrowser.yaml @@ -59,7 +59,6 @@ Container@SERVERBROWSER_PANEL: Y: 15 Width: 700 Height: 440 - ScrollVelocity: 20 Children: ScrollItem@SERVER_TEMPLATE: Width: PARENT_RIGHT-27 diff --git a/mods/cnc/chrome/settings.yaml b/mods/cnc/chrome/settings.yaml index d9f653322a..b6d4559f80 100644 --- a/mods/cnc/chrome/settings.yaml +++ b/mods/cnc/chrome/settings.yaml @@ -3,7 +3,7 @@ Container@SETTINGS_PANEL: X: (WINDOW_RIGHT - WIDTH)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2 Width: 590 - Height: 310+68 + Height: 378 Children: Label@TITLE: Width: 590 @@ -36,7 +36,7 @@ Container@SETTINGS_PANEL: Background@bg: Y: 34 Width: 590 - Height: 310 + Height: 360 Background: panel-black Children: Container@DISPLAY_PANEL: @@ -326,18 +326,33 @@ Container@SETTINGS_PANEL: Ticks: 5 MinimumValue: 10 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: - Y: 115 + Y: 135 Width: PARENT_RIGHT Font: Bold Text: Hotkeys Align: Center ScrollPanel@HOTKEY_LIST: X: 15 - Y: 135 + Y: 155 Width: 560 ItemSpacing: 4 - Height: 160 + Height: 180 Children: ScrollItem@HEADER: Width: 528 @@ -451,13 +466,13 @@ Container@SETTINGS_PANEL: Text: Check Sync around Unsynced Code Button@BACK_BUTTON: Key: escape - Y: 343 + Y: 393 Width: 140 Height: 35 Text: Back Button@RESET_BUTTON: X: 150 - Y: 343 + Y: 393 Width: 140 Height: 35 Text: Reset diff --git a/mods/ra/chrome/map-chooser.yaml b/mods/ra/chrome/map-chooser.yaml index 48146e73f4..5c87b37e5a 100644 --- a/mods/ra/chrome/map-chooser.yaml +++ b/mods/ra/chrome/map-chooser.yaml @@ -18,7 +18,6 @@ Background@MAPCHOOSER_PANEL: Y: 47 Width: PARENT_RIGHT - 40 Height: 474 - ScrollVelocity: 40 Children: ScrollItem@MAP_TEMPLATE: Width: 180 diff --git a/mods/ra/chrome/serverbrowser.yaml b/mods/ra/chrome/serverbrowser.yaml index 892b7f840b..664f8f4bb3 100644 --- a/mods/ra/chrome/serverbrowser.yaml +++ b/mods/ra/chrome/serverbrowser.yaml @@ -49,7 +49,6 @@ Background@SERVERBROWSER_PANEL: Y: 80 Width: 700 Height: 360 - ScrollVelocity: 20 Children: ScrollItem@SERVER_TEMPLATE: Width: PARENT_RIGHT-27 diff --git a/mods/ra/chrome/settings.yaml b/mods/ra/chrome/settings.yaml index 73f66b8ef2..7578d87d61 100644 --- a/mods/ra/chrome/settings.yaml +++ b/mods/ra/chrome/settings.yaml @@ -3,7 +3,7 @@ Background@SETTINGS_PANEL: X: (WINDOW_RIGHT - WIDTH)/2 Y: (WINDOW_BOTTOM- HEIGHT)/2 Width: 600 - Height: 400 + Height: 450 Children: Label@SETTINGS_LABEL_TITLE: Y: 20 @@ -330,18 +330,33 @@ Background@SETTINGS_PANEL: Ticks: 5 MinimumValue: 10 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: - Y: 115 + Y: 135 Width: PARENT_RIGHT Font: Bold Text: Hotkeys Align: Center ScrollPanel@HOTKEY_LIST: X: 15 - Y: 135 + Y: 155 Width: 560 ItemSpacing: 4 - Height: 160 + Height: 180 Children: ScrollItem@HEADER: BaseName: scrollheader