diff options
| author | kasull <qsullian@gmail.com> | 2026-03-01 20:18:08 -0500 |
|---|---|---|
| committer | kasull <qsullian@gmail.com> | 2026-03-01 20:18:08 -0500 |
| commit | 413ef78504278d37080b9b59a652e4bbd5e2a0fc (patch) | |
| tree | 67be817cf765725dd2d08c14b2d0ce8c12b20997 /src/editor/properties.cpp | |
| parent | 71dd7fcccb45a54d85ae23a95a8a8905ed21fe15 (diff) | |
editor ui rework
add responsive editor relayout for window resize
rework header with back/save, view mode buttons, and 2d view type selector
add clipped, scrollable assets and contextual tool panels
simplify tool button wiring and repeated layout logic
simplify 2d top-down editor internals and shared grid update hooks
Diffstat (limited to 'src/editor/properties.cpp')
| -rw-r--r-- | src/editor/properties.cpp | 122 |
1 files changed, 91 insertions, 31 deletions
diff --git a/src/editor/properties.cpp b/src/editor/properties.cpp index ebae177..fa3a117 100644 --- a/src/editor/properties.cpp +++ b/src/editor/properties.cpp @@ -3,6 +3,45 @@ #include "../game/assets.h" const I32 PROPVIEW_TITLE_OFFSET = 15; +const I32 PROPVIEW_PAD = 10; +const I32 PROPVIEW_ACTION_BTN_W = 20; +const I32 PROPVIEW_ACTION_BTN_GAP = 5; + +static I32 propview_col_left() { + return PROPVIEW_PAD; +} + +static I32 propview_col_right( GUI_EDITOR_PROPVIEW* view ) { + if( !view ) + return PROPVIEW_PAD; + + return max( PROPVIEW_PAD, view->w - PROPVIEW_PAD ); +} + +static I32 propview_input_width( GUI_EDITOR_PROPVIEW* view ) { + return max( 120, propview_col_right( view ) - propview_col_left() ); +} + +static I32 propview_sub_input_x( I32 x ) { + return x + 10; +} + +static I32 propview_sub_input_width( GUI_EDITOR_PROPVIEW* view, I32 x ) { + I32 right = propview_col_right( view ); + return max( 100, right - propview_sub_input_x( x ) ); +} + +static I32 propview_action_x( GUI_EDITOR_PROPVIEW* view ) { + I32 right = propview_col_right( view ); + return max( propview_col_left(), right - PROPVIEW_ACTION_BTN_W ); +} + +static I32 propview_action2_x( GUI_EDITOR_PROPVIEW* view ) { + return max( + propview_col_left(), + propview_action_x( view ) - PROPVIEW_ACTION_BTN_W - PROPVIEW_ACTION_BTN_GAP + ); +} void gui_editor_propview_select( GUI_EDITOR_PROPVIEW* view, void* what, U8 seltype ) { if( !editor->map ) @@ -27,11 +66,19 @@ void gui_editor_propview_select( GUI_EDITOR_PROPVIEW* view, void* what, U8 selty } // returns the subentry height -I32 gui_editor_propview_surfprops_subentry( I32 x, I32 y, I32* propid, SURF_PROPS* props ) { +I32 gui_editor_propview_surfprops_subentry( + GUI_EDITOR_PROPVIEW* view, + I32 x, + I32 y, + I32* propid, + SURF_PROPS* props +) { I32 oldy = y; I32 space = 20; + I32 action_x = propview_action_x( view ); + I32 action2_x = propview_action2_x( view ); gui_label( x, y, "prop id: %d", *propid ); - GUI_BUTTON* newprop = gui_button( x + 235, y, 20, 20, "+", pfn( void* ptr ) { + GUI_BUTTON* newprop = gui_button( action2_x, y, 20, 20, "+", pfn( void* ptr ) { GUI_BUTTON* btn = (GUI_BUTTON*)ptr; SURF_PROPS props; props.tex = 0; @@ -39,10 +86,12 @@ I32 gui_editor_propview_surfprops_subentry( I32 x, I32 y, I32* propid, SURF_PROP editor->map->props.push( props ); *(U32*)(btn->extra) = editor->map->props.size - 1; + // Keep the newest prop visible in the assets panel (pixel scroll). + editor->gui.assets_scroll = ( editor->map->props.size + 1 ) * 28; gui_editor_propview_update( editor->gui.props ); } ); newprop->extra = propid; - GUI_BUTTON* goprop = gui_button( x + 260, y, 20, 20, "\x1A", pfn( void* ptr ) { + GUI_BUTTON* goprop = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) { GUI_BUTTON* btn = (GUI_BUTTON*)ptr; gui_editor_propview_select( editor->gui.props, btn->extra, EDITOR_SELECT_SURFPROPS ); } ); @@ -55,7 +104,7 @@ I32 gui_editor_propview_surfprops_subentry( I32 x, I32 y, I32* propid, SURF_PROP else gui_label( x + 10, y, "texture: none" ); - GUI_BUTTON* btn = gui_button( x + 260, y, 20, 20, "\x1A", pfn( void* ptr ) { + GUI_BUTTON* btn = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) { GUI_BUTTON* btn = (GUI_BUTTON*)ptr; GL_TEX2D** ptex = (GL_TEX2D**)btn->extra; GUI_EDITOR_TEXTUREPICKER* picker = gui_editor_texturepicker( 200, 100, 400, 400, ptex ); @@ -64,7 +113,13 @@ I32 gui_editor_propview_surfprops_subentry( I32 x, I32 y, I32* propid, SURF_PROP btn->extra = &props->tex; y += space; - gui_colorinput( x + 10, y, 270, "color", &props->clr ); y += (space+18); + gui_colorinput( + propview_sub_input_x( x ), + y, + propview_sub_input_width( view, x ), + "color", + &props->clr + ); y += (space+18); return y - oldy; } @@ -83,12 +138,12 @@ void gui_editor_propview_create_wallprops( GUI_EDITOR_PROPVIEW* view ) { } ); gui_label( x, y, "idx: %d", wall_idx ); y += space; - y += gui_editor_propview_surfprops_subentry( x, y, &s->propid, props ); + y += gui_editor_propview_surfprops_subentry( view, x, y, &s->propid, props ); GUI_VECTORINPUT* posinput; - posinput = gui_vectorinput( x, y, 280, "start", (F32*)&s->start, 3, -INFINITY, INFINITY, step ); y += (space+18); + posinput = gui_vectorinput( x, y, propview_input_width( view ), "start", (F32*)&s->start, 3, -INFINITY, INFINITY, step ); y += (space+18); posinput->cb = pfn( void* ) { map_check_bounds( editor->map ); }; - posinput = gui_vectorinput( x, y, 280, "end", (F32*)&s->end, 3, -INFINITY, INFINITY, step ); y += (space+18); + posinput = gui_vectorinput( x, y, propview_input_width( view ), "end", (F32*)&s->end, 3, -INFINITY, INFINITY, step ); y += (space+18); posinput->cb = pfn( void* ) { map_check_bounds( editor->map ); }; } @@ -103,15 +158,16 @@ void gui_editor_propview_create_polyprops( GUI_EDITOR_PROPVIEW* view ) { I32 poly_idx = m->polygons.idx_where( fn( MAP_POLYGON* mp ) { return p == mp; } ); + I32 action_x = propview_action_x( view ); gui_label( x, y, "idx: %d", poly_idx ); y += space; - y += gui_editor_propview_surfprops_subentry( x, y, &p->propid, props ); + y += gui_editor_propview_surfprops_subentry( view, x, y, &p->propid, props ); gui_label( x, y, "vertices: %d", p->vertices.size ); y += space; I32 idx = 0; p->vertices.each( fn( MAP_VERTEX* v ) { gui_label( x + 10, y, "[%d] -> { %.02f, %.02f, %.02f }", idx, v->pos.x, v->pos.y, v->pos.z ); - GUI_BUTTON* btn = gui_button( x + 260, y - 2, 20, 20, "\x1A", pfn( void* ptr ) { + GUI_BUTTON* btn = gui_button( action_x, y - 2, 20, 20, "\x1A", pfn( void* ptr ) { GUI_EDITOR_PROPVIEW* view = editor->gui.props; GUI_BUTTON* btn = (GUI_BUTTON*)ptr; MAP_POLYGON* p = (MAP_POLYGON*)view->curselect; @@ -139,6 +195,7 @@ void gui_editor_propview_create_mapprops( GUI_EDITOR_PROPVIEW* view ) { gui_label( x, y, "walls: %d", m->walls.size ); y += space; gui_label( x, y, "polygons: %d", m->polygons.size ); y += space; gui_label( x, y, "props: %d", m->props.size ); y += space; + I32 action_x = propview_action_x( view ); I32 i = 0; m->props.each( fn( SURF_PROPS* p ) { if( p->tex ) @@ -146,7 +203,7 @@ void gui_editor_propview_create_mapprops( GUI_EDITOR_PROPVIEW* view ) { else gui_label( x + 10, y, "[%d] -> { %.02f, %.02f, %.02f, %.02f }", i++, p->clr.r, p->clr.g, p->clr.b, p->clr.a ); - GUI_BUTTON* btn = gui_button( x + 260, y, 20, 20, "\x1A", pfn( void* ptr ) { + GUI_BUTTON* btn = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) { GUI_BUTTON* btn = (GUI_BUTTON*)ptr; gui_editor_propview_select( editor->gui.props, btn->extra, EDITOR_SELECT_SURFPROPS ); } ); @@ -155,8 +212,8 @@ void gui_editor_propview_create_mapprops( GUI_EDITOR_PROPVIEW* view ) { } ); gui_label( x, y, "sprites: %d", m->sprites.size ); y += space; gui_label( x, y, "loaded textures: %d", m->textures.size ); y += space; - gui_vectorinput( x, y, 280, "spawn position", (F32*)&m->startpos, 3, -INFINITY, INFINITY, step ); y += (space+18); - GUI_FLOATINPUT* ang = gui_floatinput( x, y, 280, "spawn angle", &m->startang, -180.f, 180.f, 1.f ); y += (space+18); + gui_vectorinput( x, y, propview_input_width( view ), "spawn position", (F32*)&m->startpos, 3, -INFINITY, INFINITY, step ); y += (space+18); + GUI_FLOATINPUT* ang = gui_floatinput( x, y, propview_input_width( view ), "spawn angle", &m->startang, -180.f, 180.f, 1.f ); y += (space+18); ang->wraparound = 1; } @@ -174,11 +231,12 @@ void gui_editor_propview_create_pvertexprops( GUI_EDITOR_PROPVIEW* view ) { } ); F32 step = editor->propgrid? editor->grid : 0.25f; + I32 action_x = propview_action_x( view ); gui_label( x, y, "idx: %d", vert_idx ); y += space; gui_label( x, y, "polygon idx: %d", poly_idx ); - gui_button( x + 260, y - 2, 20, 20, "\x1A", pfn( void* ) { + gui_button( action_x, y - 2, 20, 20, "\x1A", pfn( void* ) { GUI_EDITOR_PROPVIEW* view = editor->gui.props; MAP_VERTEX* v = (MAP_VERTEX*)view->curselect; WORLD_MAP* m = editor->map; @@ -192,10 +250,10 @@ void gui_editor_propview_create_pvertexprops( GUI_EDITOR_PROPVIEW* view ) { } ); y += space; - GUI_VECTORINPUT* posinput = gui_vectorinput( x, y, 280, "position", (F32*)&v->pos, 3, -INFINITY, INFINITY, step ); y += (space+18); + GUI_VECTORINPUT* posinput = gui_vectorinput( x, y, propview_input_width( view ), "position", (F32*)&v->pos, 3, -INFINITY, INFINITY, step ); y += (space+18); posinput->cb = pfn( void* ptr ) { map_check_bounds( editor->map ); }; - gui_vectorinput( x, y, 280, "texture coordinates", (F32*)&v->uv, 2, 0.f, 1.f, 0.005f, "xy", "%.03f" ); y += (space+18); - gui_colorinput( x, y, 280, "color", &v->clr ); y += (space+18); + gui_vectorinput( x, y, propview_input_width( view ), "texture coordinates", (F32*)&v->uv, 2, 0.f, 1.f, 0.005f, "xy", "%.03f" ); y += (space+18); + gui_colorinput( x, y, propview_input_width( view ), "color", &v->clr ); y += (space+18); } void gui_editor_propview_create_spriteprops( GUI_EDITOR_PROPVIEW* view ) { @@ -208,19 +266,20 @@ void gui_editor_propview_create_spriteprops( GUI_EDITOR_PROPVIEW* view ) { I32 sprite_idx = m->sprites.idx_where( fn( MAP_SPRITE* ms ) { return ms == s; } ); + I32 action_x = propview_action_x( view ); F32 step = editor->propgrid? editor->grid : 0.25f; gui_label( x, y, "idx: %d", sprite_idx ); y += space; - gui_vectorinput( x, y, 280, "position", (F32*)&s->pos, 3, -INFINITY, INFINITY, step ); y += (space+18); - gui_vectorinput( x, y, 280, "size", (F32*)&s->size, 2, 1.f, INFINITY, 1.f, "wh" ); y += (space+18); - gui_colorinput( x, y, 280, "color", &s->clr ); y += (space+18); + gui_vectorinput( x, y, propview_input_width( view ), "position", (F32*)&s->pos, 3, -INFINITY, INFINITY, step ); y += (space+18); + gui_vectorinput( x, y, propview_input_width( view ), "size", (F32*)&s->size, 2, 1.f, INFINITY, 1.f, "wh" ); y += (space+18); + gui_colorinput( x, y, propview_input_width( view ), "color", &s->clr ); y += (space+18); if( s->tex ) gui_label( x, y, "texture: %s", s->tex->name ); else gui_label( x, y, "texture: none" ); - GUI_BUTTON* btn = gui_button( x + 260, y, 20, 20, "\x1A", pfn( void* ptr ) { + GUI_BUTTON* btn = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) { GUI_BUTTON* btn = (GUI_BUTTON*)ptr; GL_TEX2D** ptex = (GL_TEX2D**)btn->extra; GUI_EDITOR_TEXTUREPICKER* picker = gui_editor_texturepicker( 200, 100, 400, 400, ptex ); @@ -240,13 +299,14 @@ void gui_editor_propview_create_surfprops( GUI_EDITOR_PROPVIEW* view ) { I32 i = m->props.idx_where( fn( SURF_PROPS* mp ) { return mp == p; } ); if( i == -1 ) return; + I32 action_x = propview_action_x( view ); gui_label( x, y, "prop id: %d", i ); y += space; if( p->tex ) gui_label( x, y, "texture: %s", assets_abspath( p->tex->name ) ); else gui_label( x, y, "texture: none" ); - GUI_BUTTON* btn = gui_button( x + 260, y, 20, 20, "\x1A", pfn( void* ptr ) { + GUI_BUTTON* btn = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) { GUI_BUTTON* btn = (GUI_BUTTON*)ptr; GL_TEX2D** ptex = (GL_TEX2D**)btn->extra; GUI_EDITOR_TEXTUREPICKER* picker = gui_editor_texturepicker( 200, 100, 400, 400, ptex ); @@ -254,7 +314,7 @@ void gui_editor_propview_create_surfprops( GUI_EDITOR_PROPVIEW* view ) { } ); btn->extra = &p->tex; y += space; - gui_colorinput( x, y, 280, "color", &p->clr ); y += (space+18); + gui_colorinput( x, y, propview_input_width( view ), "color", &p->clr ); y += (space+18); } void gui_editor_propview_create_entprops( GUI_EDITOR_PROPVIEW* view ) { @@ -285,15 +345,15 @@ void gui_editor_propview_update( GUI_EDITOR_PROPVIEW* view ) { void gui_editor_propview_get_title( GUI_EDITOR_PROPVIEW* view, char* buf ) { switch( view->seltype ) { - case EDITOR_SELECT_NONE: sprintf( buf, "properties: " ); break; - case EDITOR_SELECT_POLY: sprintf( buf, "polygon properties: " ); break; - case EDITOR_SELECT_ORIGIN: sprintf( buf, "map [%s] properties: ", editor->map->name ); break; - case EDITOR_SELECT_ENT: sprintf( buf, "entity properties: " ); break; - case EDITOR_SELECT_SPRITE: sprintf( buf, "sprite properties: " ); break; - case EDITOR_SELECT_PVERTEX: sprintf( buf, "vertex properties: " ); break; - case EDITOR_SELECT_SURFPROPS: sprintf( buf, "surface properties: " ); break; + case EDITOR_SELECT_NONE: sprintf( buf, "properties" ); break; + case EDITOR_SELECT_POLY: sprintf( buf, "polygon properties" ); break; + case EDITOR_SELECT_ORIGIN: sprintf( buf, "properties" ); break; + case EDITOR_SELECT_ENT: sprintf( buf, "entity properties" ); break; + case EDITOR_SELECT_SPRITE: sprintf( buf, "sprite properties" ); break; + case EDITOR_SELECT_PVERTEX: sprintf( buf, "vertex properties" ); break; + case EDITOR_SELECT_SURFPROPS: sprintf( buf, "surface properties" ); break; case EDITOR_SELECT_WVERTEX: - case EDITOR_SELECT_WALL: sprintf( buf, "wall properties: " ); break; + case EDITOR_SELECT_WALL: sprintf( buf, "wall properties" ); break; } } |
