Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-02-05 00:03:39 +0300
committerBastien Montagne <bastien@blender.org>2021-02-05 00:03:39 +0300
commit94cf74afbb1329a9ff099e2ebd7f43ed8313f9ec (patch)
tree6859715425521345f93993ecdcf7182b060ac236 /source/blender/editors
parent7d5640ee101e6b9ddbd9f534539ae939f68bfd9b (diff)
Cleanup/refactor: Undosys: Get rid of the magic values for undo direction.
Move `eUndoStepDir` to `BKE_undo_system.h` and use its values everywhere. Note that this also introduce the `STEP_INVALID` value in that enum. Finally, kept the matching struct members in some lower-level readfile code as an `int` to avoid having to include `BKE_undo_system.h` in a lot of unrelated files.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/armature/editarmature_undo.c7
-rw-r--r--source/blender/editors/curve/editcurve_undo.c7
-rw-r--r--source/blender/editors/curve/editfont_undo.c7
-rw-r--r--source/blender/editors/gpencil/gpencil_undo.c7
-rw-r--r--source/blender/editors/include/ED_gpencil.h4
-rw-r--r--source/blender/editors/lattice/editlattice_undo.c7
-rw-r--r--source/blender/editors/mesh/editmesh_undo.c7
-rw-r--r--source/blender/editors/metaball/editmball_undo.c7
-rw-r--r--source/blender/editors/physics/particle_edit_undo.c2
-rw-r--r--source/blender/editors/sculpt_paint/paint_curve_undo.c2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_undo.c13
-rw-r--r--source/blender/editors/space_image/image_undo.c8
-rw-r--r--source/blender/editors/space_text/text_undo.c11
-rw-r--r--source/blender/editors/undo/ed_undo.c11
-rw-r--r--source/blender/editors/undo/memfile_undo.c14
15 files changed, 68 insertions, 46 deletions
diff --git a/source/blender/editors/armature/editarmature_undo.c b/source/blender/editors/armature/editarmature_undo.c
index c6d7d2eb869..337d1138b23 100644
--- a/source/blender/editors/armature/editarmature_undo.c
+++ b/source/blender/editors/armature/editarmature_undo.c
@@ -178,8 +178,11 @@ static bool armature_undosys_step_encode(struct bContext *C, struct Main *bmain,
return true;
}
-static void armature_undosys_step_decode(
- struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final))
+static void armature_undosys_step_decode(struct bContext *C,
+ struct Main *bmain,
+ UndoStep *us_p,
+ const eUndoStepDir UNUSED(dir),
+ bool UNUSED(is_final))
{
ArmatureUndoStep *us = (ArmatureUndoStep *)us_p;
diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c
index 534d29c0cc7..681f387e83e 100644
--- a/source/blender/editors/curve/editcurve_undo.c
+++ b/source/blender/editors/curve/editcurve_undo.c
@@ -238,8 +238,11 @@ static bool curve_undosys_step_encode(struct bContext *C, struct Main *bmain, Un
return true;
}
-static void curve_undosys_step_decode(
- struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final))
+static void curve_undosys_step_decode(struct bContext *C,
+ struct Main *bmain,
+ UndoStep *us_p,
+ const eUndoStepDir UNUSED(dir),
+ bool UNUSED(is_final))
{
CurveUndoStep *us = (CurveUndoStep *)us_p;
diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c
index 8559234b62f..07f062e7a53 100644
--- a/source/blender/editors/curve/editfont_undo.c
+++ b/source/blender/editors/curve/editfont_undo.c
@@ -356,8 +356,11 @@ static bool font_undosys_step_encode(struct bContext *C, struct Main *bmain, Und
return true;
}
-static void font_undosys_step_decode(
- struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final))
+static void font_undosys_step_decode(struct bContext *C,
+ struct Main *bmain,
+ UndoStep *us_p,
+ const eUndoStepDir UNUSED(dir),
+ bool UNUSED(is_final))
{
/* TODO(campbell): undo_system: use low-level API to set mode. */
ED_object_mode_set_ex(C, OB_MODE_EDIT, false, NULL);
diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c
index e545a3365e9..4e172104ce7 100644
--- a/source/blender/editors/gpencil/gpencil_undo.c
+++ b/source/blender/editors/gpencil/gpencil_undo.c
@@ -36,6 +36,7 @@
#include "BKE_blender_undo.h"
#include "BKE_context.h"
#include "BKE_gpencil.h"
+#include "BKE_undo_system.h"
#include "ED_gpencil.h"
@@ -61,19 +62,19 @@ int ED_gpencil_session_active(void)
return (BLI_listbase_is_empty(&undo_nodes) == false);
}
-int ED_undo_gpencil_step(bContext *C, const int step)
+int ED_undo_gpencil_step(bContext *C, const eUndoStepDir step)
{
bGPdata **gpd_ptr = NULL, *new_gpd = NULL;
gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
- if (step == -1) { /* undo */
+ if (step == STEP_UNDO) {
if (cur_node->prev) {
cur_node = cur_node->prev;
new_gpd = cur_node->gpd;
}
}
- else if (step == 1) {
+ else if (step == STEP_REDO) {
if (cur_node->next) {
cur_node = cur_node->next;
new_gpd = cur_node->gpd;
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index acaa6495ba9..0136d599e8a 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -62,6 +62,8 @@ struct bAnimContext;
struct wmKeyConfig;
struct wmOperator;
+enum eUndoStepDir;
+
#define GPENCIL_MINIMUM_JOIN_DIST 20.0f
/* Reproject stroke modes. */
@@ -213,7 +215,7 @@ bool ED_gpencil_anim_copybuf_paste(struct bAnimContext *ac, const short copy_mod
/* ------------ Grease-Pencil Undo System ------------------ */
int ED_gpencil_session_active(void);
-int ED_undo_gpencil_step(struct bContext *C, const int step);
+int ED_undo_gpencil_step(struct bContext *C, const enum eUndoStepDir step);
/* ------------ Grease-Pencil Armature ------------------ */
bool ED_gpencil_add_armature(const struct bContext *C,
diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c
index 3a5734706f1..3ffbc3712fc 100644
--- a/source/blender/editors/lattice/editlattice_undo.c
+++ b/source/blender/editors/lattice/editlattice_undo.c
@@ -212,8 +212,11 @@ static bool lattice_undosys_step_encode(struct bContext *C, Main *bmain, UndoSte
return true;
}
-static void lattice_undosys_step_decode(
- struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final))
+static void lattice_undosys_step_decode(struct bContext *C,
+ struct Main *bmain,
+ UndoStep *us_p,
+ const eUndoStepDir UNUSED(dir),
+ bool UNUSED(is_final))
{
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c
index 1cbbbccdfa9..83de760aaa0 100644
--- a/source/blender/editors/mesh/editmesh_undo.c
+++ b/source/blender/editors/mesh/editmesh_undo.c
@@ -744,8 +744,11 @@ static bool mesh_undosys_step_encode(struct bContext *C, struct Main *bmain, Und
return true;
}
-static void mesh_undosys_step_decode(
- struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final))
+static void mesh_undosys_step_decode(struct bContext *C,
+ struct Main *bmain,
+ UndoStep *us_p,
+ const eUndoStepDir UNUSED(dir),
+ bool UNUSED(is_final))
{
MeshUndoStep *us = (MeshUndoStep *)us_p;
diff --git a/source/blender/editors/metaball/editmball_undo.c b/source/blender/editors/metaball/editmball_undo.c
index cbc60bcc031..b817bc3a718 100644
--- a/source/blender/editors/metaball/editmball_undo.c
+++ b/source/blender/editors/metaball/editmball_undo.c
@@ -187,8 +187,11 @@ static bool mball_undosys_step_encode(struct bContext *C, struct Main *bmain, Un
return true;
}
-static void mball_undosys_step_decode(
- struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final))
+static void mball_undosys_step_decode(struct bContext *C,
+ struct Main *bmain,
+ UndoStep *us_p,
+ const eUndoStepDir UNUSED(dir),
+ bool UNUSED(is_final))
{
MBallUndoStep *us = (MBallUndoStep *)us_p;
diff --git a/source/blender/editors/physics/particle_edit_undo.c b/source/blender/editors/physics/particle_edit_undo.c
index 77b8d410d81..5d2e0e5b6ef 100644
--- a/source/blender/editors/physics/particle_edit_undo.c
+++ b/source/blender/editors/physics/particle_edit_undo.c
@@ -247,7 +247,7 @@ static bool particle_undosys_step_encode(struct bContext *C,
static void particle_undosys_step_decode(struct bContext *C,
struct Main *UNUSED(bmain),
UndoStep *us_p,
- int UNUSED(dir),
+ const eUndoStepDir UNUSED(dir),
bool UNUSED(is_final))
{
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
diff --git a/source/blender/editors/sculpt_paint/paint_curve_undo.c b/source/blender/editors/sculpt_paint/paint_curve_undo.c
index a8e22f66734..dbe522bf304 100644
--- a/source/blender/editors/sculpt_paint/paint_curve_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_curve_undo.c
@@ -126,7 +126,7 @@ static bool paintcurve_undosys_step_encode(struct bContext *C,
static void paintcurve_undosys_step_decode(struct bContext *UNUSED(C),
struct Main *UNUSED(bmain),
UndoStep *us_p,
- int UNUSED(dir),
+ const eUndoStepDir UNUSED(dir),
bool UNUSED(is_final))
{
PaintCurveUndoStep *us = (PaintCurveUndoStep *)us_p;
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 938080b392d..ec103bd2b98 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -1527,9 +1527,14 @@ static void sculpt_undosys_step_decode_redo(struct bContext *C,
}
}
-static void sculpt_undosys_step_decode(
- struct bContext *C, struct Main *bmain, UndoStep *us_p, int dir, bool UNUSED(is_final))
+static void sculpt_undosys_step_decode(struct bContext *C,
+ struct Main *bmain,
+ UndoStep *us_p,
+ const eUndoStepDir dir,
+ bool UNUSED(is_final))
{
+ BLI_assert(dir != STEP_INVALID);
+
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
/* Ensure sculpt mode. */
@@ -1568,10 +1573,10 @@ static void sculpt_undosys_step_decode(
}
SculptUndoStep *us = (SculptUndoStep *)us_p;
- if (dir < 0) {
+ if (dir == STEP_UNDO) {
sculpt_undosys_step_decode_undo(C, depsgraph, us);
}
- else {
+ else if (dir == STEP_REDO) {
sculpt_undosys_step_decode_redo(C, depsgraph, us);
}
}
diff --git a/source/blender/editors/space_image/image_undo.c b/source/blender/editors/space_image/image_undo.c
index 1d5725033e0..391c68f4231 100644
--- a/source/blender/editors/space_image/image_undo.c
+++ b/source/blender/editors/space_image/image_undo.c
@@ -947,13 +947,15 @@ static void image_undosys_step_decode_redo(ImageUndoStep *us)
}
static void image_undosys_step_decode(
- struct bContext *C, struct Main *bmain, UndoStep *us_p, int dir, bool is_final)
+ struct bContext *C, struct Main *bmain, UndoStep *us_p, const eUndoStepDir dir, bool is_final)
{
+ BLI_assert(dir != STEP_INVALID);
+
ImageUndoStep *us = (ImageUndoStep *)us_p;
- if (dir < 0) {
+ if (dir == STEP_UNDO) {
image_undosys_step_decode_undo(us, is_final);
}
- else {
+ else if (dir == STEP_REDO) {
image_undosys_step_decode_redo(us);
}
diff --git a/source/blender/editors/space_text/text_undo.c b/source/blender/editors/space_text/text_undo.c
index 61b786b2b13..f55db8c3cc9 100644
--- a/source/blender/editors/space_text/text_undo.c
+++ b/source/blender/editors/space_text/text_undo.c
@@ -196,14 +196,19 @@ static bool text_undosys_step_encode(struct bContext *C,
return true;
}
-static void text_undosys_step_decode(
- struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p, int dir, bool is_final)
+static void text_undosys_step_decode(struct bContext *C,
+ struct Main *UNUSED(bmain),
+ UndoStep *us_p,
+ const eUndoStepDir dir,
+ bool is_final)
{
+ BLI_assert(dir != STEP_INVALID);
+
TextUndoStep *us = (TextUndoStep *)us_p;
Text *text = us->text_ref.ptr;
TextState *state;
- if ((us->states[0].buf_array_state != NULL) && (dir == -1) && !is_final) {
+ if ((us->states[0].buf_array_state != NULL) && (dir == STEP_UNDO) && !is_final) {
state = &us->states[0];
}
else {
diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c
index 0771d0254e8..baa178a6a94 100644
--- a/source/blender/editors/undo/ed_undo.c
+++ b/source/blender/editors/undo/ed_undo.c
@@ -70,15 +70,6 @@
/** We only need this locally. */
static CLG_LogRef LOG = {"ed.undo"};
-/**
- * \warning Values are used in #ED_undo_gpencil_step,
- * which should eventually be replaced with the undo-system.
- */
-enum eUndoStepDir {
- STEP_REDO = 1,
- STEP_UNDO = -1,
-};
-
/* -------------------------------------------------------------------- */
/** \name Generic Undo System Access
*
@@ -276,7 +267,7 @@ static int ed_undo_step_direction(bContext *C, enum eUndoStepDir step, ReportLis
* FIXME: However, it seems to never be used in current code (`ED_gpencil_session_active` seems
* to always return false). */
if (ED_gpencil_session_active()) {
- return ED_undo_gpencil_step(C, (int)step);
+ return ED_undo_gpencil_step(C, step);
}
wmWindowManager *wm = CTX_wm_manager(C);
diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c
index eea0f29d295..51859b6a555 100644
--- a/source/blender/editors/undo/memfile_undo.c
+++ b/source/blender/editors/undo/memfile_undo.c
@@ -145,19 +145,18 @@ static int memfile_undosys_step_id_reused_cb(LibraryIDLinkCallbackData *cb_data)
static void memfile_undosys_step_decode(struct bContext *C,
struct Main *bmain,
UndoStep *us_p,
- int undo_direction,
+ const eUndoStepDir undo_direction,
bool UNUSED(is_final))
{
- BLI_assert(undo_direction != 0);
+ BLI_assert(undo_direction != STEP_INVALID);
bool use_old_bmain_data = true;
if (USER_EXPERIMENTAL_TEST(&U, use_undo_legacy)) {
use_old_bmain_data = false;
}
- else if (undo_direction > 0) {
- /* Redo case.
- * The only time we should have to force a complete redo is when current step is tagged as a
+ else if (undo_direction == STEP_REDO) {
+ /* The only time we should have to force a complete redo is when current step is tagged as a
* redo barrier.
* If previous step was not a memfile one should not matter here, current data in old bmain
* should still always be valid for unchanged data-blocks. */
@@ -165,9 +164,8 @@ static void memfile_undosys_step_decode(struct bContext *C,
use_old_bmain_data = false;
}
}
- else {
- /* Undo case.
- * Here we do not care whether current step is an undo barrier, since we are coming from
+ else if (undo_direction == STEP_UNDO) {
+ /* Here we do not care whether current step is an undo barrier, since we are coming from
* 'the future' we can still re-use old data. However, if *next* undo step
* (i.e. the one immediately in the future, the one we are coming from)
* is a barrier, then we have to force a complete undo.