Fix some scrolling issues

This commit is contained in:
mniip 2018-05-30 13:35:44 +03:00
parent 7393c577f8
commit 48a333f0de
9 changed files with 42 additions and 80 deletions

View File

@ -327,8 +327,8 @@ void EventProcess(SDL_Event event)
x *= -1;
y *= -1;
}
bool positiveDir = y == 0 ? x > 0 : y > 0;
engine->onMouseWheel(event.motion.x, event.motion.y, positiveDir ? 1 : -1);
engine->onMouseWheel(mousex, mousey, y); // TODO: pass x?
break;
}
case SDL_MOUSEMOTION:

View File

@ -390,7 +390,7 @@ void GameController::InvertAirSim()
}
void GameController::AdjustBrushSize(int direction, bool logarithmic, bool xAxis, bool yAxis)
void GameController::AdjustBrushSize(int delta, bool logarithmic, bool xAxis, bool yAxis)
{
if(xAxis && yAxis)
return;
@ -398,9 +398,9 @@ void GameController::AdjustBrushSize(int direction, bool logarithmic, bool xAxis
ui::Point newSize(0, 0);
ui::Point oldSize = gameModel->GetBrush()->GetRadius();
if(logarithmic)
newSize = gameModel->GetBrush()->GetRadius() + ui::Point(direction * ((gameModel->GetBrush()->GetRadius().X/5)>0?gameModel->GetBrush()->GetRadius().X/5:1), direction * ((gameModel->GetBrush()->GetRadius().Y/5)>0?gameModel->GetBrush()->GetRadius().Y/5:1));
newSize = gameModel->GetBrush()->GetRadius() + ui::Point(delta * std::max(gameModel->GetBrush()->GetRadius().X / 5, 1), delta * std::max(gameModel->GetBrush()->GetRadius().Y / 5, 1));
else
newSize = gameModel->GetBrush()->GetRadius() + ui::Point(direction, direction);
newSize = gameModel->GetBrush()->GetRadius() + ui::Point(delta, delta);
if(newSize.X < 0)
newSize.X = 0;
if(newSize.Y < 0)
@ -423,13 +423,13 @@ void GameController::SetBrushSize(ui::Point newSize)
gameModel->GetBrush()->SetRadius(newSize);
}
void GameController::AdjustZoomSize(int direction, bool logarithmic)
void GameController::AdjustZoomSize(int delta, bool logarithmic)
{
int newSize;
if(logarithmic)
newSize = gameModel->GetZoomSize()+(((gameModel->GetZoomSize()/10)>0?(gameModel->GetZoomSize()/10):1)*direction);
newSize = gameModel->GetZoomSize() + std::max(gameModel->GetZoomSize() / 10, 1) * delta;
else
newSize = gameModel->GetZoomSize()+direction;
newSize = gameModel->GetZoomSize() + delta;
if(newSize<5)
newSize = 5;
if(newSize>64)

View File

@ -170,7 +170,7 @@ namespace ui
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// d: The mouse wheel movement value.
// d: The vertical scroll offset
///
virtual void OnMouseWheel(int localx, int localy, int d);
@ -179,7 +179,7 @@ namespace ui
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// d: The mouse wheel movement value.
// d: The vertical scroll offset
///
virtual void OnMouseWheelInside(int localx, int localy, int d);

View File

@ -115,24 +115,19 @@ void LocalBrowserController::ClearSelection()
browserModel->ClearSelected();
}
void LocalBrowserController::NextPage()
{
if(browserModel->GetPageNum() < browserModel->GetPageCount())
browserModel->UpdateSavesList(browserModel->GetPageNum()+1);
}
void LocalBrowserController::PrevPage()
{
if(browserModel->GetPageNum()>1)
browserModel->UpdateSavesList(browserModel->GetPageNum()-1);
}
void LocalBrowserController::SetPage(int page)
{
if (page != browserModel->GetPageNum() && page > 0 && page <= browserModel->GetPageCount())
browserModel->UpdateSavesList(page);
}
void LocalBrowserController::SetPageRelative(int offset)
{
int page = std::min(std::max(browserModel->GetPageNum() + offset, 1), browserModel->GetPageCount());
if(page != browserModel->GetPageCount())
browserModel->UpdateSavesList(page);
}
void LocalBrowserController::Update()
{
if(browserModel->GetSave())

View File

@ -26,9 +26,8 @@ public:
void OpenSave(SaveFile * stamp);
bool GetMoveToFront();
void SetMoveToFront(bool move);
void NextPage();
void PrevPage();
void SetPage(int page);
void SetPageRelative(int offset);
void Update();
void Exit();
virtual ~LocalBrowserController();

View File

@ -49,31 +49,22 @@ LocalBrowserView::LocalBrowserView():
AddComponent(pageCountLabel);
AddComponent(pageTextbox);
class NextPageAction : public ui::ButtonAction
class RelativePageAction : public ui::ButtonAction
{
LocalBrowserView * v;
int offset;
public:
NextPageAction(LocalBrowserView * _v) { v = _v; }
RelativePageAction(LocalBrowserView * _v, int _offset): v(_v), offset(_offset) {}
void ActionCallback(ui::Button * sender)
{
v->c->NextPage();
v->c->SetPageRelative(offset);
}
};
nextButton->SetActionCallback(new NextPageAction(this));
nextButton->SetActionCallback(new RelativePageAction(this, 1));
nextButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
nextButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
class PrevPageAction : public ui::ButtonAction
{
LocalBrowserView * v;
public:
PrevPageAction(LocalBrowserView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->PrevPage();
}
};
previousButton->SetActionCallback(new PrevPageAction(this));
previousButton->SetActionCallback(new RelativePageAction(this, -1));
previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
previousButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
@ -254,12 +245,8 @@ void LocalBrowserView::NotifySelectedChanged(LocalBrowserModel * sender)
void LocalBrowserView::OnMouseWheel(int x, int y, int d)
{
if(!d)
return;
if(d<0)
c->NextPage();
else
c->PrevPage();
if(d)
c->SetPageRelative(d);
}
void LocalBrowserView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)

View File

@ -128,24 +128,19 @@ void SearchController::Refresh()
doRefresh = true;
}
void SearchController::PrevPage()
{
if (searchModel->GetPageNum()>1)
searchModel->UpdateSaveList(searchModel->GetPageNum()-1, searchModel->GetLastQuery());
}
void SearchController::NextPage()
{
if (searchModel->GetPageNum() < searchModel->GetPageCount())
searchModel->UpdateSaveList(searchModel->GetPageNum()+1, searchModel->GetLastQuery());
}
void SearchController::SetPage(int page)
{
if (page != searchModel->GetPageNum() && page > 0 && page <= searchModel->GetPageCount())
searchModel->UpdateSaveList(page, searchModel->GetLastQuery());
}
void SearchController::SetPageRelative(int offset)
{
int page = std::min(std::max(searchModel->GetPageNum() + offset, 1), searchModel->GetPageCount());
if(page != searchModel->GetPageCount())
searchModel->UpdateSaveList(page, searchModel->GetLastQuery());
}
void SearchController::ChangeSort()
{
if(searchModel->GetSort() == "new")

View File

@ -35,9 +35,8 @@ public:
void DoSearch(String query, bool now = false);
void DoSearch2(String query);
void Refresh();
void NextPage();
void PrevPage();
void SetPage(int page);
void SetPageRelative(int offset);
void ChangeSort();
void ShowOwn(bool show);
void ShowFavourite(bool show);

View File

@ -148,31 +148,22 @@ SearchView::SearchView():
clearSearchButton->Appearance.BorderInactive = ui::Colour(170,170,170);
AddComponent(clearSearchButton);
class NextPageAction : public ui::ButtonAction
class RelativePageAction : public ui::ButtonAction
{
SearchView * v;
int offset;
public:
NextPageAction(SearchView * _v) { v = _v; }
RelativePageAction(SearchView * _v, int _offset): v(_v), offset(_offset) {}
void ActionCallback(ui::Button * sender)
{
v->c->NextPage();
v->c->SetPageRelative(offset);
}
};
nextButton->SetActionCallback(new NextPageAction(this));
nextButton->SetActionCallback(new RelativePageAction(this, 1));
nextButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
nextButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
nextButton->Visible = false;
class PrevPageAction : public ui::ButtonAction
{
SearchView * v;
public:
PrevPageAction(SearchView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->PrevPage();
}
};
previousButton->SetActionCallback(new PrevPageAction(this));
previousButton->SetActionCallback(new RelativePageAction(this, -1));
previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
previousButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
previousButton->Visible = false;
@ -787,12 +778,8 @@ void SearchView::OnTick(float dt)
void SearchView::OnMouseWheel(int x, int y, int d)
{
if(!d)
return;
if(d<0)
c->NextPage();
else
c->PrevPage();
if(d)
c->SetPageRelative(d);
}
void SearchView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{