From 48a333f0de033326958b887c9628e72c68c28b6e Mon Sep 17 00:00:00 2001 From: mniip Date: Wed, 30 May 2018 13:35:44 +0300 Subject: [PATCH] Fix some scrolling issues --- src/PowderToySDL.cpp | 4 +-- src/gui/game/GameController.cpp | 12 ++++---- src/gui/interface/Component.h | 4 +-- .../localbrowser/LocalBrowserController.cpp | 19 +++++------- src/gui/localbrowser/LocalBrowserController.h | 3 +- src/gui/localbrowser/LocalBrowserView.cpp | 29 +++++-------------- src/gui/search/SearchController.cpp | 19 +++++------- src/gui/search/SearchController.h | 3 +- src/gui/search/SearchView.cpp | 29 +++++-------------- 9 files changed, 42 insertions(+), 80 deletions(-) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index e6c92ca5f..df6a6c813 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -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: diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index cf656f680..b52cb40b3 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -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) diff --git a/src/gui/interface/Component.h b/src/gui/interface/Component.h index 0ff5b5b90..ae42f68f3 100644 --- a/src/gui/interface/Component.h +++ b/src/gui/interface/Component.h @@ -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); diff --git a/src/gui/localbrowser/LocalBrowserController.cpp b/src/gui/localbrowser/LocalBrowserController.cpp index 1675c68fc..83e06269f 100644 --- a/src/gui/localbrowser/LocalBrowserController.cpp +++ b/src/gui/localbrowser/LocalBrowserController.cpp @@ -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()) diff --git a/src/gui/localbrowser/LocalBrowserController.h b/src/gui/localbrowser/LocalBrowserController.h index bacef1631..18edf01c5 100644 --- a/src/gui/localbrowser/LocalBrowserController.h +++ b/src/gui/localbrowser/LocalBrowserController.h @@ -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(); diff --git a/src/gui/localbrowser/LocalBrowserView.cpp b/src/gui/localbrowser/LocalBrowserView.cpp index 7f7971009..ba6619745 100644 --- a/src/gui/localbrowser/LocalBrowserView.cpp +++ b/src/gui/localbrowser/LocalBrowserView.cpp @@ -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) diff --git a/src/gui/search/SearchController.cpp b/src/gui/search/SearchController.cpp index ce461b97a..fe3eafdbe 100644 --- a/src/gui/search/SearchController.cpp +++ b/src/gui/search/SearchController.cpp @@ -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") diff --git a/src/gui/search/SearchController.h b/src/gui/search/SearchController.h index a52236920..191b6b38d 100644 --- a/src/gui/search/SearchController.h +++ b/src/gui/search/SearchController.h @@ -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); diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index 94c6cb511..e7ceefc51 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -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) {