summaryrefslogtreecommitdiff
path: root/src/editor
diff options
context:
space:
mode:
authornavewindre <boneyaard@gmail.com>2025-11-28 14:41:22 +0100
committerGitHub <noreply@github.com>2025-11-28 14:41:22 +0100
commit9c05c795d7b59c5ab94fb769f315c712b37df0cd (patch)
tree16cccf8cbb88703de798066a06f94013f89a8a5a /src/editor
parentf8b92ce3aa08b1445c9f956d8166830946562d12 (diff)
parent3e094f20d4dda90e0356aba3f0abc4b7c7015844 (diff)
Merge pull request #1 from navewindre/windows-compat
Windows compat
Diffstat (limited to 'src/editor')
-rw-r--r--src/editor/editor.h6
-rw-r--r--src/editor/gui.cpp52
-rw-r--r--src/editor/view2d.cpp144
-rw-r--r--src/editor/view3d.cpp56
4 files changed, 202 insertions, 56 deletions
diff --git a/src/editor/editor.h b/src/editor/editor.h
index 0bf2ab4..a4b1f1a 100644
--- a/src/editor/editor.h
+++ b/src/editor/editor.h
@@ -70,9 +70,13 @@ extern void editor_load_map_cb( void* );
extern void editor_new_map_cb( void* );
extern void editor_create_map_view( GAME_EDITOR* e );
+extern void editor_update_properties_column( GAME_EDITOR* e );
struct GUI_EDITORWINDOW : GUI_WINDOW {};
-struct GUI_EDITOR_3DVIEW : GUI_VIEW {};
+struct GUI_EDITOR_3DVIEW : GUI_VIEW {
+ U8 heldoutbounds;
+};
+
struct GUI_EDITOR_2DVIEW : GUI_VIEW {
F32 scale;
F32 posx, posy;
diff --git a/src/editor/gui.cpp b/src/editor/gui.cpp
index 71ce113..1060c00 100644
--- a/src/editor/gui.cpp
+++ b/src/editor/gui.cpp
@@ -121,57 +121,6 @@ void editor_create_tools_row( GAME_EDITOR* e ) {
editor_update_active_tool_label( e );
}
-void editor_update_view_settings( GAME_EDITOR* e ) {
- GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
-
- sprintf( egui->gridlabel->name, "grid size: %1.2f", e->grid );
-}
-
-void editor_grid_increment_cb( void* ) {
- if( editor->grid < 16.f ) editor->grid *= 2.f;
- editor_update_view_settings( editor );
-
- if( editor->propgrid )
- editor_update_properties_column( editor );
-}
-
-void editor_grid_decrement_cb( void* ) {
- if( editor->grid > 0.25f ) editor->grid *= 0.5f;
- editor_update_view_settings( editor );
-
- if( editor->propgrid )
- editor_update_properties_column( editor );
-}
-
-void editor_grid_propgrid_cb( void* ) {
- editor_update_properties_column( editor );
-}
-
-void editor_create_view_settings_row( GAME_EDITOR* e ) {
- I32 x = 320, y = 426;
-
- gui_label( x, y, "view settings:" ); x += 95;
- editor->gui.gridlabel = gui_label( x, y, "grid size: %1.2f", e->grid );
- x += 95;
- gui_button( x, y, 20, 20, "+", editor_grid_increment_cb );
- gui_button( x + 25, y, 20, 20, "-", editor_grid_decrement_cb );
- x += 55;
- GUI_CHECKBOX* check = gui_checkbox( x, y, "properties grid", &e->propgrid );
- check->cb = editor_grid_propgrid_cb;
- x += 120;
- gui_checkbox( x, y, "wireframe", &e->wireframe );
-
- x = 320;
- y = 440;
- gui_button( x, y, 100, 20, "compile bsp", pfn( void* b ) {
- if( editor->map->bsp )
- bsp_free( editor->map->bsp );
- editor->map->bsp = bsp_build_map( editor->map );
- } ); x += 110;
-
- gui_checkbox( x, y, "draw bsp", &e->drawbsp );
-}
-
void editor_create_map_view( GAME_EDITOR* e ) {
if( !e->map ) {
dlog( "editor_create_map_views() : no map loaded\n" );
@@ -192,7 +141,6 @@ void editor_create_map_view( GAME_EDITOR* e ) {
editor_create_properties_column( e );
editor_create_game_view_column( e );
editor_create_tools_row( e );
- editor_create_view_settings_row( e );
}
void close_new_map_popup( void* ) {
diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp
index 35fd208..1445cfc 100644
--- a/src/editor/view2d.cpp
+++ b/src/editor/view2d.cpp
@@ -1,12 +1,13 @@
#include <math.h>
#include "editor.h"
#include "../render/gl_2d.h"
-
#include "../game/objlist.h"
+#include "../game/world/bsp.h"
const I32 EDITORVIEW_TITLE_OFFSET = 15;
const I32 EDITORVIEW_GUTTERS_OFFSETX = 22;
const I32 EDITORVIEW_GUTTERS_OFFSETY = 16;
+const I32 EDITORVIEW_TOOLBAR_OFFSET = 20;
F32 gui_editor_2dview_calc_scale( GUI_EDITOR_2DVIEW* view ) {
WORLD_MAP* m = editor->map;
@@ -337,13 +338,23 @@ void gui_editor_2dview_draw_fn( void* ptr ) {
U32 offx = EDITORVIEW_GUTTERS_OFFSETX;
U32 offy = EDITORVIEW_GUTTERS_OFFSETY;
- gui_draw_push_clip( x + offx, y + offy, w - offx, h - offy );
+ gui_draw_push_clip( x + offx, y + offy, w - offx, h - offy - EDITORVIEW_TOOLBAR_OFFSET );
gui_editor_2dview_draw_polygons( view, x + offx, y + offy );
gui_editor_2dview_draw_walls( view, x + offx, y + offy );
gui_editor_2dview_draw_sprites( view, x + offx, y + offy );
gui_editor_2dview_draw_player( view, x + offx, y + offy );
gui_editor_2dview_draw_origin( view, x + offx, y + offy );
gui_draw_pop_clip();
+
+ gui_draw_push_clip( x, y + 16, view->w, view->h );
+ view->children.each( fn( GUI_BASE** childptr ) {
+ GUI_BASE* child = *childptr;
+ if( !child->enabled ) return;
+
+ if( child->draw_fn ) child->draw_fn( child );
+ else dlog( "gui_view_draw_fn(): child %p no draw_fn\n", child );
+ } );
+ gui_draw_pop_clip();
}
U8 gui_editor_2dview_input_drag( GUI_EDITOR_2DVIEW* view, U8 mouse ) {
@@ -876,11 +887,91 @@ void gui_editor_2dview_input_tool_draw( GUI_EDITOR_2DVIEW* view ) {
}
}
+void gui_editor_view2d_delete_obj( GUI_EDITOR_2DVIEW* view ) {
+ void* it;
+ U8 type;
+
+ if( view->curdrag && view->dragtype ) {
+ it = view->curdrag;
+ type = view->dragtype;
+ view->curdrag = 0;
+ view->dragtype = EDITOR_SELECT_NONE;
+ } else if( editor->gui.props->curselect ) {
+ it = editor->gui.props->curselect;
+ type = editor->gui.props->seltype;
+ view->curselect = 0;
+ view->seltype = EDITOR_SELECT_NONE;
+ }
+ else return;
+
+ U8 cleared = 1;
+ switch( type ) {
+ case EDITOR_SELECT_POLY: {
+ I32 idx = editor->map->polygons.idx_of( (MAP_POLYGON*)it );
+ if( idx != -1 )
+ editor->map->polygons.erase( idx );
+ } break;
+ case EDITOR_SELECT_WALL: {
+ I32 idx = editor->map->walls.idx_of( (MAP_WALL*)it );
+ if( idx != -1 )
+ editor->map->walls.erase( idx );
+ }; break;
+ case EDITOR_SELECT_SPRITE: {
+ I32 idx = editor->map->sprites.idx_of( (MAP_SPRITE*)it );
+ if( idx != -1 )
+ editor->map->sprites.erase( idx );
+ }; break;
+ case EDITOR_SELECT_PVERTEX: {
+ I32 vidx = -1, idx = editor->map->polygons.idx_where( fn( MAP_POLYGON* p ) {
+ vidx = p->vertices.idx_where( fn( MAP_VERTEX* v ) {
+ return v == it;
+ } );
+ return vidx != -1;
+ } );
+
+ if( idx != -1 && vidx != -1 ) {
+ MAP_POLYGON* p = &editor->map->polygons[idx];
+ if( p->vertices.size <= 3 ) {
+ editor->map->polygons.erase( idx );
+ break;
+ }
+ editor->map->polygons[idx].vertices.erase( vidx );
+ }
+ }; break;
+ case EDITOR_SELECT_WVERTEX: {
+ I32 idx = editor->map->walls.idx_where( fn( MAP_WALL* w ) {
+ return &w->end == it || &w->start == it;
+ } );
+
+ if( idx != -1 )
+ editor->map->walls.erase( idx );
+ }; break;
+ default:
+ cleared = 0; break;
+ }
+
+ if( cleared && it == editor->gui.props->curselect ) {
+ gui_editor_propview_select( editor->gui.props, 0, 0 );
+ }
+}
+
+void gui_editor_2dview_key_input( GUI_EDITOR_2DVIEW* view ) {
+ static U8 del_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;
+}
+
void gui_editor_2dview_input_fn( void* ptr ) {
GUI_EDITOR_2DVIEW* view = (GUI_EDITOR_2DVIEW*)ptr;
if( !editor->map )
return;
+ gui_editor_2dview_key_input( view );
+
I32 x = gui_relx( view );
I32 y = gui_rely( view ) + EDITORVIEW_TITLE_OFFSET;
I32 w = view->w;
@@ -902,6 +993,10 @@ void gui_editor_2dview_input_fn( void* ptr ) {
if( view->heldoutbounds )
return;
+ gui_base_input_fn( view );
+ if( my >= y + h - 18 )
+ return;
+
switch( editor->tool ) {
case EDITOR_TOOL_SELECT: return gui_editor_2dview_input_tool_select( view );
case EDITOR_TOOL_WALL:
@@ -913,6 +1008,47 @@ void gui_editor_2dview_input_fn( void* ptr ) {
}
}
+void update_view_settings( GAME_EDITOR* e ) {
+ GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
+
+ sprintf( egui->gridlabel->name, "grid: %1.2f", e->grid );
+}
+
+void grid_increment_cb( void* ) {
+ if( editor->grid < 16.f ) editor->grid *= 2.f;
+ update_view_settings( editor );
+
+ if( editor->propgrid )
+ editor_update_properties_column( editor );
+}
+
+void grid_decrement_cb( void* ) {
+ if( editor->grid > 0.25f ) editor->grid *= 0.5f;
+ update_view_settings( editor );
+
+ if( editor->propgrid )
+ editor_update_properties_column( editor );
+}
+
+void grid_propgrid_cb( void* ) {
+ editor_update_properties_column( editor );
+}
+
+void gui_editor_2dview_create_toolbar( GUI_EDITOR_2DVIEW* view ) {
+ GAME_EDITOR* e = editor;
+ I32 x = 150, y = view->h - 4;
+
+ editor->gui.gridlabel = gui_label( x, y + 1, "grid: %1.2f", e->grid );
+ x += 70;
+ gui_button( x, y, 18, 18, "+", grid_increment_cb );
+ gui_button( x + 23, y, 18, 18, "-", grid_decrement_cb );
+ x += 50;
+ GUI_CHECKBOX* check = gui_checkbox( x, y, "properties grid", &e->propgrid );
+ check->cb = grid_propgrid_cb;
+ x += 120;
+ gui_checkbox( x, y, "wireframe", &e->wireframe );
+}
+
GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h ) {
GUI_EDITOR_2DVIEW* view = new GUI_EDITOR_2DVIEW;
view->x = x;
@@ -934,5 +1070,9 @@ GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h ) {
parent->children.push( view );
view->parent = parent;
+ gui_set_view( view );
+ gui_editor_2dview_create_toolbar( view );
+ gui_set_view( (GUI_VIEW*)parent );
+
return view;
}
diff --git a/src/editor/view3d.cpp b/src/editor/view3d.cpp
index f9bd60e..f8d1def 100644
--- a/src/editor/view3d.cpp
+++ b/src/editor/view3d.cpp
@@ -6,6 +6,7 @@
#include "../game.h"
const I32 EDITORVIEW_TITLE_OFFSET = 15;
+const I32 EDITORVIEW_TOOLBAR_OFFSET = 20;
void gui_editor_3dview_draw_showpos( GUI_EDITOR_3DVIEW* view ) {
I32 x = gui_relx( view );
@@ -31,6 +32,16 @@ void gui_editor_3dview_draw_showpos( GUI_EDITOR_3DVIEW* view ) {
objl->pl->rot.y,
objl->pl->rot.x
);
+
+ if( input.mouselock ) {
+ gui_draw_str(
+ x + 2, y + 2,
+ ALIGN_L,
+ FNT_JPN12,
+ ui_clr.txt,
+ "[capturing mouse]"
+ );
+ }
}
void gui_editor_3dview_draw_fn( void* ptr ) {
@@ -55,17 +66,55 @@ void gui_editor_3dview_draw_fn( void* ptr ) {
bsp_draw( editor->map->bsp, editor->game, wnd, winsize );
else
world_draw( editor->game, objl->world, wnd, winsize );
-
+
+ gui_draw_push_clip( x, y, view->w, view->h );
+ view->children.each( fn( GUI_BASE** childptr ) {
+ GUI_BASE* child = *childptr;
+ if( !child->enabled ) return;
+
+ if( child->draw_fn ) child->draw_fn( child );
+ else dlog( "gui_view_draw_fn(): child %p no draw_fn\n", child );
+ } );
+ gui_draw_pop_clip();
gui_editor_3dview_draw_showpos( view );
}
void gui_editor_3dview_input_fn( void* ptr ) {
+ GUI_EDITOR_3DVIEW* view = (GUI_EDITOR_3DVIEW*)ptr;
+ if( !input.mouselock )
+ gui_base_input_fn( view );
+
if( !objl->pl )
return;
+ if( input.mouse.left ) {
+ I32 view_x = gui_relx( view );
+ I32 view_y = gui_rely( view ) + EDITORVIEW_TITLE_OFFSET;
+ if( input.mouse.pos.x >= view_x && input.mouse.pos.x < view_x + view->w &&
+ input.mouse.pos.y >= view_y && input.mouse.pos.y < view_y + view->h - EDITORVIEW_TOOLBAR_OFFSET ) {
+ if( !input.mouselock && !view->heldoutbounds )
+ input_capture_mouse( true );
+ } else {
+ view->heldoutbounds = 1;
+ }
+ } else view->heldoutbounds = 0;
+
game_on_tick( editor->game );
}
+void gui_editor_3dview_create_toolbar( GUI_EDITOR_3DVIEW* view ) {
+ GAME_EDITOR* e = editor;
+ I32 x = 1, y = view->h - 4;
+
+ gui_button( x, y, 90, 18, "compile bsp", pfn( void* b ) {
+ if( editor->map->bsp )
+ bsp_free( editor->map->bsp );
+ editor->map->bsp = bsp_build_map( editor->map );
+ } ); x += 100;
+
+ gui_checkbox( x, y, "draw bsp", &e->drawbsp );
+}
+
GUI_EDITOR_3DVIEW* gui_editor_3dview( I32 x, I32 y, I32 w, I32 h ) {
GUI_EDITOR_3DVIEW* view = new GUI_EDITOR_3DVIEW;
view->x = x;
@@ -84,5 +133,10 @@ GUI_EDITOR_3DVIEW* gui_editor_3dview( I32 x, I32 y, I32 w, I32 h ) {
parent->children.push( view );
view->parent = parent;
+
+ gui_set_view( view );
+ gui_editor_3dview_create_toolbar( view );
+ gui_set_view( (GUI_VIEW*)parent );
+
return view;
}