[Bf-blender-cvs] [141d5851d7d] master: Paint: decouple op->customdata from PaintStroke
Jacques Lucke
noreply at git.blender.org
Mon Feb 21 11:52:57 CET 2022
Commit: 141d5851d7d240dbe96854553c7a2c076a1b68bd
Author: Jacques Lucke
Date: Mon Feb 21 11:52:46 2022 +0100
Branches: master
https://developer.blender.org/rB141d5851d7d240dbe96854553c7a2c076a1b68bd
Paint: decouple op->customdata from PaintStroke
Previously, all operators using `PaintStroke` would have to store
the stroke in `op->customdata`. That made it impossible to store
other operator specific data in `op->customdata` that was unrelated
to the stroke.
This patch changes it so that the `PaintStroke` is passed to api
functions as a separate argument, which allows storing the stroke
as a subfield of some other struct in `op->customdata`.
===================================================================
M source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
M source/blender/editors/sculpt_paint/paint_image.c
M source/blender/editors/sculpt_paint/paint_intern.h
M source/blender/editors/sculpt_paint/paint_stroke.c
M source/blender/editors/sculpt_paint/paint_vertex.c
M source/blender/editors/sculpt_paint/sculpt.c
===================================================================
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
index ead016174c9..c4421210379 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
@@ -59,9 +59,14 @@ static int sculpt_curves_stroke_invoke(bContext *C, wmOperator *op, const wmEven
return OPERATOR_RUNNING_MODAL;
}
+static int sculpt_curves_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ return paint_stroke_modal(C, op, event, static_cast<PaintStroke *>(op->customdata));
+}
+
static void sculpt_curves_stroke_cancel(bContext *C, wmOperator *op)
{
- paint_stroke_cancel(C, op);
+ paint_stroke_cancel(C, op, static_cast<PaintStroke *>(op->customdata));
}
static void SCULPT_CURVES_OT_brush_stroke(struct wmOperatorType *ot)
@@ -71,7 +76,7 @@ static void SCULPT_CURVES_OT_brush_stroke(struct wmOperatorType *ot)
ot->description = "Sculpt curves using a brush";
ot->invoke = sculpt_curves_stroke_invoke;
- ot->modal = paint_stroke_modal;
+ ot->modal = sculpt_curves_stroke_modal;
ot->cancel = sculpt_curves_stroke_cancel;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index df9e2cf136f..ad8303418f4 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -685,7 +685,7 @@ static int paint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
event->type);
if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
- paint_stroke_free(C, op);
+ paint_stroke_free(C, op, op->customdata);
return OPERATOR_FINISHED;
}
/* add modal handler */
@@ -720,7 +720,17 @@ static int paint_exec(bContext *C, wmOperator *op)
paint_stroke_done,
0);
/* frees op->customdata */
- return paint_stroke_exec(C, op);
+ return paint_stroke_exec(C, op, op->customdata);
+}
+
+static int paint_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ return paint_stroke_modal(C, op, event, op->customdata);
+}
+
+static void paint_cancel(bContext *C, wmOperator *op)
+{
+ paint_stroke_cancel(C, op, op->customdata);
}
void PAINT_OT_image_paint(wmOperatorType *ot)
@@ -732,10 +742,10 @@ void PAINT_OT_image_paint(wmOperatorType *ot)
/* api callbacks */
ot->invoke = paint_invoke;
- ot->modal = paint_stroke_modal;
+ ot->modal = paint_modal;
ot->exec = paint_exec;
ot->poll = image_paint_poll;
- ot->cancel = paint_stroke_cancel;
+ ot->cancel = paint_cancel;
/* flags */
ot->flag = OPTYPE_BLOCKING;
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index f1e79b98b83..f7447ec31b8 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -62,7 +62,7 @@ struct PaintStroke *paint_stroke_new(struct bContext *C,
StrokeRedraw redraw,
StrokeDone done,
int event_type);
-void paint_stroke_free(struct bContext *C, struct wmOperator *op);
+void paint_stroke_free(struct bContext *C, struct wmOperator *op, struct PaintStroke *stroke);
/**
* Returns zero if the stroke dots should not be spaced, non-zero otherwise.
@@ -84,9 +84,12 @@ bool paint_supports_jitter(enum ePaintMode mode);
* Called in paint_ops.c, on each regeneration of key-maps.
*/
struct wmKeyMap *paint_stroke_modal_keymap(struct wmKeyConfig *keyconf);
-int paint_stroke_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
-int paint_stroke_exec(struct bContext *C, struct wmOperator *op);
-void paint_stroke_cancel(struct bContext *C, struct wmOperator *op);
+int paint_stroke_modal(struct bContext *C,
+ struct wmOperator *op,
+ const struct wmEvent *event,
+ struct PaintStroke *stroke);
+int paint_stroke_exec(struct bContext *C, struct wmOperator *op, struct PaintStroke *stroke);
+void paint_stroke_cancel(struct bContext *C, struct wmOperator *op, struct PaintStroke *stroke);
bool paint_stroke_flipped(struct PaintStroke *stroke);
bool paint_stroke_inverted(struct PaintStroke *stroke);
struct ViewContext *paint_stroke_view_context(struct PaintStroke *stroke);
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 9bbfb81e08e..ebb5db8d712 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -505,16 +505,13 @@ static bool paint_stroke_use_jitter(ePaintMode mode, Brush *brush, bool invert)
}
/* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */
-static void paint_brush_stroke_add_step(bContext *C,
- wmOperator *op,
- const float mouse_in[2],
- float pressure)
+static void paint_brush_stroke_add_step(
+ bContext *C, wmOperator *op, PaintStroke *stroke, const float mouse_in[2], float pressure)
{
Scene *scene = CTX_data_scene(C);
Paint *paint = BKE_paint_get_active_from_context(C);
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
Brush *brush = BKE_paint_brush(paint);
- PaintStroke *stroke = op->customdata;
UnifiedPaintSettings *ups = stroke->ups;
float mouse_out[2];
PointerRNA itemptr;
@@ -785,12 +782,12 @@ static float paint_space_stroke_spacing_variable(bContext *C,
* towards the final mouse location. */
static int paint_space_stroke(bContext *C,
wmOperator *op,
+ PaintStroke *stroke,
const float final_mouse[2],
float final_pressure)
{
const Scene *scene = CTX_data_scene(C);
ARegion *region = CTX_wm_region(C);
- PaintStroke *stroke = op->customdata;
UnifiedPaintSettings *ups = stroke->ups;
Paint *paint = BKE_paint_get_active_from_context(C);
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
@@ -852,7 +849,7 @@ static int paint_space_stroke(bContext *C,
spacing / no_pressure_spacing);
stroke->stroke_distance += spacing / stroke->zoom_2d;
- paint_brush_stroke_add_step(C, op, mouse, pressure);
+ paint_brush_stroke_add_step(C, op, stroke, mouse, pressure);
length -= spacing;
pressure = stroke->last_pressure;
@@ -929,7 +926,7 @@ PaintStroke *paint_stroke_new(bContext *C,
return stroke;
}
-void paint_stroke_free(bContext *C, wmOperator *op)
+void paint_stroke_free(bContext *C, wmOperator *UNUSED(op), PaintStroke *stroke)
{
RegionView3D *rv3d = CTX_wm_region_view3d(C);
if (rv3d) {
@@ -938,7 +935,6 @@ void paint_stroke_free(bContext *C, wmOperator *op)
BKE_paint_set_overlay_override(0);
- PaintStroke *stroke = op->customdata;
if (stroke == NULL) {
return;
}
@@ -961,12 +957,11 @@ void paint_stroke_free(bContext *C, wmOperator *op)
BLI_freelistN(&stroke->line);
- MEM_SAFE_FREE(op->customdata);
+ MEM_SAFE_FREE(stroke);
}
-static void stroke_done(bContext *C, wmOperator *op)
+static void stroke_done(bContext *C, wmOperator *op, PaintStroke *stroke)
{
- PaintStroke *stroke = op->customdata;
UnifiedPaintSettings *ups = stroke->ups;
/* reset rotation here to avoid doing so in cursor display */
@@ -988,7 +983,7 @@ static void stroke_done(bContext *C, wmOperator *op)
}
}
- paint_stroke_free(C, op);
+ paint_stroke_free(C, op, stroke);
}
bool paint_space_stroke_enabled(Brush *br, ePaintMode mode)
@@ -1230,7 +1225,7 @@ static void paint_line_strokes_spacing(bContext *C,
ups->overlap_factor = paint_stroke_integrate_overlap(stroke->brush, 1.0);
stroke->stroke_distance += spacing / stroke->zoom_2d;
- paint_brush_stroke_add_step(C, op, mouse, 1.0);
+ paint_brush_stroke_add_step(C, op, stroke, mouse, 1.0);
length -= spacing;
spacing_final = spacing;
@@ -1252,8 +1247,8 @@ static void paint_stroke_line_end(bContext *C,
if (stroke->stroke_started && (br->flag & BRUSH_LINE)) {
stroke->ups->overlap_factor = paint_stroke_integrate_overlap(br, 1.0);
- paint_brush_stroke_add_step(C, op, stroke->last_mouse_position, 1.0);
- paint_space_stroke(C, op, mouse, 1.0);
+ paint_brush_stroke_add_step(C, op, stroke, stroke->last_mouse_position, 1.0);
+ paint_space_stroke(C, op, stroke, mouse, 1.0);
}
}
@@ -1331,7 +1326,7 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str
stroke->stroke_started = stroke->test_start(C, op, stroke->last_mouse_position);
if (stroke->stroke_started) {
- paint_brush_stroke_add_step(C, op, data + 2 * j, 1.0);
+ paint_brush_stroke_add_step(C, op, stroke, data + 2 * j, 1.0);
paint_line_strokes_spacing(
C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
}
@@ -1343,7 +1338,7 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str
}
}
- stroke_done(C, op);
+ stroke_done(C, op, stroke);
#ifdef DEBUG_TIME
TIMEIT_END_AVERAGED(whole_stroke);
@@ -1384,11 +1379,10 @@ static void paint_stroke_line_constrain(PaintStroke *stroke, float mouse[2])
}
}
-int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
+int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintStroke *stroke)
{
Paint *p = BKE_paint_get_active_from_context(C);
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
- PaintStroke *stroke = op->customdata;
Brush *br = stroke->brush = BKE_paint_brush(p);
PaintSample sample_average;
float mouse[2];
@@ -1482,7 +1476,7 @@ int paint_stroke_modal(bContex
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list