From b6e5a03cd2a153677d0f19bb276d63d79767cd89 Mon Sep 17 00:00:00 2001 From: Nathan Matsuda Date: Thu, 12 Mar 2020 12:45:27 -0700 Subject: [PATCH] added screen index for multiple monitors. fixed scroll wheel zoom crash due to negative max dist Former-commit-id: 26e86f54547bcb5420667a15ddeb40842f2cb8f7 Former-commit-id: 5d84159b16a0c9a0ef487f10c1377b420af9f5e9 --- AircraftData.cpp | 1 + Input.cpp | 10 +++++++++- init.c | 2 +- map1090.REMOVED.git-id | 2 +- map1090.cpp | 7 ++++--- structs.h | 1 + 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/AircraftData.cpp b/AircraftData.cpp index b00ea94..ab5bb81 100644 --- a/AircraftData.cpp +++ b/AircraftData.cpp @@ -117,6 +117,7 @@ AircraftData::AircraftData(){ appData.screen_height = 0; appData.screen_depth = 32; appData.fullscreen = 0; + appData.screen_index = 0; // Initialize status Status.msgRate = 0; diff --git a/Input.cpp b/Input.cpp index 4c9c184..1807066 100644 --- a/Input.cpp +++ b/Input.cpp @@ -13,6 +13,10 @@ static uint64_t mstime(void) { return mst; } +template int sgn(T val) { + return (T(0) < val) - (val < T(0)); +} + void Input::getInput() { SDL_Event event; @@ -39,7 +43,11 @@ void Input::getInput() break; case SDL_MOUSEWHEEL: - appData.maxDist *= 1.0 + event.wheel.y / 10.0; + appData.maxDist *= 1.0 + 0.5 * sgn(event.wheel.y); + if(appData.maxDist < 0.001f) { + appData.maxDist = 0.001f; + } + appData.mapTargetMaxDist = 0; appData.mapMoved = 1; break; diff --git a/init.c b/init.c index 1eccded..e8224a6 100644 --- a/init.c +++ b/init.c @@ -36,7 +36,7 @@ void init(char *title) { appData.screen_height= DM.h; } - appData.window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, appData.screen_width, appData.screen_height, flags); + appData.window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED_DISPLAY(appData.screen_index), SDL_WINDOWPOS_CENTERED_DISPLAY(appData.screen_index), appData.screen_width, appData.screen_height, flags); appData.renderer = SDL_CreateRenderer(appData.window, -1, SDL_RENDERER_ACCELERATED); appData.mapTexture = SDL_CreateTexture(appData.renderer, SDL_PIXELFORMAT_ARGB8888, diff --git a/map1090.REMOVED.git-id b/map1090.REMOVED.git-id index 5805694..2fd812a 100644 --- a/map1090.REMOVED.git-id +++ b/map1090.REMOVED.git-id @@ -1 +1 @@ -3e3eb8a1241fe042f8979c8ab0fb931f24e6100f \ No newline at end of file +dbb808dc2f784e53f7c3967e7b0bb11f9ef1a825 \ No newline at end of file diff --git a/map1090.cpp b/map1090.cpp index 533724f..528613a 100644 --- a/map1090.cpp +++ b/map1090.cpp @@ -70,6 +70,7 @@ void showHelp(void) { "--help Show this help\n" "--uiscale UI global scaling (default: 1)\n" "--screensize Set frame buffer resolution (default: screen resolution)\n" + "--screenindex Set the index of the display to use (default: 0)\n" "--fullscreen Start fullscreen\n" ); } @@ -94,9 +95,7 @@ int main(int argc, char **argv) { for (j = 1; j < argc; j++) { int more = ((j + 1) < argc); // There are more arguments - if (!strcmp(argv[j],"--net-bo-port") && more) { - aircraftData.modes.net_input_beast_port = atoi(argv[++j]); - } else if (!strcmp(argv[j],"--port") && more) { + if (!strcmp(argv[j],"--port") && more) { aircraftData.modes.net_input_beast_port = atoi(argv[++j]); } else if (!strcmp(argv[j],"--server") && more) { std::strcpy(aircraftData.server, argv[++j]); @@ -110,6 +109,8 @@ int main(int argc, char **argv) { aircraftData.modes.metric = 1; } else if (!strcmp(argv[j],"--fullscreen")) { appData.fullscreen = 1; + } else if (!strcmp(argv[j],"--screenindex")) { + appData.screen_index = atoi(argv[++j]); } else if (!strcmp(argv[j],"--uiscale") && more) { appData.screen_uiscale = atoi(argv[++j]); } else if (!strcmp(argv[j],"--screensize") && more) { diff --git a/structs.h b/structs.h index 43be8ff..2b46524 100644 --- a/structs.h +++ b/structs.h @@ -36,6 +36,7 @@ typedef struct AppData int screen_height; int screen_depth; int fullscreen; + int screen_index; float centerLon; float centerLat;