From a3a5a96bfed27b02f3a9f7cc2863db988b4e41a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Jan 2014 10:54:02 +0100 Subject: [PATCH] add keyboard shortcuts for resetting position --- include/llmr/map/map.hpp | 8 ++++++++ macosx/main.mm | 30 ++++++++++++++++++++++++++++++ src/map/map.cpp | 13 +++++++++++++ 3 files changed, 51 insertions(+) diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index fb5e3a805..0947daafb 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -26,6 +26,14 @@ public: void tileLoaded(tile::ptr tile); void tileFailed(tile::ptr tile); + /* position */ + void resetNorth(); + void resetPosition(); + // void setAngle(double angle); + // void setLonLat(double lon, double lat); + // void setZoom(double zoom); + // void setLonLatZoom(double lon, double lat, double zoom); + private: bool findLoadedChildren(const tile_id& id, int32_t maxCoveringZoom, std::forward_list& retain); bool findLoadedParent(const tile_id& id, int32_t minCoveringZoom, std::forward_list& retain); diff --git a/macosx/main.mm b/macosx/main.mm index 15f472770..4f2bfec14 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -49,10 +49,40 @@ public: glfwSetMouseButtonCallback(window, mouseclick); glfwSetWindowSizeCallback(window, resize); glfwSetScrollCallback(window, scroll); + glfwSetCharCallback(window, character); + glfwSetKeyCallback(window, key); glfwSetWindowUserPointer(window, this); } + static void character(GLFWwindow *window, unsigned int codepoint) { + MapView *view = (MapView *)glfwGetWindowUserPointer(window); + switch (codepoint) { + case L'n': + case L'N': + view->map->resetNorth(); + break; + case L'r': + case L'R': + view->map->resetPosition(); + break; + } + } + + + static void key(GLFWwindow *window, int key, int scancode, int action, int mods) { + // MapView *view = (MapView *)glfwGetWindowUserPointer(window); + + if (action == GLFW_RELEASE) { + switch (key) { + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, true); + break; + } + } + } + + static void scroll(GLFWwindow *window, double xoffset, double yoffset) { MapView *view = (MapView *)glfwGetWindowUserPointer(window); double delta = yoffset * 40; diff --git a/src/map/map.cpp b/src/map/map.cpp index d9441a441..5f9e0b7ed 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -53,6 +53,19 @@ void map::rotateBy(double cx, double cy, double sx, double sy, double ex, double platform::restart(this); } +void map::resetNorth() { + transform->setAngle(0); + updateTiles(); + platform::restart(this); +} + +void map::resetPosition() { + transform->setAngle(0); + transform->setLonLat(0, 0); + transform->setZoom(0); + updateTiles(); + platform::restart(this); +} tile::ptr map::hasTile(const tile_id& id) { for (tile::ptr& tile : tiles) {