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
path: root/source
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2014-03-14 00:35:26 +0400
committerAntony Riakiotakis <kalast@gmail.com>2014-03-14 00:36:16 +0400
commit93684d5b5e3dcc6b9f0d4130ff5bdab86d2f7981 (patch)
treed103245caabd1f00a28e100277a30fd42ac8d3e4 /source
parenta8039d99f8a38ec9acb8bc048d38259bab574c53 (diff)
Fix T39156 part 2: Add support for image paint operations in undo
history operator (Ctrl + Alt + Z). This will only show paint operations now while in an image paint mode. The caveat is that user can delete previous paint operations too (even on images not on the canvas currently) so it needs some care. This is consistent with regular undo behaviour though. Sculpting also suffers from lack of Undo history support, this will be added in a separate commit.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/include/ED_sculpt.h3
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c2
-rw-r--r--source/blender/editors/sculpt_paint/paint_undo.c71
-rw-r--r--source/blender/editors/util/undo.c40
4 files changed, 109 insertions, 7 deletions
diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h
index ba69be5b4c0..6105db14d6a 100644
--- a/source/blender/editors/include/ED_sculpt.h
+++ b/source/blender/editors/include/ED_sculpt.h
@@ -67,8 +67,11 @@ typedef void (*UndoRestoreCb)(struct bContext *C, struct ListBase *lb);
typedef void (*UndoFreeCb)(struct ListBase *lb);
int ED_undo_paint_step(struct bContext *C, int type, int step, const char *name);
+void ED_undo_paint_step_num(struct bContext *C, int type, int num);
+const char *ED_undo_paint_get_name(int type, int nr, int *active);
void ED_undo_paint_free(void);
int ED_undo_paint_valid(int type, const char *name);
+bool ED_undo_paint_empty(int type);
void ED_undo_paint_push_begin(int type, const char *name, UndoRestoreCb restore, UndoFreeCb free);
void ED_undo_paint_push_end(int type);
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 1b2e708be0f..85010d1be52 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -686,7 +686,7 @@ void PAINT_OT_image_paint(wmOperatorType *ot)
ot->cancel = paint_stroke_cancel;
/* flags */
- ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING;
+ ot->flag = OPTYPE_BLOCKING;
RNA_def_enum(ot->srna, "mode", stroke_mode_items, BRUSH_STROKE_NORMAL,
"Paint Stroke Mode",
diff --git a/source/blender/editors/sculpt_paint/paint_undo.c b/source/blender/editors/sculpt_paint/paint_undo.c
index fd8cc4df41e..2b5c6d9421c 100644
--- a/source/blender/editors/sculpt_paint/paint_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_undo.c
@@ -271,6 +271,77 @@ int ED_undo_paint_step(bContext *C, int type, int step, const char *name)
return 0;
}
+static void undo_step_num(bContext *C, UndoStack *stack, int step)
+{
+ UndoElem *uel;
+ int a = 0;
+ int curnum = BLI_findindex(&stack->elems, stack->current);
+
+ for (uel = stack->elems.first; uel; uel = uel->next, a++) {
+ if (a == step) break;
+ }
+
+ if (curnum > a) {
+ while (a++ != curnum)
+ undo_stack_step(C, stack, 1, NULL);
+ }
+ else if (curnum < a){
+ while (a-- != curnum)
+ undo_stack_step(C, stack, -1, NULL);
+ }
+}
+
+void ED_undo_paint_step_num(bContext *C, int type, int step)
+{
+ if (type == UNDO_PAINT_IMAGE)
+ return undo_step_num(C, &ImageUndoStack, step);
+ else if (type == UNDO_PAINT_MESH)
+ return undo_step_num(C, &MeshUndoStack, step);
+}
+
+static char *undo_stack_get_name(UndoStack *stack, int nr, int *active)
+{
+ UndoElem *uel;
+
+ if (active) *active = 0;
+
+ uel = BLI_findlink(&stack->elems, nr);
+ if (uel) {
+ if (active && uel == stack->current)
+ *active = 1;
+ return uel->name;
+ }
+
+ return NULL;
+}
+
+const char *ED_undo_paint_get_name(int type, int nr, int *active)
+{
+ if (type == UNDO_PAINT_IMAGE)
+ return undo_stack_get_name(&ImageUndoStack, nr, active);
+ else if (type == UNDO_PAINT_MESH)
+ return undo_stack_get_name(&MeshUndoStack, nr, active);
+ return NULL;
+}
+
+bool ED_undo_paint_empty(int type)
+{
+ UndoStack *stack;
+
+ if (type == UNDO_PAINT_IMAGE)
+ stack = &ImageUndoStack;
+ else if (type == UNDO_PAINT_MESH)
+ stack = &MeshUndoStack;
+ else
+ return true;
+
+ if (stack->current == NULL) {
+ return true;
+ }
+
+ return false;
+}
+
int ED_undo_paint_valid(int type, const char *name)
{
UndoStack *stack;
diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c
index af524fa18bc..60c761cc12d 100644
--- a/source/blender/editors/util/undo.c
+++ b/source/blender/editors/util/undo.c
@@ -105,13 +105,13 @@ void ED_undo_push(bContext *C, const char *str)
}
else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) {
if (U.undosteps == 0) return;
-
+
PE_undo_push(CTX_data_scene(C), str);
}
else {
BKE_write_undo(C, str);
}
-
+
if (wm->file_saved) {
wm->file_saved = 0;
/* notifier that data changed, for save-over warning or header */
@@ -433,13 +433,27 @@ void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int UNUSED(arg_ev
enum {
UNDOSYSTEM_GLOBAL = 1,
UNDOSYSTEM_EDITMODE = 2,
- UNDOSYSTEM_PARTICLE = 3
+ UNDOSYSTEM_PARTICLE = 3,
+ UNDOSYSTEM_IMAPAINT = 4
};
static int get_undo_system(bContext *C)
{
+ Object *obact = CTX_data_active_object(C);
Object *obedit = CTX_data_edit_object(C);
-
+ ScrArea *sa = CTX_wm_area(C);
+
+ /* first check for editor undo */
+ if (sa && (sa->spacetype == SPACE_IMAGE)) {
+ SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
+
+ if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) {
+ if (!ED_undo_paint_empty(UNDO_PAINT_IMAGE))
+ return UNDOSYSTEM_IMAPAINT;
+ else
+ return UNDOSYSTEM_GLOBAL;
+ }
+ }
/* find out which undo system */
if (obedit) {
if (OB_TYPE_SUPPORT_EDITMODE(obedit->type)) {
@@ -449,8 +463,16 @@ static int get_undo_system(bContext *C)
else {
Object *obact = CTX_data_active_object(C);
- if (obact && obact->mode & OB_MODE_PARTICLE_EDIT)
- return UNDOSYSTEM_PARTICLE;
+ if (obact) {
+ if (obact->mode & OB_MODE_PARTICLE_EDIT)
+ return UNDOSYSTEM_PARTICLE;
+ else if (obact->mode & OB_MODE_TEXTURE_PAINT) {
+ if (!ED_undo_paint_empty(UNDO_PAINT_IMAGE))
+ return UNDOSYSTEM_IMAPAINT;
+ else
+ return UNDOSYSTEM_GLOBAL;
+ }
+ }
else if (U.uiflag & USER_GLOBALUNDO)
return UNDOSYSTEM_GLOBAL;
}
@@ -473,6 +495,9 @@ static EnumPropertyItem *rna_undo_itemf(bContext *C, int undosys, int *totitem)
else if (undosys == UNDOSYSTEM_EDITMODE) {
name = undo_editmode_get_name(C, i, &active);
}
+ else if (undosys == UNDOSYSTEM_IMAPAINT) {
+ name = ED_undo_paint_get_name(UNDO_PAINT_IMAGE, i, &active);
+ }
else {
name = BKE_undo_get_name(i, &active);
}
@@ -545,6 +570,9 @@ static int undo_history_exec(bContext *C, wmOperator *op)
undo_editmode_number(C, item + 1);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
}
+ else if (undosys == UNDOSYSTEM_IMAPAINT) {
+ ED_undo_paint_step_num(C, UNDO_PAINT_IMAGE, item );
+ }
else {
ED_viewport_render_kill_jobs(C, true);
BKE_undo_number(C, item);