From 62cba726a8cb6a2a83a426afabd3194926cb895f Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Tue, 19 Jan 2016 22:09:14 +0100 Subject: [PATCH] Added a panning navigation mode. --- src/Grid.cpp | 14 ++++++++++++++ src/Grid.hpp | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Grid.cpp b/src/Grid.cpp index c84b3b8..b2191b0 100644 --- a/src/Grid.cpp +++ b/src/Grid.cpp @@ -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) diff --git a/src/Grid.hpp b/src/Grid.hpp index 2582ef7..44de88d 100644 --- a/src/Grid.hpp +++ b/src/Grid.hpp @@ -173,7 +173,7 @@ protected: std::unordered_set *fields; Layout *layout; Field marker; - + bool panning; bool on_rectangle(SDL_Rect *rect); public: Grid(Layout *layout_)