Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / sculpt_paint / paint_stroke.c
index 8610153..b63f946 100644 (file)
@@ -126,7 +126,7 @@ typedef struct PaintStroke {
 
        float zoom_2d;
        int pen_flip;
-       
+
        /* line constraint */
        bool constrain_line;
        float constrained_pos[2];
@@ -149,13 +149,18 @@ static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata
                glEnable(GL_LINE_SMOOTH);
                glEnable(GL_BLEND);
 
+               ARegion *ar = stroke->vc.ar;
+
                unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
                immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
                immUniformColor4ubv(paint->paint_cursor_col);
 
                immBegin(GWN_PRIM_LINES, 2);
                immVertex2f(pos, x, y);
-               immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
+               immVertex2f(pos,
+                           stroke->last_mouse_position[0] + ar->winrct.xmin,
+                           stroke->last_mouse_position[1] + ar->winrct.ymin);
+
                immEnd();
 
                immUnbindProgram();
@@ -187,12 +192,22 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata)
 
        immBegin(GWN_PRIM_LINES, 2);
 
+       ARegion *ar = stroke->vc.ar;
+
        if (stroke->constrain_line) {
-               immVertex2f(shdr_pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
-               immVertex2f(shdr_pos, stroke->constrained_pos[0], stroke->constrained_pos[1]);
+               immVertex2f(shdr_pos,
+                           stroke->last_mouse_position[0] + ar->winrct.xmin,
+                           stroke->last_mouse_position[1] + ar->winrct.ymin);
+
+               immVertex2f(shdr_pos,
+                           stroke->constrained_pos[0] + ar->winrct.xmin,
+                           stroke->constrained_pos[1] + ar->winrct.ymin);
        }
        else {
-               immVertex2f(shdr_pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
+               immVertex2f(shdr_pos,
+                           stroke->last_mouse_position[0] + ar->winrct.xmin,
+                           stroke->last_mouse_position[1] + ar->winrct.ymin);
+
                immVertex2f(shdr_pos, x, y);
        }
 
@@ -720,10 +735,10 @@ PaintStroke *paint_stroke_new(bContext *C,
        /* initialize here */
        ups->overlap_factor = 1.0;
        ups->stroke_active = true;
-       
+
        zero_v3(ups->average_stroke_accum);
        ups->average_stroke_counter = 0;
-       
+
        /* initialize here to avoid initialization conflict with threaded strokes */
        curvemapping_initialize(br->curve);
        if (p->flags & PAINT_USE_CAVITY_MASK)
@@ -913,11 +928,11 @@ static void paint_stroke_sample_average(const PaintStroke *stroke,
                                         PaintSample *average)
 {
        int i;
-       
+
        memset(average, 0, sizeof(*average));
 
        BLI_assert(stroke->num_samples > 0);
-       
+
        for (i = 0; i < stroke->num_samples; i++) {
                add_v2_v2(average->mouse, stroke->samples[i].mouse);
                average->pressure += stroke->samples[i].pressure;
@@ -1081,17 +1096,17 @@ static void paint_stroke_line_constrain(PaintStroke *stroke, float mouse[2])
        if (stroke->constrain_line) {
                float line[2];
                float angle, len, res;
-               
+
                sub_v2_v2v2(line, mouse, stroke->last_mouse_position);
                angle = atan2f(line[1], line[0]);
                len = len_v2(line);
-               
+
                /* divide angle by PI/4 */
                angle = 4.0f * angle / (float)M_PI;
-               
+
                /* now take residue */
                res = angle - floorf(angle);
-               
+
                /* residue decides how close we are at a certain angle */
                if (res <= 0.5f) {
                        angle = floorf(angle) * (float)M_PI_4;
@@ -1099,7 +1114,7 @@ static void paint_stroke_line_constrain(PaintStroke *stroke, float mouse[2])
                else {
                        angle = (floorf(angle) + 1.0f) * (float)M_PI_4;
                }
-               
+
                mouse[0] = stroke->constrained_pos[0] = len * cosf(angle) + stroke->last_mouse_position[0];
                mouse[1] = stroke->constrained_pos[1] = len * sinf(angle) + stroke->last_mouse_position[1];
        }
@@ -1194,12 +1209,12 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
        else if (br->flag & BRUSH_LINE) {
                if (event->alt)
                        stroke->constrain_line = true;
-               else 
+               else
                        stroke->constrain_line = false;
 
                copy_v2_fl2(mouse, event->mval[0], event->mval[1]);
                paint_stroke_line_constrain(stroke, mouse);
-               
+
                if (stroke->stroke_started && (first_modal || (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)))) {
                        if ((br->mtex.brush_angle_mode & MTEX_ANGLE_RAKE) || (br->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) {
                                copy_v2_v2(stroke->ups->last_rake, stroke->last_mouse_position);