summaryrefslogtreecommitdiff
path: root/macosx
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-01-16 13:53:10 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-01-16 13:53:10 +0100
commitc01719bc04c759d66be32d534d03057366c7f1b1 (patch)
treed361458f6e1a8b4eda86a509f244dd52f243119b /macosx
parent8fd762b5f3c437beee60c7124e30f6994a6fcb3a (diff)
downloadqtlocation-mapboxgl-c01719bc04c759d66be32d534d03057366c7f1b1.tar.gz
make bundle on mac os x and persist settings
Diffstat (limited to 'macosx')
-rw-r--r--macosx/CMakeLists.txt23
-rw-r--r--macosx/Info.plist.in36
-rw-r--r--macosx/main.mm39
-rw-r--r--macosx/settings.hpp18
-rw-r--r--macosx/settings.mm62
5 files changed, 156 insertions, 22 deletions
diff --git a/macosx/CMakeLists.txt b/macosx/CMakeLists.txt
index 2a839c0c1d..0ac0d4e441 100644
--- a/macosx/CMakeLists.txt
+++ b/macosx/CMakeLists.txt
@@ -9,6 +9,7 @@ PKG_SEARCH_MODULE(GLFW REQUIRED glfw3)
SET(macosx_SOURCES
main.mm
+ settings.mm
)
SET(macosx_HEADERS
@@ -23,10 +24,30 @@ LINK_DIRECTORIES(
${GLFW_LIBRARY_DIRS}
)
-ADD_EXECUTABLE(macosx
+# Define some settings for the Bundle
+set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
+set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.mapbox.llmr.native")
+set(MACOSX_BUNDLE_ICON_FILE "macosx.icns")
+set(MACOSX_BUNDLE_INFO_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
+set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
+set(MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
+set(MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
+set(MACOSX_BUNDLE_COPYRIGHT "(c) 2014 Mapbox")
+
+# Add Mac OS X specific icon
+#list(APPEND macosx_RESOURCES ../resources/macosx.icns)
+
+# Ensures that resources end up in the Resources folder
+set_source_files_properties(${macosx_RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
+
+add_executable(macosx MACOSX_BUNDLE
${macosx_SOURCES}
+ ${macosx_RESOURCES}
)
+
+set_target_properties(macosx PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/macosx/Info.plist.in)
+
TARGET_LINK_LIBRARIES(macosx
llmr
${COCOA_LIBRARY}
diff --git a/macosx/Info.plist.in b/macosx/Info.plist.in
new file mode 100644
index 0000000000..a77546b82f
--- /dev/null
+++ b/macosx/Info.plist.in
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
+ <key>CFBundleGetInfoString</key>
+ <string>${MACOSX_BUNDLE_INFO_STRING}</string>
+ <key>CFBundleIconFile</key>
+ <string>${MACOSX_BUNDLE_ICON_FILE}</string>
+ <key>CFBundleIdentifier</key>
+ <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleLongVersionString</key>
+ <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
+ <key>CFBundleName</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
+ <key>CFBundleSignature</key>
+ <string>LLMR</string>
+ <key>CFBundleVersion</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
+ <key>CSResourcesFileMapped</key>
+ <true/>
+ <key>NSHumanReadableCopyright</key>
+ <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
+ <key>NSHighResolutionCapable</key>
+ <true/>
+</dict>
+</plist> \ No newline at end of file
diff --git a/macosx/main.mm b/macosx/main.mm
index ba75d1b35c..80a7df00d4 100644
--- a/macosx/main.mm
+++ b/macosx/main.mm
@@ -1,8 +1,10 @@
#include <llmr/llmr.hpp>
#include <GLFW/glfw3.h>
#import <Foundation/Foundation.h>
+#import <AppKit/AppKit.h>
#include <llmr/platform/platform.hpp>
#include <llmr/map/tile.hpp>
+#include "settings.hpp"
class MapView {
public:
@@ -11,7 +13,8 @@ public:
tracking(false),
rotating(false),
last_click(-1),
- map(new llmr::map()) {
+ settings(new llmr::macosx_settings()),
+ map(new llmr::map(settings)) {
}
void init() {
@@ -32,18 +35,16 @@ public:
glfwMakeContextCurrent(window);
- int stencil_bits = glfwGetWindowAttrib(window, GLFW_STENCIL_BITS);
- fprintf(stderr, "stencil bits: %d\n", stencil_bits);
-
+ settings->load();
map->setup();
-
int width, height;
glfwGetWindowSize(window, &width, &height);
map->resize(width, height);
glfwSwapInterval(1);
+ map->loadSettings();
glfwSetCursorPosCallback(window, mousemove);
glfwSetMouseButtonCallback(window, mouseclick);
@@ -56,28 +57,27 @@ public:
}
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);
+ MapView *view = (MapView *)glfwGetWindowUserPointer(window);
if (action == GLFW_RELEASE) {
switch (key) {
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, true);
break;
+ case GLFW_KEY_TAB:
+ view->map->toggleDebug();
+ break;
+ case GLFW_KEY_R:
+ if (!mods) view->map->resetPosition();
+ break;
+ case GLFW_KEY_N:
+ if (!mods) view->map->resetNorth();
+ break;
}
}
}
@@ -195,6 +195,7 @@ public:
double last_click;
GLFWwindow *window;
+ llmr::macosx_settings *settings;
llmr::map *map;
};
@@ -210,9 +211,7 @@ void restart(void *) {
void request(void *, tile::ptr tile) {
assert((bool)tile);
- // fprintf(stderr, "request %d/%d/%d\n", tile->z, tile->x, tile->y);
- // fprintf(stderr, "requesting tile\n");
// NSString *urlTemplate = @"http://api.tiles.mapbox.com/v3/mapbox.mapbox-streets-v4/%d/%d/%d.vector.pbf";
NSString *urlTemplate = @"http://localhost:3333/gl/tiles/plain/%d-%d-%d.vector.pbf";
NSString *urlString = [NSString
@@ -248,8 +247,6 @@ void request(void *, tile::ptr tile) {
return;
}
}
-
- fprintf(stderr, "[%s] status code %d\n", [urlString UTF8String], code);
}
dispatch_async(dispatch_get_main_queue(), ^ {
diff --git a/macosx/settings.hpp b/macosx/settings.hpp
new file mode 100644
index 0000000000..7c23f829ea
--- /dev/null
+++ b/macosx/settings.hpp
@@ -0,0 +1,18 @@
+#ifndef LLMR_MACOSX_SETTINGS
+#define LLMR_MACOSX_SETTINGS
+
+#include <llmr/map/settings.hpp>
+
+namespace llmr {
+
+class macosx_settings : public settings {
+public:
+ macosx_settings();
+ virtual void save();
+ virtual void load();
+ virtual void clear();
+};
+
+}
+
+#endif
diff --git a/macosx/settings.mm b/macosx/settings.mm
new file mode 100644
index 0000000000..31395781ff
--- /dev/null
+++ b/macosx/settings.mm
@@ -0,0 +1,62 @@
+#import <Foundation/Foundation.h>
+
+#include "settings.hpp"
+
+
+using namespace llmr;
+
+macosx_settings::macosx_settings() {
+ NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
+
+ // position
+ [NSNumber numberWithDouble:longitude], @"longitude",
+ [NSNumber numberWithDouble:latitude], @"latitude",
+ [NSNumber numberWithDouble:scale], @"scale",
+ [NSNumber numberWithDouble:angle], @"angle",
+
+ // debug
+ [NSNumber numberWithBool:debug], @"debug",
+
+ nil
+ ];
+
+ [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
+}
+
+void macosx_settings::load() {
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ // position
+ longitude = [defaults doubleForKey:@"longitude"];
+ latitude = [defaults doubleForKey:@"latitude"];
+ scale = [defaults doubleForKey:@"scale"];
+ angle = [defaults doubleForKey:@"angle"];
+
+ // debug
+ debug = [defaults boolForKey:@"debug"];
+}
+
+void macosx_settings::save() {
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
+
+ // position
+ [NSNumber numberWithDouble:longitude], @"longitude",
+ [NSNumber numberWithDouble:latitude], @"latitude",
+ [NSNumber numberWithDouble:scale], @"scale",
+ [NSNumber numberWithDouble:angle], @"angle",
+
+ // debug
+ [NSNumber numberWithBool:debug], @"debug",
+
+ nil
+ ];
+ [defaults setPersistentDomain:appDefaults forName:[[NSBundle mainBundle] bundleIdentifier]];
+
+ [defaults synchronize];
+}
+
+void macosx_settings::clear() {
+ // TODO
+}