diff options
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_paint.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_paint.c | 141 |
1 files changed, 70 insertions, 71 deletions
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index c07f0db7114..5909c4fc270 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -278,15 +278,11 @@ static void gp_stroke_convertcoords(tGPsdata *p, const int mval[2], float out[3] gp_get_3d_reference(p, rvec); /* method taken from editview.c - mouse_cursor() */ - /* TODO, use ED_view3d_project_float_global */ - if (ED_view3d_project_int_global(p->ar, rvec, mval_prj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { - VECSUB2D(mval_f, mval_prj, mval); - ED_view3d_win_to_delta(p->ar, mval_f, dvec); - sub_v3_v3v3(out, rvec, dvec); - } - else { - zero_v3(out); - } + ED_view3d_project_int_noclip(p->ar, rvec, mval_prj); + + VECSUB2D(mval_f, mval_prj, mval); + ED_view3d_win_to_delta(p->ar, mval_f, dvec); + sub_v3_v3v3(out, rvec, dvec); } } @@ -395,10 +391,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const int mval[2], float pressure) pts = &gps->points[gps->totpoints - 1]; - /* special case for poly lines: normally, - * depth is needed only when creating new stroke from buffer, - * but poly lines are converting to stroke instantly, - * so initialize depth buffer before converting coordinates + /* special case for poly lines: normally, depth is needed only when creating new stroke from buffer, + * but poly lines are converting to stroke instantly, so initialize depth buffer before converting coordinates */ if (gpencil_project_check(p)) { View3D *v3d = p->sa->spacedata.first; @@ -794,37 +788,6 @@ static short gp_stroke_eraser_strokeinside(const int mval[], const int UNUSED(mv return 0; } -static void gp_point_to_xy(ARegion *ar, View2D *v2d, rctf *subrect, bGPDstroke *gps, bGPDspoint *pt, - int *r_x, int *r_y) -{ - int xyval[2]; - - if (gps->flag & GP_STROKE_3DSPACE) { - if (ED_view3d_project_int_global(ar, &pt->x, xyval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { - *r_x = xyval[0]; - *r_y = xyval[1]; - } - else { - *r_x = V2D_IS_CLIPPED; - *r_y = V2D_IS_CLIPPED; - } - } - else if (gps->flag & GP_STROKE_2DSPACE) { - UI_view2d_view_to_region(v2d, pt->x, pt->y, r_x, r_y); - } - else { - if (subrect == NULL) { /* normal 3D view */ - *r_x = (int)(pt->x / 100 * ar->winx); - *r_y = (int)(pt->y / 100 * ar->winy); - } - else { /* camera view, use subrect */ - *r_x = (int)((pt->x / 100) * BLI_rctf_size_x(subrect)) + subrect->xmin; - *r_y = (int)((pt->y / 100) * BLI_rctf_size_y(subrect)) + subrect->ymin; - } - } -} - - /* eraser tool - evaluation per stroke */ // TODO: this could really do with some optimization (KD-Tree/BVH?) static void gp_stroke_eraser_dostroke(tGPsdata *p, @@ -833,6 +796,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, { bGPDspoint *pt1, *pt2; int x0 = 0, y0 = 0, x1 = 0, y1 = 0; + int xyval[2]; int i; if (gps->totpoints == 0) { @@ -842,11 +806,28 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, BLI_freelinkN(&gpf->strokes, gps); } else if (gps->totpoints == 1) { - gp_point_to_xy(p->ar, p->v2d, p->subrect, gps, gps->points, &x0, &y0); + /* get coordinates */ + if (gps->flag & GP_STROKE_3DSPACE) { + ED_view3d_project_int(p->ar, &gps->points->x, xyval); + x0 = xyval[0]; + y0 = xyval[1]; + } + else if (gps->flag & GP_STROKE_2DSPACE) { + UI_view2d_view_to_region(p->v2d, gps->points->x, gps->points->y, &x0, &y0); + } + else { + if (p->subrect == NULL) { /* normal 3D view */ + x0 = (int)(gps->points->x / 100 * p->ar->winx); + y0 = (int)(gps->points->y / 100 * p->ar->winy); + } + else { /* camera view, use subrect */ + x0 = (int)((gps->points->x / 100) * BLI_rctf_size_x(p->subrect)) + p->subrect->xmin; + y0 = (int)((gps->points->y / 100) * BLI_rctf_size_y(p->subrect)) + p->subrect->ymin; + } + } /* do boundbox check first */ - - if ((!ELEM(V2D_IS_CLIPPED, x0, y0)) && BLI_rcti_isect_pt(rect, x0, y0)) { + if (BLI_rcti_isect_pt(rect, x0, y0)) { /* only check if point is inside */ if (((x0 - mval[0]) * (x0 - mval[0]) + (y0 - mval[1]) * (y0 - mval[1])) <= rad * rad) { /* free stroke */ @@ -863,13 +844,39 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, /* get points to work with */ pt1 = gps->points + i; pt2 = gps->points + i + 1; - - gp_point_to_xy(p->ar, p->v2d, p->subrect, gps, pt1, &x0, &y0); - gp_point_to_xy(p->ar, p->v2d, p->subrect, gps, pt2, &x1, &y1); - + + /* get coordinates */ + if (gps->flag & GP_STROKE_3DSPACE) { + ED_view3d_project_int(p->ar, &pt1->x, xyval); + x0 = xyval[0]; + y0 = xyval[1]; + + ED_view3d_project_int(p->ar, &pt2->x, xyval); + x1 = xyval[0]; + y1 = xyval[1]; + } + else if (gps->flag & GP_STROKE_2DSPACE) { + UI_view2d_view_to_region(p->v2d, pt1->x, pt1->y, &x0, &y0); + + UI_view2d_view_to_region(p->v2d, pt2->x, pt2->y, &x1, &y1); + } + else { + if (p->subrect == NULL) { /* normal 3D view */ + x0 = (int)(pt1->x / 100 * p->ar->winx); + y0 = (int)(pt1->y / 100 * p->ar->winy); + x1 = (int)(pt2->x / 100 * p->ar->winx); + y1 = (int)(pt2->y / 100 * p->ar->winy); + } + else { /* camera view, use subrect */ + x0 = (int)((pt1->x / 100) * BLI_rctf_size_x(p->subrect)) + p->subrect->xmin; + y0 = (int)((pt1->y / 100) * BLI_rctf_size_y(p->subrect)) + p->subrect->ymin; + x1 = (int)((pt2->x / 100) * BLI_rctf_size_x(p->subrect)) + p->subrect->xmin; + y1 = (int)((pt2->y / 100) * BLI_rctf_size_y(p->subrect)) + p->subrect->ymin; + } + } + /* check that point segment of the boundbox of the eraser stroke */ - if (((!ELEM(V2D_IS_CLIPPED, x0, y0)) && BLI_rcti_isect_pt(rect, x0, y0)) || - ((!ELEM(V2D_IS_CLIPPED, x1, y1)) && BLI_rcti_isect_pt(rect, x1, y1))) { + if (BLI_rcti_isect_pt(rect, x0, y0) || BLI_rcti_isect_pt(rect, x1, y1)) { /* check if point segment of stroke had anything to do with * eraser region (either within stroke painted, or on its lines) * - this assumes that linewidth is irrelevant @@ -1118,7 +1125,7 @@ static void gp_paint_initstroke(tGPsdata *p, short paintmode) /* get active layer (or add a new one if non-existent) */ p->gpl = gpencil_layer_getactive(p->gpd); if (p->gpl == NULL) { - p->gpl = gpencil_layer_addnew(p->gpd, "GP_Layer", 1); + p->gpl = gpencil_layer_addnew(p->gpd); if (p->custom_color[3]) copy_v3_v3(p->gpl->color, p->custom_color); @@ -1398,17 +1405,13 @@ static void gpencil_draw_status_indicators(tGPsdata *p) /* print status info */ switch (p->paintmode) { case GP_PAINTMODE_ERASER: - ED_area_headerprint(p->sa, - "Grease Pencil Erase Session: Hold and drag LMB or RMB to erase |" - " ESC/Enter to end"); + ED_area_headerprint(p->sa, "Grease Pencil Erase Session: Hold and drag LMB or RMB to erase | ESC/Enter to end"); break; case GP_PAINTMODE_DRAW_STRAIGHT: - ED_area_headerprint(p->sa, "Grease Pencil Line Session: Hold and drag LMB to draw | " - "ESC/Enter to end"); + ED_area_headerprint(p->sa, "Grease Pencil Line Session: Hold and drag LMB to draw | ESC/Enter to end"); break; case GP_PAINTMODE_DRAW: - ED_area_headerprint(p->sa, "Grease Pencil Freehand Session: Hold and drag LMB to draw | " - "ESC/Enter to end"); + ED_area_headerprint(p->sa, "Grease Pencil Freehand Session: Hold and drag LMB to draw | ESC/Enter to end"); break; default: /* unhandled future cases */ @@ -1595,7 +1598,7 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op) gpencil_draw_exit(C, op); /* refreshes */ - WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL); + WM_event_add_notifier(C, NC_SCREEN | ND_GPENCIL | NA_EDITED, NULL); // XXX need a nicer one that will work /* done */ return OPERATOR_FINISHED; @@ -1656,7 +1659,7 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, wmEvent *event) //printf("\tGP - hotkey invoked... waiting for click-drag\n"); } - WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL); + WM_event_add_notifier(C, NC_SCREEN | ND_GPENCIL, NULL); /* add a modal handler for this operator, so that we can then draw continuous strokes */ WM_event_add_modal_handler(C, op); return OPERATOR_RUNNING_MODAL; @@ -1684,8 +1687,7 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op) //printf("\t\tGP - start stroke\n"); /* we may need to set up paint env again if we're resuming */ - /* XXX: watch it with the paintmode! in future, - * it'd be nice to allow changing paint-mode when in sketching-sessions */ + /* XXX: watch it with the paintmode! in future, it'd be nice to allow changing paint-mode when in sketching-sessions */ /* XXX: with tablet events, we may event want to check for eraser here, for nicer tablet support */ if (gp_session_initdata(C, p)) @@ -1770,7 +1772,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, wmEvent *event) estate = OPERATOR_RUNNING_MODAL; /* stroke could be smoothed, send notifier to refresh screen */ - WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL); + WM_event_add_notifier(C, NC_SCREEN | ND_GPENCIL | NA_EDITED, NULL); } else { //printf("\t\tGP - end of stroke + op\n"); @@ -1860,7 +1862,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, wmEvent *event) case OPERATOR_FINISHED: /* one last flush before we're done */ gpencil_draw_exit(C, op); - WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL); + WM_event_add_notifier(C, NC_SCREEN | ND_GPENCIL | NA_EDITED, NULL); // XXX need a nicer one that will work break; case OPERATOR_CANCELLED: @@ -1869,10 +1871,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, wmEvent *event) case OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH: /* event doesn't need to be handled */ -#if 0 - printf("unhandled event -> %d (mmb? = %d | mmv? = %d)\n", - event->type, event->type == MIDDLEMOUSE, event->type==MOUSEMOVE); -#endif + //printf("unhandled event -> %d (mmb? = %d | mmv? = %d)\n", event->type, event->type == MIDDLEMOUSE, event->type==MOUSEMOVE); break; } |