diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-06-29 02:57:02 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-06-29 04:20:09 +0300 |
commit | 4afc9d8e4d3229634b7a7e8a3896c50156a06e5c (patch) | |
tree | 2c40bf4f62b3f86b6c2ddde73cb35f0344fcb37d /source/blender/editors/interface/interface_widgets.c | |
parent | 648e8a1f1d4a33a626b60529088e9eb361d74487 (diff) |
Cleanup: de-duplicate button color flag checks
Diffstat (limited to 'source/blender/editors/interface/interface_widgets.c')
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 82 |
1 files changed, 29 insertions, 53 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index a6c8697ec2c..b185b74cd91 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2509,6 +2509,28 @@ static void widget_active_color(char cp[3]) cp[2] = cp[2] >= 240 ? 255 : cp[2] + 15; } +static const char *widget_color_blend_from_flags(const uiWidgetStateColors *wcol_state, + int state, + int drawflag) +{ + if (drawflag & UI_BUT_ANIMATED_CHANGED) { + return wcol_state->inner_changed_sel; + } + if (state & UI_BUT_ANIMATED_KEY) { + return wcol_state->inner_key_sel; + } + if (state & UI_BUT_ANIMATED) { + return wcol_state->inner_anim_sel; + } + if (state & UI_BUT_DRIVEN) { + return wcol_state->inner_driven_sel; + } + if (state & UI_BUT_OVERRIDEN) { + return wcol_state->inner_overridden_sel; + } + return NULL; +} + /* copy colors from theme, and set changes in it based on state */ static void widget_state(uiWidgetType *wt, int state, int drawflag) { @@ -2526,22 +2548,7 @@ static void widget_state(uiWidgetType *wt, int state, int drawflag) wt->wcol = *(wt->wcol_theme); - const char *color_blend = NULL; - if (drawflag & UI_BUT_ANIMATED_CHANGED) { - color_blend = wcol_state->inner_changed_sel; - } - else if (state & UI_BUT_ANIMATED_KEY) { - color_blend = wcol_state->inner_key_sel; - } - else if (state & UI_BUT_ANIMATED) { - color_blend = wcol_state->inner_anim_sel; - } - else if (state & UI_BUT_DRIVEN) { - color_blend = wcol_state->inner_driven_sel; - } - else if (state & UI_BUT_OVERRIDEN) { - color_blend = wcol_state->inner_overridden_sel; - } + const char *color_blend = widget_color_blend_from_flags(wcol_state, state, drawflag); if (state & UI_SELECT) { copy_v4_v4_char(wt->wcol.inner, wt->wcol.inner_sel); @@ -2600,44 +2607,13 @@ static void widget_state_numslider(uiWidgetType *wt, int state, int drawflag) /* now, set the inner-part so that it reflects state settings too */ /* TODO: maybe we should have separate settings for the blending colors used for this case? */ - if (state & UI_SELECT) { - - if (drawflag & UI_BUT_ANIMATED_CHANGED) { - widget_state_blend(wt->wcol.item, wcol_state->inner_changed_sel, blend); - } - else if (state & UI_BUT_ANIMATED_KEY) { - widget_state_blend(wt->wcol.item, wcol_state->inner_key_sel, blend); - } - else if (state & UI_BUT_ANIMATED) { - widget_state_blend(wt->wcol.item, wcol_state->inner_anim_sel, blend); - } - else if (state & UI_BUT_DRIVEN) { - widget_state_blend(wt->wcol.item, wcol_state->inner_driven_sel, blend); - } - else if (state & UI_BUT_OVERRIDEN) { - widget_state_blend(wt->wcol.item, wcol_state->inner_overridden_sel, blend); - } - - if (state & UI_SELECT) { - SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown); - } + const char *color_blend = widget_color_blend_from_flags(wcol_state, state, drawflag); + if (color_blend != NULL) { + widget_state_blend(wt->wcol.item, color_blend, blend); } - else { - if (drawflag & UI_BUT_ANIMATED_CHANGED) { - widget_state_blend(wt->wcol.item, wcol_state->inner_changed, blend); - } - else if (state & UI_BUT_ANIMATED_KEY) { - widget_state_blend(wt->wcol.item, wcol_state->inner_key, blend); - } - else if (state & UI_BUT_ANIMATED) { - widget_state_blend(wt->wcol.item, wcol_state->inner_anim, blend); - } - else if (state & UI_BUT_DRIVEN) { - widget_state_blend(wt->wcol.item, wcol_state->inner_driven, blend); - } - else if (state & UI_BUT_OVERRIDEN) { - widget_state_blend(wt->wcol.item, wcol_state->inner_overridden, blend); - } + + if (state & UI_SELECT) { + SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown); } } |