Added a panning navigation mode.

This commit is contained in:
Tim Schubert 2016-01-19 22:09:14 +01:00
parent 0d523b6541
commit 62cba726a8
2 changed files with 15 additions and 1 deletions

View file

@ -271,8 +271,22 @@ void Grid::handle_event(SDL_Event *event)
}
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();
}
if (event->type == SDL_MOUSEBUTTONDOWN && event->button.button == SDL_BUTTON_MIDDLE)
{
this->panning = !(this->panning);
}
}
void Grid::move(SDL_Point m)

View file

@ -173,7 +173,7 @@ protected:
std::unordered_set<Field> *fields;
Layout *layout;
Field marker;
bool panning;
bool on_rectangle(SDL_Rect *rect);
public:
Grid(Layout *layout_)