Skip to content

Commit

Permalink
Change button color when pressed
Browse files Browse the repository at this point in the history
This actually serves a practical purpose as it provides visual
indication that the button has been pressed and makes the game more
playable (for me, at least).
  • Loading branch information
fragglet committed Nov 21, 2024
1 parent b241a2b commit cf6d908
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/sdl/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ static void FingerDown(SDL_TouchFingerEvent *ev)

b = GetTouchButton(ev);
pressed_buttons[ev->fingerId] = b;
Vid_TouchButtonPress(b, true);
if (b == NULL) {
return;
}
Expand Down Expand Up @@ -777,6 +778,7 @@ static void FingerUp(SDL_TouchFingerEvent *ev)
break;
}
pressed_buttons[ev->fingerId] = NULL;
Vid_TouchButtonPress(b, false);
}

static void FingerMove(SDL_TouchFingerEvent *ev)
Expand Down
12 changes: 11 additions & 1 deletion src/touch_area.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ static void DrawTouchArea(const struct touch_button *buttons)
swcolor(3);
} else {
int x, y;
bool pressed = i < arrlen(button_pressed)
&& button_pressed[i];
GetButtonPos(b, &x, &y);
Vid_Box(x, SCR_HGHT - y,
BUTTON_WIDTH, BUTTON_HEIGHT, 3);
Vid_Box(x + 1, SCR_HGHT - y - 1,
BUTTON_WIDTH - 2, BUTTON_HEIGHT - 2,
b->type == TOUCH_BUTTON_CLOSE ? 2 : 1);
pressed ? 2 : 1);
swcolor(0);
}

Expand All @@ -103,6 +105,14 @@ const struct touch_button *Vid_GetTouchButton(int x, int y)
return NULL;
}

void Vid_TouchButtonPress(const struct touch_button *b, bool pressed)
{
int idx = b - game_buttons;
if (idx >= 0 && idx < arrlen(button_pressed)) {
button_pressed[idx] = pressed;
}
}

void Vid_DrawTouchControls(void)
{
DrawTouchArea(game_buttons);
Expand Down
1 change: 1 addition & 0 deletions src/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,6 @@ struct touch_button {

extern void Vid_DrawTouchControls(void);
extern const struct touch_button *Vid_GetTouchButton(int x, int y);
extern void Vid_TouchButtonPress(const struct touch_button *b, bool pressed);

#endif

0 comments on commit cf6d908

Please sign in to comment.