[Bf-blender-cvs] [4842dd022f3] master: Cleanup: Declare variables where initialized, lower scope
Hans Goudey
noreply at git.blender.org
Fri Sep 25 21:59:05 CEST 2020
Commit: 4842dd022f35f2f474d0ef96e03b4b18daa498dd
Author: Hans Goudey
Date: Fri Sep 25 14:57:34 2020 -0500
Branches: master
https://developer.blender.org/rB4842dd022f35f2f474d0ef96e03b4b18daa498dd
Cleanup: Declare variables where initialized, lower scope
Also use "r_" prefix for return arguments in a few places.
===================================================================
M source/blender/editors/interface/interface.c
===================================================================
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 433058260f7..99f2066a656 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -129,43 +129,38 @@ static bool ui_but_is_unit_radians(const uiBut *but)
/* ************* window matrix ************** */
-void ui_block_to_window_fl(const ARegion *region, uiBlock *block, float *x, float *y)
+void ui_block_to_window_fl(const ARegion *region, uiBlock *block, float *r_x, float *r_y)
{
- float gx, gy;
- int sx, sy, getsizex, getsizey;
+ int getsizex = BLI_rcti_size_x(®ion->winrct) + 1;
+ int getsizey = BLI_rcti_size_y(®ion->winrct) + 1;
+ int sx = region->winrct.xmin;
+ int sy = region->winrct.ymin;
- getsizex = BLI_rcti_size_x(®ion->winrct) + 1;
- getsizey = BLI_rcti_size_y(®ion->winrct) + 1;
- sx = region->winrct.xmin;
- sy = region->winrct.ymin;
-
- gx = *x;
- gy = *y;
+ float gx = *r_x;
+ float gy = *r_y;
if (block->panel) {
gx += block->panel->ofsx;
gy += block->panel->ofsy;
}
- *x = ((float)sx) +
- ((float)getsizex) * (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] +
- block->winmat[3][0]));
- *y = ((float)sy) +
- ((float)getsizey) * (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] +
- block->winmat[3][1]));
+ *r_x = ((float)sx) +
+ ((float)getsizex) * (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] +
+ block->winmat[3][0]));
+ *r_y = ((float)sy) +
+ ((float)getsizey) * (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] +
+ block->winmat[3][1]));
}
-void ui_block_to_window(const ARegion *region, uiBlock *block, int *x, int *y)
+void ui_block_to_window(const ARegion *region, uiBlock *block, int *r_x, int *r_y)
{
- float fx, fy;
-
- fx = *x;
- fy = *y;
+ float fx = *r_x;
+ float fy = *r_y;
ui_block_to_window_fl(region, block, &fx, &fy);
- *x = (int)(fx + 0.5f);
- *y = (int)(fy + 0.5f);
+ *r_x = (int)(fx + 0.5f);
+ *r_y = (int)(fy + 0.5f);
}
void ui_block_to_window_rctf(const ARegion *region,
@@ -181,9 +176,8 @@ void ui_block_to_window_rctf(const ARegion *region,
float ui_block_to_window_scale(const ARegion *region, uiBlock *block)
{
/* We could have function for this to avoid dummy arg. */
- float dummy_x;
float min_y = 0, max_y = 1;
- dummy_x = 0.0f;
+ float dummy_x = 0.0f;
ui_block_to_window_fl(region, block, &dummy_x, &min_y);
dummy_x = 0.0f;
ui_block_to_window_fl(region, block, &dummy_x, &max_y);
@@ -191,33 +185,30 @@ float ui_block_to_window_scale(const ARegion *region, uiBlock *block)
}
/* for mouse cursor */
-void ui_window_to_block_fl(const ARegion *region, uiBlock *block, float *x, float *y)
+void ui_window_to_block_fl(const ARegion *region, uiBlock *block, float *r_x, float *r_y)
{
- float a, b, c, d, e, f, px, py;
- int sx, sy, getsizex, getsizey;
+ int getsizex = BLI_rcti_size_x(®ion->winrct) + 1;
+ int getsizey = BLI_rcti_size_y(®ion->winrct) + 1;
+ int sx = region->winrct.xmin;
+ int sy = region->winrct.ymin;
- getsizex = BLI_rcti_size_x(®ion->winrct) + 1;
- getsizey = BLI_rcti_size_y(®ion->winrct) + 1;
- sx = region->winrct.xmin;
- sy = region->winrct.ymin;
+ float a = 0.5f * ((float)getsizex) * block->winmat[0][0];
+ float b = 0.5f * ((float)getsizex) * block->winmat[1][0];
+ float c = 0.5f * ((float)getsizex) * (1.0f + block->winmat[3][0]);
- a = 0.5f * ((float)getsizex) * block->winmat[0][0];
- b = 0.5f * ((float)getsizex) * block->winmat[1][0];
- c = 0.5f * ((float)getsizex) * (1.0f + block->winmat[3][0]);
+ float d = 0.5f * ((float)getsizey) * block->winmat[0][1];
+ float e = 0.5f * ((float)getsizey) * block->winmat[1][1];
+ float f = 0.5f * ((float)getsizey) * (1.0f + block->winmat[3][1]);
- d = 0.5f * ((float)getsizey) * block->winmat[0][1];
- e = 0.5f * ((float)getsizey) * block->winmat[1][1];
- f = 0.5f * ((float)getsizey) * (1.0f + block->winmat[3][1]);
+ float px = *r_x - sx;
+ float py = *r_y - sy;
- px = *x - sx;
- py = *y - sy;
-
- *y = (a * (py - f) + d * (c - px)) / (a * e - d * b);
- *x = (px - b * (*y) - c) / a;
+ *r_y = (a * (py - f) + d * (c - px)) / (a * e - d * b);
+ *r_x = (px - b * (*r_y) - c) / a;
if (block->panel) {
- *x -= block->panel->ofsx;
- *y -= block->panel->ofsy;
+ *r_x -= block->panel->ofsx;
+ *r_y -= block->panel->ofsy;
}
}
@@ -231,23 +222,21 @@ void ui_window_to_block_rctf(const struct ARegion *region,
ui_window_to_block_fl(region, block, &rct_dst->xmax, &rct_dst->ymax);
}
-void ui_window_to_block(const ARegion *region, uiBlock *block, int *x, int *y)
+void ui_window_to_block(const ARegion *region, uiBlock *block, int *r_x, int *r_y)
{
- float fx, fy;
-
- fx = *x;
- fy = *y;
+ float fx = *r_x;
+ float fy = *r_y;
ui_window_to_block_fl(region, block, &fx, &fy);
- *x = (int)(fx + 0.5f);
- *y = (int)(fy + 0.5f);
+ *r_x = (int)(fx + 0.5f);
+ *r_y = (int)(fy + 0.5f);
}
-void ui_window_to_region(const ARegion *region, int *x, int *y)
+void ui_window_to_region(const ARegion *region, int *r_x, int *r_y)
{
- *x -= region->winrct.xmin;
- *y -= region->winrct.ymin;
+ *r_x -= region->winrct.xmin;
+ *r_y -= region->winrct.ymin;
}
void ui_window_to_region_rcti(const ARegion *region, rcti *rect_dst, const rcti *rct_src)
@@ -258,10 +247,10 @@ void ui_window_to_region_rcti(const ARegion *region, rcti *rect_dst, const rcti
rect_dst->ymax = rct_src->ymax - region->winrct.ymin;
}
-void ui_region_to_window(const ARegion *region, int *x, int *y)
+void ui_region_to_window(const ARegion *region, int *r_x, int *r_y)
{
- *x += region->winrct.xmin;
- *y += region->winrct.ymin;
+ *r_x += region->winrct.xmin;
+ *r_y += region->winrct.ymin;
}
static void ui_update_flexible_spacing(const ARegion *region, uiBlock *block)
@@ -448,8 +437,6 @@ static void ui_block_bounds_calc_text(uiBlock *block, float offset)
void ui_block_bounds_calc(uiBlock *block)
{
- int xof;
-
if (BLI_listbase_is_empty(&block->buttons)) {
if (block->panel) {
block->rect.xmin = 0.0;
@@ -476,12 +463,7 @@ void ui_block_bounds_calc(uiBlock *block)
/* hardcoded exception... but that one is annoying with larger safety */
uiBut *bt = block->buttons.first;
- if (bt && STREQLEN(bt->str, "ERROR", 5)) {
- xof = 10;
- }
- else {
- xof = 40;
- }
+ int xof = (bt && STREQLEN(bt->str, "ERROR", 5)) ? 10 : 40;
block->safety.xmin = block->rect.xmin - xof;
block->safety.ymin = block->rect.ymin - xof;
@@ -491,23 +473,19 @@ void ui_block_bounds_calc(uiBlock *block)
static void ui_block_bounds_calc_centered(wmWindow *window, uiBlock *block)
{
- int xmax, ymax;
- int startx, starty;
- int width, height;
-
/* note: this is used for the splash where window bounds event has not been
* updated by ghost, get the window bounds from ghost directly */
- xmax = WM_window_pixels_x(window);
- ymax = WM_window_pixels_y(window);
+ int xmax = WM_window_pixels_x(window);
+ int ymax = WM_window_pixels_y(window);
ui_block_bounds_calc(block);
- width = BLI_rctf_size_x(&block->rect);
- height = BLI_rctf_size_y(&block->rect);
+ int width = BLI_rctf_size_x(&block->rect);
+ int height = BLI_rctf_size_y(&block->rect);
- startx = (xmax * 0.5f) - (width * 0.5f);
- starty = (ymax * 0.5f) - (height * 0.5f);
+ int startx = (xmax * 0.5f) - (width * 0.5f);
+ int starty = (ymax * 0.5f) - (height * 0.5f);
UI_block_translate(block, startx - block->rect.xmin, starty - block->rect.ymin);
@@ -531,22 +509,16 @@ static void ui_block_bounds_calc_centered_pie(uiBlock *block)
static void ui_block_bounds_calc_popup(
wmWindow *window, uiBlock *block, eBlockBoundsCalc bounds_calc, const int xy[2], int r_xy[2])
{
- int width, height, oldwidth, oldheight;
- int oldbounds, xmax, ymax, raw_x, raw_y;
- const int margin = UI_SCREEN_MARGIN;
- rcti rect, rect_bounds;
- int ofs_dummy[2];
-
- oldbounds = block->bounds;
+ int oldbounds = block->bounds;
/* compute mouse position with user defined offset */
ui_block_bounds_calc(block);
- xmax = WM_window_pixels_x(window);
- ymax = WM_window_pixels_y(window);
+ int xmax = WM_window_pixels_x(window);
+ int ymax = WM_window_pixels_y(window);
- oldwidth = BLI_rctf_size_x(&block->rect);
- oldheight = BLI_rctf_size_y(&block->rect);
+ int oldwidth = BLI_rctf_size_x(&block->rect);
+ int oldheight = BLI_rctf_size_y(&block->rect);
/* first we ensure wide enough text bounds */
if (bounds_calc == UI_BLOCK_BOUNDS_POPUP_MENU) {
@@ -561,8 +533,8 @@ static void ui_block_bounds_calc_popup(
ui_block_bounds_calc(block);
/* and we adjust the position to fit within window */
- width = BLI_rctf_size_x(&block->rect);
- height = BLI_rctf_size_y(&block->rect);
+ int width = BLI_rctf_size_x(&block->rect);
+ int height = BLI_rctf_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);
@@ -570,16 +542,21 @@ static void ui_block_bounds_calc_popup(
/* offset block based on mouse position, user offset is scaled
* along in case we resized the block in ui_block_bounds_calc_text */
- raw_x = rect.xmin = xy[0] + block->rect.xmin + (block->bounds_offset[0] * width) / oldwidth;
- raw_y = rect.ymin = xy[1] + block->rect.ymin + (block->bounds_offset[1] * height) / oldheight;
+ rcti rect;
+ int raw_x = rect.xmin = xy[0] + block->rect.xmin + (block->bounds_offset[0] * width) / oldwidth;
+ int raw_y = rect.ymin = xy[1] + block->rect.ymin +
+ (block->bounds_offset[1] * height) / oldheight;
rect.xmax = rect.xmin + width;
rect.ymax = rect.ymin + height;
+ rcti rect_bounds;
+ const int margin = UI_SCREEN_MARGIN;
rect_bounds.xmin = margin;
rect_bounds.ymin = margin;
rect_bounds.xmax = xmax - margin;
rect_bounds.ymax = ymax - UI_POPUP_MENU_TOP;
+ int ofs_dummy[
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list