3 #include "system/stacktrace.h"
4 #include "action_picker.h"
5 #include "math/extrema.h"
8 static const char *action_labels[ACTION_N] = {
9 [ACTION_NONE] = "None",
10 [ACTION_HIDE_LABEL] = "Hide Label",
11 [ACTION_TOGGLE_GOAL] = "Toggle Goal"
14 #define TEXT_SCALE vec(5.0f, 5.0f)
15 #define TEXT_COLOR COLOR_WHITE
16 #define SELECTION_COLOR COLOR_WHITE
17 #define BACKGROUND_COLOR COLOR_BLACK
19 void action_picker_render(const ActionPicker *picker,
26 camera_fill_rect_screen(
28 picker->widget.boundary,
31 const float element_height = picker->widget.boundary.h / (float)ACTION_N;
32 for (size_t i = 0; i < ACTION_N; ++i) {
33 const Vec2f element_position =
35 vec(picker->widget.boundary.x, picker->widget.boundary.y),
36 vec(0.0f, (float)i * element_height));
37 const Rect element_box =
38 rect_from_vecs(element_position,
39 vec(picker->widget.boundary.w, element_height));
42 camera_render_text_screen(
49 if (i == picker->action.type) {
50 camera_draw_thicc_rect_screen(
59 void action_picker_event(ActionPicker *picker,
60 const SDL_Event *event)
65 switch (event->type) {
66 case SDL_MOUSEBUTTONDOWN: {
67 switch (event->button.button) {
68 case SDL_BUTTON_LEFT: {
69 const Vec2f mouse_position =
70 vec((float)event->button.x,
71 (float)event->button.y);
73 const float element_height = picker->widget.boundary.h / (float)ACTION_N;
75 for (ActionType i = 0; i < ACTION_N; ++i) {
76 const Vec2f element_position =
78 vec(picker->widget.boundary.x, picker->widget.boundary.y),
79 vec(0.0f, (float)i * element_height));
80 const Rect element_box =
81 rect_from_vecs(element_position,
82 vec(picker->widget.boundary.w, element_height));
84 if (rect_contains_point(element_box, mouse_position)) {
85 picker->action.type = i;
94 switch (event->key.keysym.sym) {
96 if (picker->action.type > 0) {
97 picker->action.type--;
102 if (picker->action.type < ACTION_N) {
103 picker->action.type++;