1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
#include "editor.h"
#include "../util/string.h"
const U32 TOOLVIEW_TITLE_OFFSET = 15;
const I32 TOOLVIEW_INNER_X = 10;
const I32 TOOLVIEW_INNER_PAD = 20;
const I32 TOOLVIEW_ROW_HEIGHT = 20;
const I32 TOOLVIEW_ROW_GAP = 4;
const I32 TOOLVIEW_WALL_SHAPE_LIST_HEIGHT = 54;
GUI_EDITOR_TOOLVIEW* gui_editor_toolview_from_item_child( GUI_BASE* child ) {
if( !child || !child->parent || !child->parent->parent )
return 0;
return (GUI_EDITOR_TOOLVIEW*)child->parent->parent;
}
void gui_editor_toolview_sanitize_float_input( void* ptr ) {
GUI_FLOATINPUT* input = (GUI_FLOATINPUT*)ptr;
F32* pval = input->pval;
if( pval == &editor->tool.polysides ) {
if( !isfinite( *pval ) ) *pval = EDITOR_DEFAULT_POLY_SIDES;
F32 rounded = floorf( *pval + 0.5f );
if( rounded < EDITOR_POLY_SIDES_MIN ) rounded = EDITOR_POLY_SIDES_MIN;
if( rounded > EDITOR_POLY_SIDES_MAX ) rounded = EDITOR_POLY_SIDES_MAX;
*pval = rounded;
return;
}
if( pval == &editor->tool.wallheight ) {
if( !isfinite( *pval ) ) *pval = EDITOR_DEFAULT_WALL_HEIGHT;
if( *pval < 1.f ) *pval = 1.f;
return;
}
if( pval == &editor->tool.placementheight ) {
if( !isfinite( *pval ) ) *pval = EDITOR_DEFAULT_PLACEMENT_HEIGHT;
}
}
I32 gui_editor_toolview_create_float_input(
GUI_EDITOR_TOOLVIEW* view,
I32 y,
const char* title,
F32* pval,
F32 min,
F32 max,
F32 step,
const char* fmt
) {
GUI_FLOATINPUT* input = gui_floatinput(
TOOLVIEW_INNER_X,
y,
view->w - TOOLVIEW_INNER_PAD,
title,
pval,
min,
max,
step,
fmt
);
input->cb = gui_editor_toolview_sanitize_float_input;
if( input->cb ) input->cb( input );
return y + TOOLVIEW_ROW_HEIGHT + TOOLVIEW_ROW_GAP;
}
void gui_editor_toolview_queue_refresh( GUI_EDITOR_TOOLVIEW* view ) {
if( !view )
return;
gui_push_callback( view, pfn( void* ptr ) {
gui_editor_toolview_update( (GUI_EDITOR_TOOLVIEW*)ptr );
} );
}
void gui_editor_toolview_wallshape_dropdown_toggle_cb( void* ptr ) {
GUI_BUTTON* btn = (GUI_BUTTON*)ptr;
GUI_EDITOR_TOOLVIEW* view = gui_editor_toolview_from_item_child( btn );
if( !view )
return;
view->wallshape_dropdown_open = !view->wallshape_dropdown_open;
gui_editor_toolview_queue_refresh( view );
}
void gui_editor_toolview_wallshape_select_cb( void* ptr ) {
GUI_LIST* list = (GUI_LIST*)ptr;
GUI_EDITOR_TOOLVIEW* view = gui_editor_toolview_from_item_child( list );
if( !view )
return;
view->wallshape_dropdown_open = 0;
gui_editor_toolview_queue_refresh( view );
}
I32 gui_editor_toolview_create_wallshape_dropdown( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
static LIST<GUI_LIST_ENTRY> shape_entries{};
if( !shape_entries.size ) {
GUI_LIST_ENTRY line{};
line.val = EDITOR_WALLSHAPE_LINE;
strcpy( line.title, "line" );
shape_entries.push( line );
GUI_LIST_ENTRY polygon{};
polygon.val = EDITOR_WALLSHAPE_POLYGON;
strcpy( polygon.title, "polygon" );
shape_entries.push( polygon );
}
const char* shape_name = editor->tool.wallshape == EDITOR_WALLSHAPE_POLYGON ? "polygon" : "line";
char dropdown_title[64];
sprintf( dropdown_title, "shape: %s v", shape_name );
gui_button(
TOOLVIEW_INNER_X,
y,
view->w - TOOLVIEW_INNER_PAD,
TOOLVIEW_ROW_HEIGHT,
dropdown_title,
gui_editor_toolview_wallshape_dropdown_toggle_cb
);
y += TOOLVIEW_ROW_HEIGHT + TOOLVIEW_ROW_GAP;
if( !view->wallshape_dropdown_open )
return y;
GUI_LIST* shape = gui_list(
TOOLVIEW_INNER_X,
y,
view->w - TOOLVIEW_INNER_PAD,
TOOLVIEW_WALL_SHAPE_LIST_HEIGHT,
"shape",
&shape_entries,
&editor->tool.wallshape
);
shape->cb = gui_editor_toolview_wallshape_select_cb;
y += TOOLVIEW_WALL_SHAPE_LIST_HEIGHT + TOOLVIEW_ROW_GAP;
return y;
}
I32 gui_editor_toolview_create_poly_sides_input( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
return gui_editor_toolview_create_float_input(
view,
y,
"sides",
&editor->tool.polysides,
(F32)EDITOR_POLY_SIDES_MIN,
(F32)EDITOR_POLY_SIDES_MAX,
1.f,
"%.0f"
);
}
I32 gui_editor_toolview_create_wall_height_input( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
return gui_editor_toolview_create_float_input(
view,
y,
"wall height",
&editor->tool.wallheight,
1.f,
1024.f,
1.f,
"%.0f"
);
}
I32 gui_editor_toolview_create_placement_height_input( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
return gui_editor_toolview_create_float_input(
view,
y,
"placement z",
&editor->tool.placementheight,
-4096.f,
4096.f,
1.f,
"%.0f"
);
}
void gui_editor_toolview_get_title( GUI_EDITOR_TOOLVIEW* view, char* out ) {
switch( editor->tool.type ) {
case EDITOR_TOOL_ENT: memcpy( out, "tool: entity", 12 ); break;
case EDITOR_TOOL_WALL: memcpy( out, "tool: wall", 10 ); break;
case EDITOR_TOOL_POLY: memcpy( out, "tool: polygon", 14 ); break;
case EDITOR_TOOL_SELECT: memcpy( out, "tool: select", 12 ); break;
case EDITOR_TOOL_SPRITE: memcpy( out, "tool: sprite", 12 ); break;
default: memcpy( out, "tool: none", 10 ); break;
}
}
void gui_editor_toolview_update( GUI_EDITOR_TOOLVIEW* view ) {
if( !view )
return;
GUI_VIEW* oldview = gui_get_view();
gui_set_view( view->itemview );
gui_empty_children( view->itemview );
view->itemview->initheld = 1;
I32 y = 10;
if( editor->tool.type == EDITOR_TOOL_WALL ) {
y = gui_editor_toolview_create_wallshape_dropdown( view, y );
if( view->wallshape_dropdown_open ) {
gui_set_view( oldview );
return;
}
if( editor->tool.wallshape == EDITOR_WALLSHAPE_POLYGON ) {
y = gui_editor_toolview_create_poly_sides_input( view, y );
}
y = gui_editor_toolview_create_wall_height_input( view, y );
y = gui_editor_toolview_create_placement_height_input( view, y );
}
else if( editor->tool.type == EDITOR_TOOL_POLY ) {
y = gui_editor_toolview_create_poly_sides_input( view, y );
y = gui_editor_toolview_create_placement_height_input( view, y );
}
gui_set_view( oldview );
}
void gui_editor_toolview_draw_fn( void* ptr ) {
if( !editor->map ) return;
GUI_EDITOR_TOOLVIEW* view = (GUI_EDITOR_TOOLVIEW*)ptr;
I32 x = gui_relx( view );
I32 y = gui_rely( view );
I32 w = view->w;
I32 h = view->h;
STR<64> title{};
gui_editor_toolview_get_title( view, title );
gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, title );
y += TOOLVIEW_TITLE_OFFSET;
CLR col = gui_is_fg_window( view )? ui_clr.border : ui_clr.border_inactive;
gui_draw_frect( x, y, w, h, col );
gui_draw_frect( x+1, y+1, w-2, h-2, ui_clr.bg_sec );
view->itemview->draw_fn( view->itemview );
}
GUI_EDITOR_TOOLVIEW* gui_editor_toolview( I32 x, I32 y, I32 w, I32 h ) {
if( !gui_check_target() ) return 0;
GUI_EDITOR_TOOLVIEW* view = new GUI_EDITOR_TOOLVIEW;
view->x = x;
view->y = y;
view->w = w;
view->h = h;
view->xbound = view->w;
view->ybound = view->h + TOOLVIEW_TITLE_OFFSET;
strcpy( view->name, "EDITOR_PROP_VIEW" );
view->draw_fn = gui_editor_toolview_draw_fn;
view->input_fn = gui_base_input_fn;
view->wallshape_dropdown_open = 0;
GUI_VIEW* parent = gui_get_view();
parent->children.push( view );
view->parent = parent;
gui_set_view( view );
view->itemview = gui_view( 0, TOOLVIEW_TITLE_OFFSET, w, h );
gui_set_view( parent );
return view;
}
|