static void DrawTouchInputOverlay_ShowGrid(int alpha)
{
SDL_Rect rect;
- int grid_xsize = 18;
- int grid_ysize = 11;
+ int grid_xsize = overlay.grid_xsize;
+ int grid_ysize = overlay.grid_ysize;
int x, y;
SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha);
rect.y = (y + 0) * video.screen_height / grid_ysize;
rect.h = (y + 1) * video.screen_height / grid_ysize - rect.y;
- SDL_RenderDrawRect(sdl_renderer, &rect);
+ if (overlay.grid_button[x][y] == CHAR_GRID_BUTTON_NONE)
+ SDL_RenderDrawRect(sdl_renderer, &rect);
+ }
+ }
+
+ SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 255);
+}
+
+static void DrawTouchInputOverlay_ShowGridButtons(int alpha)
+{
+ static int alpha_max = SDL_ALPHA_OPAQUE / 2;
+ static int alpha_step = 5;
+ static int alpha_direction = 0;
+ static int alpha_highlight = 0;
+ SDL_Rect rect;
+ int grid_xsize = overlay.grid_xsize;
+ int grid_ysize = overlay.grid_ysize;
+ int x, y;
+
+ if (alpha == alpha_max)
+ {
+ if (alpha_direction < 0)
+ {
+ alpha_highlight = MAX(0, alpha_highlight - alpha_step);
+
+ if (alpha_highlight == 0)
+ alpha_direction = 1;
+ }
+ else
+ {
+ alpha_highlight = MIN(alpha_highlight + alpha_step, alpha_max);
+
+ if (alpha_highlight == alpha_max)
+ alpha_direction = -1;
+ }
+ }
+ else
+ {
+ alpha_direction = 1;
+ alpha_highlight = alpha;
+ }
+
+ SDL_SetRenderDrawBlendMode(sdl_renderer, SDL_BLENDMODE_BLEND);
+
+ for (x = 0; x < grid_xsize; x++)
+ {
+ rect.x = (x + 0) * video.screen_width / grid_xsize;
+ rect.w = (x + 1) * video.screen_width / grid_xsize - rect.x;
+
+ for (y = 0; y < grid_ysize; y++)
+ {
+ rect.y = (y + 0) * video.screen_height / grid_ysize;
+ rect.h = (y + 1) * video.screen_height / grid_ysize - rect.y;
+
+ if (overlay.grid_button[x][y] == overlay.grid_button_highlight)
+ SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha_highlight);
+ else
+ SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha);
+
+ if (overlay.grid_button[x][y] != CHAR_GRID_BUTTON_NONE)
+ SDL_RenderFillRect(sdl_renderer, &rect);
}
}
static boolean initialized = FALSE;
static boolean deactivated = TRUE;
static boolean show_grid = FALSE;
+ static boolean show_grid_buttons = FALSE;
static int width = 0, height = 0;
static int alpha_max = SDL_ALPHA_OPAQUE / 2;
static int alpha_step = 5;
else if (deactivated)
show_grid = FALSE;
+ if (overlay.show_grid_buttons)
+ show_grid_buttons = TRUE;
+ else if (deactivated)
+ show_grid_buttons = FALSE;
+
if (show_grid)
- {
DrawTouchInputOverlay_ShowGrid(alpha);
+ if (show_grid_buttons)
+ DrawTouchInputOverlay_ShowGridButtons(alpha);
+
+ if (show_grid || show_grid_buttons)
return;
- }
if (!initialized)
{
void InitOverlayInfo()
{
+ static char *default_grid_button[6][2] =
+ {
+ { " ", " ^^ " },
+ { " ", " ^^ " },
+ { " ", "<< >>" },
+ { " ", "<< >>" },
+ { "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;
+
overlay.enabled = FALSE;
overlay.active = FALSE;
overlay.show_grid = FALSE;
+ overlay.show_grid_buttons = FALSE;
+
+ overlay.grid_xsize = DEFAULT_GRID_XSIZE;
+ overlay.grid_ysize = DEFAULT_GRID_YSIZE;
+
+ 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_highlight = CHAR_GRID_BUTTON_NONE;
#if defined(PLATFORM_ANDROID)
if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
void SetOverlayShowGrid(boolean show_grid)
{
overlay.show_grid = show_grid;
+ overlay.show_grid_buttons = show_grid;
SetOverlayActive(show_grid);
#define SCREEN_KEYBOARD_POS(h) ((h) / 2)
#endif
-
/* default input keys */
#define DEFAULT_KEY_LEFT KSYM_Left
#define DEFAULT_KEY_RIGHT KSYM_Right
#define MAX_GLOBAL_ANIMS 32
#define MAX_GLOBAL_ANIM_PARTS 32
+/* minimum/maximum/default x/y grid size for virtual buttons */
+#define MIN_GRID_XSIZE 3
+#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), \
+ MAX_GRID_YSIZE)
+
+/* values for grid button characters for virtual buttons */
+#define CHAR_GRID_BUTTON_NONE ' '
+#define CHAR_GRID_BUTTON_LEFT '<'
+#define CHAR_GRID_BUTTON_RIGHT '>'
+#define CHAR_GRID_BUTTON_UP '^'
+#define CHAR_GRID_BUTTON_DOWN 'v'
+#define CHAR_GRID_BUTTON_SNAP '1'
+#define CHAR_GRID_BUTTON_DROP '2'
+
/* default name for empty highscore entry */
#define EMPTY_PLAYER_NAME "no name"
boolean active; /* overlay activated (depending on game mode) */
boolean show_grid;
+ boolean show_grid_buttons;
+
+ int grid_xsize;
+ int grid_ysize;
+
+ char grid_button[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
+ char grid_button_highlight;
};
struct JoystickInfo
"Snap Field",
"Drop Element"
};
+ char grid_button[] =
+ {
+ CHAR_GRID_BUTTON_LEFT,
+ CHAR_GRID_BUTTON_RIGHT,
+ CHAR_GRID_BUTTON_UP,
+ CHAR_GRID_BUTTON_DOWN,
+ CHAR_GRID_BUTTON_SNAP,
+ CHAR_GRID_BUTTON_DROP
+ };
int font_nr = FONT_INPUT_1_ACTIVE;
int font_height = getFontHeight(font_nr);
int ypos1 = SYSIZE / 2 - font_height * 2;
boolean success = FALSE;
boolean finished = FALSE;
int step_nr = 0;
+ char grid_button_draw = CHAR_GRID_BUTTON_NONE;
+ 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 x, y;
+
+ for (x = 0; x < MAX_GRID_XSIZE; x++)
+ for (y = 0; y < MAX_GRID_YSIZE; y++)
+ grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
+
+ overlay.grid_button_highlight = grid_button[step_nr];
FadeSetEnterMenu();
FadeOut(REDRAW_FIELD);
/* press 'Escape' to abort and keep the old key bindings */
if (key == KSYM_Escape)
{
+ for (x = 0; x < MAX_GRID_XSIZE; x++)
+ for (y = 0; y < MAX_GRID_YSIZE; y++)
+ overlay.grid_button[x][y] = grid_button_old[x][y];
+
FadeSkipNextFadeIn();
finished = TRUE;
break;
}
+ for (x = 0; x < MAX_GRID_XSIZE; x++)
+ for (y = 0; y < MAX_GRID_YSIZE; y++)
+ grid_button_tmp[x][y] = overlay.grid_button[x][y];
+
+ overlay.grid_button_highlight = grid_button[step_nr];
+
/* query next virtual button */
ClearField();
key_joystick_mapping = 0;
break;
+ case EVENT_BUTTONPRESS:
+ case EVENT_BUTTONRELEASE:
+ {
+ ButtonEvent *button = (ButtonEvent *)&event;
+
+ button->x += video.screen_xoffset;
+ button->y += video.screen_yoffset;
+
+ x = button->x * overlay.grid_xsize / video.screen_width;
+ y = button->y * overlay.grid_ysize / video.screen_height;
+
+ if (button->type == EVENT_BUTTONPRESS)
+ {
+ button_status = button->button;
+
+ grid_button_draw =
+ (overlay.grid_button[x][y] != grid_button[step_nr] ?
+ grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
+
+ set_grid_button = TRUE;
+ }
+ else
+ {
+ button_status = MB_RELEASED;
+ }
+ }
+ break;
+
+ case EVENT_MOTIONNOTIFY:
+ {
+ MotionEvent *motion = (MotionEvent *)&event;
+
+ motion->x += video.screen_xoffset;
+ motion->y += video.screen_yoffset;
+
+ x = motion->x * overlay.grid_xsize / video.screen_width;
+ y = motion->y * overlay.grid_ysize / video.screen_height;
+
+ set_grid_button = TRUE;
+ }
+ break;
+
default:
HandleOtherEvents(&event);
break;
}
+
+ if (set_grid_button)
+ {
+ overlay.grid_button[x][y] =
+ (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
+ grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
+ grid_button_tmp[x][y]);
+
+ set_grid_button = FALSE;
+ }
}
BackToFront();
}
+ overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
+
SetOverlayShowGrid(FALSE);
return success;