Added a panning navigation mode.
This commit is contained in:
parent
0d523b6541
commit
62cba726a8
2 changed files with 15 additions and 1 deletions
14
src/Grid.cpp
14
src/Grid.cpp
|
@ -271,8 +271,22 @@ void Grid::handle_event(SDL_Event *event)
|
||||||
}
|
}
|
||||||
if (event->type == SDL_MOUSEMOTION)
|
if (event->type == SDL_MOUSEMOTION)
|
||||||
{
|
{
|
||||||
|
if (this->panning)
|
||||||
|
{
|
||||||
|
SDL_Point mouse = {0, 0};
|
||||||
|
SDL_GetMouseState(&mouse.x, &mouse.y);
|
||||||
|
Point marker_pos = field_to_point(this->marker, this->layout);
|
||||||
|
SDL_Point p;
|
||||||
|
p.x = (int) marker_pos.x;
|
||||||
|
p.y = (int) marker_pos.y;
|
||||||
|
this->move(mouse - p);
|
||||||
|
}
|
||||||
this->update_marker();
|
this->update_marker();
|
||||||
}
|
}
|
||||||
|
if (event->type == SDL_MOUSEBUTTONDOWN && event->button.button == SDL_BUTTON_MIDDLE)
|
||||||
|
{
|
||||||
|
this->panning = !(this->panning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grid::move(SDL_Point m)
|
void Grid::move(SDL_Point m)
|
||||||
|
|
|
@ -173,7 +173,7 @@ protected:
|
||||||
std::unordered_set<Field> *fields;
|
std::unordered_set<Field> *fields;
|
||||||
Layout *layout;
|
Layout *layout;
|
||||||
Field marker;
|
Field marker;
|
||||||
|
bool panning;
|
||||||
bool on_rectangle(SDL_Rect *rect);
|
bool on_rectangle(SDL_Rect *rect);
|
||||||
public:
|
public:
|
||||||
Grid(Layout *layout_)
|
Grid(Layout *layout_)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue