summaryrefslogtreecommitdiff
path: root/src/editor/view2d.cpp
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-03-20 20:21:24 +0100
committerday <day@national.shitposting.agency>2026-03-20 22:52:49 +0100
commit63472b948968916d0fd06d91b9ea0fd057e39d0f (patch)
tree9d654f5c4ba258a3ea370d59506df11cae1f0c06 /src/editor/view2d.cpp
parent34d410da50e76f12c3d011293f4b544330e8ba3e (diff)
move multiple objects
Diffstat (limited to 'src/editor/view2d.cpp')
-rw-r--r--src/editor/view2d.cpp187
1 files changed, 106 insertions, 81 deletions
diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp
index 8bcd588..c4738dd 100644
--- a/src/editor/view2d.cpp
+++ b/src/editor/view2d.cpp
@@ -691,6 +691,30 @@ void gui_editor_2dview_draw_player( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
gui_draw_frect( (I32)pos2d.x-3, (I32)pos2d.y-3, 6, 6, CLR::RED() );
}
+void gui_editor_2dview_draw_object_preview( GUI_EDITOR_2DVIEW* view ) {
+ if( editor->tool.type != EDITOR_TOOL_OBJECT || !view->held )
+ return;
+
+ VEC2 pos = gui_editor_2dview_world3_to_screen( view, view->pending_object_pos );
+ I32 px = (I32)pos.x;
+ I32 py = (I32)pos.y;
+
+ if( view->pending_object_undo_type == EDITOR_SELECT_ENT ) {
+ gui_draw_line( px - 6, py, px + 6, py, CLR::WHITE( 0.8f ) );
+ gui_draw_line( px, py - 6, px, py + 6, CLR::WHITE( 0.8f ) );
+ return;
+ }
+
+ F32 wantedsize = editor->spritesize;
+ gui_draw_rect(
+ (I32)( pos.x - wantedsize * 0.5f ),
+ (I32)( pos.y - wantedsize * 0.5f ),
+ (I32)wantedsize,
+ (I32)wantedsize,
+ CLR::WHITE( 0.8f )
+ );
+}
+
void gui_editor_2dview_draw_origin( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
WORLD_MAP* m = editor->map;
@@ -814,6 +838,36 @@ VEC2 gui_editor_2dview_input_get_drag_vec( GUI_EDITOR_2DVIEW* view ) {
return { editor->grid * igridx, editor->grid * igridy };
}
+U8 gui_editor_2dview_input_select_drag_obj( GUI_EDITOR_2DVIEW* view, void* obj, U8 seltype );
+U8 gui_editor_2dview_move_group( GUI_EDITOR_2DVIEW* view ) {
+ U8 update = 0;
+ if( view->dragtype == EDITOR_SELECT_WVERTEX || view->dragtype == EDITOR_SELECT_PVERTEX )
+ return update;
+
+ GUI_EDITOR_PROPVIEW* props = editor->gui.props;
+ // update all selected objects
+ for( auto& it : props->curselect ) {
+ if( it.obj == view->curdrag ) {
+ update = 1;
+ continue;
+ }
+
+ // special case where a wall is selected but we are dragging one of its vertices
+ if( props->curselect.size == 1 && it.seltype == EDITOR_SELECT_WALL ) {
+ MAP_WALL* w = (MAP_WALL*)it.obj;
+ if( &w->start == view->curdrag || &w->end == view->curdrag ) {
+ update = 1;
+ continue;
+ }
+ }
+
+ if( gui_editor_2dview_input_select_drag_obj( view, it.obj, it.seltype ) )
+ update = 1;
+ }
+
+ return update;
+}
+
void gui_editor_2dview_input_select_onmove( GUI_EDITOR_2DVIEW* view ) {
I32 mx, my;
gui_cursor_pos( &mx, &my );
@@ -825,24 +879,22 @@ void gui_editor_2dview_input_select_onmove( GUI_EDITOR_2DVIEW* view ) {
F32 rmx = copysignf( fmodf( fabsf( dx ), editor->grid ), dx );
F32 rmy = copysignf( fmodf( fabsf( dy ), editor->grid ), dy );
+
+ GUI_EDITOR_PROPVIEW* props = editor->gui.props;
+ U8 update = !is_zero( gui_editor_2dview_input_get_drag_vec( view ) );
+ if( update && gui_editor_propview_is_selected( props, view->curdrag, view->dragtype ) ) {
+ if( gui_editor_2dview_move_group( view ) )
+ gui_editor_propview_update( props );
+ }
+
view->oldmx = mx;
view->oldmy = my;
view->mremainx = rmx;
view->mremainy = rmy;
view->dragmoved = 1;
-
- GUI_EDITOR_PROPVIEW* props = editor->gui.props;
- // special case for dragging wall vertices, just always update
- for( auto& it : props->curselect ) {
- U8 iswallv = it.seltype == EDITOR_SELECT_WALL && view->dragtype == EDITOR_SELECT_WVERTEX;
- if( it.obj == view->curdrag || iswallv )
- gui_editor_propview_update( editor->gui.props );
- }
}
-void gui_editor_2dview_input_select_drag_wall( GUI_EDITOR_2DVIEW* view ) {
- MAP_WALL* s = (MAP_WALL*)view->curdrag;
-
+void gui_editor_2dview_input_select_drag_wall( GUI_EDITOR_2DVIEW* view, MAP_WALL* s ) {
gui_editor_2dview_snap_plane( &s->start );
gui_editor_2dview_snap_plane( &s->end );
@@ -851,40 +903,31 @@ void gui_editor_2dview_input_select_drag_wall( GUI_EDITOR_2DVIEW* view ) {
gui_editor_2dview_add_plane_delta( &s->start, mv );
gui_editor_2dview_add_plane_delta( &s->end, mv );
map_check_bounds( editor->map );
-
- gui_editor_2dview_input_select_onmove( view );
}
}
-void gui_editor_2dview_input_select_drag_vertex( GUI_EDITOR_2DVIEW* view ) {
- if( view->dragtype == EDITOR_SELECT_WVERTEX ) {
- VEC3* v = (VEC3*)view->curdrag;
- gui_editor_2dview_snap_plane( v );
+void gui_editor_2dview_input_select_drag_pos( GUI_EDITOR_2DVIEW* view, VEC3* v ) {
+ gui_editor_2dview_snap_plane( v );
- VEC2 mv = gui_editor_2dview_input_get_drag_vec( view );
- if( !is_zero( mv ) ) {
- gui_editor_2dview_add_plane_delta( v, mv );
- map_check_bounds( editor->map );
- gui_editor_2dview_input_select_onmove( view );
- }
- return;
+ VEC2 mv = gui_editor_2dview_input_get_drag_vec( view );
+ if( !is_zero( mv ) ) {
+ gui_editor_2dview_add_plane_delta( v, mv );
+ map_check_bounds( editor->map );
}
+}
- MAP_VERTEX* v = (MAP_VERTEX*)view->curdrag;
+
+void gui_editor_2dview_input_select_drag_vertex( GUI_EDITOR_2DVIEW* view, MAP_VERTEX* v ) {
gui_editor_2dview_snap_plane( &v->pos );
VEC2 mv = gui_editor_2dview_input_get_drag_vec( view );
if( !is_zero( mv ) ) {
gui_editor_2dview_add_plane_delta( &v->pos, mv );
map_check_bounds( editor->map );
-
- gui_editor_2dview_input_select_onmove( view );
}
}
-void gui_editor_2dview_input_select_drag_polygon( GUI_EDITOR_2DVIEW* view ) {
- MAP_POLYGON* p = (MAP_POLYGON*)view->curdrag;
-
+void gui_editor_2dview_input_select_drag_polygon( GUI_EDITOR_2DVIEW* view, MAP_POLYGON* p ) {
VEC2 mv = gui_editor_2dview_input_get_drag_vec( view );
if( !is_zero( mv ) ) {
p->vertices.each( fn( MAP_VERTEX* v ) {
@@ -894,70 +937,55 @@ void gui_editor_2dview_input_select_drag_polygon( GUI_EDITOR_2DVIEW* view ) {
map_polygon_calc_bounds( p );
map_check_bounds( editor->map );
- gui_editor_2dview_input_select_onmove( view );
}
}
-void gui_editor_2dview_input_select_drag_sprite( GUI_EDITOR_2DVIEW* view ) {
- MAP_SPRITE* s = (MAP_SPRITE*)view->curdrag;
-
+void gui_editor_2dview_input_select_drag_sprite( GUI_EDITOR_2DVIEW* view, MAP_SPRITE* s ) {
gui_editor_2dview_snap_plane( &s->pos );
VEC2 mv = gui_editor_2dview_input_get_drag_vec( view );
if( !is_zero( mv ) ) {
gui_editor_2dview_add_plane_delta( &s->pos, mv );
- gui_editor_2dview_input_select_onmove( view );
}
}
-void gui_editor_2dview_draw_object_preview( GUI_EDITOR_2DVIEW* view ) {
- if( editor->tool.type != EDITOR_TOOL_OBJECT || !view->held )
- return;
-
- VEC2 pos = gui_editor_2dview_world3_to_screen( view, view->pending_object_pos );
- I32 px = (I32)pos.x;
- I32 py = (I32)pos.y;
-
- if( view->pending_object_undo_type == EDITOR_SELECT_ENT ) {
- gui_draw_line( px - 6, py, px + 6, py, CLR::WHITE( 0.8f ) );
- gui_draw_line( px, py - 6, px, py + 6, CLR::WHITE( 0.8f ) );
- return;
- }
-
- F32 wantedsize = editor->spritesize;
- gui_draw_rect(
- (I32)( pos.x - wantedsize * 0.5f ),
- (I32)( pos.y - wantedsize * 0.5f ),
- (I32)wantedsize,
- (I32)wantedsize,
- CLR::WHITE( 0.8f )
- );
-}
-
-void gui_editor_2dview_input_select_drag_entity( GUI_EDITOR_2DVIEW* view ) {
- MAP_ENTITY* e = (MAP_ENTITY*)view->curdrag;
+void gui_editor_2dview_input_select_drag_entity( GUI_EDITOR_2DVIEW* view, MAP_ENTITY* e ) {
gui_editor_2dview_snap_plane( &e->pos );
VEC2 mv = gui_editor_2dview_input_get_drag_vec( view );
if( !is_zero( mv ) ) {
gui_editor_2dview_add_plane_delta( &e->pos, mv );
- gui_editor_2dview_input_select_onmove( view );
}
}
-void gui_editor_2dview_input_select_drag_origin( GUI_EDITOR_2DVIEW* view ) {
- WORLD_MAP* m = editor->map;
-
+void gui_editor_2dview_input_select_drag_origin( GUI_EDITOR_2DVIEW* view, WORLD_MAP* m ) {
gui_editor_2dview_snap_plane( &m->startpos );
VEC2 mv = gui_editor_2dview_input_get_drag_vec( view );
if( !is_zero( mv ) ) {
gui_editor_2dview_add_plane_delta( &m->startpos, mv );
- gui_editor_2dview_input_select_onmove( view );
}
}
+U8 gui_editor_2dview_input_select_drag_obj( GUI_EDITOR_2DVIEW* view, void* obj, U8 seltype ) {
+ I32 mx, my;
+ gui_cursor_pos( &mx, &my );
+
+ void* p = obj;
+ switch( seltype ) {
+ case EDITOR_SELECT_WALL: gui_editor_2dview_input_select_drag_wall( view, (MAP_WALL*)p ); return 1;
+ case EDITOR_SELECT_POLY: gui_editor_2dview_input_select_drag_polygon( view, (MAP_POLYGON*)p ); return 1;
+ case EDITOR_SELECT_ENT: gui_editor_2dview_input_select_drag_entity( view, (MAP_ENTITY*)p ); return 1;
+ case EDITOR_SELECT_SPRITE: gui_editor_2dview_input_select_drag_sprite( view, (MAP_SPRITE*)p ); return 1;
+ case EDITOR_SELECT_ORIGIN: gui_editor_2dview_input_select_drag_origin( view, (WORLD_MAP*)p ); return 1;
+ case EDITOR_SELECT_PVERTEX: gui_editor_2dview_input_select_drag_vertex( view, (MAP_VERTEX*)p ); return 1;
+ case EDITOR_SELECT_WVERTEX: gui_editor_2dview_input_select_drag_pos( view, (VEC3*)p ); return 1;
+ }
+
+ return 0;
+}
+
void gui_editor_2dview_input_select_ondrop( GUI_EDITOR_2DVIEW* view ) {
if( !view->dragmoved )
gui_editor_propview_select( editor->gui.props, view->curdrag, view->dragtype, !input.keys[SDL_SCANCODE_LCTRL] );
@@ -989,19 +1017,15 @@ void gui_editor_2dview_input_select_drag( GUI_EDITOR_2DVIEW* view ) {
return;
}
- switch( view->dragtype ) {
- case EDITOR_SELECT_WALL: gui_editor_2dview_input_select_drag_wall( view ); break;
- case EDITOR_SELECT_POLY: gui_editor_2dview_input_select_drag_polygon( view ); break;
- case EDITOR_SELECT_ENT: gui_editor_2dview_input_select_drag_entity( view ); break;
- case EDITOR_SELECT_SPRITE: gui_editor_2dview_input_select_drag_sprite( view ); break;
- case EDITOR_SELECT_ORIGIN: gui_editor_2dview_input_select_drag_origin( view ); break;
- case EDITOR_SELECT_WVERTEX:
- case EDITOR_SELECT_PVERTEX:
- gui_editor_2dview_input_select_drag_vertex( view ); break;
- default: {
- view->oldmx = mx;
- view->oldmy = my;
- } break;
+ if( !gui_editor_2dview_input_select_drag_obj( view, view->curdrag, view->dragtype ) ) {
+ view->oldmx = mx;
+ view->oldmy = my;
+ return;
+ }
+
+ VEC2 mv = gui_editor_2dview_input_get_drag_vec( view );
+ if( !is_zero( mv ) ) {
+ gui_editor_2dview_input_select_onmove( view );
}
}
@@ -1403,8 +1427,6 @@ void gui_editor_view2d_delete_obj( GUI_EDITOR_2DVIEW* view ) {
view->curdrag = 0;
view->dragtype = EDITOR_SELECT_NONE;
} else if( editor->gui.props->curselect.size ) {
- view->curselect = 0;
- view->seltype = EDITOR_SELECT_NONE;
sel = editor->gui.props->curselect;
editor->gui.props->curselect.clear();
@@ -1412,6 +1434,9 @@ void gui_editor_view2d_delete_obj( GUI_EDITOR_2DVIEW* view ) {
}
else return;
+ view->curselect = 0;
+ view->seltype = EDITOR_SELECT_NONE;
+
for( auto& _it: sel ) {
void* it = _it.obj;
U8 type = _it.seltype;