summaryrefslogtreecommitdiff
path: root/src/editor
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-02-25 06:07:38 +0100
committeraura <nw@moneybot.cc>2026-02-25 06:07:44 +0100
commit25da8e01a0499c273357cb2feb2825b53e86795b (patch)
tree0888d139edf274a59ab2561a655e8f5d4f0be185 /src/editor
parentd97e17b180257f3425574eb3ba4189d312eb590a (diff)
wip on toolview
Diffstat (limited to 'src/editor')
-rw-r--r--src/editor/editor.h35
-rw-r--r--src/editor/gui.cpp60
-rw-r--r--src/editor/toolview.cpp67
-rw-r--r--src/editor/view2d.cpp8
4 files changed, 120 insertions, 50 deletions
diff --git a/src/editor/editor.h b/src/editor/editor.h
index a4b1f1a..9063f50 100644
--- a/src/editor/editor.h
+++ b/src/editor/editor.h
@@ -26,6 +26,18 @@ enum EditorSelectType_t {
EDITOR_SELECT_SURFPROPS
};
+struct GAME_EDITOR_TOOL {
+ U8 type;
+
+ /* shapes */
+ U8 walls;
+ GL_TEX2D* tex;
+
+ /* entity */
+ U32 entclass;
+ void* entprops;
+};
+
struct GAME_EDITOR {
GAME_DATA* game;
@@ -38,17 +50,16 @@ struct GAME_EDITOR {
struct GUI_EDITOR_2DVIEW* v2d;
struct GUI_EDITOR_3DVIEW* v3d;
- struct GUI_LABEL* toollabel;
-
struct GUI_LABEL* gridlabel;
struct GUI_EDITOR_PROPVIEW* props;
+ struct GUI_EDITOR_TOOLVIEW* tool;
I32 map_select{};
} gui;
U8 wireframe{};
- U8 tool{};
+ GAME_EDITOR_TOOL tool;
F32 grid{};
U8 propgrid{};
F32 spritesize{};
@@ -105,6 +116,10 @@ struct GUI_EDITOR_PROPVIEW : GUI_VIEW {
GUI_VIEW* itemview;
};
+struct GUI_EDITOR_TOOLVIEW : GUI_VIEW {
+ GUI_VIEW* itemview;
+};
+
struct GUI_EDITOR_TEXTUREPICKER : GUI_WINDOW {
struct GL_TEX2D** target;
struct GL_TEX2D* curselect;
@@ -127,13 +142,15 @@ struct GUI_EDITOR_TEXTUREPICKER : GUI_WINDOW {
GUI_CALLBACK cb;
};
-extern GUI_EDITORWINDOW* gui_editorwindow( I32 w, I32 h );
-extern GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h );
-extern GUI_EDITOR_3DVIEW* gui_editor_3dview( I32 x, I32 y, I32 w, I32 h );
-extern GUI_EDITOR_PROPVIEW* gui_editor_propview( I32 x, I32 y, I32 w, I32 h );
+extern GUI_EDITORWINDOW* gui_editorwindow( I32 w, I32 h );
+extern GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h );
+extern GUI_EDITOR_3DVIEW* gui_editor_3dview( I32 x, I32 y, I32 w, I32 h );
+extern GUI_EDITOR_PROPVIEW* gui_editor_propview( I32 x, I32 y, I32 w, I32 h );
+extern void gui_editor_propview_select( GUI_EDITOR_PROPVIEW* e, void* what, U8 seltype );
+extern void gui_editor_propview_update( GUI_EDITOR_PROPVIEW* e );
+extern GUI_EDITOR_TOOLVIEW* gui_editor_toolview( I32 x, I32 y, I32 w, I32 h );
+extern void gui_editor_toolview_update( GUI_EDITOR_TOOLVIEW* view );
extern GUI_EDITOR_TEXTUREPICKER* gui_editor_texturepicker( I32 x, I32 y, I32 w, I32 h, GL_TEX2D** target );
-extern void gui_editor_propview_select( GUI_EDITOR_PROPVIEW* e, void* what, U8 seltype );
-extern void gui_editor_propview_update( GUI_EDITOR_PROPVIEW* e );
extern GAME_EDITOR* editor;
diff --git a/src/editor/gui.cpp b/src/editor/gui.cpp
index 1060c00..39914c8 100644
--- a/src/editor/gui.cpp
+++ b/src/editor/gui.cpp
@@ -49,25 +49,6 @@ GUI_EDITORWINDOW* gui_editorwindow( I32 w, I32 h ) {
return wnd;
}
-void editor_update_active_tool_label( GAME_EDITOR* e ) {
- char lstr[256];
- switch( e->tool ) {
- case EDITOR_TOOL_SELECT:
- sprintf( lstr, "current tool: select" ); break;
- case EDITOR_TOOL_WALL:
- sprintf( lstr, "current tool: wall" ); break;
- case EDITOR_TOOL_POLY:
- sprintf( lstr, "current tool: polygon" ); break;
- case EDITOR_TOOL_SPRITE:
- sprintf( lstr, "current tool: sprite" ); break;
- case EDITOR_TOOL_ENT:
- sprintf( lstr, "current tool: entity" ); break;
- default:
- sprintf( lstr, "current tool: none" ); break;
- }
-
- strcpy( e->gui.toollabel->name, lstr );
-}
void editor_update_properties_column( GAME_EDITOR* e ) {
GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
@@ -83,6 +64,28 @@ void editor_create_properties_column( GAME_EDITOR* e ) {
gui_editor_propview_select( egui->props, e->map, EDITOR_SELECT_ORIGIN );
}
+void editor_update_toolview( GAME_EDITOR* e ) {
+ GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
+ gui_editor_toolview_update( egui->tool );
+}
+
+void settool( U8 t ) { editor->tool.type = t; }
+void editor_create_toolview_column( GAME_EDITOR* e ) {
+ GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
+
+ I32 x = 320, y = 428, off = 23;
+
+ gui_button( x, y, 45, 20, "none", pfn( void* ) { settool( EDITOR_TOOL_NONE ); } ); y += off;
+ gui_button( x, y, 45, 20, "select", pfn( void* ) { settool( EDITOR_TOOL_SELECT ); } ); y += off;
+ gui_button( x, y, 45, 20, "wall", pfn( void* ) { settool( EDITOR_TOOL_WALL ); } ); y += off;
+ gui_button( x, y, 45, 20, "poly", pfn( void* ) { settool( EDITOR_TOOL_POLY ); } ); y += off;
+ gui_button( x, y, 45, 20, "sprite", pfn( void* ) { settool( EDITOR_TOOL_SPRITE ); } ); y += off;
+ gui_button( x, y, 45, 20, "ent", pfn( void* ) { settool( EDITOR_TOOL_ENT ); } ); y += off;
+
+ egui->tool = gui_editor_toolview( 370, 425, 300, 150 );
+ gui_editor_toolview_update( egui->tool );
+}
+
void editor_create_game_view_column( GAME_EDITOR* e ) {
GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
I32 x = 320, y = 10;
@@ -104,23 +107,6 @@ void editor_create_game_view_column( GAME_EDITOR* e ) {
egui->v3d->enabled = 1;
}
-void settool( U8 t ) { editor->tool = t; editor_update_active_tool_label( editor ); }
-void editor_create_tools_row( GAME_EDITOR* e ) {
- I32 x = 10, y = 520;
-
- e->gui.toollabel = gui_label( x, y, "current tool: none" );
- y += 16;
- gui_button( x, y, 80, 20, "none", pfn( void* ) { settool( EDITOR_TOOL_NONE ); } ); x += 90;
- gui_button( x, y, 80, 20, "select", pfn( void* ) { settool( EDITOR_TOOL_SELECT ); } ); x += 90;
- gui_button( x, y, 80, 20, "wall", pfn( void* ) { settool( EDITOR_TOOL_WALL ); } ); x += 90;
-
- x = 10; y += 28;
- gui_button( x, y, 80, 20, "polygon", pfn( void* ) { settool( EDITOR_TOOL_POLY ); } ); x += 90;
- gui_button( x, y, 80, 20, "sprite", pfn( void* ) { settool( EDITOR_TOOL_SPRITE ); } ); x += 90;
- gui_button( x, y, 80, 20, "entity", pfn( void* ) { settool( EDITOR_TOOL_ENT ); } ); x += 90;
- editor_update_active_tool_label( e );
-}
-
void editor_create_map_view( GAME_EDITOR* e ) {
if( !e->map ) {
dlog( "editor_create_map_views() : no map loaded\n" );
@@ -139,8 +125,8 @@ void editor_create_map_view( GAME_EDITOR* e ) {
gui_view( 1, 1, w->w - 2, w->h - 2 );
editor_create_properties_column( e );
+ editor_create_toolview_column( e );
editor_create_game_view_column( e );
- editor_create_tools_row( e );
}
void close_new_map_popup( void* ) {
diff --git a/src/editor/toolview.cpp b/src/editor/toolview.cpp
new file mode 100644
index 0000000..2853c48
--- /dev/null
+++ b/src/editor/toolview.cpp
@@ -0,0 +1,67 @@
+#include "editor.h"
+#include "../util/string.h"
+
+const U32 TOOLVIEW_TITLE_OFFSET = 15;
+
+void gui_editor_toolview_get_title( GUI_EDITOR_TOOLVIEW* view, char* out ) {
+ switch( editor->tool.type ) {
+ case EDITOR_TOOL_ENT: memcpy( out, "tool: entity", 12 ); break;
+ case EDITOR_TOOL_WALL: memcpy( out, "tool: wall", 10 ); break;
+ case EDITOR_TOOL_POLY: memcpy( out, "tool: polygon", 14 ); break;
+ case EDITOR_TOOL_SELECT: memcpy( out, "tool: select", 12 ); break;
+ case EDITOR_TOOL_SPRITE: memcpy( out, "tool: sprite", 12 ); break;
+ default: memcpy( out, "tool: none", 10 ); break;
+ }
+}
+
+void gui_editor_toolview_update( GUI_EDITOR_TOOLVIEW* view ) {
+
+}
+
+void gui_editor_toolview_draw_fn( void* ptr ) {
+ if( !editor->map ) return;
+
+ GUI_EDITOR_TOOLVIEW* view = (GUI_EDITOR_TOOLVIEW*)ptr;
+
+ I32 x = gui_relx( view );
+ I32 y = gui_rely( view );
+ I32 w = view->w;
+ I32 h = view->h;
+
+ STR<64> title{};
+ gui_editor_toolview_get_title( view, title );
+ gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, title );
+ y += TOOLVIEW_TITLE_OFFSET;
+
+ CLR col = gui_is_fg_window( view )? ui_clr.border : ui_clr.border_inactive;
+ gui_draw_frect( x, y, w, h, col );
+ gui_draw_frect( x+1, y+1, w-2, h-2, ui_clr.bg_sec );
+
+ view->itemview->draw_fn( view->itemview );
+}
+
+GUI_EDITOR_TOOLVIEW* gui_editor_toolview( I32 x, I32 y, I32 w, I32 h ) {
+ if( !gui_check_target() ) return 0;
+
+ GUI_EDITOR_TOOLVIEW* view = new GUI_EDITOR_TOOLVIEW;
+ view->x = x;
+ view->y = y;
+ view->w = w;
+ view->h = h;
+ view->xbound = view->w;
+ view->ybound = view->h + TOOLVIEW_TITLE_OFFSET;
+ strcpy( view->name, "EDITOR_PROP_VIEW" );
+ view->draw_fn = gui_editor_toolview_draw_fn;
+ view->input_fn = gui_base_input_fn;
+
+ GUI_VIEW* parent = gui_get_view();
+ parent->children.push( view );
+ view->parent = parent;
+
+ gui_set_view( view );
+ view->itemview = gui_view( 0, TOOLVIEW_TITLE_OFFSET, w, h );
+
+ gui_set_view( parent );
+
+ return view;
+}
diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp
index faff736..ee7e4d7 100644
--- a/src/editor/view2d.cpp
+++ b/src/editor/view2d.cpp
@@ -178,7 +178,7 @@ void gui_editor_2dview_draw_polygons( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
}
}
- if( editor->tool != EDITOR_TOOL_POLY && editor->tool != EDITOR_TOOL_SELECT )
+ if( editor->tool.type != EDITOR_TOOL_POLY && editor->tool.type != EDITOR_TOOL_SELECT )
return;
// draw gizmos
p->vertices.each( fn( MAP_VERTEX* v ) {
@@ -216,7 +216,7 @@ void gui_editor_2dview_draw_walls( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) {
}
} );
- if( editor->tool != EDITOR_TOOL_WALL && editor->tool != EDITOR_TOOL_SELECT )
+ if( editor->tool.type != EDITOR_TOOL_WALL && editor->tool.type != EDITOR_TOOL_SELECT )
return;
// gizmos
@@ -892,7 +892,7 @@ void gui_editor_2dview_input_tool_draw( GUI_EDITOR_2DVIEW* view ) {
return;
}
- switch( editor->tool ) {
+ switch( editor->tool.type ) {
case EDITOR_TOOL_WALL: return gui_editor_2dview_input_tool_wall( view );
case EDITOR_TOOL_POLY: return gui_editor_2dview_input_tool_poly( view );
case EDITOR_TOOL_ENT: return gui_editor_2dview_input_tool_ent( view );
@@ -1011,7 +1011,7 @@ void gui_editor_2dview_input_fn( void* ptr ) {
if( my >= y + h - 18 )
return;
- switch( editor->tool ) {
+ switch( editor->tool.type ) {
case EDITOR_TOOL_SELECT: return gui_editor_2dview_input_tool_select( view );
case EDITOR_TOOL_WALL:
case EDITOR_TOOL_POLY: