add keyboard shortcuts for resetting position

This commit is contained in:
Konstantin Käfer
2014-01-16 10:54:02 +01:00
parent ad26f67095
commit a3a5a96bfe
3 changed files with 51 additions and 0 deletions

View File

@@ -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<tile_id>& retain);
bool findLoadedParent(const tile_id& id, int32_t minCoveringZoom, std::forward_list<tile_id>& retain);

View File

@@ -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;

View File

@@ -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) {