summaryrefslogtreecommitdiff
path: root/src/editor/view2d.cpp
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-08-13 00:51:36 +0200
committeraura <nw@moneybot.cc>2026-08-13 00:51:36 +0200
commita266df321b19558764565f3b433aa997004a5f42 (patch)
tree9d4dd1b4a6a4c21348fe222e28e21a858561b8ee /src/editor/view2d.cpp
parent17c07b5f884453130d8be3a6d91d730d80d4f8ae (diff)
path drawing more workHEADmaster
Diffstat (limited to 'src/editor/view2d.cpp')
-rw-r--r--src/editor/view2d.cpp96
1 files changed, 95 insertions, 1 deletions
diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp
index 7a7ea3e..bfeed1d 100644
--- a/src/editor/view2d.cpp
+++ b/src/editor/view2d.cpp
@@ -674,7 +674,6 @@ void gui_editor_2dview_draw_entities( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
}
void gui_editor_2dview_draw_player( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
-
if( !objl->pl )
return;
@@ -714,6 +713,44 @@ void gui_editor_2dview_draw_object_preview( GUI_EDITOR_2DVIEW* view ) {
);
}
+void gui_editor_2dview_draw_wallpath_preview( GUI_EDITOR_2DVIEW* view ) {
+ if( !view->draw_started )
+ return;
+
+ I32 mx, my;
+ gui_cursor_pos( &mx, &my );
+
+ VEC2 world = gui_editor_2dview_screen_to_world( view, mx, my );
+ F32 depth = gui_editor_2dview_placement_z();
+ VEC3 wp3 = gui_editor_2dview_plane_to_world3( world, depth );
+ gui_editor_2dview_snap_plane( &wp3 );
+
+ VEC2 start = gui_editor_2dview_world3_to_screen( view, view->draw_lastpos );
+ VEC2 end = gui_editor_2dview_world3_to_screen( view, wp3 );
+
+ F32 deg = vec_angle( start, end );
+ F32 len = vec_dist( start, end );
+
+ for( F32 dash = 0; dash < len; dash += 8.f ) {
+ VEC2 p1 = start + m_radial_offset( deg, dash );
+ VEC2 p2 = start + m_radial_offset( deg, dash + 6.f );
+
+ gui_draw_line( p1.x, p1.y, p2.x, p2.y, CLR::CYAN() );
+ }
+}
+
+
+void gui_editor_2dview_draw_polypath_preview( GUI_EDITOR_2DVIEW* view ) {
+
+}
+
+void gui_editor_2dview_draw_path_preview( GUI_EDITOR_2DVIEW* view ) {
+ switch( editor->tool.type ) {
+ case EDITOR_TOOL_WALL: return gui_editor_2dview_draw_wallpath_preview( view );
+ case EDITOR_TOOL_POLY: return gui_editor_2dview_draw_polypath_preview( view );
+ }
+}
+
void gui_editor_2dview_draw_origin( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
WORLD_MAP* m = editor->map;
@@ -764,6 +801,7 @@ void gui_editor_2dview_draw_fn( void* ptr ) {
gui_editor_2dview_draw_player( view, x + offx, y + offy );
gui_editor_2dview_draw_origin( view, x + offx, y + offy );
gui_editor_2dview_draw_poly_preview( view );
+ gui_editor_2dview_draw_path_preview( view );
gui_editor_2dview_draw_object_preview( view );
gui_draw_pop_clip();
@@ -1362,6 +1400,59 @@ void gui_editor_2dview_input_tool_wall_shape( GUI_EDITOR_2DVIEW* view ) {
}
+void gui_editor_2dview_input_tool_wall_path( GUI_EDITOR_2DVIEW* view ) {
+ U8 m1 = gui_mbutton_down( 0 );
+ if( !m1 ) {
+ view->held = 0;
+ return;
+ }
+
+ if( view->held )
+ return;
+
+ view->held = 1;
+ I32 mx, my;
+ gui_cursor_pos( &mx, &my );
+
+ VEC2 world = gui_editor_2dview_screen_to_world( view, mx, my );
+ F32 depth = gui_editor_2dview_placement_z();
+ VEC3 wp3 = gui_editor_2dview_plane_to_world3( world, depth );
+
+ gui_editor_2dview_snap_plane( &wp3 );
+ if( !view->draw_started ) {
+ view->draw_startpos = wp3;
+ view->draw_lastpos = wp3;
+ view->draw_started = 1;
+ } else {
+ if( wp3 != view->draw_lastpos ) {
+ MAP_WALL neww;
+ neww.start = view->draw_lastpos;
+ neww.end = wp3;
+ neww.end.z = gui_editor_2dview_wall_height();
+ neww.propid = 0;
+
+
+ I32 idx = editor->map->walls.size;
+ editor->map->walls.push( neww );
+ editor_undo_record_create_walls( editor, idx, 1 );
+ gui_editor_2dview_check_bounds_preserve_view( view );
+ gui_editor_propview_update( editor->gui.props );
+ // TODO : creating objects within level
+ // causes a crash due to stale pointer in
+ // editor properties on list reallocation
+ // fixme
+ }
+
+ if( wp3 == view->draw_startpos || wp3 == view->draw_lastpos ) {
+ view->draw_lastpos = view->draw_startpos = {};
+ view->draw_started = 0;
+ return;
+ }
+ }
+
+ view->draw_lastpos = wp3;
+}
+
void gui_editor_2dview_input_tool_wall_line( GUI_EDITOR_2DVIEW* view ) {
U8 m1 = gui_mbutton_down( 0 );
if( !m1 ) {
@@ -1404,6 +1495,7 @@ void gui_editor_2dview_input_tool_wall_line( GUI_EDITOR_2DVIEW* view ) {
view->oldmy = my;
view->mremainx = 0.0;
view->mremainy = 0.0;
+ gui_editor_propview_update( editor->gui.props );
return;
}
@@ -1416,6 +1508,7 @@ void gui_editor_2dview_input_tool_wall_line( GUI_EDITOR_2DVIEW* view ) {
void gui_editor_2dview_input_tool_wall( GUI_EDITOR_2DVIEW* view ) {
switch( editor->tool.wallshape ) {
+ case EDITOR_WALLSHAPE_PATH: return gui_editor_2dview_input_tool_wall_path( view );
case EDITOR_WALLSHAPE_POLYGON: return gui_editor_2dview_input_tool_wall_shape( view );
default: return gui_editor_2dview_input_tool_wall_line( view );
}
@@ -1514,6 +1607,7 @@ void gui_editor_2dview_input_tool_draw( GUI_EDITOR_2DVIEW* view ) {
U8 m2 = !m1 && gui_mbutton_down( 1 );
if( gui_editor_2dview_input_drag( view, m2 ) ) {
+ view->draw_started = 0;
return;
}