diff options
| author | kasull <qsullian@gmail.com> | 2026-03-03 12:22:40 -0500 |
|---|---|---|
| committer | kasull <qsullian@gmail.com> | 2026-03-03 12:22:40 -0500 |
| commit | 5c4e9c8b140b14ba9671b8efcc47d71c6c4f2217 (patch) | |
| tree | c011086a55a9fff0130a71a66f1c06029410b135 /src/editor/view2d.cpp | |
| parent | 413ef78504278d37080b9b59a652e4bbd5e2a0fc (diff) | |
ui header/menu and add undo/redo for creation actions
full-width toolbar/menubar layer
move save into file menu and add edit menu actions for undo/redo
menubar dropdown interaction modal
update header/view-type labels and menu layout behavior
creation-history tracking for walls and polygons
undo (ctrl+z) and redo (ctrl+r) in 2d editor
improve list/button visual states
Diffstat (limited to 'src/editor/view2d.cpp')
| -rw-r--r-- | src/editor/view2d.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp index 6814fd2..b68846e 100644 --- a/src/editor/view2d.cpp +++ b/src/editor/view2d.cpp @@ -433,7 +433,9 @@ void gui_editor_2dview_create_poly_from_drag( GUI_EDITOR_2DVIEW* view ) { } map_polygon_calc_bounds( &newp ); + I32 poly_idx = editor->map->polygons.size; editor->map->polygons.push( newp ); + editor_undo_record_create_poly( editor, poly_idx ); gui_editor_2dview_check_bounds_preserve_view( view ); } @@ -443,6 +445,7 @@ void gui_editor_2dview_create_wallpoly_from_drag( GUI_EDITOR_2DVIEW* view ) { return; I32 propid = gui_editor_2dview_find_or_create_wallpoly_propid(); + I32 first_wall_idx = editor->map->walls.size; F32 depth = gui_editor_2dview_placement_z(); F32 wallheight = gui_editor_2dview_wall_height(); @@ -459,6 +462,8 @@ void gui_editor_2dview_create_wallpoly_from_drag( GUI_EDITOR_2DVIEW* view ) { wall.propid = propid; editor->map->walls.push( wall ); } + I32 new_wall_count = editor->map->walls.size - first_wall_idx; + editor_undo_record_create_walls( editor, first_wall_idx, new_wall_count ); gui_editor_2dview_check_bounds_preserve_view( view ); } @@ -1141,8 +1146,11 @@ void gui_editor_2dview_input_tool_wall( GUI_EDITOR_2DVIEW* view ) { U8 m1 = gui_mbutton_down( 0 ); if( !m1 ) { if( view->held ) { + if( view->pending_wall_undo_idx >= 0 ) + editor_undo_record_create_walls( editor, view->pending_wall_undo_idx, 1 ); gui_editor_2dview_check_bounds_preserve_view( view ); } + view->pending_wall_undo_idx = -1; view->held = 0; view->curdrag = 0; return; @@ -1168,6 +1176,7 @@ void gui_editor_2dview_input_tool_wall( GUI_EDITOR_2DVIEW* view ) { I32 idx = editor->map->walls.size; editor->map->walls.push( neww ); + view->pending_wall_undo_idx = idx; view->curdrag = &editor->map->walls[idx].end; view->held = 1; @@ -1338,12 +1347,31 @@ void gui_editor_view2d_delete_obj( GUI_EDITOR_2DVIEW* view ) { void gui_editor_2dview_key_input( GUI_EDITOR_2DVIEW* view ) { static U8 del_held = 0; + static U8 undo_held = 0; + static U8 redo_held = 0; if( kb_down( SDLK_DELETE ) && !input.mouselock ) { if( !del_held ) gui_editor_view2d_delete_obj( view ); del_held = 1; } else del_held = 0; + + U8 ctrl = kb_down( SDLK_LCTRL ) || kb_down( SDLK_RCTRL ); + U8 z = kb_down( SDLK_z ); + if( ctrl && z && !input.mouselock ) { + if( !undo_held ) + editor_undo( editor ); + + undo_held = 1; + } else undo_held = 0; + + U8 r = kb_down( SDLK_r ); + if( ctrl && r && !input.mouselock ) { + if( !redo_held ) + editor_redo( editor ); + + redo_held = 1; + } else redo_held = 0; } void gui_editor_2dview_input_fn( void* ptr ) { @@ -1469,6 +1497,7 @@ GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h ) { view->poly_drag = 0; view->poly_start = { 0.f, 0.f }; view->poly_end = { 0.f, 0.f }; + view->pending_wall_undo_idx = -1; GUI_BASE* parent = gui_get_view(); if( !parent ) |
