Add Ctrl+i shortcut to enable/disable FPS counter
Disable FPS counter on start, and use Ctrl+i to enable/disable it.
This commit is contained in:
parent
000ced9ba8
commit
d977202224
4 changed files with 23 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "inputmanager.h"
|
||||
|
||||
#include "convert.h"
|
||||
#include "lockutil.h"
|
||||
#include "log.h"
|
||||
|
||||
static struct point get_mouse_point(void) {
|
||||
|
@ -78,6 +79,18 @@ static void turn_screen_on(struct controller *controller) {
|
|||
}
|
||||
}
|
||||
|
||||
static void switch_fps_counter_state(struct frames *frames) {
|
||||
mutex_lock(frames->mutex);
|
||||
if (frames->fps_counter.started) {
|
||||
LOGI("FPS counter stopped");
|
||||
fps_counter_stop(&frames->fps_counter);
|
||||
} else {
|
||||
LOGI("FPS counter started");
|
||||
fps_counter_start(&frames->fps_counter);
|
||||
}
|
||||
mutex_unlock(frames->mutex);
|
||||
}
|
||||
|
||||
void input_manager_process_text_input(struct input_manager *input_manager,
|
||||
const SDL_TextInputEvent *event) {
|
||||
if (is_ctrl_down()) {
|
||||
|
@ -143,6 +156,9 @@ void input_manager_process_key(struct input_manager *input_manager,
|
|||
case SDLK_g:
|
||||
screen_resize_to_pixel_perfect(input_manager->screen);
|
||||
return;
|
||||
case SDLK_i:
|
||||
switch_fps_counter_state(input_manager->frames);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
|
||||
#include "common.h"
|
||||
#include "controller.h"
|
||||
#include "fpscounter.h"
|
||||
#include "frames.h"
|
||||
#include "screen.h"
|
||||
|
||||
struct input_manager {
|
||||
struct controller *controller;
|
||||
struct frames *frames;
|
||||
struct screen *screen;
|
||||
};
|
||||
|
||||
|
|
|
@ -82,6 +82,9 @@ static void usage(const char *arg0) {
|
|||
"\n"
|
||||
" Right-click\n"
|
||||
" turn screen on\n"
|
||||
"\n"
|
||||
" Ctrl+i\n"
|
||||
" enable/disable FPS counter (print frames/second in logs)\n"
|
||||
"\n",
|
||||
arg0,
|
||||
DEFAULT_BIT_RATE,
|
||||
|
|
|
@ -32,6 +32,7 @@ static struct controller controller;
|
|||
|
||||
static struct input_manager input_manager = {
|
||||
.controller = &controller,
|
||||
.frames = &frames,
|
||||
.screen = &screen,
|
||||
};
|
||||
|
||||
|
@ -50,7 +51,6 @@ static void event_loop(void) {
|
|||
screen.has_frame = SDL_TRUE;
|
||||
// this is the very first frame, show the window
|
||||
screen_show_window(&screen);
|
||||
fps_counter_start(&frames.fps_counter);
|
||||
}
|
||||
if (!screen_update_frame(&screen, &frames)) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue