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:
authorJacques Lucke <jacques@blender.org>2022-02-21 13:52:46 +0300
committerJacques Lucke <jacques@blender.org>2022-02-21 13:52:46 +0300
commit141d5851d7d240dbe96854553c7a2c076a1b68bd (patch)
tree5be034d7e8dd01091b23d7704ff4c3bf4b54ef4c /source/blender/editors/sculpt_paint/paint_stroke.c
parent5be74160c06a51fa61dce6293ddbd538562e766b (diff)
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`.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c56
1 files changed, 24 insertions, 32 deletions
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(bContext *C, wmOperator *op, const wmEvent *event)
op->type->cancel(C, op);
}
else {
- paint_stroke_cancel(C, op);
+ paint_stroke_cancel(C, op, stroke);
}
return OPERATOR_CANCELLED;
}
@@ -1492,13 +1486,13 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
copy_v2_fl2(mouse, event->mval[0], event->mval[1]);
paint_stroke_line_constrain(stroke, mouse);
paint_stroke_line_end(C, op, stroke, mouse);
- stroke_done(C, op);
+ stroke_done(C, op, stroke);
return OPERATOR_FINISHED;
}
}
else if (ELEM(event->type, EVT_RETKEY, EVT_SPACEKEY)) {
paint_stroke_line_end(C, op, stroke, sample_average.mouse);
- stroke_done(C, op);
+ stroke_done(C, op, stroke);
return OPERATOR_FINISHED;
}
else if (br->flag & BRUSH_LINE) {
@@ -1530,7 +1524,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (paint_smooth_stroke(stroke, &sample_average, mode, mouse, &pressure)) {
if (stroke->stroke_started) {
if (paint_space_stroke_enabled(br, mode)) {
- if (paint_space_stroke(C, op, mouse, pressure)) {
+ if (paint_space_stroke(C, op, stroke, mouse, pressure)) {
redraw = true;
}
}
@@ -1538,7 +1532,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
float dmouse[2];
sub_v2_v2v2(dmouse, mouse, stroke->last_mouse_position);
stroke->stroke_distance += len_v2(dmouse);
- paint_brush_stroke_add_step(C, op, mouse, pressure);
+ paint_brush_stroke_add_step(C, op, stroke, mouse, pressure);
redraw = true;
}
}
@@ -1549,7 +1543,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
* instead of waiting till we have moved the space distance */
if (first_dab && paint_space_stroke_enabled(br, mode) && !(br->flag & BRUSH_SMOOTH_STROKE)) {
stroke->ups->overlap_factor = paint_stroke_integrate_overlap(br, 1.0);
- paint_brush_stroke_add_step(C, op, sample_average.mouse, sample_average.pressure);
+ paint_brush_stroke_add_step(C, op, stroke, sample_average.mouse, sample_average.pressure);
redraw = true;
}
@@ -1572,10 +1566,8 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_RUNNING_MODAL;
}
-int paint_stroke_exec(bContext *C, wmOperator *op)
+int paint_stroke_exec(bContext *C, wmOperator *op, PaintStroke *stroke)
{
- PaintStroke *stroke = op->customdata;
-
/* only when executed for the first time */
if (stroke->stroke_started == 0) {
PropertyRNA *strokeprop;
@@ -1599,14 +1591,14 @@ int paint_stroke_exec(bContext *C, wmOperator *op)
bool ok = (stroke->stroke_started != 0);
- stroke_done(C, op);
+ stroke_done(C, op, stroke);
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
-void paint_stroke_cancel(bContext *C, wmOperator *op)
+void paint_stroke_cancel(bContext *C, wmOperator *op, PaintStroke *stroke)
{
- stroke_done(C, op);
+ stroke_done(C, op, stroke);
}
ViewContext *paint_stroke_view_context(PaintStroke *stroke)