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:
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index ea5175df39a..9d727dc689f 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -90,7 +90,9 @@ typedef struct PaintStroke {
int stroke_started;
/* event that started stroke, for modal() return */
int event_type;
-
+ /* check if stroke variables have been initialized */
+ bool stroke_init;
+ /* check if various brush mapping variables have been initialized */
bool brush_init;
float initial_mouse[2];
/* cached_pressure stores initial pressure for size pressure influence mainly */
@@ -389,17 +391,17 @@ static float paint_space_stroke_spacing_variable(const Scene *scene, PaintStroke
* are aligned nicely with no overlap. for this the spacing needs to be
* the average of the previous and next size. */
float s = paint_space_stroke_spacing(scene, stroke, 1.0f, pressure);
- float q = s*dpressure/(2.0f*length);
- float pressure_fac = (1.0f + q)/(1.0f - q);
+ float q = s * dpressure / (2.0f * length);
+ float pressure_fac = (1.0f + q) / (1.0f - q);
float last_size_pressure = stroke->last_pressure;
- float new_size_pressure = stroke->last_pressure*pressure_fac;
+ float new_size_pressure = stroke->last_pressure * pressure_fac;
/* average spacing */
float last_spacing = paint_space_stroke_spacing(scene, stroke, last_size_pressure, pressure);
float new_spacing = paint_space_stroke_spacing(scene, stroke, new_size_pressure, pressure);
- return 0.5f*(last_spacing + new_spacing);
+ return 0.5f * (last_spacing + new_spacing);
}
else {
/* no size pressure */
@@ -432,9 +434,9 @@ static int paint_space_stroke(bContext *C, wmOperator *op, const float final_mou
float spacing = paint_space_stroke_spacing_variable(scene, stroke, pressure, dpressure, length);
if (length >= spacing) {
- mouse[0] = stroke->last_mouse_position[0] + dmouse[0]*spacing;
- mouse[1] = stroke->last_mouse_position[1] + dmouse[1]*spacing;
- pressure = stroke->last_pressure + (spacing/length)*dpressure;
+ mouse[0] = stroke->last_mouse_position[0] + dmouse[0] * spacing;
+ mouse[1] = stroke->last_mouse_position[1] + dmouse[1] * spacing;
+ pressure = stroke->last_pressure + (spacing / length) * dpressure;
paint_brush_stroke_add_step(C, op, mouse, pressure);
@@ -654,7 +656,8 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
PaintStroke *stroke = op->customdata;
PaintSample sample_average;
float mouse[2];
- int first = 0;
+ bool first_dab = false;
+ bool first_modal = false;
float zoomx, zoomy;
bool redraw = false;
float pressure;
@@ -675,23 +678,28 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (event->type == NDOF_MOTION)
return OPERATOR_PASS_THROUGH;
+ /* one time initialization */
+ if(!stroke->stroke_init) {
+ stroke->smooth_stroke_cursor =
+ WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke);
+
+ stroke->stroke_init = true;
+ first_modal = true;
+ }
+
+ /* one time stroke initialization */
if (!stroke->stroke_started) {
- copy_v2_v2(stroke->last_mouse_position, sample_average.mouse);
stroke->last_pressure = sample_average.pressure;
+ copy_v2_v2(stroke->last_mouse_position, sample_average.mouse);
stroke->stroke_started = stroke->test_start(C, op, sample_average.mouse);
BLI_assert((stroke->stroke_started & ~1) == 0); /* 0/1 */
- stroke->last_pressure = pressure;
if (stroke->stroke_started) {
- stroke->smooth_stroke_cursor =
- WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke);
-
if (stroke->brush->flag & BRUSH_AIRBRUSH)
stroke->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, stroke->brush->rate);
- }
- first = 1;
- //ED_region_tag_redraw(ar);
+ first_dab = true;
+ }
}
/* Cancel */
@@ -702,16 +710,15 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
return paint_stroke_cancel(C, op);
}
- if (event->type == stroke->event_type && event->val == KM_RELEASE) {
+ if (event->type == stroke->event_type && event->val == KM_RELEASE && !first_modal) {
stroke_done(C, op);
return OPERATOR_FINISHED;
}
- else if ((first) ||
- (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) ||
+ else if (first_modal || (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) ||
(event->type == TIMER && (event->customdata == stroke->timer)) )
{
- if (stroke->stroke_started) {
- if (paint_smooth_stroke(stroke, mouse, &pressure, &sample_average, mode)) {
+ if (paint_smooth_stroke(stroke, mouse, &pressure, &sample_average, mode)) {
+ if (stroke->stroke_started) {
if (paint_space_stroke_enabled(stroke->brush, mode)) {
if (paint_space_stroke(C, op, mouse, pressure))
redraw = true;
@@ -726,8 +733,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* we want the stroke to have the first daub at the start location
* instead of waiting till we have moved the space distance */
- if (first &&
- stroke->stroke_started &&
+ if (first_dab &&
paint_space_stroke_enabled(stroke->brush, mode) &&
!(stroke->brush->flag & BRUSH_ANCHORED) &&
!(stroke->brush->flag & BRUSH_SMOOTH_STROKE))