mouse pan and reset offset
This commit is contained in:
parent
7189f28c00
commit
2026f8ac8d
5 changed files with 32 additions and 1 deletions
|
|
@ -155,6 +155,17 @@ void kubo_context_input_right(struct kubo_context *context) {
|
|||
}
|
||||
}
|
||||
|
||||
void kubo_context_reset_offset(struct kubo_context *context) {
|
||||
switch (context->state.id) {
|
||||
case KUBO_CONTEXT_NORMAL:
|
||||
context->offset_x = 0;
|
||||
context->offset_y = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void select_next_wall(struct kubo_context *context) {
|
||||
if (!context->walls.count) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -74,4 +74,6 @@ void kubo_context_input_down(struct kubo_context *context);
|
|||
void kubo_context_input_left(struct kubo_context *context);
|
||||
void kubo_context_input_right(struct kubo_context *context);
|
||||
|
||||
void kubo_context_reset_offset(struct kubo_context *context);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ static void key_input(struct kubo_context *context) {
|
|||
kubo_context_delete_wall(context);
|
||||
break;
|
||||
|
||||
case KEY_SPACE:
|
||||
kubo_context_reset_offset(context);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ static void window_render(struct kubo_context *context);
|
|||
static void window_left_mouse(struct kubo_context *context);
|
||||
static void window_right_mouse(struct kubo_context *context);
|
||||
|
||||
static void pan(struct kubo_context *context);
|
||||
|
||||
static void new_wall_click(struct kubo_context *context);
|
||||
static void new_wall_end(struct kubo_context *context);
|
||||
|
||||
|
|
@ -30,7 +32,7 @@ void kubo_window_init() {
|
|||
InitWindow(KUBO_WINDOW_WIDTH, KUBO_WINDOW_HEIGHT, "Kubo");
|
||||
EnableEventWaiting();
|
||||
SetExitKey(0);
|
||||
SetTargetFPS(60);
|
||||
SetTargetFPS(KUBO_TARGET_FPS);
|
||||
}
|
||||
|
||||
void kubo_window_cleanup() { CloseWindow(); }
|
||||
|
|
@ -41,6 +43,7 @@ bool kubo_window_should_close(struct kubo_context *context) {
|
|||
|
||||
void kubo_window_tick(struct kubo_context *context) {
|
||||
window_render(context);
|
||||
pan(context);
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
window_left_mouse(context);
|
||||
}
|
||||
|
|
@ -91,6 +94,15 @@ static void window_right_mouse(struct kubo_context *context) {
|
|||
}
|
||||
}
|
||||
|
||||
static void pan(struct kubo_context *context) {
|
||||
if (context->state.id == KUBO_CONTEXT_NORMAL &&
|
||||
IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
Vector2 delta = GetMouseDelta();
|
||||
context->offset_x += delta.x;
|
||||
context->offset_y += delta.y;
|
||||
}
|
||||
}
|
||||
|
||||
static void new_wall_click(struct kubo_context *context) {
|
||||
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@
|
|||
#define KUBO_WINDOW_WIDTH 1000
|
||||
#define KUBO_WINDOW_HEIGHT 800
|
||||
|
||||
#define KUBO_TARGET_FPS 165
|
||||
|
||||
void kubo_window_init();
|
||||
void kubo_window_cleanup();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue