diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-25 08:17:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-25 08:21:13 +0300 |
commit | ca0cc0518f23ad0fa8c0a3c3614d6a469f4af20e (patch) | |
tree | ff9b030fd8ed97ccbde0ab620f2c4516c3f8911c | |
parent | dec9e34361b4ca0c3b90926f753477944818f80a (diff) |
Cleanup: simplify toggle button logic
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 41 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 8 |
2 files changed, 15 insertions, 34 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 7448de07e0e..6474ccc7794 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -856,44 +856,23 @@ static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) { - double value; - int w, lvalue, push; - - value = ui_but_value_get(but); - lvalue = (int)value; - + const double value = ui_but_value_get(but); + int value_toggle; if (but->bit) { - w = UI_BITBUT_TEST(lvalue, but->bitnr); - if (w) { - lvalue = UI_BITBUT_CLR(lvalue, but->bitnr); - } - else { - lvalue = UI_BITBUT_SET(lvalue, but->bitnr); - } - - ui_but_value_set(but, (double)lvalue); - if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) { - ui_but_update_edited(but); - } + value_toggle = UI_BITBUT_VALUE_TOGGLED((int)value, but->bitnr); } else { - - if (value == 0.0) { - push = 1; - } - else { - push = 0; - } - + value_toggle = (value == 0.0); if (ELEM(but->type, UI_BTYPE_TOGGLE_N, UI_BTYPE_ICON_TOGGLE_N, UI_BTYPE_CHECKBOX_N)) { - push = !push; - } - ui_but_value_set(but, (double)push); - if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) { - ui_but_update_edited(but); + value_toggle = !value_toggle; } } + ui_but_value_set(but, (double)value_toggle); + if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) { + ui_but_update_edited(but); + } + ui_apply_but_func(C, but); data->retval = but->retval; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 58d81be1b51..eefed26ef55 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -115,9 +115,11 @@ extern const short ui_radial_dir_to_angle[8]; /* bit button defines */ /* Bit operations */ -#define UI_BITBUT_TEST(a, b) ( ( (a) & 1 << (b) ) != 0) -#define UI_BITBUT_SET(a, b) ( (a) | 1 << (b) ) -#define UI_BITBUT_CLR(a, b) ( (a) & ~(1 << (b)) ) +#define UI_BITBUT_TEST(a, b) (((a) & (1 << (b))) != 0) +#define UI_BITBUT_VALUE_TOGGLED(a, b) ((a) ^ (1 << (b))) +#define UI_BITBUT_VALUE_ENABLED(a, b) ((a) | (1 << (b))) +#define UI_BITBUT_VALUE_DISABLED(a, b) ((a) & ~(1 << (b))) + /* bit-row */ #define UI_BITBUT_ROW(min, max) (((max) >= 31 ? 0xFFFFFFFF : (1 << ((max) + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) ) |