refactor window, separate mouse, key input
This commit is contained in:
parent
01a6c5e4ff
commit
f768cff6d2
2 changed files with 33 additions and 10 deletions
|
|
@ -30,11 +30,12 @@ bool kubo_window_should_close(struct kubo_context *context) {
|
|||
}
|
||||
|
||||
void kubo_window_tick(struct kubo_context *context) {
|
||||
kubo_window_render(context);
|
||||
kubo_window_input(context);
|
||||
window_render(context);
|
||||
window_mouse_input(context);
|
||||
window_key_input(context);
|
||||
}
|
||||
|
||||
void kubo_window_render(struct kubo_context *context) {
|
||||
static void window_render(struct kubo_context *context) {
|
||||
BeginDrawing();
|
||||
ClearBackground(WHITE);
|
||||
|
||||
|
|
@ -50,13 +51,9 @@ void kubo_window_render(struct kubo_context *context) {
|
|||
EndDrawing();
|
||||
}
|
||||
|
||||
void kubo_window_input(struct kubo_context *context) {
|
||||
static void window_mouse_input(struct kubo_context *context) {
|
||||
int bar_limit = GetScreenHeight() - KUBO_BAR_HEIGHT;
|
||||
|
||||
if (IsKeyPressed(KEY_Q)) {
|
||||
context->exit_pending = true;
|
||||
}
|
||||
|
||||
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
|
|
@ -69,3 +66,28 @@ void kubo_window_input(struct kubo_context *context) {
|
|||
current_wall->state = KUBO_WALL_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
static void window_key_input(struct kubo_context *context) {
|
||||
int key_code = GetKeyPressed();
|
||||
|
||||
if (!key_code) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (key_code) {
|
||||
case KEY_Q:
|
||||
context->exit_pending = true;
|
||||
break;
|
||||
|
||||
case KEY_W:
|
||||
context->state = KUBO_CONTEXT_STATE_WALL_NEW;
|
||||
break;
|
||||
|
||||
case KEY_S:
|
||||
context->state = KUBO_CONTEXT_STATE_WALL_SELECT;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ bool kubo_window_should_close(struct kubo_context *context);
|
|||
|
||||
void kubo_window_tick(struct kubo_context *context);
|
||||
|
||||
void kubo_window_render(struct kubo_context *context);
|
||||
void kubo_window_input(struct kubo_context *context);
|
||||
static void window_render(struct kubo_context *context);
|
||||
static void window_mouse_input(struct kubo_context *context);
|
||||
static void window_key_input(struct kubo_context *context);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue