Skip to content

Commit

Permalink
fixes laamaa#106: add timer to reset messages on window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
laamaa committed Apr 19, 2023
1 parent 3043cbc commit b9961cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <SDL.h>
#include <stdio.h>

#include "SDL_timer.h"
#include "config.h"
#include "input.h"
#include "render.h"
Expand Down Expand Up @@ -392,8 +393,12 @@ void handle_sdl_events(config_params_s *conf) {
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED)
{
SDL_Log("Resizing window...");
key = (input_msg_s){special, msg_reset_display};
static uint32_t ticks_window_resized = 0;
if (SDL_GetTicks() - ticks_window_resized > 500) {
SDL_Log("Resizing window...");
key = (input_msg_s){special, msg_reset_display};
ticks_window_resized = SDL_GetTicks();
}
}
break;

Expand Down
5 changes: 3 additions & 2 deletions input.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define INPUT_H_

#include <stdint.h>
#include "config.h"

typedef enum input_buttons_t {
INPUT_UP,
Expand Down Expand Up @@ -38,6 +39,6 @@ typedef struct input_msg_s {

int initialize_game_controllers();
void close_game_controllers();
input_msg_s get_input_msg();
input_msg_s get_input_msg(config_params_s *conf);

#endif
#endif

0 comments on commit b9961cc

Please sign in to comment.