From 372f23024163e0fab57a847ddda41f06857efd7e Mon Sep 17 00:00:00 2001 From: aura Date: Mon, 27 Jul 2026 11:55:57 +0200 Subject: undo/redo props - WIP --- src/editor/properties.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/editor/properties.cpp') diff --git a/src/editor/properties.cpp b/src/editor/properties.cpp index a9835e4..109e622 100644 --- a/src/editor/properties.cpp +++ b/src/editor/properties.cpp @@ -111,6 +111,8 @@ U8 gui_editor_propview_is_selected( GUI_EDITOR_PROPVIEW *e, void *what, U8 selty void gui_editor_propview_sync_props_value( GUI_EDITOR_PROPVIEW* view, EDITOR_PROP* prop ) { void* valuep = eprop_ptr( prop ); + + EDITOR_UNDO_ACTION rec{ .type = EDITOR_UNDO_EDITPROPS }; for( auto& it : view->curselect ) { EOBJECT* eobj = (EOBJECT*)it.obj; EDITOR_PROP* otherp = eprop_from_name( eobj, prop->displayname ); @@ -118,10 +120,22 @@ void gui_editor_propview_sync_props_value( GUI_EDITOR_PROPVIEW* view, EDITOR_PRO if( otherp && otherp->type == prop->type ) { void* targetp = eprop_ptr( otherp ); - if( targetp != valuep ) + if( targetp != valuep ) { + EDITOR_UNDO_PROPS::CHANGES changes; + + void* oldval = alloca( prop->size ); + memcpy( oldval, targetp, prop->size ); memcpy( targetp, valuep, prop->size ); + + changes.props.push( { prop->hash, prop->size, oldval, targetp } ); + changes.obj = eobj; + rec.props.changes.push( changes ); + } } } + + if( rec.props.changes.size ) + editor->undo_actions.push( rec ); } void gui_editor_propview_sync_props_value( GUI_EDITOR_PROPVIEW* view, const char* propname ) { @@ -134,6 +148,10 @@ void gui_editor_propview_sync_props_value( GUI_EDITOR_PROPVIEW* view, const char } void gui_editor_propview_sync_props_fdiff( GUI_EDITOR_PROPVIEW* view, EDITOR_PROP* prop, F32* fdiff, U32 valc ) { + if( !fdiff ) + return; + + EDITOR_UNDO_ACTION rec{ .type = EDITOR_UNDO_EDITPROPS }; for( auto& it : view->curselect ) { EOBJECT* eobj = (EOBJECT*)it.obj; EDITOR_PROP* otherp = eprop_from_name( eobj, prop->displayname ); @@ -144,10 +162,21 @@ void gui_editor_propview_sync_props_fdiff( GUI_EDITOR_PROPVIEW* view, EDITOR_PRO if( targetp == eprop_ptr( prop ) ) continue; + EDITOR_UNDO_PROPS::CHANGES changes; + F32* oldval = (F32*)alloca( prop->size ); + memcpy( oldval, targetp, prop->size ); + for( U32 i = 0; i < valc; ++i ) targetp[i] += fdiff[i]; + + changes.props.push( { prop->hash, prop->size, oldval, targetp } ); + changes.obj = eobj; + rec.props.changes.push( changes ); } } + + if( rec.props.changes.size ) + editor->undo_actions.push( rec ); } void gui_editor_propview_sync_props_fdiff( GUI_EDITOR_PROPVIEW* view, const char* propname, F32* fdiff, U32 valc ) { -- cgit v1.2.3