The engine now uses the SDL2.0 scroll events properly.
Scroll speed is now a user preference.
This commit is contained in:
1
AUTHORS
1
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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<int>("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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<string, ProductionTabGroup> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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<DropDownButtonWidget>("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<SliderWidget>("SCROLLSPEED_SLIDER").Value = gs.ViewportEdgeScrollStep;
|
||||
panel.Get<SliderWidget>("UI_SCROLLSPEED_SLIDER").Value = gs.UIScrollSpeed;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ Container@MAPCHOOSER_PANEL:
|
||||
Y: 45
|
||||
Width: PARENT_RIGHT - 30
|
||||
Height: 440
|
||||
ScrollVelocity: 40
|
||||
Children:
|
||||
ScrollItem@MAP_TEMPLATE:
|
||||
Width: 168
|
||||
|
||||
@@ -59,7 +59,6 @@ Container@SERVERBROWSER_PANEL:
|
||||
Y: 15
|
||||
Width: 700
|
||||
Height: 440
|
||||
ScrollVelocity: 20
|
||||
Children:
|
||||
ScrollItem@SERVER_TEMPLATE:
|
||||
Width: PARENT_RIGHT-27
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -18,7 +18,6 @@ Background@MAPCHOOSER_PANEL:
|
||||
Y: 47
|
||||
Width: PARENT_RIGHT - 40
|
||||
Height: 474
|
||||
ScrollVelocity: 40
|
||||
Children:
|
||||
ScrollItem@MAP_TEMPLATE:
|
||||
Width: 180
|
||||
|
||||
@@ -49,7 +49,6 @@ Background@SERVERBROWSER_PANEL:
|
||||
Y: 80
|
||||
Width: 700
|
||||
Height: 360
|
||||
ScrollVelocity: 20
|
||||
Children:
|
||||
ScrollItem@SERVER_TEMPLATE:
|
||||
Width: PARENT_RIGHT-27
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user