Refactor MomentumScroll to be more in line with other interface prefs

This commit is contained in:
Tamás Bálint Misius 2020-10-10 21:57:29 +02:00
parent ba72dc7a22
commit bdcf486a8d
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
6 changed files with 23 additions and 7 deletions

View File

@ -64,6 +64,7 @@ bool fullscreen = false;
bool altFullscreen = false; bool altFullscreen = false;
bool forceIntegerScaling = true; bool forceIntegerScaling = true;
bool resizable = false; bool resizable = false;
bool momentumScroll = true;
void ClipboardPush(ByteString text) void ClipboardPush(ByteString text)
@ -696,6 +697,7 @@ int main(int argc, char * argv[])
fullscreen = Client::Ref().GetPrefBool("Fullscreen", false); fullscreen = Client::Ref().GetPrefBool("Fullscreen", false);
altFullscreen = Client::Ref().GetPrefBool("AltFullscreen", false); altFullscreen = Client::Ref().GetPrefBool("AltFullscreen", false);
forceIntegerScaling = Client::Ref().GetPrefBool("ForceIntegerScaling", true); forceIntegerScaling = Client::Ref().GetPrefBool("ForceIntegerScaling", true);
momentumScroll = Client::Ref().GetPrefBool("MomentumScroll", true);
if(arguments["kiosk"] == "true") if(arguments["kiosk"] == "true")
@ -785,6 +787,7 @@ int main(int argc, char * argv[])
ui::Engine::Ref().Fullscreen = fullscreen; ui::Engine::Ref().Fullscreen = fullscreen;
ui::Engine::Ref().SetAltFullscreen(altFullscreen); ui::Engine::Ref().SetAltFullscreen(altFullscreen);
ui::Engine::Ref().SetForceIntegerScaling(forceIntegerScaling); ui::Engine::Ref().SetForceIntegerScaling(forceIntegerScaling);
ui::Engine::Ref().SetMomentumScroll(momentumScroll);
engine = &ui::Engine::Ref(); engine = &ui::Engine::Ref();
engine->SetMaxSize(desktopWidth, desktopHeight); engine->SetMaxSize(desktopWidth, desktopHeight);

View File

@ -34,7 +34,8 @@ Engine::Engine():
mousexp_(0), mousexp_(0),
mouseyp_(0), mouseyp_(0),
maxWidth(0), maxWidth(0),
maxHeight(0) maxHeight(0),
momentumScroll(false)
{ {
} }

View File

@ -119,6 +119,19 @@ namespace ui
int maxWidth; int maxWidth;
int maxHeight; int maxHeight;
bool momentumScroll;
public:
inline void SetMomentumScroll(bool newMomentumScroll)
{
momentumScroll = newMomentumScroll;
}
inline bool GetMomentumScroll() const
{
return momentumScroll;
}
}; };
} }

View File

@ -1,4 +1,5 @@
#include "ScrollPanel.h" #include "ScrollPanel.h"
#include "Engine.h"
#include "graphics/Graphics.h" #include "graphics/Graphics.h"
@ -21,10 +22,8 @@ ScrollPanel::ScrollPanel(Point position, Point size):
scrollbarSelected(false), scrollbarSelected(false),
scrollbarInitialYOffset(0), scrollbarInitialYOffset(0),
scrollbarInitialYClick(0), scrollbarInitialYClick(0),
scrollbarClickLocation(0), scrollbarClickLocation(0)
momentumScroll(false)
{ {
momentumScroll = Client::Ref().GetPrefBool("MomentumScroll", true);
} }
int ScrollPanel::GetScrollLimit() int ScrollPanel::GetScrollLimit()
@ -46,7 +45,7 @@ void ScrollPanel::XOnMouseWheelInside(int localx, int localy, int d)
{ {
if (!d) if (!d)
return; return;
if (momentumScroll) if (ui::Engine::Ref().GetMomentumScroll())
yScrollVel -= d * 2; yScrollVel -= d * 2;
else else
yScrollVel -= d * 20; yScrollVel -= d * 20;
@ -144,7 +143,7 @@ void ScrollPanel::XTick(float dt)
offsetX += xScrollVel; offsetX += xScrollVel;
if (momentumScroll) if (ui::Engine::Ref().GetMomentumScroll())
{ {
if (yScrollVel > -0.5f && yScrollVel < 0.5) if (yScrollVel > -0.5f && yScrollVel < 0.5)
yScrollVel = 0; yScrollVel = 0;

View File

@ -16,7 +16,6 @@ namespace ui
bool isMouseInsideScrollbar; bool isMouseInsideScrollbar;
bool isMouseInsideScrollbarArea; bool isMouseInsideScrollbarArea;
bool scrollbarSelected; bool scrollbarSelected;
bool momentumScroll;
int scrollbarInitialYOffset; int scrollbarInitialYOffset;
int scrollbarInitialYClick; int scrollbarInitialYClick;
int scrollbarClickLocation; int scrollbarClickLocation;

View File

@ -234,6 +234,7 @@ bool OptionsModel::GetMomentumScroll()
void OptionsModel::SetMomentumScroll(bool state) void OptionsModel::SetMomentumScroll(bool state)
{ {
Client::Ref().SetPref("MomentumScroll", state); Client::Ref().SetPref("MomentumScroll", state);
ui::Engine::Ref().SetMomentumScroll(state);
notifySettingsChanged(); notifySettingsChanged();
} }