added screen index for multiple monitors. fixed scroll wheel zoom crash due to negative max dist

Former-commit-id: f9807a6a36d059205f98a970e1d74a7e6e0c175a
Former-commit-id: 3ff991dca29e947c067c452c3fe6e742fe47b03d
This commit is contained in:
Nathan Matsuda 2020-03-12 12:46:26 -07:00
parent bdaae19854
commit 15a7dc59c0
6 changed files with 17 additions and 6 deletions

View file

@ -117,6 +117,7 @@ AircraftData::AircraftData(){
appData.screen_height = 0; appData.screen_height = 0;
appData.screen_depth = 32; appData.screen_depth = 32;
appData.fullscreen = 0; appData.fullscreen = 0;
appData.screen_index = 0;
// Initialize status // Initialize status
Status.msgRate = 0; Status.msgRate = 0;

View file

@ -13,6 +13,10 @@ static uint64_t mstime(void) {
return mst; return mst;
} }
template <typename T> int sgn(T val) {
return (T(0) < val) - (val < T(0));
}
void Input::getInput() void Input::getInput()
{ {
SDL_Event event; SDL_Event event;
@ -39,7 +43,11 @@ void Input::getInput()
break; break;
case SDL_MOUSEWHEEL: 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.mapTargetMaxDist = 0;
appData.mapMoved = 1; appData.mapMoved = 1;
break; break;

2
init.c
View file

@ -36,7 +36,7 @@ void init(char *title) {
appData.screen_height= DM.h; 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.renderer = SDL_CreateRenderer(appData.window, -1, SDL_RENDERER_ACCELERATED);
appData.mapTexture = SDL_CreateTexture(appData.renderer, appData.mapTexture = SDL_CreateTexture(appData.renderer,
SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888,

View file

@ -1 +1 @@
3e3eb8a1241fe042f8979c8ab0fb931f24e6100f dbb808dc2f784e53f7c3967e7b0bb11f9ef1a825

View file

@ -70,6 +70,7 @@ void showHelp(void) {
"--help Show this help\n" "--help Show this help\n"
"--uiscale <factor> UI global scaling (default: 1)\n" "--uiscale <factor> UI global scaling (default: 1)\n"
"--screensize <width> <height> Set frame buffer resolution (default: screen resolution)\n" "--screensize <width> <height> Set frame buffer resolution (default: screen resolution)\n"
"--screenindex <i> Set the index of the display to use (default: 0)\n"
"--fullscreen Start fullscreen\n" "--fullscreen Start fullscreen\n"
); );
} }
@ -94,9 +95,7 @@ int main(int argc, char **argv) {
for (j = 1; j < argc; j++) { for (j = 1; j < argc; j++) {
int more = ((j + 1) < argc); // There are more arguments int more = ((j + 1) < argc); // There are more arguments
if (!strcmp(argv[j],"--net-bo-port") && more) { if (!strcmp(argv[j],"--port") && more) {
aircraftData.modes.net_input_beast_port = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--port") && more) {
aircraftData.modes.net_input_beast_port = atoi(argv[++j]); aircraftData.modes.net_input_beast_port = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--server") && more) { } else if (!strcmp(argv[j],"--server") && more) {
std::strcpy(aircraftData.server, argv[++j]); std::strcpy(aircraftData.server, argv[++j]);
@ -110,6 +109,8 @@ int main(int argc, char **argv) {
aircraftData.modes.metric = 1; aircraftData.modes.metric = 1;
} else if (!strcmp(argv[j],"--fullscreen")) { } else if (!strcmp(argv[j],"--fullscreen")) {
appData.fullscreen = 1; appData.fullscreen = 1;
} else if (!strcmp(argv[j],"--screenindex")) {
appData.screen_index = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--uiscale") && more) { } else if (!strcmp(argv[j],"--uiscale") && more) {
appData.screen_uiscale = atoi(argv[++j]); appData.screen_uiscale = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--screensize") && more) { } else if (!strcmp(argv[j],"--screensize") && more) {

View file

@ -36,6 +36,7 @@ typedef struct AppData
int screen_height; int screen_height;
int screen_depth; int screen_depth;
int fullscreen; int fullscreen;
int screen_index;
float centerLon; float centerLon;
float centerLat; float centerLat;