From 87627cd206d108069804a37f7c7694f672f67479 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 11 May 2018 01:30:30 +0200 Subject: [PATCH] moved virtual buttons definitions to setup data structures --- src/events.c | 8 ++++---- src/files.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ src/init.c | 15 +++++++++++--- src/libgame/system.c | 44 ++++----------------------------------- src/libgame/system.h | 18 +++++++++------- src/screens.c | 2 +- 6 files changed, 81 insertions(+), 55 deletions(-) diff --git a/src/events.c b/src/events.c index 4fcbd199..21209318 100644 --- a/src/events.c +++ b/src/events.c @@ -653,17 +653,17 @@ void HandleWindowEvent(WindowEvent *event) // save active virtual buttons (in case of just configuring them) for (x = 0; x < MAX_GRID_XSIZE; x++) for (y = 0; y < MAX_GRID_YSIZE; y++) - overlay.grid_button_all[nr][x][y] = overlay.grid_button[x][y]; + setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y]; } nr = GRID_ACTIVE_NR(); - overlay.grid_xsize = overlay.grid_xsize_all[nr]; - overlay.grid_ysize = overlay.grid_ysize_all[nr]; + overlay.grid_xsize = setup.touch.grid_xsize[nr]; + overlay.grid_ysize = setup.touch.grid_ysize[nr]; for (x = 0; x < MAX_GRID_XSIZE; x++) for (y = 0; y < MAX_GRID_YSIZE; y++) - overlay.grid_button[x][y] = overlay.grid_button_all[nr][x][y]; + overlay.grid_button[x][y] = setup.touch.grid_button[nr][x][y]; } } } diff --git a/src/files.c b/src/files.c index 3f456937..86fcdc71 100644 --- a/src/files.c +++ b/src/files.c @@ -8721,6 +8721,55 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->touch.move_distance = TOUCH_MOVE_DISTANCE_DEFAULT; /* percent */ si->touch.drop_distance = TOUCH_DROP_DISTANCE_DEFAULT; /* percent */ + for (i = 0; i < 2; i++) + { + char *default_grid_button[6][2] = + { + { " ", " ^^ " }, + { " ", " ^^ " }, + { " ", "<< >>" }, + { " ", "<< >>" }, + { "111222", " vv " }, + { "111222", " vv " } + }; + int grid_xsize = DEFAULT_GRID_XSIZE(i); + int grid_ysize = DEFAULT_GRID_YSIZE(i); + int min_xsize = MIN(6, grid_xsize); + int min_ysize = MIN(6, grid_ysize); + int startx = grid_xsize - min_xsize; + int starty = grid_ysize - min_ysize; + int x, y; + + // virtual buttons grid can only be set to defaults if video is initialized + // (this will be repeated if virtual buttons are not loaded from setup file) + if (video.initialized) + { + si->touch.grid_xsize[i] = grid_xsize; + si->touch.grid_ysize[i] = grid_ysize; + } + else + { + si->touch.grid_xsize[i] = -1; + si->touch.grid_ysize[i] = -1; + } + + for (x = 0; x < MAX_GRID_XSIZE; x++) + for (y = 0; y < MAX_GRID_YSIZE; y++) + si->touch.grid_button[i][x][y] = CHAR_GRID_BUTTON_NONE; + + for (x = 0; x < min_xsize; x++) + for (y = 0; y < min_ysize; y++) + si->touch.grid_button[i][x][starty + y] = + default_grid_button[y][0][x]; + + for (x = 0; x < min_xsize; x++) + for (y = 0; y < min_ysize; y++) + si->touch.grid_button[i][startx + x][starty + y] = + default_grid_button[y][1][x]; + } + + si->touch.grid_initialized = video.initialized; + si->editor.el_boulderdash = TRUE; si->editor.el_emerald_mine = TRUE; si->editor.el_emerald_mine_club = TRUE; diff --git a/src/init.c b/src/init.c index 3e0f01db..863704ef 100644 --- a/src/init.c +++ b/src/init.c @@ -5237,6 +5237,17 @@ static void InitMixer() StartMixer(); } +static void InitVideoOverlay() +{ + // if virtual buttons are not loaded from setup file, repeat initializing + // virtual buttons grid with default values now that video is initialized + if (!setup.touch.grid_initialized) + InitSetup(); + + InitTileCursorInfo(); + InitOverlayInfo(); +} + void InitGfxBuffers() { static int win_xsize_last = -1; @@ -6013,9 +6024,7 @@ void OpenAll() InitVideoDefaults(); InitVideoDisplay(); InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen); - - InitTileCursorInfo(); - InitOverlayInfo(); + InitVideoOverlay(); print_timestamp_time("[init video stuff]"); diff --git a/src/libgame/system.c b/src/libgame/system.c index 3363ac2b..b7970fd5 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -325,56 +325,20 @@ void InitTileCursorInfo() void InitOverlayInfo() { - static char *default_grid_button[6][2] = - { - { " ", " ^^ " }, - { " ", " ^^ " }, - { " ", "<< >>" }, - { " ", "<< >>" }, - { "111222", " vv " }, - { "111222", " vv " } - }; int nr = GRID_ACTIVE_NR(); - int i, x, y; + int x, y; overlay.enabled = FALSE; overlay.active = FALSE; overlay.show_grid = FALSE; - for (i = 0; i < 2; i++) - { - int grid_xsize = DEFAULT_GRID_XSIZE(i); - int grid_ysize = DEFAULT_GRID_YSIZE(i); - int min_xsize = MIN(6, grid_xsize); - int min_ysize = MIN(6, grid_ysize); - int startx = grid_xsize - min_xsize; - int starty = grid_ysize - min_ysize; - - overlay.grid_xsize_all[i] = grid_xsize; - overlay.grid_ysize_all[i] = grid_ysize; - - for (x = 0; x < MAX_GRID_XSIZE; x++) - for (y = 0; y < MAX_GRID_YSIZE; y++) - overlay.grid_button_all[i][x][y] = CHAR_GRID_BUTTON_NONE; - - for (x = 0; x < min_xsize; x++) - for (y = 0; y < min_ysize; y++) - overlay.grid_button_all[i][x][starty + y] = - default_grid_button[y][0][x]; - - for (x = 0; x < min_xsize; x++) - for (y = 0; y < min_ysize; y++) - overlay.grid_button_all[i][startx + x][starty + y] = - default_grid_button[y][1][x]; - } - - overlay.grid_xsize = overlay.grid_xsize_all[nr]; - overlay.grid_ysize = overlay.grid_ysize_all[nr]; + overlay.grid_xsize = setup.touch.grid_xsize[nr]; + overlay.grid_ysize = setup.touch.grid_ysize[nr]; for (x = 0; x < MAX_GRID_XSIZE; x++) for (y = 0; y < MAX_GRID_YSIZE; y++) - overlay.grid_button[x][y] = overlay.grid_button_all[nr][x][y]; + overlay.grid_button[x][y] = setup.touch.grid_button[nr][x][y]; overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE; diff --git a/src/libgame/system.h b/src/libgame/system.h index 480ef0d4..4ef22022 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -456,10 +456,10 @@ #define MIN_GRID_YSIZE 3 #define MAX_GRID_XSIZE 32 #define MAX_GRID_YSIZE 32 -#define GRID_REAL_WIDTH MAX(video.screen_width, \ - video.screen_height) -#define GRID_REAL_HEIGHT MIN(video.screen_width, \ - video.screen_height) +#define GRID_REAL_WIDTH MAX(1, MAX(video.screen_width, \ + video.screen_height)) +#define GRID_REAL_HEIGHT MAX(1, MIN(video.screen_width, \ + video.screen_height)) #define DEFAULT_GRID_XSIZE_0 18 #define DEFAULT_GRID_YSIZE_0 MIN(MAX(MIN_GRID_YSIZE, \ DEFAULT_GRID_XSIZE_0 * \ @@ -1017,12 +1017,9 @@ struct OverlayInfo boolean show_grid; - int grid_xsize_all[2]; - int grid_ysize_all[2]; int grid_xsize; int grid_ysize; - char grid_button_all[2][MAX_GRID_XSIZE][MAX_GRID_YSIZE]; char grid_button[MAX_GRID_XSIZE][MAX_GRID_YSIZE]; char grid_button_highlight; }; @@ -1053,6 +1050,13 @@ struct SetupTouchInfo char *control_type; int move_distance; int drop_distance; + + int grid_xsize[2]; + int grid_ysize[2]; + + char grid_button[2][MAX_GRID_XSIZE][MAX_GRID_YSIZE]; + + boolean grid_initialized; }; struct SetupInputInfo diff --git a/src/screens.c b/src/screens.c index 8b5c2bb4..f49f8959 100644 --- a/src/screens.c +++ b/src/screens.c @@ -7397,7 +7397,7 @@ boolean ConfigureVirtualButtonsMain() for (x = 0; x < MAX_GRID_XSIZE; x++) for (y = 0; y < MAX_GRID_YSIZE; y++) - overlay.grid_button_all[nr][x][y] = overlay.grid_button[x][y]; + setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y]; overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE; -- 2.34.1