73 lines
2.3 KiB
C
73 lines
2.3 KiB
C
/*
|
|
* Copyright Luka Jankovic 2025
|
|
*
|
|
* This file is part of Kubo.
|
|
*
|
|
* Kubo is free software: you can redistribute it and/or modify it under the
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
* version.
|
|
*
|
|
* Kubo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* Kubo. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#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);
|
|
}
|
|
|
|
void kubo_window_render(struct kubo_context *context) {
|
|
BeginDrawing();
|
|
ClearBackground(WHITE);
|
|
|
|
for (int i = 0; i < context->walls.count; i++) {
|
|
struct kubo_wall *wall = kubo_wall_arr_get(&context->walls, i);
|
|
assert(wall != NULL);
|
|
|
|
DrawSplineLinear(wall->vertices.data, wall->vertices.count, 10.f,
|
|
BLACK);
|
|
|
|
if (wall->state == KUBO_WALL_DRAWING) {
|
|
Vector2 mouse = GetMousePosition();
|
|
Vector2 points[] = {wall->vertices.data[wall->vertices.count - 1],
|
|
mouse};
|
|
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_add_vertex(current_wall, new_pos);
|
|
current_wall->state = KUBO_WALL_DRAWING;
|
|
} else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
|
|
current_wall->state = KUBO_WALL_DONE;
|
|
}
|
|
}
|