Change ScrollPanel scroll behaviour

Small change to replace the momentum-based scrolling with the more common method of scrolling with each scroll wheel step.
This commit is contained in:
grufkork 2020-10-03 23:04:53 +02:00 committed by Tamás Bálint Misius
parent 1f7e9095da
commit 02b26a9da3
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
9 changed files with 56 additions and 7 deletions

2
.gitignore vendored
View File

@ -20,6 +20,8 @@ generated/*
includes/*
recordings/
font/*
Debug/*
Release/*
generate
Makefile.me
*.xcodeproj

View File

@ -4,6 +4,8 @@
#include "common/tpt-minmax.h"
#include "client/Client.h"
using namespace ui;
ScrollPanel::ScrollPanel(Point position, Point size):
@ -19,9 +21,10 @@ ScrollPanel::ScrollPanel(Point position, Point size):
scrollbarSelected(false),
scrollbarInitialYOffset(0),
scrollbarInitialYClick(0),
scrollbarClickLocation(0)
scrollbarClickLocation(0),
momentumScroll(false)
{
momentumScroll = Client::Ref().GetPrefBool("MomentumScroll", true);
}
int ScrollPanel::GetScrollLimit()
@ -43,7 +46,10 @@ void ScrollPanel::XOnMouseWheelInside(int localx, int localy, int d)
{
if (!d)
return;
yScrollVel -= d*2;
if (momentumScroll)
yScrollVel -= d * 2;
else
yScrollVel -= d * 20;
}
void ScrollPanel::Draw(const Point& screenPos)
@ -124,9 +130,6 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
void ScrollPanel::XTick(float dt)
{
if (yScrollVel > -0.5f && yScrollVel < 0.5)
yScrollVel = 0;
if (xScrollVel > 7.0f) xScrollVel = 7.0f;
if (xScrollVel < -7.0f) xScrollVel = -7.0f;
if (xScrollVel > -0.5f && xScrollVel < 0.5)
@ -140,7 +143,18 @@ void ScrollPanel::XTick(float dt)
offsetY += yScrollVel;
offsetX += xScrollVel;
yScrollVel*=0.98f;
if (momentumScroll)
{
if (yScrollVel > -0.5f && yScrollVel < 0.5)
yScrollVel = 0;
yScrollVel *= 0.98f;
}
else
{
yScrollVel = 0.0f;
}
xScrollVel*=0.98f;
if (oldOffsetY!=int(offsetY))

View File

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

View File

@ -112,6 +112,11 @@ void OptionsController::SetPerfectCircle(bool perfectCircle)
model->SetPerfectCircle(perfectCircle);
}
void OptionsController::SetMomentumScroll(bool momentumScroll)
{
model->SetMomentumScroll(momentumScroll);
}
void OptionsController::Exit()
{
view->CloseActiveWindow();

View File

@ -33,6 +33,7 @@ public:
void SetMouseClickrequired(bool mouseClickRequired);
void SetIncludePressure(bool includePressure);
void SetPerfectCircle(bool perfectCircle);
void SetMomentumScroll(bool momentumScroll);
void Exit();
OptionsView * GetView();

View File

@ -226,6 +226,17 @@ void OptionsModel::SetPerfectCircle(bool perfectCircle)
notifySettingsChanged();
}
bool OptionsModel::GetMomentumScroll()
{
return Client::Ref().GetPrefBool("MomentumScroll", true);
}
void OptionsModel::SetMomentumScroll(bool state)
{
Client::Ref().SetPref("MomentumScroll", state);
notifySettingsChanged();
}
void OptionsModel::notifySettingsChanged()
{
for (size_t i = 0; i < observers.size(); i++)

View File

@ -51,6 +51,8 @@ public:
void SetIncludePressure(bool includePressure);
bool GetPerfectCircle();
void SetPerfectCircle(bool perfectCircle);
bool GetMomentumScroll();
void SetMomentumScroll(bool momentumScroll);
virtual ~OptionsModel();
};

View File

@ -239,6 +239,17 @@ OptionsView::OptionsView():
scrollPanel->AddChild(tempLabel);
scrollPanel->AddChild(showAvatars);
currentY += 20;
momentumScroll = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Momentum/Old Scrolling", "");
autowidth(momentumScroll);
momentumScroll->SetActionCallback({ [this] { c->SetMomentumScroll(momentumScroll->GetChecked()); } });
tempLabel = new ui::Label(ui::Point(momentumScroll->Position.X + Graphics::textwidth(momentumScroll->GetText()) + 20, currentY), ui::Point(1, 16), "\bg- Accelerating instead of step scroll");
autowidth(tempLabel);
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
scrollPanel->AddChild(tempLabel);
scrollPanel->AddChild(momentumScroll);
currentY+=20;
mouseClickRequired = new ui::Checkbox(ui::Point(8, currentY), ui::Point(1, 16), "Sticky Categories", "");
autowidth(mouseClickRequired);
@ -338,6 +349,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
mouseClickRequired->SetChecked(sender->GetMouseClickRequired());
includePressure->SetChecked(sender->GetIncludePressure());
perfectCirclePressure->SetChecked(sender->GetPerfectCircle());
momentumScroll->SetChecked(sender->GetMomentumScroll());
}
void OptionsView::AttachController(OptionsController * c_)

View File

@ -31,6 +31,7 @@ class OptionsView: public ui::Window
ui::Checkbox * fastquit;
ui::DropDown * decoSpace;
ui::Checkbox * showAvatars;
ui::Checkbox * momentumScroll;
ui::Checkbox * mouseClickRequired;
ui::Checkbox * includePressure;
ui::Checkbox * perfectCirclePressure;