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
|
||||
* scene file management
|
||||
* basic command framework
|
||||
* pan (teseting needed)
|
||||
|
||||
### In progress
|
||||
|
||||
* pan
|
||||
* fix scene load active wall bug
|
||||
|
||||
### 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}};
|
||||
|
||||
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) {
|
||||
if (!context) {
|
||||
|
|
@ -36,6 +38,9 @@ void kubo_context_init(struct kubo_context *context) {
|
|||
context->exit_pending = false;
|
||||
|
||||
context->state = kubo_context_states[KUBO_CONTEXT_NORMAL];
|
||||
|
||||
context->offset_x = 0;
|
||||
context->offset_y = 0;
|
||||
}
|
||||
|
||||
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_context_select_next_wall(context);
|
||||
select_next_wall(context);
|
||||
}
|
||||
|
||||
void kubo_context_select_next_wall(struct kubo_context *context) {
|
||||
if (context->state.id != KUBO_CONTEXT_WALL_SELECT ||
|
||||
!context->walls.count) {
|
||||
void kubo_context_input_up(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_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;
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +166,7 @@ void kubo_context_select_next_wall(struct kubo_context *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 ||
|
||||
!context->walls.count) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
#include "kubo_dynarray.h"
|
||||
#include "kubo_wall.h"
|
||||
|
||||
#define KUBO_CONTEXT_OFFSET_JMP 100
|
||||
|
||||
KUBO_DYNARRAY_REGISTER(kubo_wall_arr, struct kubo_wall *)
|
||||
|
||||
enum kubo_context_state {
|
||||
|
|
@ -49,6 +51,9 @@ struct kubo_context {
|
|||
struct kubo_wall_arr walls;
|
||||
struct kubo_context_state_data state;
|
||||
|
||||
int offset_x;
|
||||
int offset_y;
|
||||
|
||||
// KUBO_CONTEXT_WALL_SELECT
|
||||
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);
|
||||
void kubo_context_delete_wall(struct kubo_context *context);
|
||||
|
||||
void kubo_context_select_next_wall(struct kubo_context *context);
|
||||
void kubo_context_select_prev_wall(struct kubo_context *context);
|
||||
void kubo_context_input_up(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
|
||||
|
|
|
|||
15
kubo_input.c
15
kubo_input.c
|
|
@ -51,21 +51,28 @@ static void key_input(struct kubo_context *context) {
|
|||
break;
|
||||
|
||||
case KEY_RIGHT:
|
||||
case KEY_UP:
|
||||
case KEY_L:
|
||||
kubo_context_input_right(context);
|
||||
break;
|
||||
|
||||
case KEY_UP:
|
||||
case KEY_K:
|
||||
kubo_context_select_next_wall(context);
|
||||
kubo_context_input_up(context);
|
||||
break;
|
||||
|
||||
case KEY_LEFT:
|
||||
case KEY_H:
|
||||
kubo_context_input_left(context);
|
||||
break;
|
||||
|
||||
case KEY_DOWN:
|
||||
case KEY_J:
|
||||
case KEY_H:
|
||||
kubo_context_select_prev_wall(context);
|
||||
kubo_context_input_down(context);
|
||||
break;
|
||||
|
||||
case KEY_X:
|
||||
kubo_context_delete_wall(context);
|
||||
break;
|
||||
|
||||
default:
|
||||
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);
|
||||
}
|
||||
|
||||
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 =
|
||||
(select && wall->state == KUBO_WALL_SELECTED) ? BLUE : BLACK;
|
||||
|
||||
DrawSplineLinear(wall->vertices.data, wall->vertices.count, 10.f,
|
||||
wall_color);
|
||||
Vector2 *points = malloc(sizeof(Vector2) * wall->vertices.count);
|
||||
|
||||
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) {
|
||||
Vector2 mouse = GetMousePosition();
|
||||
Vector2 points[] = {wall->vertices.data[wall->vertices.count - 1],
|
||||
mouse};
|
||||
DrawSplineLinear(points, 2, 10.f, wall_color);
|
||||
Vector2 mouse_points[] = {points[wall->vertices.count - 1], mouse};
|
||||
|
||||
DrawSplineLinear(mouse_points, 2, 10.f, wall_color);
|
||||
}
|
||||
|
||||
free(points);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@
|
|||
#ifndef KUBO_WALL_H
|
||||
#define KUBO_WALL_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.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);
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ static void window_render(struct kubo_context *context) {
|
|||
struct kubo_wall *wall = kubo_wall_arr_get(&context->walls, i);
|
||||
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);
|
||||
|
|
@ -99,6 +100,8 @@ static void new_wall_click(struct kubo_context *context) {
|
|||
|
||||
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;
|
||||
|
|
|
|||
40
scene.yaml
40
scene.yaml
|
|
@ -1,11 +1,31 @@
|
|||
walls:
|
||||
- vertices:
|
||||
- [100, 100]
|
||||
- [100, 200]
|
||||
- vertices:
|
||||
- [100, 300]
|
||||
- [100, 500]
|
||||
- [200, 500]
|
||||
- vertices:
|
||||
- [300, 300]
|
||||
- [500, 500]
|
||||
- vertices:
|
||||
- - 100
|
||||
- 100
|
||||
- - 100
|
||||
- 200
|
||||
- vertices:
|
||||
- - 100
|
||||
- 300
|
||||
- - 100
|
||||
- 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