panning
This commit is contained in:
parent
162e7a7fb0
commit
7189f28c00
8 changed files with 139 additions and 33 deletions
|
|
@ -25,10 +25,11 @@ $ ./kubo
|
||||||
* wall rendering
|
* wall rendering
|
||||||
* scene file management
|
* scene file management
|
||||||
* basic command framework
|
* basic command framework
|
||||||
|
* pan (teseting needed)
|
||||||
|
|
||||||
### In progress
|
### In progress
|
||||||
|
|
||||||
* pan
|
* fix scene load active wall bug
|
||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ static const struct kubo_context_state_data kubo_context_states[] = {
|
||||||
{.id = KUBO_CONTEXT_WALL_SELECT, .label = "Wall Select", .color = BLUE}};
|
{.id = KUBO_CONTEXT_WALL_SELECT, .label = "Wall Select", .color = BLUE}};
|
||||||
|
|
||||||
static inline void wall_select_refresh(struct kubo_context *context);
|
static inline void wall_select_refresh(struct kubo_context *context);
|
||||||
|
static void select_next_wall(struct kubo_context *context);
|
||||||
|
static void select_prev_wall(struct kubo_context *context);
|
||||||
|
|
||||||
void kubo_context_init(struct kubo_context *context) {
|
void kubo_context_init(struct kubo_context *context) {
|
||||||
if (!context) {
|
if (!context) {
|
||||||
|
|
@ -36,6 +38,9 @@ void kubo_context_init(struct kubo_context *context) {
|
||||||
context->exit_pending = false;
|
context->exit_pending = false;
|
||||||
|
|
||||||
context->state = kubo_context_states[KUBO_CONTEXT_NORMAL];
|
context->state = kubo_context_states[KUBO_CONTEXT_NORMAL];
|
||||||
|
|
||||||
|
context->offset_x = 0;
|
||||||
|
context->offset_y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kubo_context_cleanup(struct kubo_context *context) {
|
void kubo_context_cleanup(struct kubo_context *context) {
|
||||||
|
|
@ -95,12 +100,63 @@ void kubo_context_delete_wall(struct kubo_context *context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
kubo_wall_arr_del(&context->walls, context->wall_select_index);
|
kubo_wall_arr_del(&context->walls, context->wall_select_index);
|
||||||
kubo_context_select_next_wall(context);
|
select_next_wall(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kubo_context_select_next_wall(struct kubo_context *context) {
|
void kubo_context_input_up(struct kubo_context *context) {
|
||||||
if (context->state.id != KUBO_CONTEXT_WALL_SELECT ||
|
switch (context->state.id) {
|
||||||
!context->walls.count) {
|
case KUBO_CONTEXT_NORMAL:
|
||||||
|
context->offset_y -= KUBO_CONTEXT_OFFSET_JMP;
|
||||||
|
break;
|
||||||
|
case KUBO_CONTEXT_WALL_SELECT:
|
||||||
|
select_next_wall(context);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void kubo_context_input_down(struct kubo_context *context) {
|
||||||
|
switch (context->state.id) {
|
||||||
|
case KUBO_CONTEXT_NORMAL:
|
||||||
|
context->offset_y += KUBO_CONTEXT_OFFSET_JMP;
|
||||||
|
break;
|
||||||
|
case KUBO_CONTEXT_WALL_SELECT:
|
||||||
|
select_prev_wall(context);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void kubo_context_input_left(struct kubo_context *context) {
|
||||||
|
switch (context->state.id) {
|
||||||
|
case KUBO_CONTEXT_NORMAL:
|
||||||
|
context->offset_x -= KUBO_CONTEXT_OFFSET_JMP;
|
||||||
|
break;
|
||||||
|
case KUBO_CONTEXT_WALL_SELECT:
|
||||||
|
select_prev_wall(context);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void kubo_context_input_right(struct kubo_context *context) {
|
||||||
|
switch (context->state.id) {
|
||||||
|
case KUBO_CONTEXT_NORMAL:
|
||||||
|
context->offset_x += KUBO_CONTEXT_OFFSET_JMP;
|
||||||
|
break;
|
||||||
|
case KUBO_CONTEXT_WALL_SELECT:
|
||||||
|
select_next_wall(context);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_next_wall(struct kubo_context *context) {
|
||||||
|
if (!context->walls.count) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +166,7 @@ void kubo_context_select_next_wall(struct kubo_context *context) {
|
||||||
wall_select_refresh(context);
|
wall_select_refresh(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kubo_context_select_prev_wall(struct kubo_context *context) {
|
static void select_prev_wall(struct kubo_context *context) {
|
||||||
if (context->state.id != KUBO_CONTEXT_WALL_SELECT ||
|
if (context->state.id != KUBO_CONTEXT_WALL_SELECT ||
|
||||||
!context->walls.count) {
|
!context->walls.count) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@
|
||||||
#include "kubo_dynarray.h"
|
#include "kubo_dynarray.h"
|
||||||
#include "kubo_wall.h"
|
#include "kubo_wall.h"
|
||||||
|
|
||||||
|
#define KUBO_CONTEXT_OFFSET_JMP 100
|
||||||
|
|
||||||
KUBO_DYNARRAY_REGISTER(kubo_wall_arr, struct kubo_wall *)
|
KUBO_DYNARRAY_REGISTER(kubo_wall_arr, struct kubo_wall *)
|
||||||
|
|
||||||
enum kubo_context_state {
|
enum kubo_context_state {
|
||||||
|
|
@ -49,6 +51,9 @@ struct kubo_context {
|
||||||
struct kubo_wall_arr walls;
|
struct kubo_wall_arr walls;
|
||||||
struct kubo_context_state_data state;
|
struct kubo_context_state_data state;
|
||||||
|
|
||||||
|
int offset_x;
|
||||||
|
int offset_y;
|
||||||
|
|
||||||
// KUBO_CONTEXT_WALL_SELECT
|
// KUBO_CONTEXT_WALL_SELECT
|
||||||
size_t wall_select_index;
|
size_t wall_select_index;
|
||||||
};
|
};
|
||||||
|
|
@ -64,7 +69,9 @@ void kubo_context_accept_cmd(struct kubo_context *context);
|
||||||
struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context);
|
struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context);
|
||||||
void kubo_context_delete_wall(struct kubo_context *context);
|
void kubo_context_delete_wall(struct kubo_context *context);
|
||||||
|
|
||||||
void kubo_context_select_next_wall(struct kubo_context *context);
|
void kubo_context_input_up(struct kubo_context *context);
|
||||||
void kubo_context_select_prev_wall(struct kubo_context *context);
|
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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
15
kubo_input.c
15
kubo_input.c
|
|
@ -51,21 +51,28 @@ static void key_input(struct kubo_context *context) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
case KEY_UP:
|
|
||||||
case KEY_L:
|
case KEY_L:
|
||||||
|
kubo_context_input_right(context);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_UP:
|
||||||
case KEY_K:
|
case KEY_K:
|
||||||
kubo_context_select_next_wall(context);
|
kubo_context_input_up(context);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
|
case KEY_H:
|
||||||
|
kubo_context_input_left(context);
|
||||||
|
break;
|
||||||
|
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
case KEY_J:
|
case KEY_J:
|
||||||
case KEY_H:
|
kubo_context_input_down(context);
|
||||||
kubo_context_select_prev_wall(context);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_X:
|
case KEY_X:
|
||||||
kubo_context_delete_wall(context);
|
kubo_context_delete_wall(context);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
25
kubo_wall.c
25
kubo_wall.c
|
|
@ -40,18 +40,29 @@ Vector2 kubo_wall_get_vertex(struct kubo_wall *wall, size_t index) {
|
||||||
return kubo_vector2_arr_get(&wall->vertices, index);
|
return kubo_vector2_arr_get(&wall->vertices, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kubo_wall_render(struct kubo_wall *wall, bool select) {
|
void kubo_wall_render(struct kubo_wall *wall, bool select, int offset_x,
|
||||||
|
int offset_y) {
|
||||||
Color wall_color =
|
Color wall_color =
|
||||||
(select && wall->state == KUBO_WALL_SELECTED) ? BLUE : BLACK;
|
(select && wall->state == KUBO_WALL_SELECTED) ? BLUE : BLACK;
|
||||||
|
|
||||||
DrawSplineLinear(wall->vertices.data, wall->vertices.count, 10.f,
|
Vector2 *points = malloc(sizeof(Vector2) * wall->vertices.count);
|
||||||
wall_color);
|
|
||||||
|
for (size_t i = 0; i < wall->vertices.count; i++) {
|
||||||
|
|
||||||
|
points[i] = kubo_vector2_arr_get(&wall->vertices, i);
|
||||||
|
|
||||||
|
points[i].x += offset_x;
|
||||||
|
points[i].y += offset_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawSplineLinear(points, wall->vertices.count, 10.f, wall_color);
|
||||||
|
|
||||||
if (wall->state == KUBO_WALL_DRAWING) {
|
if (wall->state == KUBO_WALL_DRAWING) {
|
||||||
Vector2 mouse = GetMousePosition();
|
Vector2 mouse = GetMousePosition();
|
||||||
Vector2 points[] = {wall->vertices.data[wall->vertices.count - 1],
|
Vector2 mouse_points[] = {points[wall->vertices.count - 1], mouse};
|
||||||
mouse};
|
|
||||||
DrawSplineLinear(points, 2, 10.f, wall_color);
|
DrawSplineLinear(mouse_points, 2, 10.f, wall_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(points);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@
|
||||||
#ifndef KUBO_WALL_H
|
#ifndef KUBO_WALL_H
|
||||||
#define KUBO_WALL_H
|
#define KUBO_WALL_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "kubo_dynarray.h"
|
#include "kubo_dynarray.h"
|
||||||
|
|
||||||
|
|
@ -46,7 +47,7 @@ void kubo_wall_cleanup(struct kubo_wall *wall);
|
||||||
bool kubo_wall_add_vertex(struct kubo_wall *wall, Vector2 vec);
|
bool kubo_wall_add_vertex(struct kubo_wall *wall, Vector2 vec);
|
||||||
Vector2 kubo_wall_get_vertex(struct kubo_wall *wall, size_t index);
|
Vector2 kubo_wall_get_vertex(struct kubo_wall *wall, size_t index);
|
||||||
|
|
||||||
void kubo_wall_render(struct kubo_wall *wall, bool select);
|
void kubo_wall_render(struct kubo_wall *wall, bool select, int offset_x,
|
||||||
|
int offset_y);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ static void window_render(struct kubo_context *context) {
|
||||||
struct kubo_wall *wall = kubo_wall_arr_get(&context->walls, i);
|
struct kubo_wall *wall = kubo_wall_arr_get(&context->walls, i);
|
||||||
assert(wall != NULL);
|
assert(wall != NULL);
|
||||||
|
|
||||||
kubo_wall_render(wall, context->state.id == KUBO_CONTEXT_WALL_SELECT);
|
kubo_wall_render(wall, context->state.id == KUBO_CONTEXT_WALL_SELECT,
|
||||||
|
context->offset_x, context->offset_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
kubo_bar_render(context);
|
kubo_bar_render(context);
|
||||||
|
|
@ -99,6 +100,8 @@ static void new_wall_click(struct kubo_context *context) {
|
||||||
|
|
||||||
int bar_limit = GetScreenHeight() - KUBO_BAR_HEIGHT;
|
int bar_limit = GetScreenHeight() - KUBO_BAR_HEIGHT;
|
||||||
Vector2 new_pos = GetMousePosition();
|
Vector2 new_pos = GetMousePosition();
|
||||||
|
new_pos.x -= context->offset_x;
|
||||||
|
new_pos.y -= context->offset_y;
|
||||||
if (new_pos.y < bar_limit) {
|
if (new_pos.y < bar_limit) {
|
||||||
kubo_wall_add_vertex(current_wall, new_pos);
|
kubo_wall_add_vertex(current_wall, new_pos);
|
||||||
current_wall->state = KUBO_WALL_DRAWING;
|
current_wall->state = KUBO_WALL_DRAWING;
|
||||||
|
|
|
||||||
40
scene.yaml
40
scene.yaml
|
|
@ -1,11 +1,31 @@
|
||||||
walls:
|
walls:
|
||||||
- vertices:
|
- vertices:
|
||||||
- [100, 100]
|
- - 100
|
||||||
- [100, 200]
|
- 100
|
||||||
- vertices:
|
- - 100
|
||||||
- [100, 300]
|
- 200
|
||||||
- [100, 500]
|
- vertices:
|
||||||
- [200, 500]
|
- - 100
|
||||||
- vertices:
|
- 300
|
||||||
- [300, 300]
|
- - 100
|
||||||
- [500, 500]
|
- 500
|
||||||
|
- - 200
|
||||||
|
- 500
|
||||||
|
- vertices:
|
||||||
|
- - 300
|
||||||
|
- 300
|
||||||
|
- - 500
|
||||||
|
- 500
|
||||||
|
- - 594
|
||||||
|
- 420
|
||||||
|
- vertices:
|
||||||
|
- - 589
|
||||||
|
- 276
|
||||||
|
- - 710
|
||||||
|
- 366
|
||||||
|
- - 616
|
||||||
|
- 453
|
||||||
|
- - 729
|
||||||
|
- 493
|
||||||
|
- - 644
|
||||||
|
- 594
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue