Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface/view2d.c')
-rw-r--r--source/blender/editors/interface/view2d.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index d498f57e8e3..86322b0c0ea 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -96,11 +96,11 @@ static void view2d_masks(View2D *v2d)
/* check size if: */
if (v2d->scroll & V2D_SCROLL_HORIZONTAL)
if (!(v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL))
- if (v2d->tot.xmax - v2d->tot.xmin <= v2d->cur.xmax - v2d->cur.xmin)
+ if (BLI_RCT_SIZE_X(&v2d->tot) <= BLI_RCT_SIZE_X(&v2d->cur))
v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
if (v2d->scroll & V2D_SCROLL_VERTICAL)
if (!(v2d->scroll & V2D_SCROLL_SCALE_VERTICAL))
- if (v2d->tot.ymax - v2d->tot.ymin <= v2d->cur.ymax - v2d->cur.ymin)
+ if (BLI_RCT_SIZE_Y(&v2d->tot) <= BLI_RCT_SIZE_Y(&v2d->cur))
v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
#endif
scroll = view2d_scroll_mapped(v2d->scroll);
@@ -328,8 +328,8 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
rctf *cur, *tot;
/* use mask as size of region that View2D resides in, as it takes into account scrollbars already */
- winx = (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
- winy = (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
+ winx = (float)(BLI_RCT_SIZE_X(&v2d->mask) + 1);
+ winy = (float)(BLI_RCT_SIZE_Y(&v2d->mask) + 1);
/* get pointers to rcts for less typing */
cur = &v2d->cur;
@@ -347,10 +347,10 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
* - firstly, we calculate the sizes of the rects
* - curwidth and curheight are saved as reference... modify width and height values here
*/
- totwidth = tot->xmax - tot->xmin;
- totheight = tot->ymax - tot->ymin;
- curwidth = width = cur->xmax - cur->xmin;
- curheight = height = cur->ymax - cur->ymin;
+ totwidth = BLI_RCT_SIZE_X(tot);
+ totheight = BLI_RCT_SIZE_Y(tot);
+ curwidth = width = BLI_RCT_SIZE_X(cur);
+ curheight = height = BLI_RCT_SIZE_Y(cur);
/* if zoom is locked, size on the appropriate axis is reset to mask size */
if (v2d->keepzoom & V2D_LOCKZOOM_X)
@@ -499,13 +499,13 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
/* resize from centerpoint, unless otherwise specified */
if (width != curwidth) {
if (v2d->keepofs & V2D_LOCKOFS_X) {
- cur->xmax += width - (cur->xmax - cur->xmin);
+ cur->xmax += width - BLI_RCT_SIZE_X(cur);
}
else if (v2d->keepofs & V2D_KEEPOFS_X) {
if (v2d->align & V2D_ALIGN_NO_POS_X)
- cur->xmin -= width - (cur->xmax - cur->xmin);
+ cur->xmin -= width - BLI_RCT_SIZE_X(cur);
else
- cur->xmax += width - (cur->xmax - cur->xmin);
+ cur->xmax += width - BLI_RCT_SIZE_X(cur);
}
else {
temp = BLI_RCT_CENTER_X(cur);
@@ -517,13 +517,13 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
}
if (height != curheight) {
if (v2d->keepofs & V2D_LOCKOFS_Y) {
- cur->ymax += height - (cur->ymax - cur->ymin);
+ cur->ymax += height - BLI_RCT_SIZE_Y(cur);
}
else if (v2d->keepofs & V2D_KEEPOFS_Y) {
if (v2d->align & V2D_ALIGN_NO_POS_Y)
- cur->ymin -= height - (cur->ymax - cur->ymin);
+ cur->ymin -= height - BLI_RCT_SIZE_Y(cur);
else
- cur->ymax += height - (cur->ymax - cur->ymin);
+ cur->ymax += height - BLI_RCT_SIZE_Y(cur);
}
else {
temp = BLI_RCT_CENTER_Y(cur);
@@ -540,8 +540,8 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
float temp, diff;
/* recalculate extents of cur */
- curwidth = cur->xmax - cur->xmin;
- curheight = cur->ymax - cur->ymin;
+ curwidth = BLI_RCT_SIZE_X(cur);
+ curheight = BLI_RCT_SIZE_Y(cur);
/* width */
if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM | V2D_LOCKZOOM_X | V2D_LIMITZOOM)) ) {
@@ -791,8 +791,8 @@ void UI_view2d_curRect_reset(View2D *v2d)
float width, height;
/* assume width and height of 'cur' rect by default, should be same size as mask */
- width = (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
- height = (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
+ width = (float)(BLI_RCT_SIZE_X(&v2d->mask) + 1);
+ height = (float)(BLI_RCT_SIZE_Y(&v2d->mask) + 1);
/* handle width - posx and negx flags are mutually exclusive, so watch out */
if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
@@ -958,8 +958,8 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked)
*curmasked = v2d->cur;
if (view2d_scroll_mapped(v2d->scroll)) {
- float dx = (v2d->cur.xmax - v2d->cur.xmin) / ((float)(v2d->mask.xmax - v2d->mask.xmin + 1));
- float dy = (v2d->cur.ymax - v2d->cur.ymin) / ((float)(v2d->mask.ymax - v2d->mask.ymin + 1));
+ float dx = BLI_RCT_SIZE_X(&v2d->cur) / ((float)(BLI_RCT_SIZE_X(&v2d->mask) + 1));
+ float dy = BLI_RCT_SIZE_Y(&v2d->cur) / ((float)(BLI_RCT_SIZE_Y(&v2d->mask) + 1));
if (v2d->mask.xmin != 0)
curmasked->xmin -= dx * (float)v2d->mask.xmin;
@@ -985,8 +985,8 @@ void UI_view2d_view_ortho(View2D *v2d)
*/
/* XXX brecht: instead of zero at least use a tiny offset, otherwise
* pixel rounding is effectively random due to float inaccuracy */
- xofs = 0.001f * (v2d->cur.xmax - v2d->cur.xmin) / (v2d->mask.xmax - v2d->mask.xmin);
- yofs = 0.001f * (v2d->cur.ymax - v2d->cur.ymin) / (v2d->mask.ymax - v2d->mask.ymin);
+ xofs = 0.001f * BLI_RCT_SIZE_X(&v2d->cur) / BLI_RCT_SIZE_X(&v2d->mask);
+ yofs = 0.001f * BLI_RCT_SIZE_Y(&v2d->cur) / BLI_RCT_SIZE_Y(&v2d->mask);
/* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */
view2d_map_cur_using_mask(v2d, &curmasked);
@@ -1044,8 +1044,8 @@ void UI_view2d_view_orthoSpecial(ARegion *ar, View2D *v2d, short xaxis)
void UI_view2d_view_restore(const bContext *C)
{
ARegion *ar = CTX_wm_region(C);
- int width = ar->winrct.xmax - ar->winrct.xmin + 1;
- int height = ar->winrct.ymax - ar->winrct.ymin + 1;
+ int width = BLI_RCT_SIZE_X(&ar->winrct) + 1;
+ int height = BLI_RCT_SIZE_Y(&ar->winrct) + 1;
wmOrtho2(0.0f, (float)width, 0.0f, (float)height);
glLoadIdentity();
@@ -1140,8 +1140,8 @@ View2DGrid *UI_view2d_grid_calc(Scene *scene, View2D *v2d, short xunits, short x
/* calculate x-axis grid scale (only if both args are valid) */
if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) {
- space = v2d->cur.xmax - v2d->cur.xmin;
- pixels = (float)(v2d->mask.xmax - v2d->mask.xmin);
+ space = BLI_RCT_SIZE_X(&v2d->cur);
+ pixels = (float)BLI_RCT_SIZE_X(&v2d->mask);
if (pixels != 0.0f) {
grid->dx = (U.v2d_min_gridsize * space) / (seconddiv * pixels);
@@ -1158,7 +1158,7 @@ View2DGrid *UI_view2d_grid_calc(Scene *scene, View2D *v2d, short xunits, short x
/* calculate y-axis grid scale (only if both args are valid) */
if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) {
- space = v2d->cur.ymax - v2d->cur.ymin;
+ space = BLI_RCT_SIZE_Y(&v2d->cur);
pixels = (float)winy;
grid->dy = U.v2d_min_gridsize * space / pixels;
@@ -1206,7 +1206,7 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
vec2[1] = v2d->cur.ymax;
/* minor gridlines */
- step = (v2d->mask.xmax - v2d->mask.xmin + 1) / U.v2d_min_gridsize;
+ step = (BLI_RCT_SIZE_X(&v2d->mask) + 1) / U.v2d_min_gridsize;
UI_ThemeColor(TH_GRID);
for (a = 0; a < step; a++) {
@@ -1240,7 +1240,7 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
vec1[0] = grid->startx;
vec2[0] = v2d->cur.xmax;
- step = (v2d->mask.ymax - v2d->mask.ymin + 1) / U.v2d_min_gridsize;
+ step = (BLI_RCT_SIZE_Y(&v2d->mask) + 1) / U.v2d_min_gridsize;
UI_ThemeColor(TH_GRID);
for (a = 0; a <= step; a++) {
@@ -1457,7 +1457,7 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, short
/* horizontal scrollers */
if (scroll & V2D_SCROLL_HORIZONTAL) {
/* scroller 'button' extents */
- totsize = v2d->tot.xmax - v2d->tot.xmin;
+ totsize = BLI_RCT_SIZE_X(&v2d->tot);
scrollsize = (float)(hor.xmax - hor.xmin);
if (totsize == 0.0f) totsize = 1.0f; /* avoid divide by zero */
@@ -1498,7 +1498,7 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, short
/* vertical scrollers */
if (scroll & V2D_SCROLL_VERTICAL) {
/* scroller 'button' extents */
- totsize = v2d->tot.ymax - v2d->tot.ymin;
+ totsize = BLI_RCT_SIZE_Y(&v2d->tot);
scrollsize = (float)(vert.ymax - vert.ymin);
if (totsize == 0.0f) totsize = 1.0f; /* avoid divide by zero */
@@ -1649,10 +1649,10 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
* - fac is x-coordinate to draw to
* - dfac is gap between scale markings
*/
- fac = (grid->startx - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
+ fac = (grid->startx - v2d->cur.xmin) / BLI_RCT_SIZE_X(&v2d->cur);
fac = (float)hor.xmin + fac * (hor.xmax - hor.xmin);
- dfac = (grid->dx) / (v2d->cur.xmax - v2d->cur.xmin);
+ dfac = grid->dx / BLI_RCT_SIZE_X(&v2d->cur);
dfac = dfac * (hor.xmax - hor.xmin);
/* set starting value, and text color */
@@ -1763,10 +1763,10 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
* - these involve a correction for horizontal scrollbar
* NOTE: it's assumed that that scrollbar is there if this is involved!
*/
- fac = (grid->starty - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
+ fac = (grid->starty - v2d->cur.ymin) / BLI_RCT_SIZE_Y(&v2d->cur);
fac = vert.ymin + fac * (vert.ymax - vert.ymin);
- dfac = (grid->dy) / (v2d->cur.ymax - v2d->cur.ymin);
+ dfac = grid->dy / BLI_RCT_SIZE_Y(&v2d->cur);
dfac = dfac * (vert.ymax - vert.ymin);
/* set starting value, and text color */
@@ -1925,17 +1925,17 @@ void UI_view2d_region_to_view(View2D *v2d, int x, int y, float *r_viewx, float *
float div, ofs;
if (r_viewx) {
- div = (float)(v2d->mask.xmax - v2d->mask.xmin);
+ div = (float)BLI_RCT_SIZE_X(&v2d->mask);
ofs = (float)v2d->mask.xmin;
- *r_viewx = v2d->cur.xmin + (v2d->cur.xmax - v2d->cur.xmin) * ((float)x - ofs) / div;
+ *r_viewx = v2d->cur.xmin + BLI_RCT_SIZE_X(&v2d->cur) * ((float)x - ofs) / div;
}
if (r_viewy) {
- div = (float)(v2d->mask.ymax - v2d->mask.ymin);
+ div = (float)BLI_RCT_SIZE_Y(&v2d->mask);
ofs = (float)v2d->mask.ymin;
- *r_viewy = v2d->cur.ymin + (v2d->cur.ymax - v2d->cur.ymin) * ((float)y - ofs) / div;
+ *r_viewy = v2d->cur.ymin + BLI_RCT_SIZE_Y(&v2d->cur) * ((float)y - ofs) / div;
}
}
@@ -1954,15 +1954,15 @@ void UI_view2d_view_to_region(View2D *v2d, float x, float y, int *regionx, int *
*regiony = V2D_IS_CLIPPED;
/* express given coordinates as proportional values */
- x = (x - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
- y = (y - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
+ x = (x - v2d->cur.xmin) / BLI_RCT_SIZE_X(&v2d->cur);
+ y = (y - v2d->cur.ymin) / BLI_RCT_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 * (v2d->mask.xmax - v2d->mask.xmin));
+ *regionx = (int)(v2d->mask.xmin + x * BLI_RCT_SIZE_X(&v2d->mask));
if (regiony)
- *regiony = (int)(v2d->mask.ymin + y * (v2d->mask.ymax - v2d->mask.ymin));
+ *regiony = (int)(v2d->mask.ymin + y * BLI_RCT_SIZE_Y(&v2d->mask));
}
}
@@ -1975,12 +1975,12 @@ void UI_view2d_view_to_region(View2D *v2d, float x, float y, int *regionx, int *
void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, int *regionx, int *regiony)
{
/* step 1: express given coordinates as proportional values */
- x = (x - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
- y = (y - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
+ x = (x - v2d->cur.xmin) / BLI_RCT_SIZE_X(&v2d->cur);
+ y = (y - v2d->cur.ymin) / BLI_RCT_SIZE_Y(&v2d->cur);
/* step 2: convert proportional distances to screen coordinates */
- x = v2d->mask.xmin + x * (v2d->mask.xmax - v2d->mask.xmin);
- y = v2d->mask.ymin + y * (v2d->mask.ymax - v2d->mask.ymin);
+ x = v2d->mask.xmin + x * BLI_RCT_SIZE_X(&v2d->mask);
+ y = v2d->mask.ymin + y * BLI_RCT_SIZE_Y(&v2d->mask);
/* although we don't clamp to lie within region bounds, we must avoid exceeding size of ints */
if (regionx) {
@@ -2033,8 +2033,8 @@ View2D *UI_view2d_fromcontext_rwin(const bContext *C)
*/
void UI_view2d_getscale(View2D *v2d, float *x, float *y)
{
- if (x) *x = (v2d->mask.xmax - v2d->mask.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
- if (y) *y = (v2d->mask.ymax - v2d->mask.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
+ if (x) *x = BLI_RCT_SIZE_X(&v2d->mask) / BLI_RCT_SIZE_X(&v2d->cur);
+ if (y) *y = BLI_RCT_SIZE_Y(&v2d->mask) / BLI_RCT_SIZE_Y(&v2d->cur);
}
/* Check if mouse is within scrollers