[Bf-blender-cvs] [9ae0e58] master: View2d: API Cleanup for view<->region conversion
Campbell Barton
noreply at git.blender.org
Mon Apr 21 09:00:20 CEST 2014
Commit: 9ae0e585b0aab466c978ec1a55c824d902faa3b4
Author: Campbell Barton
Date: Mon Apr 21 16:47:16 2014 +1000
https://developer.blender.org/rB9ae0e585b0aab466c978ec1a55c824d902faa3b4
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
===================================================================
M source/blender/editors/animation/anim_markers.c
M source/blender/editors/animation/anim_ops.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/include/UI_view2d.h
M source/blender/editors/interface/interface_regions.c
M source/blender/editors/interface/view2d.c
M source/blender/editors/interface/view2d_ops.c
M source/blender/editors/mask/mask_draw.c
M source/blender/editors/screen/area.c
M source/blender/editors/sculpt_paint/paint_image_2d.c
M source/blender/editors/space_action/action_select.c
M source/blender/editors/space_clip/clip_draw.c
M source/blender/editors/space_clip/clip_editor.c
M source/blender/editors/space_clip/clip_graph_ops.c
M source/blender/editors/space_clip/space_clip.c
M source/blender/editors/space_file/file_ops.c
M source/blender/editors/space_graph/graph_select.c
M source/blender/editors/space_image/image_draw.c
M source/blender/editors/space_image/image_edit.c
M source/blender/editors/space_info/info_report.c
M source/blender/editors/space_nla/nla_select.c
M source/blender/editors/space_node/node_select.c
M source/blender/editors/space_outliner/outliner_edit.c
M source/blender/editors/space_outliner/outliner_select.c
M source/blender/editors/space_outliner/outliner_tools.c
M source/blender/editors/space_sequencer/sequencer_edit.c
M source/blender/editors/space_sequencer/sequencer_select.c
M source/blender/editors/transform/transform.c
M source/blender/editors/transform/transform_snap.c
M source/blender/editors/uvedit/uvedit_ops.c
M source/blender/makesrna/intern/rna_screen.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_operators.c
M source/blenderplayer/bad_level_call_stubs/stubs.c
===================================================================
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index 9cba7d0..1def533 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 072b4c4..d9a5d71 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 4a688f1..d559871 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 6bbaca7..2f94114 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 b087469..9551414 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 f34fc3c..3b18007 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 9ce21e7..9bbf6e7 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
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list