Skip to content

Commit

Permalink
Fix some scrolling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mniip committed May 30, 2018
1 parent 7393c57 commit 48a333f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/PowderToySDL.cpp
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions src/gui/game/GameController.cpp
Expand Up @@ -390,17 +390,17 @@ 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;

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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/interface/Component.h
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
17 changes: 6 additions & 11 deletions src/gui/localbrowser/LocalBrowserController.cpp
Expand Up @@ -115,21 +115,16 @@ void LocalBrowserController::ClearSelection()
browserModel->ClearSelected();
}

void LocalBrowserController::NextPage()
{
if(browserModel->GetPageNum() < browserModel->GetPageCount())
browserModel->UpdateSavesList(browserModel->GetPageNum()+1);
}

void LocalBrowserController::PrevPage()
void LocalBrowserController::SetPage(int page)
{
if(browserModel->GetPageNum()>1)
browserModel->UpdateSavesList(browserModel->GetPageNum()-1);
if (page != browserModel->GetPageNum() && page > 0 && page <= browserModel->GetPageCount())
browserModel->UpdateSavesList(page);
}

void LocalBrowserController::SetPage(int page)
void LocalBrowserController::SetPageRelative(int offset)
{
if (page != browserModel->GetPageNum() && page > 0 && page <= browserModel->GetPageCount())
int page = std::min(std::max(browserModel->GetPageNum() + offset, 1), browserModel->GetPageCount());
if(page != browserModel->GetPageCount())
browserModel->UpdateSavesList(page);
}

Expand Down
3 changes: 1 addition & 2 deletions src/gui/localbrowser/LocalBrowserController.h
Expand Up @@ -26,9 +26,8 @@ class LocalBrowserController {
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();
Expand Down
29 changes: 8 additions & 21 deletions src/gui/localbrowser/LocalBrowserView.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
17 changes: 6 additions & 11 deletions src/gui/search/SearchController.cpp
Expand Up @@ -128,21 +128,16 @@ void SearchController::Refresh()
doRefresh = true;
}

void SearchController::PrevPage()
{
if (searchModel->GetPageNum()>1)
searchModel->UpdateSaveList(searchModel->GetPageNum()-1, searchModel->GetLastQuery());
}

void SearchController::NextPage()
void SearchController::SetPage(int page)
{
if (searchModel->GetPageNum() < searchModel->GetPageCount())
searchModel->UpdateSaveList(searchModel->GetPageNum()+1, searchModel->GetLastQuery());
if (page != searchModel->GetPageNum() && page > 0 && page <= searchModel->GetPageCount())
searchModel->UpdateSaveList(page, searchModel->GetLastQuery());
}

void SearchController::SetPage(int page)
void SearchController::SetPageRelative(int offset)
{
if (page != searchModel->GetPageNum() && page > 0 && page <= searchModel->GetPageCount())
int page = std::min(std::max(searchModel->GetPageNum() + offset, 1), searchModel->GetPageCount());
if(page != searchModel->GetPageCount())
searchModel->UpdateSaveList(page, searchModel->GetLastQuery());
}

Expand Down
3 changes: 1 addition & 2 deletions src/gui/search/SearchController.h
Expand Up @@ -35,9 +35,8 @@ class SearchController
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);
Expand Down
29 changes: 8 additions & 21 deletions src/gui/search/SearchView.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 48a333f

Please sign in to comment.