summaryrefslogtreecommitdiff
path: root/src/editor
diff options
context:
space:
mode:
Diffstat (limited to 'src/editor')
-rw-r--r--src/editor/editor.h16
-rw-r--r--src/editor/editor_contextmenu.cpp35
-rw-r--r--src/editor/editor_menubar.cpp22
-rw-r--r--src/editor/properties.cpp79
-rw-r--r--src/editor/properties.h75
5 files changed, 165 insertions, 62 deletions
diff --git a/src/editor/editor.h b/src/editor/editor.h
index 828f2e4..33396df 100644
--- a/src/editor/editor.h
+++ b/src/editor/editor.h
@@ -66,7 +66,7 @@ enum EditorObjectType_t {
typedef void( *EDITOR_CONTEXTMENU_CALLBACK )( void* data );
struct EDITOR_CONTEXTMENU_ITEM;
-typedef U8( *EDITOR_CONTEXTMENU_ENABLED_CALLBACK )( const EDITOR_CONTEXTMENU_ITEM* item );
+typedef U8( *EDITOR_CONTEXTMENU_ENABLED_CALLBACK )( EDITOR_CONTEXTMENU_ITEM* item );
struct EDITOR_CONTEXTMENU_ITEM {
char text[64]{};
@@ -209,9 +209,6 @@ extern void editor_create_map_view( GAME_EDITOR* e );
extern void editor_update_properties_column( GAME_EDITOR* e );
extern const char* editor_tool_name();
extern void editor_set_view_mode( I32 mode );
-extern void editor_show_contextmenu( I32 x, I32 y, LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title = 0 );
-extern void editor_hide_contextmenu();
-extern U8 editor_contextmenu_open();
extern void editor_undo_clear( GAME_EDITOR* e );
extern void editor_undo_record_create_walls( GAME_EDITOR* e, I32 start_idx, I32 count );
extern void editor_undo_record_create_poly( GAME_EDITOR* e, I32 start_idx );
@@ -220,6 +217,17 @@ extern void editor_undo_record_create_entity( GAME_EDITOR* e, I32 start_idx );
extern U8 editor_undo( GAME_EDITOR* e );
extern U8 editor_redo( GAME_EDITOR* e );
+extern void editor_show_contextmenu( I32 x, I32 y, LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title = 0 );
+extern void editor_hide_contextmenu();
+extern U8 editor_contextmenu_open();
+extern void editor_contextmenu_set_item(
+ EDITOR_CONTEXTMENU_ITEM* item,
+ const char* text,
+ EDITOR_CONTEXTMENU_CALLBACK cb = 0,
+ void* data = 0,
+ EDITOR_CONTEXTMENU_ENABLED_CALLBACK enabled_cb = 0
+);
+
struct GUI_EDITORWINDOW : GUI_WINDOW {};
struct GUI_EDITOR_3DVIEW : GUI_VIEW {
U8 heldoutbounds;
diff --git a/src/editor/editor_contextmenu.cpp b/src/editor/editor_contextmenu.cpp
index 2b0bb1f..4f9dbe6 100644
--- a/src/editor/editor_contextmenu.cpp
+++ b/src/editor/editor_contextmenu.cpp
@@ -1,6 +1,6 @@
#include "editor_gui_internal.h"
-static U8 editor_contextmenu_item_enabled( const EDITOR_CONTEXTMENU_ITEM* item ) {
+U8 editor_contextmenu_item_enabled( EDITOR_CONTEXTMENU_ITEM* item ) {
if( !item )
return 0;
@@ -10,15 +10,15 @@ static U8 editor_contextmenu_item_enabled( const EDITOR_CONTEXTMENU_ITEM* item )
return item->enabled;
}
-static I32 editor_contextmenu_title_h( const GUI_EDITOR_CONTEXTMENU* menu ) {
+I32 editor_contextmenu_title_h( GUI_EDITOR_CONTEXTMENU* menu ) {
return ( menu && menu->title[0] ) ? 18 : 0;
}
-static I32 editor_contextmenu_row_h() {
+I32 editor_contextmenu_row_h() {
return 20;
}
-static I32 editor_contextmenu_width( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) {
+I32 editor_contextmenu_width( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) {
I32 width = EDITOR_TOOLBAR_DROPDOWN_W;
if( title && title[0] ) {
I32 text_w = 0;
@@ -38,7 +38,7 @@ static I32 editor_contextmenu_width( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const
return width;
}
-static I32 editor_contextmenu_height( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) {
+I32 editor_contextmenu_height( LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) {
I32 height = 4 + editor_contextmenu_row_h() * ( items ? (I32)items->size : 0 );
if( title && title[0] )
height += 18 + 1;
@@ -52,7 +52,7 @@ static I32 editor_contextmenu_items_y( GUI_EDITOR_CONTEXTMENU* menu ) {
return y;
}
-static I32 editor_contextmenu_hit_test( GUI_EDITOR_CONTEXTMENU* menu, I32 mx, I32 my ) {
+I32 editor_contextmenu_hit_test( GUI_EDITOR_CONTEXTMENU* menu, I32 mx, I32 my ) {
if( !menu || !menu->items )
return -1;
@@ -72,7 +72,7 @@ static I32 editor_contextmenu_hit_test( GUI_EDITOR_CONTEXTMENU* menu, I32 mx, I3
return idx;
}
-static void gui_editor_contextmenu_draw_fn( void* ptr ) {
+void gui_editor_contextmenu_draw_fn( void* ptr ) {
GUI_EDITOR_CONTEXTMENU* menu = (GUI_EDITOR_CONTEXTMENU*)ptr;
if( !menu || !menu->items || !menu->items->size )
return;
@@ -128,7 +128,7 @@ static void gui_editor_contextmenu_draw_fn( void* ptr ) {
}
}
-static void gui_editor_contextmenu_input_fn( void* ptr ) {
+void gui_editor_contextmenu_input_fn( void* ptr ) {
GUI_EDITOR_CONTEXTMENU* menu = (GUI_EDITOR_CONTEXTMENU*)ptr;
if( !menu || !menu->items || !menu->items->size )
return;
@@ -199,6 +199,25 @@ U8 editor_contextmenu_open() {
return editor && editor->gui.contextmenu && editor->gui.contextmenu->enabled;
}
+
+void editor_contextmenu_set_item(
+ EDITOR_CONTEXTMENU_ITEM* item,
+ const char* text,
+ EDITOR_CONTEXTMENU_CALLBACK cb,
+ void* data,
+ EDITOR_CONTEXTMENU_ENABLED_CALLBACK enabled_cb
+) {
+ if( !item )
+ return;
+
+ item->items.clear();
+ snprintf( item->text, sizeof( item->text ), "%s", text ? text : "" );
+ item->cb = cb;
+ item->data = data;
+ item->enabled = 1;
+ item->enabled_cb = enabled_cb;
+}
+
void editor_show_contextmenu( I32 x, I32 y, LIST<EDITOR_CONTEXTMENU_ITEM>* items, const char* title ) {
editor_hide_contextmenu();
if( !editor || !editor->wnd || !items || !items->size )
diff --git a/src/editor/editor_menubar.cpp b/src/editor/editor_menubar.cpp
index cfb12a3..cef2650 100644
--- a/src/editor/editor_menubar.cpp
+++ b/src/editor/editor_menubar.cpp
@@ -66,24 +66,6 @@ void editor_raise_header_toolbar( GAME_EDITOR* e ) {
parent->children.push( bar );
}
-void editor_contextmenu_set_item(
- EDITOR_CONTEXTMENU_ITEM* item,
- const char* text,
- EDITOR_CONTEXTMENU_CALLBACK cb = 0,
- void* data = 0,
- EDITOR_CONTEXTMENU_ENABLED_CALLBACK enabled_cb = 0
-) {
- if( !item )
- return;
-
- item->items.clear();
- snprintf( item->text, sizeof( item->text ), "%s", text ? text : "" );
- item->cb = cb;
- item->data = data;
- item->enabled = 1;
- item->enabled_cb = enabled_cb;
-}
-
void editor_contextmenu_save_cb( void* ) {
if( editor )
editor_save_map( editor );
@@ -107,11 +89,11 @@ void editor_contextmenu_set_tool_cb( void* data ) {
editor_settool( (U8)(I64)data );
}
-U8 editor_contextmenu_undo_enabled( const EDITOR_CONTEXTMENU_ITEM* ) {
+U8 editor_contextmenu_undo_enabled( EDITOR_CONTEXTMENU_ITEM* ) {
return editor && editor->undo_actions.size > 0;
}
-U8 editor_contextmenu_redo_enabled( const EDITOR_CONTEXTMENU_ITEM* ) {
+U8 editor_contextmenu_redo_enabled( EDITOR_CONTEXTMENU_ITEM* ) {
return editor && editor->redo_actions.size > 0;
}
diff --git a/src/editor/properties.cpp b/src/editor/properties.cpp
index f3e9473..e97ac72 100644
--- a/src/editor/properties.cpp
+++ b/src/editor/properties.cpp
@@ -1,3 +1,4 @@
+#include "properties.h"
#include "editor.h"
#include "../render/gl.h"
#include "../game/assets.h"
@@ -66,6 +67,63 @@ void gui_editor_propview_select( GUI_EDITOR_PROPVIEW* view, void* what, U8 selty
gui_editor_propview_update( view );
}
+
+void gui_editor_propview_create_eobj_prop( GUI_EDITOR_PROPVIEW* view, EDITOR_PROP* prop, I32* x, I32* y, I32 space ) {
+ F32 step = editor->propgrid ? editor->grid : 0.25f;
+ F32 w = propview_input_width( view );
+ F32 action_x = propview_action_x( view );
+ const char* n = prop->displayname;
+ F32 min = prop->min;
+ F32 max = prop->max;
+
+ switch( prop->type ) {
+ case EPROP_F32: gui_floatinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), min, max, step ); *y += (space+18); break;
+ case EPROP_VEC2: gui_vectorinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), 2, min, max, step, "xy", "%.03f" ); *y += (space+18); break;
+ case EPROP_VEC3: gui_vectorinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), 3, min, max, step, "xyz", "%.03f" ); *y += (space+18); break;
+ case EPROP_VEC4: gui_vectorinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), 3, min, max, step, "xyzw", "%0.03f" ); *y += (space+18); break;
+ case EPROP_CLR: gui_colorinput( *x, *y, w, n, (CLR*)eprop_ptr( prop ) );
+ case EPROP_MAPPROP: {
+ MAP_PROPREF* ref = (MAP_PROPREF*)eprop_ptr( prop );
+ SURF_PROPS* props = map_get_props( editor->map, ref->id );
+ gui_label( *x, *y, n );
+ GUI_BUTTON* btn = gui_button( action_x, *y, 20, 20, "\x1A", pfn( void* ptr ) {
+ GUI_BUTTON* btn = (GUI_BUTTON*)ptr;
+ gui_editor_propview_select( editor->gui.props, btn->extra, EDITOR_SELECT_SURFPROPS );
+ } ); btn->extra = props;
+ *y += space;
+ } break;
+ case EPROP_TEXTURE: {
+ GL_TEX2D** tex = (GL_TEX2D**)eprop_ptr( prop );
+ if( *tex ) gui_label( *x, *y, "%s: %s", n, (*tex)->name );
+ else gui_label( *x, *y, "%s: none", n );
+ GUI_BUTTON* btn = gui_button( action_x, *y, 20, 20, "\x1A", pfn( void* ptr ) {
+ GUI_BUTTON* btn = (GUI_BUTTON*)ptr;
+ GL_TEX2D** ptex = (GL_TEX2D**)btn->extra;
+ GUI_EDITOR_TEXTUREPICKER* picker = gui_editor_texturepicker( 200, 100, 400, 400, ptex );
+ picker->cb = pfn( void* ) { gui_editor_propview_update( editor->gui.props ); };
+ } ); btn->extra = tex;
+ } break;
+ }
+}
+
+void gui_editor_propview_create_eobj_prop_ro( GUI_EDITOR_PROPVIEW* view, EDITOR_PROP* prop, I32* x, I32* y, I32 space ) {
+
+}
+
+void gui_editor_propview_create_eobj_props( GUI_EDITOR_PROPVIEW* view, I32* x, I32* y ) {
+ MAP_SPRITE* e = (MAP_SPRITE*)view->curselect;
+ I32 space = 20;
+
+ for( auto& it : e->eprops ) {
+ EDITOR_PROP* eprop = eprop_from_ref( e, it );
+ if( eprop->readonly )
+ gui_editor_propview_create_eobj_prop_ro( view, eprop, x, y, space );
+ else
+ gui_editor_propview_create_eobj_prop( view, eprop, x, y, space );
+ }
+}
+
+
// returns the subentry height
I32 gui_editor_propview_surfprops_subentry(
GUI_EDITOR_PROPVIEW* view,
@@ -258,6 +316,7 @@ void gui_editor_propview_create_pvertexprops( GUI_EDITOR_PROPVIEW* view ) {
gui_colorinput( x, y, propview_input_width( view ), "color", &v->clr ); y += (space+18);
}
+
void gui_editor_propview_create_spriteprops( GUI_EDITOR_PROPVIEW* view ) {
MAP_SPRITE* s = (MAP_SPRITE*)view->curselect;
WORLD_MAP* m = editor->map;
@@ -268,27 +327,9 @@ void gui_editor_propview_create_spriteprops( GUI_EDITOR_PROPVIEW* view ) {
I32 sprite_idx = m->sprites.idx_where( fn( MAP_SPRITE* ms ) {
return ms == s;
} );
- I32 action_x = propview_action_x( view );
-
- F32 step = editor->propgrid? editor->grid : 0.25f;
gui_label( x, y, "idx: %d", sprite_idx ); y += space;
- gui_vectorinput( x, y, propview_input_width( view ), "position", (F32*)&s->pos, 3, -INFINITY, INFINITY, step ); y += (space+18);
- gui_vectorinput( x, y, propview_input_width( view ), "size", (F32*)&s->size, 2, 1.f, INFINITY, 1.f, "wh" ); y += (space+18);
- gui_colorinput( x, y, propview_input_width( view ), "color", &s->clr ); y += (space+18);
- if( s->tex )
- gui_label( x, y, "texture: %s", s->tex->name );
- else
- gui_label( x, y, "texture: none" );
-
- GUI_BUTTON* btn = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) {
- GUI_BUTTON* btn = (GUI_BUTTON*)ptr;
- GL_TEX2D** ptex = (GL_TEX2D**)btn->extra;
- GUI_EDITOR_TEXTUREPICKER* picker = gui_editor_texturepicker( 200, 100, 400, 400, ptex );
- picker->cb = pfn( void* ) { gui_editor_propview_update( editor->gui.props ); };
- } );
- btn->extra = &s->tex;
- y += space;
+ return gui_editor_propview_create_eobj_props( view, &x, &y );
}
void gui_editor_propview_create_surfprops( GUI_EDITOR_PROPVIEW* view ) {
diff --git a/src/editor/properties.h b/src/editor/properties.h
index 01edbbf..1eb51f8 100644
--- a/src/editor/properties.h
+++ b/src/editor/properties.h
@@ -8,17 +8,22 @@
#define EPROP( _type, name, value, display ) \
_type name = value; \
- EDITOR_PROP name##_prop{ .pdata = &name, .type = eprop_type<_type>(), .displayname = display, .parent = this };
+ EDITOR_PROP name##_prop{ &name, eprop_type<_type>(), display, this, 0 };
+
+#define EPROP_RO( _type, name, value, display ) \
+ _type name = value; \
+ EDITOR_PROP name##_prop{ .pdata = &name, .type = eprop_type<_type>(), .displayname = display, .parent = this, .readonly = 1 };
#define EPROP_RANGED( _type, name, value, display, _min, _max ) \
_type name{ value }; \
EDITOR_PROP{ \
- .pdata = &name, \
- .type = eprop_type<_type>(), \
- .displayname = display, \
- .parent = this, \
- .min = _min, \
- .max = _max \
+ &name, \
+ eprop_type<_type>(), \
+ display, \
+ this, \
+ _min, \
+ _max, \
+ 0 \
}
enum EditorPropType_t {
@@ -45,9 +50,13 @@ enum EditorPropType_t {
EPROP_TEXTURE_LIST,
};
+struct EPROP_ENTRY {
+ U64 offset;
+};
+
// editor map object
struct EOBJECT {
- LIST<struct EDITOR_PROP*> eprops{};
+ LIST<EPROP_ENTRY> eprops{};
};
template <typename T>
@@ -55,13 +64,49 @@ concept __eobject_base = __is_base_of(EOBJECT, T);
// editor object property
struct EDITOR_PROP {
- void* pdata;
+ EDITOR_PROP( void* _pdata, U8 _type, STR _displayname, struct EOBJECT* _parent, U8 _readonly = 0 ) {
+ type = _type;
+ displayname = _displayname;
+ min = -INFINITY;
+ max = INFINITY;
+ readonly = _readonly;
+
+ U64 _this = (U64)this;
+ U64 pdata = (U64)_pdata;
+ U64 parent = (U64)_parent;
+ U64 offset = _this - parent;
+
+ _parent->eprops.push( { offset } );
+
+ offset = _this - pdata;
+ dataoff = offset;
+ }
+
+
+ EDITOR_PROP( void* _pdata, U8 _type, STR _displayname, struct EOBJECT* _parent, F32 _min, F32 _max, U8 _readonly = 0 ) {
+ type = _type;
+ displayname = _displayname;
+ min = _min;
+ max = _max;
+ readonly = _readonly;
+
+ U64 _this = (U64)this;
+ U64 pdata = (U64)_pdata;
+ U64 parent = (U64)_parent;
+ U64 offset = _this - parent;
+
+ _parent->eprops.push( { offset } );
+
+ offset = _this - pdata;
+ dataoff = offset;
+ }
+
+ U64 dataoff;
U8 type;
STR displayname;
F64 min{ -INFINITY };
F64 max{ INFINITY };
- struct EOBJECT* parent;
-
+ U8 readonly;
template <typename T> struct __eprop_type {
static const U8 type = EPROP_INVALID;
@@ -88,6 +133,14 @@ struct EDITOR_PROP {
template <> struct __eprop_type<LIST<struct MAP_TEXTURE_ENTRY*>> { static const U8 type = EPROP_TEXTURE_LIST; };
};
+inline EDITOR_PROP* eprop_from_ref( EOBJECT* obj, EPROP_ENTRY e ) {
+ return (EDITOR_PROP*)( (U64)obj + e.offset );
+}
+
+inline void* eprop_ptr( EDITOR_PROP* prop ) {
+ return (void*)( (U64)prop - prop->dataoff);
+}
+
template <typename T>
const U8 eprop_type() {
return EDITOR_PROP::__eprop_type<T>::type;