Commit: 6e06936c0e4172e612acd33910b1d8cc32f977c6 Author: Valentin Date: Tue Aug 25 13:15:29 2020 -0500 Branches: master https://developer.blender.org/rB6e06936c0e4172e612acd33910b1d8cc32f977c6
Cleanup in interface_handlers.c - Reduce variables scope - Use some const prefixes - Initialize variables at declaration - Use comparison to boolean false instead of 0 Differential Revision: https://developer.blender.org/D8678 =================================================================== M source/blender/editors/interface/interface_handlers.c =================================================================== diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 77cd3e00f3c..eca438415cd 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1618,9 +1618,7 @@ static bool ui_selectcontext_begin(bContext *C, uiBut *but, uiSelectContextStore /* if there is a valid property that is editable... */ if (ptr.data && prop) { - CollectionPointerLink *link; bool use_path_from_id; - int i; /* some facts we want to know */ const bool is_array = RNA_property_array_check(prop); @@ -1631,8 +1629,11 @@ static bool ui_selectcontext_begin(bContext *C, uiBut *but, uiSelectContextStore selctx_data->elems_len = BLI_listbase_count(&lb); selctx_data->elems = MEM_mallocN(sizeof(uiSelectContextElem) * selctx_data->elems_len, __func__); - - for (i = 0, link = lb.first; i < selctx_data->elems_len; i++, link = link->next) { + int i; + LISTBASE_FOREACH_INDEX (CollectionPointerLink *, link, &lb, i) { + if (i >= selctx_data->elems_len) { + break; + } uiSelectContextElem *other = &selctx_data->elems[i]; /* TODO,. de-duplicate copy_to_selected_button */ if (link->ptr.data != ptr.data) { @@ -1737,7 +1738,6 @@ static void ui_selectcontext_apply(bContext *C, PropertyRNA *prop = but->rnaprop; PropertyRNA *lprop = but->rnaprop; int index = but->rnaindex; - int i; const bool use_delta = (selctx_data->is_copy == false); union { @@ -1792,7 +1792,7 @@ static void ui_selectcontext_apply(bContext *C, tmparray[index] = true; - for (i = 0; i < selctx_data->elems_len; i++) { + for (int i = 0; i < selctx_data->elems_len; i++) { uiSelectContextElem *other = &selctx_data->elems[i]; PointerRNA lptr = other->ptr; RNA_property_boolean_set_array(&lptr, lprop, tmparray); @@ -1807,7 +1807,7 @@ static void ui_selectcontext_apply(bContext *C, } # endif - for (i = 0; i < selctx_data->elems_len; i++) { + for (int i = 0; i < selctx_data->elems_len; i++) { uiSelectContextElem *other = &selctx_data->elems[i]; PointerRNA lptr = other->ptr; @@ -2770,11 +2770,10 @@ void ui_but_clipboard_free(void) static int ui_text_position_from_hidden(uiBut *but, int pos) { const char *strpos, *butstr; - int i; butstr = (but->editstr) ? but->editstr : but->drawstr; - - for (i = 0, strpos = butstr; i < pos; i++) { + strpos = butstr; + for (int i = 0; i < pos; i++) { strpos = BLI_str_find_next_char_utf8(strpos, NULL); } @@ -3559,10 +3558,8 @@ static void ui_do_but_textedit( /* for double click: we do a press again for when you first click on button * (selects all text, no cursor pos) */ if (event->val == KM_PRESS || event->val == KM_DBL_CLICK) { - float mx, my; - - mx = event->x; - my = event->y; + float mx = event->x; + float my = event->y; ui_window_to_block_fl(data->region, block, &mx, &my); if (ui_but_contains_pt(but, mx, my)) { @@ -3832,12 +3829,12 @@ static void ui_do_but_textedit( static void ui_do_but_textedit_select( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { - int mx, my, retval = WM_UI_HANDLER_CONTINUE; + int retval = WM_UI_HANDLER_CONTINUE; switch (event->type) { case MOUSEMOVE: { - mx = event->x; - my = event->y; + int mx = event->x; + int my = event->y; ui_window_to_block(data->region, block, &mx, &my); ui_textedit_set_cursor_select(but, data, event->x); @@ -4297,7 +4294,7 @@ static int ui_do_but_HOTKEYEVT(bContext *C, if (event->type == LEFTMOUSE && event->val == KM_PRESS) { /* only cancel if click outside the button */ - if (ui_but_contains_point_px(but, but->active->region, event->x, event->y) == 0) { + if (ui_but_contains_point_px(but, but->active->region, event->x, event->y) == false) { /* data->cancel doesn't work, this button opens immediate */ if (but->flag & UI_BUT_IMMEDIATE) { ui_but_value_set(but, 0); @@ -4933,13 +4930,14 @@ static void ui_numedit_set_active(uiBut *but) static int ui_do_but_NUM( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { - int mx, my; /* mouse location scaled to fit the UI */ - int screen_mx, screen_my; /* mouse location kept at screen pixel coords */ int click = 0; int retval = WM_UI_HANDLER_CONTINUE; - mx = screen_mx = event->x; - my = screen_my = event->y; + /* mouse location scaled to fit the UI */ + int mx = event->x; + int my = event->y; + /* mouse location kept at screen pixel coords */ + const int screen_mx = event->x; ui_window_to_block(data->region, block, &mx, &my); ui_numedit_set_active(but); @@ -5245,11 +5243,11 @@ static bool ui_numedit_but_SLI(uiBut *but, static int ui_do_but_SLI( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { - int mx, my, click = 0; + int click = 0; int retval = WM_UI_HANDLER_CONTINUE; - mx = event->x; - my = event->y; + int mx = event->x; + int my = event->y; ui_window_to_block(data->region, block, &mx, &my); if (data->state == BUTTON_STATE_HIGHLIGHT) { @@ -5448,12 +5446,11 @@ static int ui_do_but_SLI( static int ui_do_but_SCROLL( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { - int mx, my /*, click = 0 */; int retval = WM_UI_HANDLER_CONTINUE; bool horizontal = (BLI_rctf_size_x(&but->rect) > BLI_rctf_size_y(&but->rect)); - mx = event->x; - my = event->y; + int mx = event->x; + int my = event->y; ui_window_to_block(data->region, block, &mx, &my); if (data->state == BUTTON_STATE_HIGHLIGHT) { @@ -5470,12 +5467,6 @@ static int ui_do_but_SCROLL( button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); retval = WM_UI_HANDLER_BREAK; } - /* UNUSED - otherwise code is ok, add back if needed */ -#if 0 - else if (ELEM(event->type, PADENTER, RETKEY) && event->val == KM_PRESS) { - click = 1; - } -#endif } } else if (data->state == BUTTON_STATE_NUM_EDITING) { @@ -5506,7 +5497,6 @@ static int ui_do_but_SCROLL( static int ui_do_but_GRIP( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { - int mx, my; int retval = WM_UI_HANDLER_CONTINUE; const bool horizontal = (BLI_rctf_size_x(&but->rect) < BLI_rctf_size_y(&but->rect)); @@ -5516,8 +5506,8 @@ static int ui_do_but_GRIP( * See T37739. */ - mx = event->x; - my = event->y; + int mx = event->x; + int my = event->y; ui_window_to_block(data->region, block, &mx, &my); if (data->state == BUTTON_STATE_HIGHLIGHT) { @@ -5666,7 +5656,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, co static bool ui_numedit_but_UNITVEC( uiBut *but, uiHandleButtonData *data, int mx, int my, const enum eSnapType snap) { - float dx, dy, rad, radsq, mrad, *fp; + float rad, radsq, mrad, *fp; int mdx, mdy; bool changed = true; @@ -5694,8 +5684,8 @@ static bool ui_numedit_but_UNITVEC( mdx = mdy = 0; } - dx = (float)(mx + mdx - data->dragstartx); - dy = (float)(my + mdy - data->dragstarty); + float dx = (float)(mx + mdx - data->dragstartx); + float dy = (float)(my + mdy - data->dragstarty); fp = data->vec; mrad = dx * dx + dy * dy; @@ -5724,11 +5714,10 @@ static bool ui_numedit_but_UNITVEC( const int snap_steps = (snap == SNAP_ON) ? 4 : 12; /* 45 or 15 degree increments */ const float snap_steps_angle = M_PI / snap_steps; float angle, angle_snap; - int i; /* round each axis of 'fp' to the next increment * do this in "angle" space - this gives increments of same size */ - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { angle = asinf(fp[i]); angle_snap = roundf((angle / snap_steps_angle)) * snap_steps_angle; fp[i] = sinf(angle_snap); @@ -5903,10 +5892,8 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co static int ui_do_but_UNITVEC( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { - int mx, my; - - mx = event->x; - my = event->y; + int mx = event->x; + int my = event->y; ui_window_to_block(data->region, block, &mx, &my); if (data->state == BUTTON_STATE_HIGHLIGHT) { @@ -6199,10 +6186,8 @@ static int ui_do_but_HSVCUBE( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { uiButHSVCube *hsv_but = (uiButHSVCube *)but; - int mx, my; - - mx = event->x; - my = event->y; + int mx = event->x; + int my = event->y; ui_window_to_block(data->region, block, &mx, &my); if (data->state == BUTTON_STATE_HIGHLIGHT) { @@ -6477,9 +6462,8 @@ static int ui_do_but_HSVCIRCLE( { ColorPicker *cpicker = but->custom_data; float *hsv = cpicker->color_data; - int mx, my; - mx = event->x; - my = event->y; + int mx = event->x; + int my = event->y; ui_window_to_block(data->region, block, &mx, &my); if (data->state == BUTTON_STATE_HIGHLIGHT) { @@ -6581,7 +6565,6 @@ static int ui_do_but_HSVCIRCLE( static bool ui_numedit_but_COLORBAND(uiBut *but, uiHandleButtonData *data, int mx) { - float dx; bool changed = false; if (data->draglastx == mx) { @@ -6592,7 +6575,7 @@ static bool ui_numedit_but_COLORBAND(uiBut *but, uiHandleButtonData *data, int m return changed; } - dx = ((float)(mx - data->draglastx)) / BLI_rctf_size_x(&but->rect); + float dx = ((float)(mx - data->draglastx)) / BLI_rctf_size_x(&but->rect); data->dragcbd->pos += dx; CLAMP(data->dragcbd->pos, 0.0f, 1.0f); @@ -6609,13 +6592,9 @@ static int ui_do_but_COLORBAND( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { ColorBand *coba; - CBData *cbd; - /* ignore zoom-level for mindist */ - int mindist = @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
