replace context offset with Camera2D
This commit is contained in:
parent
2026f8ac8d
commit
af7d6dee00
11 changed files with 132 additions and 70 deletions
|
|
@ -18,12 +18,12 @@
|
|||
|
||||
#include "kubo_window.h"
|
||||
|
||||
Camera2D camera = {0};
|
||||
|
||||
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);
|
||||
|
||||
|
|
@ -33,6 +33,8 @@ void kubo_window_init() {
|
|||
EnableEventWaiting();
|
||||
SetExitKey(0);
|
||||
SetTargetFPS(KUBO_TARGET_FPS);
|
||||
|
||||
camera.zoom = 1.0f;
|
||||
}
|
||||
|
||||
void kubo_window_cleanup() { CloseWindow(); }
|
||||
|
|
@ -43,18 +45,26 @@ bool kubo_window_should_close(struct kubo_context *context) {
|
|||
|
||||
void kubo_window_tick(struct kubo_context *context) {
|
||||
window_render(context);
|
||||
pan(context);
|
||||
|
||||
kubo_camera_zoom(&camera);
|
||||
if ((context->state.id == KUBO_CONTEXT_NORMAL &&
|
||||
IsMouseButtonDown(MOUSE_BUTTON_LEFT)) ||
|
||||
IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)) {
|
||||
kubo_camera_pan(&camera);
|
||||
}
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
window_left_mouse(context);
|
||||
}
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
|
||||
window_right_mouse(context);
|
||||
}
|
||||
kubo_input_handle(context);
|
||||
kubo_input_handle(context, &camera);
|
||||
}
|
||||
|
||||
static void window_render(struct kubo_context *context) {
|
||||
BeginDrawing();
|
||||
BeginMode2D(camera);
|
||||
ClearBackground(WHITE);
|
||||
|
||||
for (size_t i = 0; i < context->walls.count; i++) {
|
||||
|
|
@ -62,9 +72,11 @@ static void window_render(struct kubo_context *context) {
|
|||
assert(wall != NULL);
|
||||
|
||||
kubo_wall_render(wall, context->state.id == KUBO_CONTEXT_WALL_SELECT,
|
||||
context->offset_x, context->offset_y);
|
||||
&camera);
|
||||
}
|
||||
|
||||
EndMode2D();
|
||||
|
||||
kubo_bar_render(context);
|
||||
|
||||
EndDrawing();
|
||||
|
|
@ -94,15 +106,6 @@ 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);
|
||||
|
||||
|
|
@ -110,14 +113,9 @@ static void new_wall_click(struct kubo_context *context) {
|
|||
return;
|
||||
}
|
||||
|
||||
int bar_limit = GetScreenHeight() - KUBO_BAR_HEIGHT;
|
||||
Vector2 new_pos = GetMousePosition();
|
||||
new_pos.x -= context->offset_x;
|
||||
new_pos.y -= context->offset_y;
|
||||
if (new_pos.y < bar_limit) {
|
||||
kubo_wall_add_vertex(current_wall, new_pos);
|
||||
current_wall->state = KUBO_WALL_DRAWING;
|
||||
}
|
||||
Vector2 new_pos = GetScreenToWorld2D(GetMousePosition(), camera);
|
||||
kubo_wall_add_vertex(current_wall, new_pos);
|
||||
current_wall->state = KUBO_WALL_DRAWING;
|
||||
}
|
||||
|
||||
static void new_wall_end(struct kubo_context *context) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue