67 lines
2 KiB
C
67 lines
2 KiB
C
#include "kubo_window.h"
|
|
|
|
void kubo_window_init(struct kubo_context *context) {
|
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
|
InitWindow(KUBO_WINDOW_WIDTH, KUBO_WINDOW_HEIGHT, "Kubo");
|
|
}
|
|
|
|
void kubo_window_cleanup(struct kubo_context *context) { CloseWindow(); }
|
|
|
|
bool kubo_window_should_close(struct kubo_context *context) {
|
|
return context->exit_pending || WindowShouldClose();
|
|
}
|
|
|
|
void kubo_window_tick(struct kubo_context *context) {
|
|
kubo_window_render(context);
|
|
kubo_window_input(context);
|
|
}
|
|
|
|
Vector2 start;
|
|
Vector2 end;
|
|
int state;
|
|
|
|
void kubo_window_render(struct kubo_context *context) {
|
|
BeginDrawing();
|
|
ClearBackground(WHITE);
|
|
|
|
if (state == 1) {
|
|
Vector2 mouse_pos = GetMousePosition();
|
|
Vector2 points[] = {start, mouse_pos};
|
|
DrawSplineLinear(points, 2, 10.f, BLACK);
|
|
} else if (state == 2) {
|
|
Vector2 mouse_pos = GetMousePosition();
|
|
Vector2 points[] = {start, end};
|
|
DrawSplineLinear(points, 2, 10.f, BLACK);
|
|
}
|
|
|
|
for (int i = 0; i < context->num_walls; i++) {
|
|
DrawSplineLinear(context->walls[i]->vertices,
|
|
context->walls[i]->num_vertices, 10.f, BLACK);
|
|
if (context->walls[i]->state == KUBO_WALL_STARTED) {
|
|
Vector2 mouse_pos = GetMousePosition();
|
|
Vector2 points[] = {
|
|
context->walls[i]
|
|
->vertices[context->walls[i]->num_vertices - 1],
|
|
mouse_pos};
|
|
DrawSplineLinear(points, 2, 10.f, BLACK);
|
|
}
|
|
}
|
|
|
|
EndDrawing();
|
|
}
|
|
|
|
void kubo_window_input(struct kubo_context *context) {
|
|
if (IsKeyPressed(KEY_Q)) {
|
|
context->exit_pending = true;
|
|
}
|
|
|
|
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
|
|
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
|
Vector2 new_pos = GetMousePosition();
|
|
kubo_wall_append(current_wall, new_pos);
|
|
current_wall->state = KUBO_WALL_STARTED;
|
|
} else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
|
|
current_wall->state = KUBO_WALL_DONE;
|
|
}
|
|
}
|