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 account linked to committer's email address
6 changed files with 23 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

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