From 98beda156c5e5c05c340abc929c585b8556e99fc Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 15 May 2013 11:16:01 +0000 Subject: [PATCH] Fix part of #35372: distorted strokes when painting zoomed out with a small brush size. Interpolated mouse coordinates should not get rounded to integers. --- source/blender/editors/include/UI_view2d.h | 2 +- source/blender/editors/interface/view2d.c | 2 +- source/blender/editors/sculpt_paint/paint_image.c | 10 ++++------ .../blender/editors/sculpt_paint/paint_image_2d.c | 2 +- .../editors/sculpt_paint/paint_image_proj.c | 14 ++++---------- source/blender/editors/sculpt_paint/paint_intern.h | 6 +++--- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 100e72e18ed..3b364f5674b 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -189,7 +189,7 @@ void UI_view2d_listview_visible_cells(struct View2D *v2d, short columnwidth, sho int *row_min, int *row_max); /* coordinate conversion */ -void UI_view2d_region_to_view(struct View2D *v2d, int x, int y, float *viewx, float *viewy); +void UI_view2d_region_to_view(struct View2D *v2d, float x, float y, float *viewx, float *viewy); void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *regionx, int *regiony); void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, int *regionx, int *region_y); diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 74047abb17e..766a91df5db 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -1961,7 +1961,7 @@ void UI_view2d_listview_visible_cells(View2D *v2d, short columnwidth, short rowh * - x,y = coordinates to convert * - viewx,viewy = resultant coordinates */ -void UI_view2d_region_to_view(View2D *v2d, int x, int y, float *r_viewx, float *r_viewy) +void UI_view2d_region_to_view(View2D *v2d, float x, float y, float *r_viewx, float *r_viewy) { float div, ofs; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 92b82d84c38..6547b336119 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -446,7 +446,7 @@ typedef struct PaintOperation { void *custom_paint; - int prevmouse[2]; + float prevmouse[2]; double starttime; ViewContext vc; @@ -545,13 +545,11 @@ static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, Po float startsize = BKE_brush_size_get(scene, brush); float startalpha = BKE_brush_alpha_get(scene, brush); - float mousef[2]; + float mouse[2]; float pressure; - int mouse[2], redraw, eraser; + int redraw, eraser; - RNA_float_get_array(itemptr, "mouse", mousef); - mouse[0] = (int)(mousef[0]); - mouse[1] = (int)(mousef[1]); + RNA_float_get_array(itemptr, "mouse", mouse); pressure = RNA_float_get(itemptr, "pressure"); eraser = RNA_boolean_get(itemptr, "pen_flip"); diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index 48a23641bdb..956dcc858f8 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -1016,7 +1016,7 @@ static void paint_2d_canvas_free(ImagePaintState *s) image_undo_remove_masks(); } -int paint_2d_stroke(void *ps, const int prev_mval[2], const int mval[2], int eraser) +int paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int eraser) { float newuv[2], olduv[2]; int redraw = 0; diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 0aef1ccf9fe..d7cea395409 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -3206,7 +3206,7 @@ static void project_paint_begin(ProjPaintState *ps) BLI_linklist_free(image_LinkList, NULL); } -static void paint_proj_begin_clone(ProjPaintState *ps, const int mouse[2]) +static void paint_proj_begin_clone(ProjPaintState *ps, const float mouse[2]) { /* setup clone offset */ if (ps->tool == PAINT_TOOL_CLONE) { @@ -4044,23 +4044,17 @@ static int project_paint_op(void *state, const float lastpos[2], const float pos } -int paint_proj_stroke(bContext *C, void *pps, const int prevmval_i[2], const int mval_i[2]) +int paint_proj_stroke(bContext *C, void *pps, const float prev_pos[2], const float pos[2]) { ProjPaintState *ps = pps; int a, redraw; - float pos[2], prev_pos[2]; - - pos[0] = (float)(mval_i[0]); - pos[1] = (float)(mval_i[1]); - - prev_pos[0] = (float)(prevmval_i[0]); - prev_pos[1] = (float)(prevmval_i[1]); /* clone gets special treatment here to avoid going through image initialization */ if (ps->tool == PAINT_TOOL_CLONE && ps->mode == BRUSH_STROKE_INVERT) { Scene *scene = ps->scene; View3D *v3d = ps->v3d; float *cursor = give_cursor(scene, v3d); + int mval_i[2] = {(int)pos[0], (int)pos[1]}; view3d_operator_needs_opengl(C); @@ -4160,7 +4154,7 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int return; } -void *paint_proj_new_stroke(bContext *C, Object *ob, const int mouse[2], int mode) +void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int mode) { ProjPaintState *ps = MEM_callocN(sizeof(ProjPaintState), "ProjectionPaintState"); project_state_init(C, ob, ps, mode); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 0085998bd58..a4230439737 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -141,9 +141,9 @@ int get_imapaint_zoom(struct bContext *C, float *zoomx, float *zoomy); void *paint_2d_new_stroke(struct bContext *, struct wmOperator *); void paint_2d_redraw(const bContext *C, void *ps, int final); void paint_2d_stroke_done(void *ps); -int paint_2d_stroke(void *ps, const int prev_mval[2], const int mval[2], int eraser); -void *paint_proj_new_stroke(struct bContext *C, struct Object *ob, const int mouse[2], int mode); -int paint_proj_stroke(struct bContext *C, void *ps, const int prevmval_i[2], const int mval_i[2]); +int paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int eraser); +void *paint_proj_new_stroke(struct bContext *C, struct Object *ob, const float mouse[2], int mode); +int paint_proj_stroke(struct bContext *C, void *ps, const float prevmval_i[2], const float mval_i[2]); void paint_proj_stroke_done(void *ps); void paint_brush_init_tex(struct Brush *brush); void paint_brush_exit_tex(struct Brush *brush);