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')
-rw-r--r--source/blender/editors/interface/interface.c22
-rw-r--r--source/blender/editors/interface/interface_draw.c38
-rw-r--r--source/blender/editors/interface/interface_handlers.c62
-rw-r--r--source/blender/editors/interface/interface_panel.c12
-rw-r--r--source/blender/editors/interface/interface_regions.c18
-rw-r--r--source/blender/editors/interface/interface_style.c12
-rw-r--r--source/blender/editors/interface/interface_templates.c23
-rw-r--r--source/blender/editors/interface/interface_widgets.c101
-rw-r--r--source/blender/editors/interface/view2d.c98
-rw-r--r--source/blender/editors/interface/view2d_ops.c52
10 files changed, 220 insertions, 218 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index f728e999667..10917f23cdd 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -99,8 +99,8 @@ void ui_block_to_window_fl(const ARegion *ar, uiBlock *block, float *x, float *y
float gx, gy;
int sx, sy, getsizex, getsizey;
- getsizex = ar->winrct.xmax - ar->winrct.xmin + 1;
- getsizey = ar->winrct.ymax - ar->winrct.ymin + 1;
+ getsizex = BLI_RCT_SIZE_X(&ar->winrct) + 1;
+ getsizey = BLI_RCT_SIZE_Y(&ar->winrct) + 1;
sx = ar->winrct.xmin;
sy = ar->winrct.ymin;
@@ -145,8 +145,8 @@ void ui_window_to_block_fl(const ARegion *ar, uiBlock *block, float *x, float *y
float a, b, c, d, e, f, px, py;
int sx, sy, getsizex, getsizey;
- getsizex = ar->winrct.xmax - ar->winrct.xmin + 1;
- getsizey = ar->winrct.ymax - ar->winrct.ymin + 1;
+ getsizex = BLI_RCT_SIZE_X(&ar->winrct) + 1;
+ getsizey = BLI_RCT_SIZE_Y(&ar->winrct) + 1;
sx = ar->winrct.xmin;
sy = ar->winrct.ymin;
@@ -272,7 +272,7 @@ void ui_bounds_block(uiBlock *block)
block->rect.ymax += block->bounds;
}
- block->rect.xmax = block->rect.xmin + maxf(block->rect.xmax - block->rect.xmin, block->minbounds);
+ block->rect.xmax = block->rect.xmin + maxf(BLI_RCT_SIZE_X(&block->rect), block->minbounds);
/* hardcoded exception... but that one is annoying with larger safety */
bt = block->buttons.first;
@@ -325,8 +325,8 @@ static void ui_popup_bounds_block(const bContext *C, uiBlock *block, int bounds_
wm_window_get_size(window, &xmax, &ymax);
- oldwidth = block->rect.xmax - block->rect.xmin;
- oldheight = block->rect.ymax - block->rect.ymin;
+ oldwidth = BLI_RCT_SIZE_X(&block->rect);
+ oldheight = BLI_RCT_SIZE_Y(&block->rect);
/* first we ensure wide enough text bounds */
if (bounds_calc == UI_BLOCK_BOUNDS_POPUP_MENU) {
@@ -341,8 +341,8 @@ static void ui_popup_bounds_block(const bContext *C, uiBlock *block, int bounds_
ui_bounds_block(block);
/* and we adjust the position to fit within window */
- width = block->rect.xmax - block->rect.xmin;
- height = block->rect.ymax - block->rect.ymin;
+ width = BLI_RCT_SIZE_X(&block->rect);
+ height = BLI_RCT_SIZE_Y(&block->rect);
/* avoid divide by zero below, caused by calling with no UI, but better not crash */
oldwidth = oldwidth > 0 ? oldwidth : MAX2(1, width);
@@ -2204,7 +2204,7 @@ void ui_check_but(uiBut *but)
/* safety is 4 to enable small number buttons (like 'users') */
- // okwidth= -4 + (but->rect.xmax - but->rect.xmin); // UNUSED
+ // okwidth= -4 + (BLI_RCT_SIZE_X(&but->rect)); // UNUSED
/* name: */
switch (but->type) {
@@ -2212,7 +2212,7 @@ void ui_check_but(uiBut *but)
case MENU:
case ICONTEXTROW:
- if (but->rect.xmax - but->rect.xmin > 24) {
+ if (BLI_RCT_SIZE_X(&but->rect) > 24.0f) {
UI_GET_BUT_VALUE_INIT(but, value);
ui_set_name_menu(but, (int)value);
}
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 109978780c2..e66c0409192 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -493,8 +493,8 @@ static void ui_draw_but_CHARTAB(uiBut *but)
charmax = G.charmax = 0xffff;
/* Calculate the size of the button */
- width = abs(rect->xmax - rect->xmin);
- height = abs(rect->ymax - rect->ymin);
+ width = absBLI_RCT_SIZE_X(rect);
+ height = absBLI_RCT_SIZE_Y(rect);
butw = floor(width / 12);
buth = floor(height / 6);
@@ -642,8 +642,8 @@ static void draw_scope_end(rctf *rect, GLint *scissor)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* scale widget */
- scaler_x1 = rect->xmin + (rect->xmax - rect->xmin) / 2 - SCOPE_RESIZE_PAD;
- scaler_x2 = rect->xmin + (rect->xmax - rect->xmin) / 2 + SCOPE_RESIZE_PAD;
+ scaler_x1 = rect->xmin + BLI_RCT_SIZE_X(rect) / 2 - SCOPE_RESIZE_PAD;
+ scaler_x2 = rect->xmin + BLI_RCT_SIZE_X(rect) / 2 + SCOPE_RESIZE_PAD;
glColor4f(0.f, 0.f, 0.f, 0.25f);
fdrawline(scaler_x1, rect->ymin - 4, scaler_x2, rect->ymin - 4);
@@ -805,9 +805,9 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
if (scopes->wavefrm_yfac < 0.5f)
scopes->wavefrm_yfac = 0.98f;
- w = rect.xmax - rect.xmin - 7;
- h = (rect.ymax - rect.ymin) * scopes->wavefrm_yfac;
- yofs = rect.ymin + (rect.ymax - rect.ymin - h) / 2.0f;
+ w = BLI_RCT_SIZE_X(&rect) - 7;
+ h = BLI_RCT_SIZE_Y(&rect) * scopes->wavefrm_yfac;
+ yofs = rect.ymin + (BLI_RCT_SIZE_Y(&rect) - h) / 2.0f;
w3 = w / 3.0f;
/* log scale for alpha */
@@ -1033,8 +1033,8 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2;
rect.ymax = (float)recti->ymax - 1;
- w = rect.xmax - rect.xmin;
- h = rect.ymax - rect.ymin;
+ w = BLI_RCT_SIZE_X(&rect);
+ h = BLI_RCT_SIZE_Y(&rect);
centerx = rect.xmin + w / 2;
centery = rect.ymin + h / 2;
diam = (w < h) ? w : h;
@@ -1262,12 +1262,12 @@ void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect)
/* transform to button */
glPushMatrix();
- glTranslatef(rect->xmin + 0.5f * (rect->xmax - rect->xmin), rect->ymin + 0.5f * (rect->ymax - rect->ymin), 0.0f);
+ glTranslatef(rect->xmin + 0.5f * BLI_RCT_SIZE_X(rect), rect->ymin + 0.5f * BLI_RCT_SIZE_Y(rect), 0.0f);
- if (rect->xmax - rect->xmin < rect->ymax - rect->ymin)
- size = (rect->xmax - rect->xmin) / 200.f;
+ if (BLI_RCT_SIZE_X(rect) < BLI_RCT_SIZE_Y(rect))
+ size = BLI_RCT_SIZE_X(rect) / 200.f;
else
- size = (rect->ymax - rect->ymin) / 200.f;
+ size = BLI_RCT_SIZE_Y(rect) / 200.f;
glScalef(size, size, size);
@@ -1368,8 +1368,8 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect
glScissor(scissor_new.xmin, scissor_new.ymin, scissor_new.xmax - scissor_new.xmin, scissor_new.ymax - scissor_new.ymin);
/* calculate offset and zoom */
- zoomx = (rect->xmax - rect->xmin - 2.0f * but->aspect) / (cumap->curr.xmax - cumap->curr.xmin);
- zoomy = (rect->ymax - rect->ymin - 2.0f * but->aspect) / (cumap->curr.ymax - cumap->curr.ymin);
+ zoomx = (BLI_RCT_SIZE_X(rect) - 2.0f * but->aspect) / BLI_RCT_SIZE_X(&cumap->curr);
+ zoomy = (BLI_RCT_SIZE_Y(rect) - 2.0f * but->aspect) / BLI_RCT_SIZE_Y(&cumap->curr);
offsx = cumap->curr.xmin - but->aspect / zoomx;
offsy = cumap->curr.ymin - but->aspect / zoomy;
@@ -1545,8 +1545,8 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2;
rect.ymax = (float)recti->ymax - 1;
- width = rect.xmax - rect.xmin + 1;
- height = rect.ymax - rect.ymin;
+ width = BLI_RCT_SIZE_X(&rect) + 1;
+ height = BLI_RCT_SIZE_Y(&rect);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -1621,8 +1621,8 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
glTranslatef(rect.xmin + track_pos[0], rect.ymin + track_pos[1], 0.f);
glScissor(ar->winrct.xmin + rect.xmin,
ar->winrct.ymin + rect.ymin,
- rect.xmax - rect.xmin,
- rect.ymax - rect.ymin);
+ BLI_RCT_SIZE_X(&rect),
+ BLI_RCT_SIZE_Y(&rect));
for (a = 0; a < 2; a++) {
if (a == 1) {
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 50b6de5ce46..d78a677ea58 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -690,7 +690,7 @@ static int ui_but_mouse_inside_icon(uiBut *but, ARegion *ar, wmEvent *event)
if (but->imb) ; /* use button size itself */
else if (but->flag & UI_ICON_LEFT) {
- rect.xmax = rect.xmin + (rect.ymax - rect.ymin);
+ rect.xmax = rect.xmin + (BLI_RCT_SIZE_Y(&rect));
}
else {
int delta = BLI_RCT_SIZE_X(&rect) - BLI_RCT_SIZE_Y(&rect);
@@ -714,7 +714,7 @@ static int ui_but_start_drag(bContext *C, uiBut *but, uiHandleButtonData *data,
drag = WM_event_start_drag(C, but->icon, but->dragtype, but->dragpoin, ui_get_but_val(but));
if (but->imb)
- WM_event_drag_image(drag, but->imb, but->imb_scale, but->rect.xmax - but->rect.xmin, but->rect.ymax - but->rect.ymin);
+ WM_event_drag_image(drag, but->imb, but->imb_scale, BLI_RCT_SIZE_X(&but->rect), BLI_RCT_SIZE_Y(&but->rect));
return 1;
}
@@ -1295,7 +1295,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
/* XXX solve generic */
if (but->type == NUM || but->type == NUMSLI)
- startx += (int)(0.5f * (but->rect.ymax - but->rect.ymin));
+ startx += (int)(0.5f * (BLI_RCT_SIZE_Y(&but->rect)));
else if (ELEM(but->type, TEX, SEARCH_MENU)) {
startx += 5;
if (but->flag & UI_HAS_ICON)
@@ -2610,7 +2610,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
softmax = but->softmax;
if (!ui_is_but_float(but)) {
- if (mx < (but->rect.xmin + (but->rect.xmax - but->rect.xmin) / 3 - 3)) {
+ if (mx < (but->rect.xmin + BLI_RCT_SIZE_X(&but->rect) / 3 - 3)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
temp = (int)data->value - 1;
@@ -2621,7 +2621,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
- else if (mx > (but->rect.xmin + (2 * (but->rect.xmax - but->rect.xmin) / 3) + 3)) {
+ else if (mx > (but->rect.xmin + (2 * BLI_RCT_SIZE_X(&but->rect) / 3) + 3)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
temp = (int)data->value + 1;
@@ -2636,7 +2636,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
}
else {
- if (mx < (but->rect.xmin + (but->rect.xmax - but->rect.xmin) / 3 - 3)) {
+ if (mx < (but->rect.xmin + BLI_RCT_SIZE_X(&but->rect) / 3 - 3)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
tempf = (float)data->value - 0.01f * but->a1;
@@ -2645,7 +2645,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
- else if (mx > but->rect.xmin + (2 * ((but->rect.xmax - but->rect.xmin) / 3) + 3)) {
+ else if (mx > but->rect.xmin + (2 * (BLI_RCT_SIZE_X(&but->rect) / 3) + 3)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
tempf = (float)data->value + 0.01f * but->a1;
@@ -2673,14 +2673,14 @@ static int ui_numedit_but_SLI(uiBut *but, uiHandleButtonData *data, const short
softmax = but->softmax;
softrange = softmax - softmin;
- if (but->type == NUMSLI) deler = ((but->rect.xmax - but->rect.xmin) - 5.0f * but->aspect);
- else if (but->type == HSVSLI) deler = ((but->rect.xmax - but->rect.xmin) / 2.0f - 5.0f * but->aspect);
+ if (but->type == NUMSLI) deler = (BLI_RCT_SIZE_X(&but->rect) - 5.0f * but->aspect);
+ else if (but->type == HSVSLI) deler = (BLI_RCT_SIZE_X(&but->rect) / 2.0f - 5.0f * but->aspect);
else if (but->type == SCROLL) {
- int horizontal = (but->rect.xmax - but->rect.xmin > but->rect.ymax - but->rect.ymin);
- float size = (horizontal) ? (but->rect.xmax - but->rect.xmin) : -(but->rect.ymax - but->rect.ymin);
+ int horizontal = (BLI_RCT_SIZE_X(&but->rect) > BLI_RCT_SIZE_Y(&but->rect));
+ float size = (horizontal) ? BLI_RCT_SIZE_X(&but->rect) : -BLI_RCT_SIZE_Y(&but->rect);
deler = size * (but->softmax - but->softmin) / (but->softmax - but->softmin + but->a1);
}
- else deler = (but->rect.xmax - but->rect.xmin - 5.0f * but->aspect);
+ else deler = (BLI_RCT_SIZE_X(&but->rect) - 5.0f * but->aspect);
f = (float)(mx - data->dragstartx) / deler + data->dragfstart;
@@ -2830,12 +2830,12 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
#if 0
if (but->type == SLI) {
- f = (float)(mx - but->rect.xmin) / (but->rect.xmax - but->rect.xmin); /* same as below */
+ f = (float)(mx - but->rect.xmin) / (BLI_RCT_SIZE_X(&but->rect)); /* same as below */
}
else
#endif
{
- f = (float)(mx - but->rect.xmin) / (but->rect.xmax - but->rect.xmin);
+ f = (float)(mx - but->rect.xmin) / (BLI_RCT_SIZE_X(&but->rect));
}
f = softmin + f * softrange;
@@ -2876,7 +2876,7 @@ static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
{
int mx, my /*, click= 0 */;
int retval = WM_UI_HANDLER_CONTINUE;
- int horizontal = (but->rect.xmax - but->rect.xmin > but->rect.ymax - but->rect.ymin);
+ int horizontal = (BLI_RCT_SIZE_X(&but->rect) > BLI_RCT_SIZE_Y(&but->rect));
mx = event->x;
my = event->y;
@@ -3033,7 +3033,7 @@ static int ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data, int mx, i
* else we'll get a harmless but annoying jump when first clicking */
fp = data->origvec;
- rad = (but->rect.xmax - but->rect.xmin);
+ rad = BLI_RCT_SIZE_X(&but->rect);
radsq = rad * rad;
if (fp[2] > 0.0f) {
@@ -3141,8 +3141,8 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
/* relative position within box */
- x = ((float)mx_fl - but->rect.xmin) / (but->rect.xmax - but->rect.xmin);
- y = ((float)my_fl - but->rect.ymin) / (but->rect.ymax - but->rect.ymin);
+ x = ((float)mx_fl - but->rect.xmin) / BLI_RCT_SIZE_X(&but->rect);
+ y = ((float)my_fl - but->rect.ymin) / BLI_RCT_SIZE_Y(&but->rect);
CLAMP(x, 0.0f, 1.0f);
CLAMP(y, 0.0f, 1.0f);
@@ -3539,7 +3539,7 @@ static int ui_numedit_but_COLORBAND(uiBut *but, uiHandleButtonData *data, int mx
if (data->draglastx == mx)
return changed;
- dx = ((float)(mx - data->draglastx)) / (but->rect.xmax - but->rect.xmin);
+ dx = ((float)(mx - data->draglastx)) / BLI_RCT_SIZE_X(&but->rect);
data->dragcbd->pos += dx;
CLAMP(data->dragcbd->pos, 0.0f, 1.0f);
@@ -3568,7 +3568,7 @@ static int ui_do_but_COLORBAND(bContext *C, uiBlock *block, uiBut *but, uiHandle
if (event->ctrl) {
/* insert new key on mouse location */
- float pos = ((float)(mx - but->rect.xmin)) / (but->rect.xmax - but->rect.xmin);
+ float pos = ((float)(mx - but->rect.xmin)) / BLI_RCT_SIZE_X(&but->rect);
colorband_element_add(coba, pos);
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
@@ -3580,7 +3580,7 @@ static int ui_do_but_COLORBAND(bContext *C, uiBlock *block, uiBut *but, uiHandle
/* activate new key when mouse is close */
for (a = 0, cbd = coba->data; a < coba->tot; a++, cbd++) {
- xco = but->rect.xmin + (cbd->pos * (but->rect.xmax - but->rect.xmin));
+ xco = but->rect.xmin + (cbd->pos * BLI_RCT_SIZE_X(&but->rect));
xco = ABS(xco - mx);
if (a == coba->cur) xco += 5; // selected one disadvantage
if (xco < mindist) {
@@ -3621,8 +3621,8 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
float fx, fy, zoomx, zoomy /*, offsx, offsy */ /* UNUSED */;
int a, changed = 0;
- zoomx = (but->rect.xmax - but->rect.xmin) / (cumap->curr.xmax - cumap->curr.xmin);
- zoomy = (but->rect.ymax - but->rect.ymin) / (cumap->curr.ymax - cumap->curr.ymin);
+ zoomx = BLI_RCT_SIZE_X(&but->rect) / BLI_RCT_SIZE_X(&cumap->curr);
+ zoomy = BLI_RCT_SIZE_Y(&but->rect) / BLI_RCT_SIZE_Y(&cumap->curr);
/* offsx= cumap->curr.xmin; */
/* offsy= cumap->curr.ymin; */
@@ -3717,8 +3717,8 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
float dist, mindist = 200.0f; // 14 pixels radius
int sel = -1;
- zoomx = (but->rect.xmax - but->rect.xmin) / (cumap->curr.xmax - cumap->curr.xmin);
- zoomy = (but->rect.ymax - but->rect.ymin) / (cumap->curr.ymax - cumap->curr.ymin);
+ zoomx = BLI_RCT_SIZE_X(&but->rect) / BLI_RCT_SIZE_X(&cumap->curr);
+ zoomy = BLI_RCT_SIZE_Y(&but->rect) / BLI_RCT_SIZE_Y(&cumap->curr);
offsx = cumap->curr.xmin;
offsy = cumap->curr.ymin;
@@ -3862,7 +3862,7 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx
if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
/* resize histogram widget itself */
- hist->height = (but->rect.ymax - but->rect.ymin) + (data->dragstarty - my);
+ hist->height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
}
else {
/* scale histogram values (dy / 10 for better control) */
@@ -3946,7 +3946,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx,
if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
/* resize waveform widget itself */
- scopes->wavefrm_height = (but->rect.ymax - but->rect.ymin) + (data->dragstarty - my);
+ scopes->wavefrm_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
}
else {
/* scale waveform values */
@@ -4028,7 +4028,7 @@ static int ui_numedit_but_VECTORSCOPE(uiBut *but, uiHandleButtonData *data, int
if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
/* resize vectorscope widget itself */
- scopes->vecscope_height = (but->rect.ymax - but->rect.ymin) + (data->dragstarty - my);
+ scopes->vecscope_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
}
data->draglastx = mx;
@@ -4098,8 +4098,8 @@ static int ui_do_but_CHARTAB(bContext *UNUSED(C), uiBlock *UNUSED(block), uiBut
if (data->state == BUTTON_STATE_HIGHLIGHT) {
if (ELEM3(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_PRESS) {
/* Calculate the size of the button */
- width = abs(but->rect.xmax - but->rect.xmin);
- height = abs(but->rect.ymax - but->rect.ymin);
+ width = abs(BLI_RCT_SIZE_X(&but->rect));
+ height = abs(BLI_RCT_SIZE_Y(&but->rect));
butw = floor(width / 12);
buth = floor(height / 6);
@@ -4231,7 +4231,7 @@ static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonDa
if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
/* resize preview widget itself */
- scopes->track_preview_height = (but->rect.ymax - but->rect.ymin) + (data->dragstarty - my);
+ scopes->track_preview_height = BLI_RCT_SIZE_Y(&but->rect) + (data->dragstarty - my);
}
else {
if (!scopes->track_locked) {
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 3bbf5b17312..512cda13df1 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -360,11 +360,11 @@ void UI_DrawTriIcon(float x, float y, char dir)
static void ui_draw_tria_rect(rctf *rect, char dir)
{
if (dir == 'h') {
- float half = 0.5f * (rect->ymax - rect->ymin);
+ float half = 0.5f * BLI_RCT_SIZE_Y(rect);
ui_draw_anti_tria(rect->xmin, rect->ymin, rect->xmin, rect->ymax, rect->xmax, rect->ymin + half);
}
else {
- float half = 0.5f * (rect->xmax - rect->xmin);
+ float half = 0.5f * BLI_RCT_SIZE_X(rect);
ui_draw_anti_tria(rect->xmin, rect->ymax, rect->xmax, rect->ymax, rect->xmin + half, rect->ymin);
}
}
@@ -483,8 +483,8 @@ static void rectf_scale(rctf *rect, float scale)
{
float centx = 0.5f * (rect->xmin + rect->xmax);
float centy = 0.5f * (rect->ymin + rect->ymax);
- float sizex = 0.5f * scale * (rect->xmax - rect->xmin);
- float sizey = 0.5f * scale * (rect->ymax - rect->ymin);
+ float sizex = 0.5f * scale * BLI_RCT_SIZE_X(rect);
+ float sizey = 0.5f * scale * BLI_RCT_SIZE_Y(rect);
rect->xmin = centx - sizex;
rect->xmax = centx + sizex;
@@ -985,8 +985,8 @@ static void ui_do_drag(const bContext *C, wmEvent *event, Panel *panel)
dx = (event->x - data->startx) & ~(PNL_GRID - 1);
dy = (event->y - data->starty) & ~(PNL_GRID - 1);
- dx *= (float)(ar->v2d.cur.xmax - ar->v2d.cur.xmin) / (float)(ar->winrct.xmax - ar->winrct.xmin);
- dy *= (float)(ar->v2d.cur.ymax - ar->v2d.cur.ymin) / (float)(ar->winrct.ymax - ar->winrct.ymin);
+ dx *= (float)BLI_RCT_SIZE_X(&ar->v2d.cur) / (float)BLI_RCT_SIZE_X(&ar->winrct);
+ dy *= (float)BLI_RCT_SIZE_Y(&ar->v2d.cur) / (float)BLI_RCT_SIZE_Y(&ar->winrct);
if (data->state == PANEL_STATE_DRAG_SCALE) {
panel->sizex = MAX2(data->startsizex + dx, UI_PANEL_MINX);
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index c44a45c2150..35488430b22 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -1095,13 +1095,13 @@ static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
if (data->items.more) {
ui_searchbox_butrect(&rect, data, data->items.maxitem - 1);
glEnable(GL_BLEND);
- UI_icon_draw((rect.xmax - rect.xmin) / 2, rect.ymin - 9, ICON_TRIA_DOWN);
+ UI_icon_draw((BLI_RCT_SIZE_X(&rect)) / 2, rect.ymin - 9, ICON_TRIA_DOWN);
glDisable(GL_BLEND);
}
if (data->items.offset) {
ui_searchbox_butrect(&rect, data, 0);
glEnable(GL_BLEND);
- UI_icon_draw((rect.xmax - rect.xmin) / 2, rect.ymax - 7, ICON_TRIA_UP);
+ UI_icon_draw((BLI_RCT_SIZE_X(&rect)) / 2, rect.ymax - 7, ICON_TRIA_UP);
glDisable(GL_BLEND);
}
}
@@ -1176,16 +1176,16 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but)
/* widget rect, in region coords */
data->bbox.xmin = MENU_SHADOW_SIDE;
- data->bbox.xmax = (ar->winrct.xmax - ar->winrct.xmin) - MENU_SHADOW_SIDE;
+ data->bbox.xmax = BLI_RCT_SIZE_X(&ar->winrct) - MENU_SHADOW_SIDE;
data->bbox.ymin = MENU_SHADOW_BOTTOM;
- data->bbox.ymax = (ar->winrct.ymax - ar->winrct.ymin) - MENU_SHADOW_BOTTOM;
+ data->bbox.ymax = BLI_RCT_SIZE_Y(&ar->winrct) - MENU_SHADOW_BOTTOM;
/* check if button is lower half */
if (but->rect.ymax < BLI_RCT_CENTER_Y(&but->block->rect)) {
- data->bbox.ymin += (but->rect.ymax - but->rect.ymin);
+ data->bbox.ymin += BLI_RCT_SIZE_Y(&but->rect);
}
else {
- data->bbox.ymax -= (but->rect.ymax - but->rect.ymin);
+ data->bbox.ymax -= BLI_RCT_SIZE_Y(&but->rect);
}
}
else {
@@ -1356,15 +1356,15 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
}
}
- /* aspect = (float)(block->rect.xmax - block->rect.xmin + 4);*/ /*UNUSED*/
+ /* aspect = (float)(BLI_RCT_SIZE_X(&block->rect) + 4);*/ /*UNUSED*/
ui_block_to_window_fl(butregion, but->block, &block->rect.xmin, &block->rect.ymin);
ui_block_to_window_fl(butregion, but->block, &block->rect.xmax, &block->rect.ymax);
//block->rect.xmin -= 2.0; block->rect.ymin -= 2.0;
//block->rect.xmax += 2.0; block->rect.ymax += 2.0;
- xsize = block->rect.xmax - block->rect.xmin + 4; /* 4 for shadow */
- ysize = block->rect.ymax - block->rect.ymin + 4;
+ xsize = BLI_RCT_SIZE_X(&block->rect) + 4; /* 4 for shadow */
+ ysize = BLI_RCT_SIZE_Y(&block->rect) + 4;
/* aspect /= (float)xsize;*/ /*UNUSED*/
{
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index 779341160c5..ee0613ea0d0 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -152,17 +152,17 @@ void uiStyleFontDrawExt(uiFontStyle *fs, rcti *rect, const char *str,
uiStyleFontSet(fs);
height = BLF_ascender(fs->uifont_id);
- yofs = ceil(0.5f * (rect->ymax - rect->ymin - height));
+ yofs = ceil(0.5f * (BLI_RCT_SIZE_Y(rect) - height));
if (fs->align == UI_STYLE_TEXT_CENTER) {
- xofs = floor(0.5f * (rect->xmax - rect->xmin - BLF_width(fs->uifont_id, str)));
+ xofs = floor(0.5f * (BLI_RCT_SIZE_X(rect) - BLF_width(fs->uifont_id, str)));
/* don't center text if it chops off the start of the text, 2 gives some margin */
if (xofs < 2) {
xofs = 2;
}
}
else if (fs->align == UI_STYLE_TEXT_RIGHT) {
- xofs = rect->xmax - rect->xmin - BLF_width(fs->uifont_id, str) - 1;
+ xofs = BLI_RCT_SIZE_X(rect) - BLF_width(fs->uifont_id, str) - 1;
}
/* clip is very strict, so we give it some space */
@@ -209,7 +209,7 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, const char *str)
height = BLF_ascender(fs->uifont_id);
/* becomes x-offset when rotated */
- xofs = ceil(0.5f * (rect->ymax - rect->ymin - height));
+ xofs = ceil(0.5f * (BLI_RCT_SIZE_Y(rect) - height));
/* ignore UI_STYLE, always aligned to top */
@@ -219,8 +219,8 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, const char *str)
angle = 90.0f;
/* translate rect to vertical */
- txtrect.xmin = rect->xmin - (rect->ymax - rect->ymin);
- txtrect.ymin = rect->ymin - (rect->xmax - rect->xmin);
+ txtrect.xmin = rect->xmin - BLI_RCT_SIZE_Y(rect);
+ txtrect.ymin = rect->ymin - BLI_RCT_SIZE_X(rect);
txtrect.xmax = rect->xmin;
txtrect.ymax = rect->ymin;
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 7c4f181b9de..24dccb2eecf 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -40,6 +40,7 @@
#include "BLI_utildefines.h"
#include "BLI_string.h"
#include "BLI_ghash.h"
+#include "BLI_rect.h"
#include "BLF_translation.h"
@@ -1378,7 +1379,7 @@ static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand
static void colorband_buttons_small(uiLayout *layout, uiBlock *block, ColorBand *coba, rctf *butr, RNAUpdateCb *cb)
{
uiBut *bt;
- float unit = (butr->xmax - butr->xmin) / 14.0f;
+ float unit = BLI_RCT_SIZE_X(butr) / 14.0f;
float xs = butr->xmin;
uiBlockBeginAlign(block);
@@ -1404,7 +1405,7 @@ static void colorband_buttons_small(uiLayout *layout, uiBlock *block, ColorBand
TIP_("Set interpolation between color stops"));
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
- bt = uiDefBut(block, BUT_COLORBAND, 0, "", xs, butr->ymin, butr->xmax - butr->xmin, UI_UNIT_Y, coba, 0, 0, 0, 0, "");
+ bt = uiDefBut(block, BUT_COLORBAND, 0, "", xs, butr->ymin, BLI_RCT_SIZE_X(butr), UI_UNIT_Y, coba, 0, 0, 0, 0, "");
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
uiBlockEndAlign(block);
@@ -1479,7 +1480,7 @@ void uiTemplateHistogram(uiLayout *layout, PointerRNA *ptr, const char *propname
hist->height = (hist->height <= UI_UNIT_Y) ? UI_UNIT_Y : hist->height;
- bt = uiDefBut(block, HISTOGRAM, 0, "", rect.xmin, rect.ymin, rect.xmax - rect.xmin, hist->height, hist, 0, 0, 0, 0, "");
+ bt = uiDefBut(block, HISTOGRAM, 0, "", rect.xmin, rect.ymin, BLI_RCT_SIZE_X(&rect), hist->height, hist, 0, 0, 0, 0, "");
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
MEM_freeN(cb);
@@ -1516,7 +1517,7 @@ void uiTemplateWaveform(uiLayout *layout, PointerRNA *ptr, const char *propname)
scopes->wavefrm_height = (scopes->wavefrm_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->wavefrm_height;
- bt = uiDefBut(block, WAVEFORM, 0, "", rect.xmin, rect.ymin, rect.xmax - rect.xmin, scopes->wavefrm_height, scopes, 0, 0, 0, 0, "");
+ bt = uiDefBut(block, WAVEFORM, 0, "", rect.xmin, rect.ymin, BLI_RCT_SIZE_X(&rect), scopes->wavefrm_height, scopes, 0, 0, 0, 0, "");
(void)bt; /* UNUSED */
MEM_freeN(cb);
@@ -1553,7 +1554,7 @@ void uiTemplateVectorscope(uiLayout *layout, PointerRNA *ptr, const char *propna
scopes->vecscope_height = (scopes->vecscope_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->vecscope_height;
- bt = uiDefBut(block, VECTORSCOPE, 0, "", rect.xmin, rect.ymin, rect.xmax - rect.xmin, scopes->vecscope_height, scopes, 0, 0, 0, 0, "");
+ bt = uiDefBut(block, VECTORSCOPE, 0, "", rect.xmin, rect.ymin, BLI_RCT_SIZE_X(&rect), scopes->vecscope_height, scopes, 0, 0, 0, 0, "");
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
MEM_freeN(cb);
@@ -1568,11 +1569,11 @@ static void curvemap_buttons_zoom_in(bContext *C, void *cumap_v, void *UNUSED(ar
float d;
/* we allow 20 times zoom */
- if ( (cumap->curr.xmax - cumap->curr.xmin) > 0.04f * (cumap->clipr.xmax - cumap->clipr.xmin) ) {
- d = 0.1154f * (cumap->curr.xmax - cumap->curr.xmin);
+ if (BLI_RCT_SIZE_X(&cumap->curr) > 0.04f * BLI_RCT_SIZE_X(&cumap->clipr)) {
+ d = 0.1154f * BLI_RCT_SIZE_X(&cumap->curr);
cumap->curr.xmin += d;
cumap->curr.xmax -= d;
- d = 0.1154f * (cumap->curr.ymax - cumap->curr.ymin);
+ d = 0.1154f * BLI_RCT_SIZE_Y(&cumap->curr);
cumap->curr.ymin += d;
cumap->curr.ymax -= d;
}
@@ -1586,8 +1587,8 @@ static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void *UNUSED(u
float d, d1;
/* we allow 20 times zoom, but don't view outside clip */
- if ( (cumap->curr.xmax - cumap->curr.xmin) < 20.0f * (cumap->clipr.xmax - cumap->clipr.xmin) ) {
- d = d1 = 0.15f * (cumap->curr.xmax - cumap->curr.xmin);
+ if (BLI_RCT_SIZE_X(&cumap->curr) < 20.0f * BLI_RCT_SIZE_X(&cumap->clipr)) {
+ d = d1 = 0.15f * BLI_RCT_SIZE_X(&cumap->curr);
if (cumap->flag & CUMA_DO_CLIP)
if (cumap->curr.xmin - d < cumap->clipr.xmin)
@@ -1600,7 +1601,7 @@ static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void *UNUSED(u
d1 = -cumap->curr.xmax + cumap->clipr.xmax;
cumap->curr.xmax += d1;
- d = d1 = 0.15f * (cumap->curr.ymax - cumap->curr.ymin);
+ d = d1 = 0.15f * BLI_RCT_SIZE_Y(&cumap->curr);
if (cumap->flag & CUMA_DO_CLIP)
if (cumap->curr.ymin - d < cumap->clipr.ymin)
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 3c944781d80..bf5b3fbe8c7 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -260,8 +260,8 @@ static int round_box_shadow_edges(float (*vert)[2], rcti *rect, float rad, int r
rad += step;
- if (2.0f * rad > rect->ymax - rect->ymin)
- rad = 0.5f * (rect->ymax - rect->ymin);
+ if (2.0f * rad > BLI_RCT_SIZE_Y(rect))
+ rad = 0.5f * BLI_RCT_SIZE_Y(rect);
minx = rect->xmin - step;
miny = rect->ymin - step;
@@ -346,8 +346,8 @@ static void round_box__edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, fl
const int vnum = ((roundboxalign & (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT)) == (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT) ||
(roundboxalign & (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) == (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) ? 1 : 2;
- minsize = mini((rect->xmax - rect->xmin) * hnum,
- (rect->ymax - rect->ymin) * vnum);
+ minsize = mini(BLI_RCT_SIZE_X(rect) * hnum,
+ BLI_RCT_SIZE_Y(rect) * vnum);
if (2.0f * rad > minsize)
rad = 0.5f * minsize;
@@ -492,7 +492,7 @@ static void widget_num_tria(uiWidgetTrias *tria, rcti *rect, float triasize, cha
float centx, centy, sizex, sizey, minsize;
int a, i1 = 0, i2 = 1;
- minsize = MIN2(rect->xmax - rect->xmin, rect->ymax - rect->ymin);
+ minsize = mini(BLI_RCT_SIZE_X(rect), BLI_RCT_SIZE_Y(rect));
/* center position and size */
centx = (float)rect->xmin + 0.5f * minsize;
@@ -527,7 +527,7 @@ static void widget_scroll_circle(uiWidgetTrias *tria, rcti *rect, float triasize
float centx, centy, sizex, sizey, minsize;
int a, i1 = 0, i2 = 1;
- minsize = MIN2(rect->xmax - rect->xmin, rect->ymax - rect->ymin);
+ minsize = mini(BLI_RCT_SIZE_X(rect), BLI_RCT_SIZE_Y(rect));
/* center position and size */
centx = (float)rect->xmin + 0.5f * minsize;
@@ -571,14 +571,14 @@ static void widget_menu_trias(uiWidgetTrias *tria, rcti *rect)
int a;
/* center position and size */
- centx = rect->xmax - 0.5f * (rect->ymax - rect->ymin);
- centy = rect->ymin + 0.5f * (rect->ymax - rect->ymin);
- size = 0.4f * (rect->ymax - rect->ymin);
+ centx = rect->xmax - 0.5f * BLI_RCT_SIZE_Y(rect);
+ centy = rect->ymin + 0.5f * BLI_RCT_SIZE_Y(rect);
+ size = 0.4f * BLI_RCT_SIZE_Y(rect);
/* XXX exception */
- asp = ((float)rect->xmax - rect->xmin) / ((float)rect->ymax - rect->ymin);
+ asp = ((float)BLI_RCT_SIZE_X(rect)) / ((float)BLI_RCT_SIZE_Y(rect));
if (asp > 1.2f && asp < 2.6f)
- centx = rect->xmax - 0.3f * (rect->ymax - rect->ymin);
+ centx = rect->xmax - 0.3f * BLI_RCT_SIZE_Y(rect);
for (a = 0; a < 6; a++) {
tria->vec[a][0] = size * menu_tria_vert[a][0] + centx;
@@ -595,9 +595,9 @@ static void widget_check_trias(uiWidgetTrias *tria, rcti *rect)
int a;
/* center position and size */
- centx = rect->xmin + 0.5f * (rect->ymax - rect->ymin);
- centy = rect->ymin + 0.5f * (rect->ymax - rect->ymin);
- size = 0.5f * (rect->ymax - rect->ymin);
+ centx = rect->xmin + 0.5f * BLI_RCT_SIZE_Y(rect);
+ centy = rect->ymin + 0.5f * BLI_RCT_SIZE_Y(rect);
+ size = 0.5f * BLI_RCT_SIZE_Y(rect);
for (a = 0; a < 6; a++) {
tria->vec[a][0] = size * check_tria_vert[a][0] + centx;
@@ -841,8 +841,8 @@ static void widget_draw_preview(BIFIconID icon, float UNUSED(alpha), rcti *rect)
if (icon == ICON_NONE)
return;
- w = rect->xmax - rect->xmin;
- h = rect->ymax - rect->ymin;
+ w = BLI_RCT_SIZE_X(rect);
+ h = BLI_RCT_SIZE_Y(rect);
size = MIN2(w, h);
size -= PREVIEW_PAD * 2; /* padding */
@@ -970,7 +970,7 @@ static void ui_text_clip_give_next_off(uiBut *but)
static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
{
int border = (but->flag & UI_BUT_ALIGN_RIGHT) ? 8 : 10;
- int okwidth = rect->xmax - rect->xmin - border;
+ int okwidth = BLI_RCT_SIZE_X(rect) - border;
if (but->flag & UI_HAS_ICON) okwidth -= UI_DPI_ICON_SIZE;
@@ -1033,7 +1033,7 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
{
int border = (but->flag & UI_BUT_ALIGN_RIGHT) ? 8 : 10;
- int okwidth = rect->xmax - rect->xmin - border;
+ int okwidth = BLI_RCT_SIZE_X(rect) - border;
char *cpoin = NULL;
char *cpend = but->drawstr + strlen(but->drawstr);
@@ -1265,7 +1265,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
}
else if (but->type == MENU && (but->flag & UI_BUT_NODE_LINK)) {
int tmp = rect->xmin;
- rect->xmin = rect->xmax - (rect->ymax - rect->ymin) - 1;
+ rect->xmin = rect->xmax - BLI_RCT_SIZE_Y(rect) - 1;
widget_draw_icon(but, ICON_LAYER_USED, 1.0f, rect);
rect->xmin = tmp;
}
@@ -1847,10 +1847,10 @@ void ui_hsvcircle_vals_from_pos(float *valrad, float *valdist, rcti *rect, float
float centy = BLI_RCT_CENTER_Y_FL(rect);
float radius, dist;
- if (rect->xmax - rect->xmin > rect->ymax - rect->ymin)
- radius = (float)(rect->ymax - rect->ymin) / 2;
+ if (BLI_RCT_SIZE_X(rect) > BLI_RCT_SIZE_Y(rect))
+ radius = (float)BLI_RCT_SIZE_Y(rect) / 2;
else
- radius = (float)(rect->xmax - rect->xmin) / 2;
+ radius = (float)BLI_RCT_SIZE_X(rect) / 2;
mx -= centx;
my -= centy;
@@ -1879,10 +1879,10 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
centx = BLI_RCT_CENTER_X_FL(rect);
centy = BLI_RCT_CENTER_Y_FL(rect);
- if (rect->xmax - rect->xmin > rect->ymax - rect->ymin)
- radius = (float)(rect->ymax - rect->ymin) / 2;
+ if (BLI_RCT_SIZE_X(rect) > BLI_RCT_SIZE_Y(rect))
+ radius = (float)BLI_RCT_SIZE_Y(rect) / 2;
else
- radius = (float)(rect->xmax - rect->xmin) / 2;
+ radius = (float)BLI_RCT_SIZE_X(rect) / 2;
/* color */
ui_get_but_vectorf(but, rgb);
@@ -2058,10 +2058,10 @@ void ui_draw_gradient(rcti *rect, const float hsv[3], const int type, const floa
}
/* rect */
- sx1 = rect->xmin + dx * (rect->xmax - rect->xmin);
- sx2 = rect->xmin + (dx + color_step) * (rect->xmax - rect->xmin);
+ sx1 = rect->xmin + dx * BLI_RCT_SIZE_X(rect);
+ sx2 = rect->xmin + (dx + color_step) * BLI_RCT_SIZE_X(rect);
sy = rect->ymin;
- dy = (rect->ymax - rect->ymin) / 3.0;
+ dy = BLI_RCT_SIZE_Y(rect) / 3.0;
glBegin(GL_QUADS);
for (a = 0; a < 3; a++, sy += dy) {
@@ -2116,8 +2116,8 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
}
/* cursor */
- x = rect->xmin + x * (rect->xmax - rect->xmin);
- y = rect->ymin + y * (rect->ymax - rect->ymin);
+ x = rect->xmin + x * BLI_RCT_SIZE_X(rect);
+ y = rect->ymin + y * BLI_RCT_SIZE_Y(rect);
CLAMP(x, rect->xmin + 3.0f, rect->xmax - 3.0f);
CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f);
@@ -2132,7 +2132,7 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
{
uiWidgetBase wtb;
- float rad = 0.5f * (rect->xmax - rect->xmin);
+ float rad = 0.5f * BLI_RCT_SIZE_X(rect);
float x, y;
float rgb[3], hsv[3], v, range;
int color_profile = but->block->color_profile;
@@ -2166,8 +2166,8 @@ static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
widgetbase_draw(&wtb, &wcol_tmp);
/* cursor */
- x = rect->xmin + 0.5f * (rect->xmax - rect->xmin);
- y = rect->ymin + v * (rect->ymax - rect->ymin);
+ x = rect->xmin + 0.5f * BLI_RCT_SIZE_X(rect);
+ y = rect->ymin + v * BLI_RCT_SIZE_Y(rect);
CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f);
ui_hsv_cursor(x, y);
@@ -2178,7 +2178,7 @@ static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
/* ************ separator, for menus etc ***************** */
static void ui_draw_separator(rcti *rect, uiWidgetColors *wcol)
{
- int y = rect->ymin + (rect->ymax - rect->ymin) / 2 - 1;
+ int y = rect->ymin + BLI_RCT_SIZE_Y(rect) / 2 - 1;
unsigned char col[4];
col[0] = wcol->text[0];
@@ -2197,7 +2197,7 @@ static void ui_draw_separator(rcti *rect, uiWidgetColors *wcol)
static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
{
uiWidgetBase wtb;
- float rad = 0.5f * (rect->ymax - rect->ymin);
+ float rad = 0.5f * BLI_RCT_SIZE_Y(rect);
float textofs = rad * 0.75f;
if (state & UI_SELECT)
@@ -2278,12 +2278,12 @@ void uiWidgetScrollDraw(uiWidgetColors *wcol, rcti *rect, rcti *slider, int stat
widget_init(&wtb);
/* determine horizontal/vertical */
- horizontal = (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
+ horizontal = (BLI_RCT_SIZE_X(rect) > BLI_RCT_SIZE_Y(rect));
if (horizontal)
- rad = 0.5f * (rect->ymax - rect->ymin);
+ rad = 0.5f * BLI_RCT_SIZE_Y(rect);
else
- rad = 0.5f * (rect->xmax - rect->xmin);
+ rad = 0.5f * BLI_RCT_SIZE_X(rect);
wtb.shadedir = (horizontal) ? 1 : 0;
@@ -2295,9 +2295,10 @@ void uiWidgetScrollDraw(uiWidgetColors *wcol, rcti *rect, rcti *slider, int stat
widgetbase_draw(&wtb, wcol);
/* slider */
- if (slider->xmax - slider->xmin < 2 || slider->ymax - slider->ymin < 2) ;
+ if ((BLI_RCT_SIZE_X(slider) < 2) || (BLI_RCT_SIZE_Y(slider) < 2)) {
+ /* pass */
+ }
else {
-
SWAP(short, wcol->shadetop, wcol->shadedown);
copy_v4_v4_char(wcol->inner, wcol->item);
@@ -2360,15 +2361,15 @@ static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
rect1 = *rect;
/* determine horizontal/vertical */
- horizontal = (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
+ horizontal = (BLI_RCT_SIZE_X(rect) > BLI_RCT_SIZE_Y(rect));
if (horizontal) {
- fac = (rect->xmax - rect->xmin) / (size);
+ fac = BLI_RCT_SIZE_X(rect) / size;
rect1.xmin = rect1.xmin + ceilf(fac * ((float)value - but->softmin));
rect1.xmax = rect1.xmin + ceilf(fac * (but->a1 - but->softmin));
/* ensure minimium size */
- min = rect->ymax - rect->ymin;
+ min = BLI_RCT_SIZE_Y(rect);
if (rect1.xmax - rect1.xmin < min) {
rect1.xmax = rect1.xmin + min;
@@ -2380,12 +2381,12 @@ static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
}
}
else {
- fac = (rect->ymax - rect->ymin) / (size);
+ fac = BLI_RCT_SIZE_Y(rect) / size;
rect1.ymax = rect1.ymax - ceilf(fac * ((float)value - but->softmin));
rect1.ymin = rect1.ymax - ceilf(fac * (but->a1 - but->softmin));
/* ensure minimium size */
- min = rect->xmax - rect->xmin;
+ min = BLI_RCT_SIZE_X(rect);
if (rect1.ymax - rect1.ymin < min) {
rect1.ymax = rect1.ymin + min;
@@ -2461,7 +2462,7 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s
/* backdrop first */
/* fully rounded */
- offs = 0.5f * (rect->ymax - rect->ymin);
+ offs = 0.5f * BLI_RCT_SIZE_Y(rect);
toffs = offs * 0.75f;
round_box_edges(&wtb, roundboxalign, rect, offs);
@@ -2615,7 +2616,7 @@ static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state),
widgetbase_draw(&wtb, wcol);
/* text space */
- rect->xmax -= (rect->ymax - rect->ymin);
+ rect->xmax -= BLI_RCT_SIZE_Y(rect);
}
static void widget_menuiconbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
@@ -2658,7 +2659,7 @@ static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int
{
if (state & UI_ACTIVE) {
uiWidgetBase wtb;
- float rad = 0.5f * (rect->ymax - rect->ymin); /* 4.0f */
+ float rad = 0.5f * BLI_RCT_SIZE_Y(rect); /* 4.0f */
widget_init(&wtb);
@@ -2724,7 +2725,7 @@ static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int UN
widgetbase_draw(&wtb, wcol);
/* text space */
- rect->xmin += (rect->ymax - rect->ymin) * 0.7 + delta;
+ rect->xmin += BLI_RCT_SIZE_Y(rect) * 0.7 + delta;
}
@@ -2786,7 +2787,7 @@ static void widget_but(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int
static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
{
uiWidgetBase wtb;
- float rad = 5.0f; /* 0.5f * (rect->ymax - rect->ymin); */
+ float rad = 5.0f; /* 0.5f * BLI_RCT_SIZE_Y(rect); */
widget_init(&wtb);
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
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index f12a9e06312..258025eefc9 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -119,10 +119,10 @@ static int view_pan_init(bContext *C, wmOperator *op)
vpd->ar = ar;
/* calculate translation factor - based on size of view */
- winx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1);
- winy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1);
- vpd->facx = (v2d->cur.xmax - v2d->cur.xmin) / winx;
- vpd->facy = (v2d->cur.ymax - v2d->cur.ymin) / winy;
+ winx = (float)(BLI_RCT_SIZE_X(&ar->winrct) + 1);
+ winy = (float)(BLI_RCT_SIZE_Y(&ar->winrct) + 1);
+ vpd->facx = (BLI_RCT_SIZE_X(&v2d->cur)) / winx;
+ vpd->facy = (BLI_RCT_SIZE_Y(&v2d->cur)) / winy;
return 1;
}
@@ -590,12 +590,12 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op)
facy = RNA_float_get(op->ptr, "zoomfacy");
if (facx >= 0.0f) {
- dx = (v2d->cur.xmax - v2d->cur.xmin) * facx;
- dy = (v2d->cur.ymax - v2d->cur.ymin) * facy;
+ dx = BLI_RCT_SIZE_X(&v2d->cur) * facx;
+ dy = BLI_RCT_SIZE_Y(&v2d->cur) * facy;
}
else {
- dx = ((v2d->cur.xmax - v2d->cur.xmin) / (1.0f + 2.0f * facx)) * facx;
- dy = ((v2d->cur.ymax - v2d->cur.ymin) / (1.0f + 2.0f * facy)) * facy;
+ dx = (BLI_RCT_SIZE_X(&v2d->cur) / (1.0f + 2.0f * facx)) * facx;
+ dy = (BLI_RCT_SIZE_Y(&v2d->cur) / (1.0f + 2.0f * facy)) * facy;
}
/* only resize view on an axis if change is allowed */
@@ -611,7 +611,7 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op)
}
else {
if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
- float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
+ float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_RCT_SIZE_X(&v2d->cur);
float mval_faci = 1.0f - mval_fac;
float ofs = (mval_fac * dx) - (mval_faci * dx);
@@ -636,7 +636,7 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op)
}
else {
if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
- float mval_fac = (vzd->my_2d - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
+ float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_RCT_SIZE_Y(&v2d->cur);
float mval_faci = 1.0f - mval_fac;
float ofs = (mval_fac * dy) - (mval_faci * dy);
@@ -821,7 +821,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
}
else {
if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
- float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
+ float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_RCT_SIZE_X(&v2d->cur);
float mval_faci = 1.0f - mval_fac;
float ofs = (mval_fac * dx) - (mval_faci * dx);
@@ -840,7 +840,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
}
else {
if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
- float mval_fac = (vzd->my_2d - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
+ float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_RCT_SIZE_Y(&v2d->cur);
float mval_faci = 1.0f - mval_fac;
float ofs = (mval_fac * dy) - (mval_faci * dy);
@@ -918,8 +918,8 @@ static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
* with magnify information that is stored in x axis
*/
fac = 0.01f * (event->x - event->prevx);
- dx = fac * (v2d->cur.xmax - v2d->cur.xmin) / 10.0f;
- dy = fac * (v2d->cur.ymax - v2d->cur.ymin) / 10.0f;
+ dx = fac * BLI_RCT_SIZE_X(&v2d->cur) / 10.0f;
+ dy = fac * BLI_RCT_SIZE_Y(&v2d->cur) / 10.0f;
RNA_float_set(op->ptr, "deltax", dx);
RNA_float_set(op->ptr, "deltay", dy);
@@ -985,14 +985,14 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
float dist;
/* x-axis transform */
- dist = (v2d->mask.xmax - v2d->mask.xmin) / 2.0f;
+ dist = BLI_RCT_SIZE_X(&v2d->mask) / 2.0f;
dx = 1.0f - (fabsf(vzd->lastx - dist) + 2.0f) / (fabsf(event->x - dist) + 2.0f);
- dx *= 0.5f * (v2d->cur.xmax - v2d->cur.xmin);
+ dx *= 0.5f * BLI_RCT_SIZE_X(&v2d->cur);
/* y-axis transform */
- dist = (v2d->mask.ymax - v2d->mask.ymin) / 2.0f;
+ dist = BLI_RCT_SIZE_Y(&v2d->mask) / 2.0f;
dy = 1.0f - (fabsf(vzd->lasty - dist) + 2.0f) / (fabsf(event->y - dist) + 2.0f);
- dy *= 0.5f * (v2d->cur.ymax - v2d->cur.ymin);
+ dy *= 0.5f * BLI_RCT_SIZE_Y(&v2d->cur);
}
else {
/* 'continuous' or 'dolly' */
@@ -1000,11 +1000,11 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
/* x-axis transform */
fac = 0.01f * (event->x - vzd->lastx);
- dx = fac * (v2d->cur.xmax - v2d->cur.xmin);
+ dx = fac * BLI_RCT_SIZE_X(&v2d->cur);
/* y-axis transform */
fac = 0.01f * (event->y - vzd->lasty);
- dy = fac * (v2d->cur.ymax - v2d->cur.ymin);
+ dy = fac * BLI_RCT_SIZE_Y(&v2d->cur);
#if 0
/* continuous zoom shouldn't move that fast... */
if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
@@ -1138,7 +1138,7 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
/* TODO: is this zoom factor calculation valid? It seems to produce same results everytime... */
if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
size = (cur_new.xmax - cur_new.xmin);
- zoom = size / (rect.xmax - rect.xmin);
+ zoom = size / BLI_RCT_SIZE_X(&rect);
center = BLI_RCT_CENTER_X(&cur_new);
cur_new.xmin = center - (size * zoom);
@@ -1146,7 +1146,7 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
}
if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
size = (cur_new.ymax - cur_new.ymin);
- zoom = size / (rect.ymax - rect.ymin);
+ zoom = size / BLI_RCT_SIZE_Y(&rect);
center = BLI_RCT_CENTER_Y(&cur_new);
cur_new.ymin = center - (size * zoom);
@@ -1478,7 +1478,7 @@ static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event,
if (in_scroller == 'h') {
/* horizontal scroller - calculate adjustment factor first */
mask_size = (float)(v2d->hor.xmax - v2d->hor.xmin);
- vsm->fac = (v2d->tot.xmax - v2d->tot.xmin) / mask_size;
+ vsm->fac = BLI_RCT_SIZE_X(&v2d->tot) / mask_size;
/* get 'zone' (i.e. which part of scroller is activated) */
vsm->zone = mouse_in_scroller_handle(event->mval[0], v2d->hor.xmin, v2d->hor.xmax, scrollers->hor_min, scrollers->hor_max);
@@ -1494,7 +1494,7 @@ static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event,
else {
/* vertical scroller - calculate adjustment factor first */
mask_size = (float)(v2d->vert.ymax - v2d->vert.ymin);
- vsm->fac = (v2d->tot.ymax - v2d->tot.ymin) / mask_size;
+ vsm->fac = BLI_RCT_SIZE_Y(&v2d->tot) / mask_size;
/* get 'zone' (i.e. which part of scroller is activated) */
vsm->zone = mouse_in_scroller_handle(event->mval[1], v2d->vert.ymin, v2d->vert.ymax, scrollers->vert_min, scrollers->vert_max);
@@ -1774,8 +1774,8 @@ static int reset_exec(bContext *C, wmOperator *UNUSED(op))
int winx, winy;
/* zoom 1.0 */
- 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);
v2d->cur.xmax = v2d->cur.xmin + winx;
v2d->cur.ymax = v2d->cur.ymin + winy;