From: Holger Schemel Date: Wed, 9 May 2018 19:24:04 +0000 (+0200) Subject: added separate grid buttons for landscape and portrait screen orientation X-Git-Tag: 4.1.1.0~169 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=6cf6b75d5b9c84476a121cfd2ff11a0351ecba47;p=rocksndiamonds.git added separate grid buttons for landscape and portrait screen orientation Separate grid buttons can be configured for landscape and portrait screen orientation. The correct grid buttons are currently only selected at the start of the program, but not after the screen was rotated. --- diff --git a/src/libgame/system.c b/src/libgame/system.c index 33246588..5b7cede4 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -334,15 +334,8 @@ void InitOverlayInfo() { "111222", " vv " }, { "111222", " vv " } }; - int min_xsize, min_ysize; - int startx, starty; - int x, y; - - min_xsize = MIN(6, DEFAULT_GRID_XSIZE); - min_ysize = MIN(6, DEFAULT_GRID_YSIZE); - - startx = DEFAULT_GRID_XSIZE - min_xsize; - starty = DEFAULT_GRID_YSIZE - min_ysize; + int nr = GRID_ACTIVE_NR(); + int i, x, y; overlay.enabled = FALSE; overlay.active = FALSE; @@ -350,22 +343,39 @@ void InitOverlayInfo() overlay.show_grid = FALSE; overlay.show_grid_buttons = FALSE; - overlay.grid_xsize = DEFAULT_GRID_XSIZE; - overlay.grid_ysize = DEFAULT_GRID_YSIZE; + 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]; for (x = 0; x < MAX_GRID_XSIZE; x++) for (y = 0; y < MAX_GRID_YSIZE; y++) - overlay.grid_button[x][y] = CHAR_GRID_BUTTON_NONE; - - for (x = 0; x < min_xsize; x++) - for (y = 0; y < min_ysize; y++) - overlay.grid_button[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[startx + x][starty + y] = - default_grid_button[y][1][x]; + overlay.grid_button[x][y] = overlay.grid_button_all[nr][x][y]; overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE; diff --git a/src/libgame/system.h b/src/libgame/system.h index 06a47c3c..b5c5fcee 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -456,12 +456,30 @@ #define MIN_GRID_YSIZE 3 #define MAX_GRID_XSIZE 32 #define MAX_GRID_YSIZE 32 -#define DEFAULT_GRID_XSIZE 18 -#define DEFAULT_GRID_YSIZE MIN(MAX(MIN_GRID_YSIZE, \ - DEFAULT_GRID_XSIZE * \ - video.screen_height / \ - video.screen_width), \ +#define GRID_REAL_WIDTH MAX(video.screen_width, \ + video.screen_height) +#define GRID_REAL_HEIGHT 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 * \ + GRID_REAL_HEIGHT / \ + GRID_REAL_WIDTH), \ MAX_GRID_YSIZE) +#define DEFAULT_GRID_XSIZE_1 13 +#define DEFAULT_GRID_YSIZE_1 MIN(MAX(MIN_GRID_YSIZE, \ + DEFAULT_GRID_XSIZE_1 * \ + GRID_REAL_WIDTH / \ + GRID_REAL_HEIGHT), \ + MAX_GRID_YSIZE) + +#define DEFAULT_GRID_XSIZE(n) (n == 0 ? DEFAULT_GRID_XSIZE_0 : \ + DEFAULT_GRID_XSIZE_1) +#define DEFAULT_GRID_YSIZE(n) (n == 0 ? DEFAULT_GRID_YSIZE_0 : \ + DEFAULT_GRID_YSIZE_1) + +#define GRID_ACTIVE_NR() (video.screen_width > \ + video.screen_height ? 0 : 1) /* values for grid button characters for virtual buttons */ #define CHAR_GRID_BUTTON_NONE ' ' @@ -1000,9 +1018,12 @@ struct OverlayInfo boolean show_grid; boolean show_grid_buttons; + 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; }; diff --git a/src/screens.c b/src/screens.c index 1444fe8b..3dd571fe 100644 --- a/src/screens.c +++ b/src/screens.c @@ -7206,6 +7206,7 @@ boolean ConfigureVirtualButtonsMain() char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE]; char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE]; boolean set_grid_button = FALSE; + int nr = GRID_ACTIVE_NR(); int x, y; for (x = 0; x < MAX_GRID_XSIZE; x++) @@ -7369,6 +7370,10 @@ boolean ConfigureVirtualButtonsMain() BackToFront(); } + 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]; + overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE; SetOverlayShowGrid(FALSE);