From 9ae0e585b0aab466c978ec1a55c824d902faa3b4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 21 Apr 2014 16:47:16 +1000 Subject: View2d: API Cleanup for view<->region conversion View2D had some inconsistencies making it error prone in some cases. - Inconstant checking for NULL x/y args. Disallow NULL args for x/y destination pointers, instead add: - UI_view2d_region_to_view_x/y - UI_view2d_view_to_region_x/y - '_no_clip' suffix wasn't always used for non-clipping conversion, switch it around and use a '_clip' suffix for all funcs that clip. - UI_view2d_text_cache_add now clips before adding cache. - '_clip' funcs return a bool to quickly check if its in the view. - add conversion for rectangles, since this is a common task: - UI_view2d_view_to_region_rcti - UI_view2d_region_to_view_rctf --- source/blender/editors/animation/anim_markers.c | 21 +- source/blender/editors/animation/anim_ops.c | 6 +- source/blender/editors/gpencil/gpencil_edit.c | 2 +- source/blender/editors/gpencil/gpencil_paint.c | 2 +- source/blender/editors/include/UI_view2d.h | 21 +- .../blender/editors/interface/interface_regions.c | 5 +- source/blender/editors/interface/view2d.c | 216 +++++++++++++++------ source/blender/editors/interface/view2d_ops.c | 6 +- source/blender/editors/mask/mask_draw.c | 2 +- source/blender/editors/screen/area.c | 4 +- .../blender/editors/sculpt_paint/paint_image_2d.c | 4 +- .../blender/editors/space_action/action_select.c | 4 +- source/blender/editors/space_clip/clip_draw.c | 14 +- source/blender/editors/space_clip/clip_editor.c | 4 +- source/blender/editors/space_clip/clip_graph_ops.c | 12 +- source/blender/editors/space_clip/space_clip.c | 2 +- source/blender/editors/space_file/file_ops.c | 16 +- source/blender/editors/space_graph/graph_select.c | 18 +- source/blender/editors/space_image/image_draw.c | 8 +- source/blender/editors/space_image/image_edit.c | 6 +- source/blender/editors/space_info/info_report.c | 9 - source/blender/editors/space_nla/nla_select.c | 8 +- source/blender/editors/space_node/node_select.c | 11 +- .../blender/editors/space_outliner/outliner_edit.c | 4 +- .../editors/space_outliner/outliner_select.c | 9 +- .../editors/space_outliner/outliner_tools.c | 2 +- .../editors/space_sequencer/sequencer_edit.c | 8 +- .../editors/space_sequencer/sequencer_select.c | 14 +- source/blender/editors/transform/transform.c | 14 +- source/blender/editors/transform/transform_snap.c | 5 +- source/blender/editors/uvedit/uvedit_ops.c | 11 +- source/blender/makesrna/intern/rna_screen.c | 4 +- source/blender/windowmanager/WM_api.h | 1 + source/blender/windowmanager/intern/wm_operators.c | 7 + 34 files changed, 278 insertions(+), 202 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 9cba7d04c3e..1def5339b23 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -1024,22 +1024,18 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool ARegion *ar = CTX_wm_region(C); View2D *v2d = UI_view2d_fromcontext(C); float viewx; - int x, y, cfra; + int x, cfra; if (markers == NULL) return OPERATOR_PASS_THROUGH; x = event->x - ar->winrct.xmin; - y = event->y - ar->winrct.ymin; - UI_view2d_region_to_view(v2d, x, y, &viewx, NULL); + viewx = UI_view2d_region_to_view_x(v2d, x); cfra = ED_markers_find_nearest_marker_time(markers, viewx); - if (extend) - select_timeline_marker_frame(markers, cfra, 1); - else - select_timeline_marker_frame(markers, cfra, 0); + select_timeline_marker_frame(markers, cfra, extend); #ifdef DURIAN_CAMERA_SWITCH @@ -1150,22 +1146,19 @@ static int ed_marker_border_select_exec(bContext *C, wmOperator *op) View2D *v2d = UI_view2d_fromcontext(C); ListBase *markers = ED_context_get_markers(C); TimeMarker *marker; - float xminf, xmaxf, yminf, ymaxf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); bool extend = RNA_boolean_get(op->ptr, "extend"); - rcti rect; + rctf rect; - WM_operator_properties_border_to_rcti(op, &rect); - - UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin, &xminf, &yminf); - UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax, &xmaxf, &ymaxf); + WM_operator_properties_border_to_rctf(op, &rect); + UI_view2d_region_to_view_rctf(v2d, &rect, &rect); if (markers == NULL) return 0; /* XXX marker context */ for (marker = markers->first; marker; marker = marker->next) { - if ((marker->frame > xminf) && (marker->frame <= xmaxf)) { + if (BLI_rctf_isect_x(&rect, marker->frame)) { switch (gesture_mode) { case GESTURE_MODAL_SELECT: marker->flag |= SELECT; diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index 072b4c4c201..d9a5d713480 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -124,7 +124,7 @@ static int frame_from_event(bContext *C, const wmEvent *event) int frame; /* convert from region coordinates to View2D 'tot' space */ - UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &viewx, NULL); + viewx = UI_view2d_region_to_view_x(®ion->v2d, event->mval[0]); /* round result to nearest int (frames are ints!) */ frame = iroundf(viewx); @@ -212,8 +212,8 @@ static int previewrange_define_exec(bContext *C, wmOperator *op) WM_operator_properties_border_to_rcti(op, &rect); /* convert min/max values to frames (i.e. region to 'tot' rect) */ - UI_view2d_region_to_view(&ar->v2d, rect.xmin, 0, &sfra, NULL); - UI_view2d_region_to_view(&ar->v2d, rect.xmax, 0, &efra, NULL); + sfra = UI_view2d_region_to_view_x(&ar->v2d, rect.xmin); + efra = UI_view2d_region_to_view_x(&ar->v2d, rect.xmax); /* set start/end frames for preview-range * - must clamp within allowable limits diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 4a688f11767..d5598718736 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -457,7 +457,7 @@ static void gp_strokepoint_convertcoords(bContext *C, bGPDstroke *gps, bGPDspoin /* get screen coordinate */ if (gps->flag & GP_STROKE_2DSPACE) { View2D *v2d = &ar->v2d; - UI_view2d_to_region_float(v2d, pt->x, pt->y, &mvalf[0], &mvalf[1]); + UI_view2d_view_to_region_fl(v2d, pt->x, pt->y, &mvalf[0], &mvalf[1]); } else { if (subrect) { diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 6bbaca73eb5..2f941142d9e 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -907,7 +907,7 @@ static void gp_point_to_xy(ARegion *ar, View2D *v2d, rctf *subrect, bGPDstroke * } } else if (gps->flag & GP_STROKE_2DSPACE) { - UI_view2d_view_to_region(v2d, pt->x, pt->y, r_x, r_y); + UI_view2d_view_to_region_clip(v2d, pt->x, pt->y, r_x, r_y); } else { if (subrect == NULL) { /* normal 3D view */ diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index b087469887b..95514149e90 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -34,6 +34,8 @@ #ifndef __UI_VIEW2D_H__ #define __UI_VIEW2D_H__ +#include "BLI_compiler_attrs.h" + /* ------------------------------------------ */ /* Settings and Defines: */ @@ -190,10 +192,19 @@ void UI_view2d_listview_visible_cells(struct View2D *v2d, float columnwidth, flo int *row_min, int *row_max); /* coordinate conversion */ -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); -void UI_view2d_to_region_float(struct View2D *v2d, float x, float y, float *regionx, float *regiony); +float UI_view2d_region_to_view_x(struct View2D *v2d, float x); +float UI_view2d_region_to_view_y(struct View2D *v2d, float y); +void UI_view2d_region_to_view(struct View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL(); +void UI_view2d_region_to_view_rctf(struct View2D *v2d, const struct rctf *rect_src, struct rctf *rect_dst) ATTR_NONNULL(); + +float UI_view2d_view_to_region_x(struct View2D *v2d, float x); +float UI_view2d_view_to_region_y(struct View2D *v2d, float y); +bool UI_view2d_view_to_region_clip(struct View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL(); + +void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL(); +void UI_view2d_view_to_region_fl(struct View2D *v2d, float x, float y, float *r_region_x, float *r_region_y) ATTR_NONNULL(); +void UI_view2d_view_to_region_rcti(struct View2D *v2d, const struct rctf *rect_src, struct rcti *rect_dst) ATTR_NONNULL(); +bool UI_view2d_view_to_region_rcti_clip(struct View2D *v2d, const struct rctf *rect_src, struct rcti *rect_dst) ATTR_NONNULL(); /* utilities */ struct View2D *UI_view2d_fromcontext(const struct bContext *C); @@ -211,7 +222,7 @@ short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, /* cached text drawing in v2d, to allow pixel-aligned draw as post process */ void UI_view2d_text_cache_add(struct View2D *v2d, float x, float y, const char *str, size_t str_len, const char col[4]); -void UI_view2d_text_cache_rectf(struct View2D *v2d, const struct rctf *rect, const char *str, size_t str_len, const char col[4]); +void UI_view2d_text_cache_rectf(struct View2D *v2d, const struct rctf *rect_view, const char *str, size_t str_len, const char col[4]); void UI_view2d_text_cache_draw(struct ARegion *ar); /* operators */ diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index f34fc3c9135..3b180078e5f 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1092,8 +1092,7 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) BLI_rcti_rctf_copy(&rect_i, &rect_fl); if (butregion->v2d.cur.xmin != butregion->v2d.cur.xmax) { - UI_view2d_to_region_no_clip(&butregion->v2d, rect_fl.xmin, rect_fl.ymin, &rect_i.xmin, &rect_i.ymin); - UI_view2d_to_region_no_clip(&butregion->v2d, rect_fl.xmax, rect_fl.ymax, &rect_i.xmax, &rect_i.ymax); + UI_view2d_view_to_region_rcti(&butregion->v2d, &rect_fl, &rect_i); } BLI_rcti_translate(&rect_i, butregion->winrct.xmin, butregion->winrct.ymin); @@ -1118,7 +1117,7 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) int newy1 = but->rect.ymax + ofsy; if (butregion->v2d.cur.xmin != butregion->v2d.cur.xmax) - UI_view2d_to_region_no_clip(&butregion->v2d, 0, newy1, NULL, &newy1); + newy1 = UI_view2d_view_to_region_y(&butregion->v2d, newy1); newy1 += butregion->winrct.ymin; diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 9ce21e70eb4..9bbf6e77cd8 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -70,6 +70,35 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, int resize, int mask_ /* *********************************************************************** */ +BLI_INLINE int clamp_float_to_int(const float f) +{ + const float min = INT_MIN; + const float max = INT_MAX; + + if (UNLIKELY(f < min)) { + return min; + } + else if (UNLIKELY(f > max)) { + return max; + } + else { + return (int)f; + } +} + +/** + * use instead of #BLI_rcti_rctf_copy so we have consistent behavior + * with users of #clamp_float_to_int. + */ +BLI_INLINE void clamp_rctf_to_rcti(rcti *dst, const rctf *src) +{ + dst->xmin = clamp_float_to_int(src->xmin); + dst->xmax = clamp_float_to_int(src->xmax); + dst->ymin = clamp_float_to_int(src->ymin); + dst->ymax = clamp_float_to_int(src->ymax); +} + + /* XXX still unresolved: scrolls hide/unhide vs region mask handling */ /* XXX there's V2D_SCROLL_HORIZONTAL_HIDE and V2D_SCROLL_HORIZONTAL_FULLR ... */ @@ -1952,7 +1981,7 @@ void UI_view2d_listview_visible_cells(View2D *v2d, float columnwidth, float rowh /* min */ UI_view2d_listview_view_to_cell(v2d, columnwidth, rowheight, startx, starty, v2d->cur.xmin, v2d->cur.ymin, column_min, row_min); - + /* max*/ UI_view2d_listview_view_to_cell(v2d, columnwidth, rowheight, startx, starty, v2d->cur.xmax, v2d->cur.ymax, column_max, row_max); @@ -1962,28 +1991,44 @@ void UI_view2d_listview_visible_cells(View2D *v2d, float columnwidth, float rowh /* *********************************************************************** */ /* Coordinate Conversions */ +float UI_view2d_region_to_view_x(struct View2D *v2d, float x) +{ + return (v2d->cur.xmin + (BLI_rctf_size_x(&v2d->cur) * (x - v2d->mask.xmin) / BLI_rcti_size_x(&v2d->mask))); +} +float UI_view2d_region_to_view_y(struct View2D *v2d, float y) +{ + return (v2d->cur.ymin + (BLI_rctf_size_y(&v2d->cur) * (y - v2d->mask.ymin) / BLI_rcti_size_y(&v2d->mask))); +} + /* Convert from screen/region space to 2d-View space * * - x,y = coordinates to convert * - viewx,viewy = resultant coordinates */ -void UI_view2d_region_to_view(View2D *v2d, float x, float y, float *r_viewx, float *r_viewy) +void UI_view2d_region_to_view(View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) { - float div, ofs; + *r_view_x = UI_view2d_region_to_view_x(v2d, x); + *r_view_y = UI_view2d_region_to_view_y(v2d, y); +} - if (r_viewx) { - div = (float)BLI_rcti_size_x(&v2d->mask); - ofs = (float)v2d->mask.xmin; - - *r_viewx = v2d->cur.xmin + BLI_rctf_size_x(&v2d->cur) * ((float)x - ofs) / div; - } +void UI_view2d_region_to_view_rctf(View2D *v2d, const rctf *rect_src, rctf *rect_dst) +{ + const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)}; + const float mask_size[2] = {BLI_rcti_size_x(&v2d->mask), BLI_rcti_size_y(&v2d->mask)}; - if (r_viewy) { - div = (float)BLI_rcti_size_y(&v2d->mask); - ofs = (float)v2d->mask.ymin; - - *r_viewy = v2d->cur.ymin + BLI_rctf_size_y(&v2d->cur) * ((float)y - ofs) / div; - } + rect_dst->xmin = (v2d->cur.xmin + (cur_size[0] * (rect_src->xmin - v2d->mask.xmin) / mask_size[0])); + rect_dst->xmax = (v2d->cur.xmin + (cur_size[0] * (rect_src->xmax - v2d->mask.xmin) / mask_size[0])); + rect_dst->ymin = (v2d->cur.ymin + (cur_size[1] * (rect_src->ymin - v2d->mask.ymin) / mask_size[1])); + rect_dst->ymax = (v2d->cur.ymin + (cur_size[1] * (rect_src->ymax - v2d->mask.ymin) / mask_size[1])); +} + +float UI_view2d_view_to_region_x(View2D *v2d, float x) +{ + return (v2d->mask.xmin + (((x - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur)) * BLI_rcti_size_x(&v2d->mask))); +} +float UI_view2d_view_to_region_y(View2D *v2d, float y) +{ + return (v2d->mask.ymin + (((y - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur)) * BLI_rcti_size_y(&v2d->mask))); } /* Convert from 2d-View space to screen/region space @@ -1992,24 +2037,24 @@ void UI_view2d_region_to_view(View2D *v2d, float x, float y, float *r_viewx, flo * - x,y = coordinates to convert * - regionx,regiony = resultant coordinates */ -void UI_view2d_view_to_region(View2D *v2d, float x, float y, int *regionx, int *regiony) +bool UI_view2d_view_to_region_clip(View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) { - /* set initial value in case coordinate lies outside of bounds */ - if (regionx) - *regionx = V2D_IS_CLIPPED; - if (regiony) - *regiony = V2D_IS_CLIPPED; - /* express given coordinates as proportional values */ x = (x - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur); y = (y - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur); /* check if values are within bounds */ if ((x >= 0.0f) && (x <= 1.0f) && (y >= 0.0f) && (y <= 1.0f)) { - if (regionx) - *regionx = (int)(v2d->mask.xmin + x * BLI_rcti_size_x(&v2d->mask)); - if (regiony) - *regiony = (int)(v2d->mask.ymin + y * BLI_rcti_size_y(&v2d->mask)); + *r_region_x = (int)(v2d->mask.xmin + (x * BLI_rcti_size_x(&v2d->mask))); + *r_region_y = (int)(v2d->mask.ymin + (y * BLI_rcti_size_y(&v2d->mask))); + + return true; + } + else { + /* set initial value in case coordinate lies outside of bounds */ + *r_region_x = *r_region_y = V2D_IS_CLIPPED; + + return false; } } @@ -2019,38 +2064,86 @@ void UI_view2d_view_to_region(View2D *v2d, float x, float y, int *regionx, int * * - x,y = coordinates to convert * - regionx,regiony = resultant coordinates */ -void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, int *regionx, int *regiony) +void UI_view2d_view_to_region(View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) { /* step 1: express given coordinates as proportional values */ x = (x - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur); y = (y - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur); - + /* step 2: convert proportional distances to screen coordinates */ - x = v2d->mask.xmin + x * BLI_rcti_size_x(&v2d->mask); - y = v2d->mask.ymin + y * BLI_rcti_size_y(&v2d->mask); - + x = v2d->mask.xmin + (x * BLI_rcti_size_x(&v2d->mask)); + y = v2d->mask.ymin + (y * BLI_rcti_size_y(&v2d->mask)); + /* although we don't clamp to lie within region bounds, we must avoid exceeding size of ints */ - if (regionx) { - if (x < INT_MIN) *regionx = INT_MIN; - else if (x > INT_MAX) *regionx = INT_MAX; - else *regionx = (int)x; - } - if (regiony) { - if (y < INT_MIN) *regiony = INT_MIN; - else if (y > INT_MAX) *regiony = INT_MAX; - else *regiony = (int)y; - } + *r_region_x = clamp_float_to_int(x); + *r_region_y = clamp_float_to_int(y); } -void UI_view2d_to_region_float(View2D *v2d, float x, float y, float *regionx, float *regiony) +void UI_view2d_view_to_region_fl(View2D *v2d, float x, float y, float *r_region_x, float *r_region_y) { /* express given coordinates as proportional values */ x = (x - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur); y = (y - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur); /* convert proportional distances to screen coordinates */ - *regionx = v2d->mask.xmin + x * BLI_rcti_size_x(&v2d->mask); - *regiony = v2d->mask.ymin + y * BLI_rcti_size_y(&v2d->mask); + *r_region_x = v2d->mask.xmin + (x * BLI_rcti_size_x(&v2d->mask)); + *r_region_y = v2d->mask.ymin + (y * BLI_rcti_size_y(&v2d->mask)); +} + +void UI_view2d_view_to_region_rcti(View2D *v2d, const rctf *rect_src, rcti *rect_dst) +{ + const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)}; + const float mask_size[2] = {BLI_rcti_size_x(&v2d->mask), BLI_rcti_size_y(&v2d->mask)}; + rctf rect_tmp; + + /* step 1: express given coordinates as proportional values */ + rect_tmp.xmin = (rect_src->xmin - v2d->cur.xmin) / cur_size[0]; + rect_tmp.xmax = (rect_src->xmax - v2d->cur.xmin) / cur_size[0]; + rect_tmp.ymin = (rect_src->ymin - v2d->cur.ymin) / cur_size[1]; + rect_tmp.ymax = (rect_src->ymax - v2d->cur.ymin) / cur_size[1]; + + + /* step 2: convert proportional distances to screen coordinates */ + rect_tmp.xmin = v2d->mask.xmin + (rect_tmp.xmin * mask_size[0]); + rect_tmp.xmax = v2d->mask.xmin + (rect_tmp.xmax * mask_size[0]); + rect_tmp.ymin = v2d->mask.ymin + (rect_tmp.ymin * mask_size[1]); + rect_tmp.ymax = v2d->mask.ymin + (rect_tmp.ymax * mask_size[1]); + + clamp_rctf_to_rcti(rect_dst, &rect_tmp); +} + +bool UI_view2d_view_to_region_rcti_clip(View2D *v2d, const rctf *rect_src, rcti *rect_dst) +{ + const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)}; + const float mask_size[2] = {BLI_rcti_size_x(&v2d->mask), BLI_rcti_size_y(&v2d->mask)}; + rctf rect_tmp; + + BLI_assert(rect_src->xmin <= rect_src->xmax && rect_src->ymin <= rect_src->ymax); + + /* step 1: express given coordinates as proportional values */ + rect_tmp.xmin = (rect_src->xmin - v2d->cur.xmin) / cur_size[0]; + rect_tmp.xmax = (rect_src->xmax - v2d->cur.xmin) / cur_size[0]; + rect_tmp.ymin = (rect_src->ymin - v2d->cur.ymin) / cur_size[1]; + rect_tmp.ymax = (rect_src->ymax - v2d->cur.ymin) / cur_size[1]; + + if (((rect_tmp.xmax < 0.0f) || (rect_tmp.xmin > 1.0f) || + (rect_tmp.ymax < 0.0f) || (rect_tmp.ymin > 1.0f)) == 0) + { + /* step 2: convert proportional distances to screen coordinates */ + rect_tmp.xmin = v2d->mask.xmin + (rect_tmp.xmin * mask_size[0]); + rect_tmp.xmax = v2d->mask.ymin + (rect_tmp.xmax * mask_size[0]); + rect_tmp.ymin = v2d->mask.ymin + (rect_tmp.ymin * mask_size[1]); + rect_tmp.ymax = v2d->mask.ymin + (rect_tmp.ymax * mask_size[1]); + + clamp_rctf_to_rcti(rect_dst, &rect_tmp); + + return true; + } + else { + rect_dst->xmin = rect_dst->xmax = rect_dst->ymin = rect_dst->ymax = V2D_IS_CLIPPED; + + return false; + } } /* *********************************************************************** */ @@ -2199,9 +2292,7 @@ void UI_view2d_text_cache_add(View2D *v2d, float x, float y, const char *str, si BLI_assert(str_len == strlen(str)); - UI_view2d_view_to_region(v2d, x, y, mval, mval + 1); - - if (mval[0] != V2D_IS_CLIPPED && mval[1] != V2D_IS_CLIPPED) { + if (UI_view2d_view_to_region_clip(v2d, x, y, &mval[0], &mval[1])) { int alloc_len = str_len + 1; View2DString *v2s; @@ -2225,30 +2316,33 @@ void UI_view2d_text_cache_add(View2D *v2d, float x, float y, const char *str, si } /* no clip (yet) */ -void UI_view2d_text_cache_rectf(View2D *v2d, const rctf *rect, const char *str, size_t str_len, const char col[4]) +void UI_view2d_text_cache_rectf(View2D *v2d, const rctf *rect_view, const char *str, size_t str_len, const char col[4]) { - int alloc_len = str_len; - View2DString *v2s; + rcti rect; BLI_assert(str_len == strlen(str)); - if (g_v2d_strings_arena == NULL) { - g_v2d_strings_arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 14), __func__); - } + if (UI_view2d_view_to_region_rcti_clip(v2d, rect_view, &rect)) { + int alloc_len = str_len + 1; + View2DString *v2s; + + if (g_v2d_strings_arena == NULL) { + g_v2d_strings_arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 14), __func__); + } - v2s = BLI_memarena_alloc(g_v2d_strings_arena, sizeof(View2DString) + alloc_len); + v2s = BLI_memarena_alloc(g_v2d_strings_arena, sizeof(View2DString) + alloc_len); - BLI_LINKS_PREPEND(g_v2d_strings, v2s); + BLI_LINKS_PREPEND(g_v2d_strings, v2s); - v2s->col.pack = *((int *)col); + v2s->col.pack = *((int *)col); - UI_view2d_to_region_no_clip(v2d, rect->xmin, rect->ymin, &v2s->rect.xmin, &v2s->rect.ymin); - UI_view2d_to_region_no_clip(v2d, rect->xmax, rect->ymax, &v2s->rect.xmax, &v2s->rect.ymax); + v2s->rect = rect; - v2s->mval[0] = v2s->rect.xmin; - v2s->mval[1] = v2s->rect.ymin; + v2s->mval[0] = v2s->rect.xmin; + v2s->mval[1] = v2s->rect.ymin; - memcpy(v2s + 1, str, alloc_len); + memcpy(v2s + 1, str, alloc_len); + } } diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 2271b91806b..fe3190aa76e 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -757,7 +757,7 @@ static int view_zoomin_invoke(bContext *C, wmOperator *op, const wmEvent *event) ARegion *ar = CTX_wm_region(C); /* store initial mouse position (in view space) */ - UI_view2d_region_to_view(&ar->v2d, + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &vzd->mx_2d, &vzd->my_2d); } @@ -1182,8 +1182,8 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op) const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); /* convert coordinates of rect to 'tot' rect coordinates */ - UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin); - UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax); + WM_operator_properties_border_to_rctf(op, &rect); + UI_view2d_region_to_view_rctf(v2d, &rect, &rect); /* check if zooming in/out view */ gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index 08896b39682..35b14d1378d 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -738,7 +738,7 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar, float xofs, yofs; /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y); /* w = BLI_rctf_size_x(&v2d->tot); */ diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 30f7c637868..468c3a0524b 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -1925,8 +1925,8 @@ void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy) /* the image is located inside (0, 0), (1, 1) as set by view2d */ UI_ThemeColorShade(TH_BACK, 20); - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x1, &y1); - UI_view2d_to_region_no_clip(&ar->v2d, 1.0f, 1.0f, &x2, &y2); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x1, &y1); + UI_view2d_view_to_region(&ar->v2d, 1.0f, 1.0f, &x2, &y2); glRectf(x1, y1, x2, y2); /* gridsize adapted to zoom level */ diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index c15d481b01e..cf2655bae7f 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -529,8 +529,8 @@ static void brush_painter_2d_tex_mapping(ImagePaintState *s, int size, const flo if (mapmode == MTEX_MAP_MODE_STENCIL) { /* map from view coordinates of brush to region coordinates */ - UI_view2d_to_region_no_clip(s->v2d, ipos[0] * invw, ipos[1] * invh, &xmin, &ymin); - UI_view2d_to_region_no_clip(s->v2d, (ipos[0] + size) * invw, (ipos[1] + size) * invh, &xmax, &ymax); + UI_view2d_view_to_region(s->v2d, ipos[0] * invw, ipos[1] * invh, &xmin, &ymin); + UI_view2d_view_to_region(s->v2d, (ipos[0] + size) * invw, (ipos[1] + size) * invh, &xmax, &ymax); /* output mapping from brush ibuf x/y to region coordinates */ mapping->xmin = xmin; diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index 14cc38ed296..8b133facbb3 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -203,7 +203,7 @@ enum { } /*eActKeys_BorderSelect_Mode*/; -static void borderselect_action(bAnimContext *ac, rcti rect, short mode, short selectmode) +static void borderselect_action(bAnimContext *ac, const rcti rect, short mode, short selectmode) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; @@ -890,7 +890,7 @@ static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, const wm float x; /* determine which side of the current frame mouse is on */ - UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, NULL); + x = UI_view2d_region_to_view_x(v2d, event->mval[0]); if (x < CFRA) RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_LEFT); else diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index eaf12a8d51c..7425d0cf5ff 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -279,7 +279,7 @@ static void draw_movieclip_muted(ARegion *ar, int width, int height, float zoomx int x, y; /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y); glColor3f(0.0f, 0.0f, 0.0f); glRectf(x, y, x + zoomx * width, y + zoomy * height); @@ -293,7 +293,7 @@ static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, int x, y; /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y); /* checkerboard for case alpha */ if (ibuf->planes == 32) { @@ -328,7 +328,7 @@ static void draw_stabilization_border(SpaceClip *sc, ARegion *ar, int width, int MovieClip *clip = ED_space_clip_get_clip(sc); /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y); /* draw boundary border for frame if stabilization is enabled */ if (sc->flag & SC_SHOW_STABLE && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) { @@ -1256,12 +1256,12 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie /* ** find window pixel coordinates of origin ** */ - /* UI_view2d_to_region_no_clip return integer values, this could + /* UI_view2d_view_to_region_no_clip return integer values, this could * lead to 1px flickering when view is locked to selection during playbeck. * to avoid this flickering, calculate base point in the same way as it happens - * in UI_view2d_to_region_no_clip, but do it in floats here */ + * in UI_view2d_view_to_region_no_clip, but do it in floats here */ - UI_view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y); + UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y); glPushMatrix(); glTranslatef(x, y, 0); @@ -1503,7 +1503,7 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, if ((sc->flag & SC_SHOW_GRID) == 0 && (sc->flag & SC_MANUAL_CALIBRATION) == 0) return; - UI_view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y); + UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y); glPushMatrix(); glTranslatef(x, y, 0); diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 4fe12fdd7e9..c5dcc745da1 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -453,7 +453,7 @@ void ED_clip_point_stable_pos(SpaceClip *sc, ARegion *ar, float x, float y, floa ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); ED_space_clip_get_size(sc, &width, &height); - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy); pos[0] = (x - sx) / zoomx; pos[1] = (y - sy) / zoomy; @@ -489,7 +489,7 @@ void ED_clip_point_stable_pos__reverse(SpaceClip *sc, ARegion *ar, const float c int width, height; int sx, sy; - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy); ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c index 2aaf064ef53..074d76c1a41 100644 --- a/source/blender/editors/space_clip/clip_graph_ops.c +++ b/source/blender/editors/space_clip/clip_graph_ops.c @@ -193,8 +193,8 @@ static bool mouse_select_knot(bContext *C, float co[2], bool extend) if (userdata.marker) { int x1, y1, x2, y2; - UI_view2d_view_to_region(v2d, co[0], co[1], &x1, &y1); - UI_view2d_view_to_region(v2d, userdata.min_co[0], userdata.min_co[1], &x2, &y2); + UI_view2d_view_to_region_clip(v2d, co[0], co[1], &x1, &y1); + UI_view2d_view_to_region_clip(v2d, userdata.min_co[0], userdata.min_co[1], &x2, &y2); if (abs(x2 - x1) <= delta && abs(y2 - y1) <= delta) { if (!extend) { @@ -366,17 +366,15 @@ static int border_select_graph_exec(bContext *C, wmOperator *op) MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); BorderSelectuserData userdata; - rcti rect; + rctf rect; if (act_track == NULL) { return OPERATOR_CANCELLED; } /* get rectangle from operator */ - WM_operator_properties_border_to_rcti(op, &rect); - - UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &userdata.rect.xmin, &userdata.rect.ymin); - UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &userdata.rect.xmax, &userdata.rect.ymax); + WM_operator_properties_border_to_rctf(op, &rect); + UI_view2d_region_to_view_rctf(&ar->v2d, &rect, &userdata.rect); userdata.changed = false; userdata.mode = RNA_int_get(op->ptr, "gesture_mode"); diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index ad425d21612..b2af3c41a18 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -1184,7 +1184,7 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar) clip_draw_main(C, sc, ar); /* TODO(sergey): would be nice to find a way to de-duplicate all this space conversions */ - UI_view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y); + UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y); ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); ED_space_clip_get_aspect(sc, &aspx, &aspy); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 8becb287cf1..9c8bcc09a3e 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -69,18 +69,24 @@ #include /* ---------- FILE SELECTION ------------ */ -static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect) +static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect_region) { FileSelection sel; - float fxmin, fymin, fxmax, fymax; View2D *v2d = &ar->v2d; rcti rect_view; + rctf rect_view_fl; + rctf rect_region_fl; - UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin, &fxmin, &fymin); - UI_view2d_region_to_view(v2d, rect->xmax, rect->ymax, &fxmax, &fymax); + BLI_rctf_rcti_copy(&rect_region_fl, rect_region); - BLI_rcti_init(&rect_view, (int)(v2d->tot.xmin + fxmin), (int)(v2d->tot.xmin + fxmax), (int)(v2d->tot.ymax - fymin), (int)(v2d->tot.ymax - fymax)); + UI_view2d_region_to_view_rctf(v2d, &rect_region_fl, &rect_view_fl); + + BLI_rcti_init(&rect_view, + (int)(v2d->tot.xmin + rect_view_fl.xmin), + (int)(v2d->tot.xmin + rect_view_fl.xmax), + (int)(v2d->tot.ymax - rect_view_fl.ymin), + (int)(v2d->tot.ymax - rect_view_fl.ymax)); sel = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view); diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c index 23bc8e94ef8..08f561726d9 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -233,8 +233,7 @@ static void borderselect_graphkeys( rctf rectf, scaled_rectf; /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */ - UI_view2d_region_to_view(v2d, rectf_view->xmin, rectf_view->ymin, &rectf.xmin, &rectf.ymin); - UI_view2d_region_to_view(v2d, rectf_view->xmax, rectf_view->ymax, &rectf.xmax, &rectf.ymax); + UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf); /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); @@ -952,7 +951,7 @@ static int graphkeys_select_leftright_invoke(bContext *C, wmOperator *op, const float x; /* determine which side of the current frame mouse is on */ - UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, NULL); + x = UI_view2d_region_to_view_x(v2d, event->mval[0]); if (x < CFRA) RNA_enum_set(op->ptr, "mode", GRAPHKEYS_LRSEL_LEFT); else @@ -1036,7 +1035,9 @@ static bool fcurve_handle_sel_check(SpaceIpo *sipo, BezTriple *bezt) /* check if the given vertex is within bounds or not */ // TODO: should we return if we hit something? -static void nearest_fcurve_vert_store(ListBase *matches, View2D *v2d, FCurve *fcu, BezTriple *bezt, FPoint *fpt, short hpoint, const int mval[2], float unit_scale) +static void nearest_fcurve_vert_store( + ListBase *matches, View2D *v2d, FCurve *fcu, + BezTriple *bezt, FPoint *fpt, short hpoint, const int mval[2], float unit_scale) { /* Keyframes or Samples? */ if (bezt) { @@ -1047,13 +1048,12 @@ static void nearest_fcurve_vert_store(ListBase *matches, View2D *v2d, FCurve *fc * needed to access the relevant vertex coordinates in the 3x3 * 'vec' matrix */ - UI_view2d_view_to_region(v2d, bezt->vec[hpoint + 1][0], bezt->vec[hpoint + 1][1] * unit_scale, &screen_co[0], &screen_co[1]); + UI_view2d_view_to_region_clip(v2d, + bezt->vec[hpoint + 1][0], bezt->vec[hpoint + 1][1] * unit_scale, + &screen_co[0], &screen_co[1]); /* check if distance from mouse cursor to vert in screen space is within tolerance */ - // XXX: inlined distance calculation, since we cannot do this on ints using the math lib... - //dist = len_v2v2(mval, screen_co); - dist = sqrt((mval[0] - screen_co[0]) * (mval[0] - screen_co[0]) + - (mval[1] - screen_co[1]) * (mval[1] - screen_co[1])); + dist = len_v2v2_int(mval, screen_co); if (dist <= GVERTSEL_TOL) { tNearestVertInfo *nvi = (tNearestVertInfo *)matches->last; diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 158f9ba031b..4e1b60123a6 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -107,7 +107,7 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar, float zoomx, rcti *tile; /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y); glPushMatrix(); glTranslatef(x, y, 0.0f); @@ -509,7 +509,7 @@ static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, glaDefine2DArea(&ar->winrct); /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, fx, fy, &x, &y); + UI_view2d_view_to_region(&ar->v2d, fx, fy, &x, &y); /* this part is generic image display */ if (sima->flag & SI_SHOW_ALPHA) { @@ -600,7 +600,7 @@ static void draw_image_buffer_tiled(SpaceImage *sima, ARegion *ar, Scene *scene, /* draw repeated */ for (sy = 0; sy + dy <= ibuf->y; sy += dy) { for (sx = 0; sx + dx <= ibuf->x; sx += dx) { - UI_view2d_to_region_no_clip(&ar->v2d, fx + (float)sx / (float)ibuf->x, fy + (float)sy / (float)ibuf->y, &x, &y); + UI_view2d_view_to_region(&ar->v2d, fx + (float)sx / (float)ibuf->x, fy + (float)sy / (float)ibuf->y, &x, &y); glaDrawPixelsSafe(x, y, dx, dy, dx, GL_RGBA, GL_UNSIGNED_BYTE, rect); } @@ -779,7 +779,7 @@ static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scen clonerect = get_alpha_clone_image(C, scene, &w, &h); if (clonerect) { - UI_view2d_to_region_no_clip(&ar->v2d, brush->clone.offset[0], brush->clone.offset[1], &x, &y); + UI_view2d_view_to_region(&ar->v2d, brush->clone.offset[0], brush->clone.offset[1], &x, &y); glPixelZoom(zoomx, zoomy); diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c index deabcfa85f4..9c1bfd230e3 100644 --- a/source/blender/editors/space_image/image_edit.c +++ b/source/blender/editors/space_image/image_edit.c @@ -257,7 +257,7 @@ void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, const int mval[2], float ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); ED_space_image_get_size(sima, &width, &height); - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy); co[0] = ((mval[0] - sx) / zoomx) / width; co[1] = ((mval[1] - sy) / zoomy) / height; @@ -271,7 +271,7 @@ void ED_image_point_pos(SpaceImage *sima, ARegion *ar, float x, float y, float * ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); ED_space_image_get_size(sima, &width, &height); - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy); *xr = ((x - sx) / zoomx) / width; *yr = ((y - sy) / zoomy) / height; @@ -283,7 +283,7 @@ void ED_image_point_pos__reverse(SpaceImage *sima, ARegion *ar, const float co[2 int width, height; int sx, sy; - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy); ED_space_image_get_size(sima, &width, &height); ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c index 2135166abe9..7dc46d51ca0 100644 --- a/source/blender/editors/space_info/info_report.c +++ b/source/blender/editors/space_info/info_report.c @@ -236,15 +236,6 @@ static int borderselect_exec(bContext *C, wmOperator *op) WM_operator_properties_border_to_rcti(op, &rect); -#if 0 - mval[0] = rect.xmin; - mval[1] = rect.ymin; - UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin); - mval[0] = rect.xmax; - mval[1] = rect.ymax; - UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax); -#endif - if (!extend) { for (report = reports->list.first; report; report = report->next) { diff --git a/source/blender/editors/space_nla/nla_select.c b/source/blender/editors/space_nla/nla_select.c index 2bd2b660bcd..58eb8776168 100644 --- a/source/blender/editors/space_nla/nla_select.c +++ b/source/blender/editors/space_nla/nla_select.c @@ -464,7 +464,7 @@ static int nlaedit_select_leftright_invoke(bContext *C, wmOperator *op, const wm float x; /* determine which side of the current frame mouse is on */ - UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, NULL); + x = UI_view2d_region_to_view_x(v2d, event->mval[0]); if (x < CFRA) RNA_int_set(op->ptr, "mode", NLAEDIT_LRSEL_LEFT); else @@ -515,7 +515,7 @@ static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], s Scene *scene = ac->scene; NlaStrip *strip = NULL; int channel_index; - float xmin, xmax, dummy; + float xmin, xmax; float x, y; @@ -526,8 +526,8 @@ static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], s /* x-range to check is +/- 7 (in screen/region-space) on either side of mouse click * (that is the size of keyframe icons, so user should be expecting similar tolerances) */ - UI_view2d_region_to_view(v2d, mval[0] - 7, mval[1], &xmin, &dummy); - UI_view2d_region_to_view(v2d, mval[0] + 7, mval[1], &xmax, &dummy); + xmin = UI_view2d_region_to_view_x(v2d, mval[0] - 7); + xmax = UI_view2d_region_to_view_x(v2d, mval[0] + 7); /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS); diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index d9e1f4fa611..63323f0e370 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -445,15 +445,12 @@ static int node_borderselect_exec(bContext *C, wmOperator *op) SpaceNode *snode = CTX_wm_space_node(C); ARegion *ar = CTX_wm_region(C); bNode *node; - rcti rect; rctf rectf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); const bool extend = RNA_boolean_get(op->ptr, "extend"); - WM_operator_properties_border_to_rcti(op, &rect); - - UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); - UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); + WM_operator_properties_border_to_rctf(op, &rectf); + UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf); for (node = snode->edittree->nodes.first; node; node = node->next) { if (BLI_rctf_isect(&rectf, &node->totr, NULL)) { @@ -593,9 +590,7 @@ static bool do_lasso_select_node(bContext *C, const int mcords[][2], short moves BLI_rctf_cent_y(&node->totr)}; /* marker in screen coords */ - UI_view2d_view_to_region(&ar->v2d, - cent[0], cent[1], - &screen_co[0], &screen_co[1]); + UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_co[0], &screen_co[1]); if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) && BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX)) diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index 117730cdb9e..17e1e032bbf 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -185,7 +185,7 @@ static int outliner_item_openclose(bContext *C, wmOperator *op, const wmEvent *e float fmval[2]; const bool all = RNA_boolean_get(op->ptr, "all"); - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1); + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); for (te = soops->tree.first; te; te = te->next) { if (do_outliner_item_openclose(C, soops, te, all, fmval)) @@ -275,7 +275,7 @@ static int outliner_item_rename(bContext *C, wmOperator *UNUSED(op), const wmEve float fmval[2]; bool changed = false; - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1); + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); for (te = soops->tree.first; te; te = te->next) { if (do_outliner_item_rename(C, ar, soops, te, fmval)) { diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index 9fa17cd1120..daf8033e312 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -985,7 +985,7 @@ int outliner_item_do_activate(bContext *C, int x, int y, bool extend, bool recur TreeElement *te; float fmval[2]; - UI_view2d_region_to_view(&ar->v2d, x, y, fmval, fmval + 1); + UI_view2d_region_to_view(&ar->v2d, x, y, &fmval[0], &fmval[1]); if (!ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF) && !(soops->flag & SO_HIDE_RESTRICTCOLS) && @@ -1079,14 +1079,11 @@ static int outliner_border_select_exec(bContext *C, wmOperator *op) SpaceOops *soops = CTX_wm_space_outliner(C); ARegion *ar = CTX_wm_region(C); TreeElement *te; - rcti rect; rctf rectf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); - WM_operator_properties_border_to_rcti(op, &rect); - - UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); - UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); + WM_operator_properties_border_to_rctf(op, &rectf); + UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf); for (te = soops->tree.first; te; te = te->next) { outliner_item_border_select(scene, soops, &rectf, te, gesture_mode); diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 9f31bbb3320..0c274aaf110 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -1345,7 +1345,7 @@ static int outliner_operation(bContext *C, wmOperator *UNUSED(op), const wmEvent TreeElement *te; float fmval[2]; - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1); + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); for (te = soops->tree.first; te; te = te->next) { if (do_outliner_operation_event(C, scene, ar, soops, te, event, fmval)) { diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 8c664a1f423..f14eb2f1b18 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -2955,17 +2955,13 @@ void SEQUENCER_OT_swap_data(wmOperatorType *ot) static int view_ghost_border_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); - Editing *ed = BKE_sequencer_editing_get(scene, false); View2D *v2d = UI_view2d_fromcontext(C); rctf rect; /* convert coordinates of rect to 'tot' rect coordinates */ - UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin); - UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax); - - if (ed == NULL) - return OPERATOR_CANCELLED; + WM_operator_properties_border_to_rctf(op, &rect); + UI_view2d_region_to_view_rctf(v2d, &rect, &rect); rect.xmin /= fabsf(BLI_rctf_size_x(&v2d->tot)); rect.ymin /= fabsf(BLI_rctf_size_y(&v2d->tot)); diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index 496be65cf0e..cfae0056a35 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -361,7 +361,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, const wmEvent *e /* use different logic for this */ float x; ED_sequencer_deselect_all(scene); - UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, NULL); + x = UI_view2d_region_to_view_x(v2d, event->mval[0]); SEQP_BEGIN (ed, seq) { @@ -849,23 +849,15 @@ static int sequencer_borderselect_exec(bContext *C, wmOperator *op) View2D *v2d = UI_view2d_fromcontext(C); Sequence *seq; - rcti rect; rctf rectf, rq; const bool select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); const bool extend = RNA_boolean_get(op->ptr, "extend"); - int mval[2]; if (ed == NULL) return OPERATOR_CANCELLED; - WM_operator_properties_border_to_rcti(op, &rect); - - mval[0] = rect.xmin; - mval[1] = rect.ymin; - UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin); - mval[0] = rect.xmax; - mval[1] = rect.ymax; - UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax); + WM_operator_properties_border_to_rctf(op, &rectf); + UI_view2d_region_to_view_rctf(v2d, &rectf, &rectf); for (seq = ed->seqbasep->first; seq; seq = seq->next) { seq_rectf(seq, &rq); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 88261d5e8ca..a1c17f9a851 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -374,7 +374,7 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr v[0] = vec[0] / aspx; v[1] = vec[1] / aspy; - UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1); + UI_view2d_view_to_region(t->view, v[0], v[1], &adr[0], &adr[1]); } } else if (t->spacetype == SPACE_ACTION) { @@ -385,12 +385,12 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr if (sact->flag & SACTION_DRAWTIME) { //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base)); /* same as below */ - UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1); + UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]); } else #endif { - UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1); + UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]); } adr[0] = out[0]; @@ -399,14 +399,14 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr else if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) { int out[2] = {0, 0}; - UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1); + UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]); adr[0] = out[0]; adr[1] = out[1]; } else if (t->spacetype == SPACE_SEQ) { /* XXX not tested yet, but should work */ int out[2] = {0, 0}; - UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1); + UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]); adr[0] = out[0]; adr[1] = out[1]; } @@ -452,14 +452,14 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr v[0] /= aspx; v[1] /= aspy; - UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1); + UI_view2d_view_to_region(t->view, v[0], v[1], &adr[0], &adr[1]); } else { BLI_assert(0); } } else if (t->spacetype == SPACE_NODE) { - UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], adr, adr + 1); + UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &adr[0], &adr[1]); } } void projectIntView(TransInfo *t, const float vec[3], int adr[2]) diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 9226b05d1dd..a14f0c22b37 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -1011,7 +1011,7 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) Image *ima = ED_space_image(t->sa->spacedata.first); float aspx, aspy, co[2]; - UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], co, co + 1); + UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], &co[0], &co[1]); if (ED_uvedit_nearest_uv(t->scene, t->obedit, ima, co, t->tsnap.snapPoint)) { ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); @@ -2268,8 +2268,7 @@ static bool snapNode(ToolSettings *ts, SpaceNode *UNUSED(snode), ARegion *ar, bN rcti totr; int new_dist; - UI_view2d_to_region_no_clip(v2d, node->totr.xmin, node->totr.ymin, &totr.xmin, &totr.ymin); - UI_view2d_to_region_no_clip(v2d, node->totr.xmax, node->totr.ymax, &totr.xmax, &totr.ymax); + UI_view2d_view_to_region_rcti(v2d, &node->totr, &totr); if (border & NODE_LEFT) { new_dist = abs(totr.xmin - mval[0]); diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 0706ac3278b..3a5c1335dd9 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -2796,7 +2796,6 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) BMIter iter, liter; MTexPoly *tf; MLoopUV *luv; - rcti rect; rctf rectf; bool changed, pinned, select, extend; const bool use_face_center = (ts->uv_flag & UV_SYNC_SELECTION) ? @@ -2807,10 +2806,8 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY); /* get rectangle from operator */ - WM_operator_properties_border_to_rcti(op, &rect); - - UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); - UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); + WM_operator_properties_border_to_rctf(op, &rectf); + UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf); /* figure out what to select/deselect */ select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); @@ -3071,7 +3068,7 @@ static bool do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short mo if (select != uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) { float cent[2]; uv_poly_center(efa, cent, cd_loop_uv_offset); - UI_view2d_view_to_region(&ar->v2d, cent[0], cent[1], &screen_uv[0], &screen_uv[1]); + UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_uv[0], &screen_uv[1]); if (BLI_rcti_isect_pt_v(&rect, screen_uv) && BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) { @@ -3093,7 +3090,7 @@ static bool do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short mo BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if ((select) != (uvedit_uv_select_test(scene, l, cd_loop_uv_offset))) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - UI_view2d_view_to_region(&ar->v2d, luv->uv[0], luv->uv[1], &screen_uv[0], &screen_uv[1]); + UI_view2d_view_to_region_clip(&ar->v2d, luv->uv[0], luv->uv[1], &screen_uv[0], &screen_uv[1]); if (BLI_rcti_isect_pt_v(&rect, screen_uv) && BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) { diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index 1d9464ab7c5..e0431fcff16 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -176,9 +176,9 @@ static void rna_View2D_region_to_view(struct View2D *v2d, int x, int y, float re static void rna_View2D_view_to_region(struct View2D *v2d, float x, float y, int clip, int result[2]) { if (clip) - UI_view2d_view_to_region(v2d, x, y, &result[0], &result[1]); + UI_view2d_view_to_region_clip(v2d, x, y, &result[0], &result[1]); else - UI_view2d_to_region_no_clip(v2d, x, y, &result[0], &result[1]); + UI_view2d_view_to_region(v2d, x, y, &result[0], &result[1]); } #else diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 661e940facb..dd00e691f5a 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -252,6 +252,7 @@ void WM_operator_properties_free(struct PointerRNA *ptr); void WM_operator_properties_filesel(struct wmOperatorType *ot, int filter, short type, short action, short flag, short display); void WM_operator_properties_border(struct wmOperatorType *ot); void WM_operator_properties_border_to_rcti(struct wmOperator *op, struct rcti *rect); +void WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect); void WM_operator_properties_gesture_border(struct wmOperatorType *ot, bool extend); void WM_operator_properties_mouse_select(struct wmOperatorType *ot); void WM_operator_properties_gesture_straightline(struct wmOperatorType *ot, int cursor); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 4ff987d1094..6ca8405dc7d 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1294,6 +1294,13 @@ void WM_operator_properties_border_to_rcti(struct wmOperator *op, rcti *rect) rect->ymax = RNA_int_get(op->ptr, "ymax"); } +void WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect) +{ + rcti rect_i; + WM_operator_properties_border_to_rcti(op, &rect_i); + BLI_rctf_rcti_copy(rect, &rect_i); +} + void WM_operator_properties_gesture_border(wmOperatorType *ot, bool extend) { RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX); -- cgit v1.2.3