Remove Grid and ActionPicker
parent
0d5bf93205
commit
71ee35bf61
|
@ -121,8 +121,6 @@ add_executable(nothing
|
|||
src/ui/wiggly_text.c
|
||||
src/ui/slider.h
|
||||
src/ui/slider.c
|
||||
src/ui/grid.h
|
||||
src/ui/grid.c
|
||||
src/game/level/level_editor.h
|
||||
src/game/level/level_editor.c
|
||||
src/game/level/level_editor/color_picker.h
|
||||
|
@ -143,8 +141,6 @@ add_executable(nothing
|
|||
src/game/level/level_editor/background_layer.c
|
||||
src/game/level/level_editor/undo_history.h
|
||||
src/game/level/level_editor/undo_history.c
|
||||
src/game/level/level_editor/action_picker.h
|
||||
src/game/level/level_editor/action_picker.c
|
||||
src/system/log.h
|
||||
src/system/log.c
|
||||
src/system/lt.h
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "src/ui/history.c"
|
||||
#include "src/ui/wiggly_text.c"
|
||||
#include "src/ui/slider.c"
|
||||
#include "src/ui/grid.c"
|
||||
#include "src/game/level/level_editor.c"
|
||||
#include "src/game/level/level_editor/color_picker.c"
|
||||
#include "src/game/level/level_editor/rect_layer.c"
|
||||
|
@ -42,7 +41,6 @@
|
|||
#include "src/game/level/level_editor/label_layer.c"
|
||||
#include "src/game/level/level_editor/background_layer.c"
|
||||
#include "src/game/level/level_editor/undo_history.c"
|
||||
#include "src/game/level/level_editor/action_picker.c"
|
||||
#include "src/system/log.c"
|
||||
#include "src/system/lt_adapters.c"
|
||||
#include "src/system/nth_alloc.c"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "game/camera.h"
|
||||
#include "game/sound_samples.h"
|
||||
#include "game/level/boxes.h"
|
||||
#include "game/level/level_editor/action_picker.h"
|
||||
#include "game/level/level_editor/color_picker.h"
|
||||
#include "game/level/level_editor/rect_layer.h"
|
||||
#include "game/level/level_editor/point_layer.h"
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "game/level/level_editor/layer.h"
|
||||
#include "game/level/level_editor/layer_picker.h"
|
||||
#include "game/level/level_editor/undo_history.h"
|
||||
#include "game/level/level_editor/action_picker.h"
|
||||
#include "ui/wiggly_text.h"
|
||||
#include "ui/cursor.h"
|
||||
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "system/stacktrace.h"
|
||||
#include "action_picker.h"
|
||||
#include "math/extrema.h"
|
||||
#include "math/vec.h"
|
||||
|
||||
static const char *action_labels[ACTION_N] = {
|
||||
[ACTION_NONE] = "None",
|
||||
[ACTION_HIDE_LABEL] = "Hide Label",
|
||||
[ACTION_TOGGLE_GOAL] = "Toggle Goal"
|
||||
};
|
||||
|
||||
#define TEXT_SCALE vec(5.0f, 5.0f)
|
||||
#define TEXT_COLOR COLOR_WHITE
|
||||
#define SELECTION_COLOR COLOR_WHITE
|
||||
#define BACKGROUND_COLOR COLOR_BLACK
|
||||
|
||||
void action_picker_render(const ActionPicker *picker,
|
||||
const Camera *camera)
|
||||
{
|
||||
trace_assert(picker);
|
||||
trace_assert(camera);
|
||||
(void) action_labels;
|
||||
|
||||
camera_fill_rect_screen(
|
||||
camera,
|
||||
picker->widget.boundary,
|
||||
BACKGROUND_COLOR);
|
||||
|
||||
const float element_height = picker->widget.boundary.h / (float)ACTION_N;
|
||||
for (size_t i = 0; i < ACTION_N; ++i) {
|
||||
const Vec2f element_position =
|
||||
vec_sum(
|
||||
vec(picker->widget.boundary.x, picker->widget.boundary.y),
|
||||
vec(0.0f, (float)i * element_height));
|
||||
const Rect element_box =
|
||||
rect_from_vecs(element_position,
|
||||
vec(picker->widget.boundary.w, element_height));
|
||||
|
||||
|
||||
camera_render_text_screen(
|
||||
camera,
|
||||
action_labels[i],
|
||||
TEXT_SCALE,
|
||||
TEXT_COLOR,
|
||||
element_position);
|
||||
|
||||
if (i == picker->action.type) {
|
||||
camera_draw_thicc_rect_screen(
|
||||
camera,
|
||||
element_box,
|
||||
SELECTION_COLOR,
|
||||
5.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void action_picker_event(ActionPicker *picker,
|
||||
const SDL_Event *event)
|
||||
{
|
||||
trace_assert(picker);
|
||||
trace_assert(event);
|
||||
|
||||
switch (event->type) {
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
switch (event->button.button) {
|
||||
case SDL_BUTTON_LEFT: {
|
||||
const Vec2f mouse_position =
|
||||
vec((float)event->button.x,
|
||||
(float)event->button.y);
|
||||
|
||||
const float element_height = picker->widget.boundary.h / (float)ACTION_N;
|
||||
|
||||
for (ActionType i = 0; i < ACTION_N; ++i) {
|
||||
const Vec2f element_position =
|
||||
vec_sum(
|
||||
vec(picker->widget.boundary.x, picker->widget.boundary.y),
|
||||
vec(0.0f, (float)i * element_height));
|
||||
const Rect element_box =
|
||||
rect_from_vecs(element_position,
|
||||
vec(picker->widget.boundary.w, element_height));
|
||||
|
||||
if (rect_contains_point(element_box, mouse_position)) {
|
||||
picker->action.type = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
} break;
|
||||
|
||||
case SDL_KEYDOWN: {
|
||||
switch (event->key.keysym.sym) {
|
||||
case SDLK_UP: {
|
||||
if (picker->action.type > 0) {
|
||||
picker->action.type--;
|
||||
}
|
||||
} break;
|
||||
|
||||
case SDLK_DOWN: {
|
||||
if (picker->action.type < ACTION_N) {
|
||||
picker->action.type++;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef ACTION_PICKER_H_
|
||||
#define ACTION_PICKER_H_
|
||||
|
||||
#include "game/level/action.h"
|
||||
#include "game/camera.h"
|
||||
#include "ui/grid.h"
|
||||
|
||||
typedef struct {
|
||||
Widget widget;
|
||||
Action action;
|
||||
} ActionPicker;
|
||||
|
||||
void action_picker_render(const ActionPicker *action_picker,
|
||||
const Camera *camera);
|
||||
void action_picker_event(ActionPicker *action_picker,
|
||||
const SDL_Event *event);
|
||||
|
||||
#endif // ACTION_PICKER_H_
|
|
@ -15,7 +15,6 @@
|
|||
#include "ui/edit_field.h"
|
||||
#include "undo_history.h"
|
||||
#include "game/level/action.h"
|
||||
#include "action_picker.h"
|
||||
#include "game.h"
|
||||
#include "math/extrema.h"
|
||||
|
||||
|
@ -63,7 +62,6 @@ struct RectLayer {
|
|||
Dynarray colors;
|
||||
Dynarray actions;
|
||||
ColorPicker color_picker;
|
||||
ActionPicker action_picker;
|
||||
Vec2f create_begin;
|
||||
Vec2f create_end;
|
||||
int selection;
|
||||
|
@ -74,7 +72,6 @@ struct RectLayer {
|
|||
Rect inter_rect;
|
||||
int id_name_counter;
|
||||
const char *id_name_prefix;
|
||||
Grid *grid;
|
||||
Cursor *cursor;
|
||||
|
||||
int snapping_enabled;
|
||||
|
@ -857,20 +854,6 @@ RectLayer *create_rect_layer(const char *id_name_prefix, Cursor *cursor)
|
|||
layer->id_edit_field.font_size = RECT_LAYER_ID_LABEL_SIZE;
|
||||
layer->id_edit_field.font_color = COLOR_BLACK;
|
||||
|
||||
layer->grid =
|
||||
PUSH_LT(
|
||||
lt,
|
||||
nth_calloc(
|
||||
1,
|
||||
sizeof(Grid) + sizeof(Widget*) * RECT_LAYER_GRID_ROWS * RECT_LAYER_GRID_COLUMNS),
|
||||
free);
|
||||
if (layer->grid == NULL) {
|
||||
RETURN_LT(lt, NULL);
|
||||
}
|
||||
layer->grid->rows = RECT_LAYER_GRID_ROWS;
|
||||
layer->grid->columns = RECT_LAYER_GRID_COLUMNS;
|
||||
grid_put_widget(layer->grid, &layer->action_picker.widget, 0, RECT_LAYER_GRID_COLUMNS - 1);
|
||||
|
||||
layer->color_picker = create_color_picker_from_rgba(rgba(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
layer->selection = -1;
|
||||
layer->id_name_prefix = id_name_prefix;
|
||||
|
@ -1102,18 +1085,6 @@ int rect_layer_event(RectLayer *layer,
|
|||
trace_assert(event);
|
||||
trace_assert(undo_history);
|
||||
|
||||
switch (event->type) {
|
||||
case SDL_WINDOWEVENT: {
|
||||
switch (event->window.event) {
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED: {
|
||||
grid_relayout(layer->grid, rect(0.0f, 0.0f,
|
||||
(float) event->window.data1,
|
||||
(float) event->window.data2));
|
||||
} break;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
switch (layer->state) {
|
||||
case RECT_LAYER_IDLE:
|
||||
return rect_layer_event_idle(layer, event, camera, undo_history);
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#include "grid.h"
|
||||
|
||||
void grid_relayout(Grid *grid, Rect boundary)
|
||||
{
|
||||
const float cell_width = boundary.w / (float) grid->columns;
|
||||
const float cell_height = boundary.h / (float) grid->rows;
|
||||
|
||||
for (size_t row = 0; row < grid->rows; ++row) {
|
||||
for (size_t column = 0; column < grid->columns; ++column) {
|
||||
Widget *cell = grid->cells[row * grid->columns + column];
|
||||
if (cell) {
|
||||
cell->boundary = rect(
|
||||
boundary.x + (float) column * cell_width,
|
||||
boundary.y + (float) row * cell_height,
|
||||
cell_width, cell_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef GRID_H_
|
||||
#define GRID_H_
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "system/nth_alloc.h"
|
||||
#include "math/rect.h"
|
||||
|
||||
typedef struct {
|
||||
Rect boundary;
|
||||
} Widget;
|
||||
|
||||
typedef struct {
|
||||
size_t rows;
|
||||
size_t columns;
|
||||
Widget *cells[];
|
||||
} Grid;
|
||||
|
||||
static inline
|
||||
void grid_put_widget(Grid *grid, Widget *widget,
|
||||
size_t row, size_t column)
|
||||
{
|
||||
assert(grid);
|
||||
assert(widget);
|
||||
assert(row < grid->rows);
|
||||
assert(column < grid->columns);
|
||||
grid->cells[row * grid->columns + column] = widget;
|
||||
}
|
||||
|
||||
void grid_relayout(Grid *grid, Rect boundary);
|
||||
|
||||
#endif // GRID_H_
|
Loading…
Reference in New Issue