diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-06-04 14:13:00 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-06-04 14:36:33 +0300 |
commit | c7c3908b8ee2fd5d17178a95b62d35725435d116 (patch) | |
tree | 9acea7d54864285923655d41df9366021f76a23f /source/blender/editors/physics/particle_edit.c | |
parent | 0f320295228505b1b66c543c71f75ed828cfd87e (diff) |
Cleanup: split particle & texture paint mode switching into utility functions
Diffstat (limited to 'source/blender/editors/physics/particle_edit.c')
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 86 |
1 files changed, 56 insertions, 30 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 3639cd64b7c..ef5ed806c1e 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -3230,9 +3230,9 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata) } } -static void toggle_particle_cursor(bContext *C, int enable) +static void toggle_particle_cursor(Scene *scene, bool enable) { - ParticleEditSettings *pset = PE_settings(CTX_data_scene(C)); + ParticleEditSettings *pset = PE_settings(scene); if (pset->paintcursor && !enable) { WM_paint_cursor_end(pset->paintcursor); @@ -5268,10 +5268,60 @@ static void free_all_psys_edit(Object *object) } } +void ED_object_particle_edit_mode_enter_ex(Depsgraph *depsgraph, Scene *scene, Object *ob) +{ + PTCacheEdit *edit; + + ob->mode |= OB_MODE_PARTICLE_EDIT; + + edit = PE_create_current(depsgraph, scene, ob); + + /* Mesh may have changed since last entering editmode. + * note, this may have run before if the edit data was just created, + * so could avoid this and speed up a little. */ + if (edit && edit->psys) { + /* Make sure pointer to the evaluated modifier data is up to date, + * with possible changes applied when object was outside of the + * edit mode. */ + Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); + edit->psmd_eval = (ParticleSystemModifierData *)BKE_modifiers_findby_name( + object_eval, edit->psmd->modifier.name); + recalc_emitter_field(depsgraph, ob, edit->psys); + } + + toggle_particle_cursor(scene, true); + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_PARTICLE, NULL); +} + +void ED_object_particle_edit_mode_enter(bContext *C) +{ + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + ED_object_particle_edit_mode_enter_ex(depsgraph, scene, ob); +} + +void ED_object_particle_edit_mode_exit_ex(Scene *scene, Object *ob) +{ + ob->mode &= ~OB_MODE_PARTICLE_EDIT; + toggle_particle_cursor(scene, false); + free_all_psys_edit(ob); + + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); +} + +void ED_object_particle_edit_mode_exit(bContext *C) +{ + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + ED_object_particle_edit_mode_exit_ex(scene, ob); +} + static int particle_edit_toggle_exec(bContext *C, wmOperator *op) { struct wmMsgBus *mbus = CTX_wm_message_bus(C); - Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_PARTICLE_EDIT; @@ -5284,37 +5334,13 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op) } if (!is_mode_set) { - PTCacheEdit *edit; - - ob->mode |= mode_flag; - - edit = PE_create_current(depsgraph, scene, ob); - - /* Mesh may have changed since last entering editmode. - * note, this may have run before if the edit data was just created, - * so could avoid this and speed up a little. */ - if (edit && edit->psys) { - /* Make sure pointer to the evaluated modifier data is up to date, - * with possible changes applied when object was outside of the - * edit mode. */ - Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); - edit->psmd_eval = (ParticleSystemModifierData *)BKE_modifiers_findby_name( - object_eval, edit->psmd->modifier.name); - recalc_emitter_field(depsgraph, ob, edit->psys); - } - - toggle_particle_cursor(C, 1); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_PARTICLE, NULL); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + ED_object_particle_edit_mode_enter_ex(depsgraph, scene, ob); } else { - ob->mode &= ~mode_flag; - toggle_particle_cursor(C, 0); - free_all_psys_edit(ob); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); + ED_object_particle_edit_mode_exit_ex(scene, ob); } - DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); - WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode); WM_toolsystem_update_from_context_view3d(C); |