diff options
author | Justin R. Miller <incanus@codesorcery.net> | 2014-02-21 14:18:48 -0800 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2014-02-21 14:18:48 -0800 |
commit | e59a5f1c1a9dd2f1921070cb4c03956c1278429b (patch) | |
tree | 60febe484201a548e37ef741e1e33f1c005f9e60 /macosx | |
parent | cfbde8242977c7a1b691261dcd3611915de5714b (diff) | |
parent | 32da0768b72da5a40a92f8c62465dbe16de2e41e (diff) | |
download | qtlocation-mapboxgl-e59a5f1c1a9dd2f1921070cb4c03956c1278429b.tar.gz |
Merge branch 'master' into tile-cancels
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/llmr-app.gyp | 2 | ||||
-rw-r--r-- | macosx/main.mm | 40 |
2 files changed, 26 insertions, 16 deletions
diff --git a/macosx/llmr-app.gyp b/macosx/llmr-app.gyp index b206e8d76a..069f5bb80f 100644 --- a/macosx/llmr-app.gyp +++ b/macosx/llmr-app.gyp @@ -46,7 +46,7 @@ 'CLANG_ENABLE_OBJC_ARC': 'YES' }, "dependencies": [ - "../llmr.gyp:llmr-osx" + "../llmr.gyp:llmr-x86" ] } ] diff --git a/macosx/main.mm b/macosx/main.mm index 49fa13ea43..1a37419c5f 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -6,9 +6,9 @@ #include <llmr/map/tile.hpp> #include "settings.hpp" -#include <thread> +#include <cstdio> -NSString *const MBXNeedsRenderNotification = @"MBXNeedsRenderNotification"; +#include <thread> class MapView { public: @@ -40,8 +40,14 @@ public: glfwSetWindowUserPointer(window, this); glfwMakeContextCurrent(window); + + int width, height; + glfwGetWindowSize(window, &width, &height); + int fb_width, fb_height; + glfwGetFramebufferSize(window, &fb_width, &fb_height); + settings.load(); - map.setup(); + map.setup((double)fb_width / width); resize(window, 0, 0); @@ -56,15 +62,9 @@ public: glfwSetScrollCallback(window, scroll); glfwSetCharCallback(window, character); glfwSetKeyCallback(window, key); - - renderObserver = [[NSNotificationCenter defaultCenter] addObserverForName:MBXNeedsRenderNotification - object:nil - queue:[NSOperationQueue mainQueue] - usingBlock: ^ (NSNotification * notification) { - dirty = true; - }]; } + static void character(GLFWwindow *window, unsigned int codepoint) { } @@ -111,6 +111,7 @@ public: scale = 1.0 / scale; } + mapView->map.startScaling(); mapView->map.scaleBy(scale, mapView->last_x, mapView->last_y); } @@ -133,11 +134,14 @@ public: if (mapView->rotating) { mapView->start_x = mapView->last_x; mapView->start_y = mapView->last_y; + } else { + mapView->map.stopRotating(); } } else if (button == GLFW_MOUSE_BUTTON_LEFT) { mapView->tracking = action == GLFW_PRESS; if (action == GLFW_RELEASE) { + mapView->map.stopPanning(); double now = glfwGetTime(); if (now - mapView->last_click < 0.4) { mapView->map.scaleBy(2.0, mapView->last_x, mapView->last_y); @@ -150,8 +154,14 @@ public: static void mousemove(GLFWwindow *window, double x, double y) { MapView *mapView = (MapView *)glfwGetWindowUserPointer(window); if (mapView->tracking) { - mapView->map.moveBy(x - mapView->last_x, y - mapView->last_y); + double dx = x - mapView->last_x; + double dy = y - mapView->last_y; + if (dx || dy) { + mapView->map.startPanning(); + mapView->map.moveBy(dx, dy); + } } else if (mapView->rotating) { + mapView->map.startRotating(); mapView->map.rotateBy(mapView->start_x, mapView->start_y, mapView->last_x, mapView->last_y, x, y); } mapView->last_x = x; @@ -199,7 +209,6 @@ public: } ~MapView() { - [[NSNotificationCenter defaultCenter] removeObserver:renderObserver]; glfwTerminate(); } @@ -216,8 +225,6 @@ public: GLFWwindow *window; llmr::Settings_MacOSX settings; llmr::Map map; - - id renderObserver; }; MapView *mapView; @@ -226,8 +233,11 @@ NSOperationQueue *queue; namespace llmr { namespace platform { -void restart(void *) { +void restart() { mapView->dirty = true; + CGEventRef event = CGEventCreate(NULL); + CGEventSetType(event, kCGEventMouseMoved); + [[NSApplication sharedApplication] postEvent: [NSEvent eventWithCGEvent:event] atStart:NO]; } void request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback) |