diff options
author | Julian Eisel <julian@blender.org> | 2020-08-07 14:04:31 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-08-07 14:04:31 +0300 |
commit | 0d2d4a6d4a75ac38c41f872c88255eab70e88ab7 (patch) | |
tree | b7a7518af86dddba48e05a98b3c2be55e8804721 /source/blender/editors/interface/interface.c | |
parent | 9b416c66fb714bdfd15a481489dbf650d0f389ea (diff) | |
parent | cfc6f9eb18e701f5be601b95c45004e8cf7fbc81 (diff) |
Merge branch 'master' into temp-ui-button-type-refactortemp-ui-button-type-refactor
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r-- | source/blender/editors/interface/interface.c | 116 |
1 files changed, 85 insertions, 31 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index bc3d9b59583..a84ca33a7d7 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -44,6 +44,7 @@ #include "BLI_utildefines.h" +#include "BKE_animsys.h" #include "BKE_context.h" #include "BKE_idprop.h" #include "BKE_main.h" @@ -51,7 +52,6 @@ #include "BKE_screen.h" #include "BKE_unit.h" -#include "GPU_glew.h" #include "GPU_matrix.h" #include "GPU_state.h" @@ -737,8 +737,8 @@ static bool ui_but_update_from_old_block(const bContext *C, #else BLI_assert(*but_old_p == NULL || BLI_findindex(&oldblock->buttons, *but_old_p) != -1); - /* fastpath - avoid loop-in-loop, calling 'ui_but_find_old' - * as long as old/new buttons are aligned */ + /* Fast-path - avoid loop-in-loop, calling #ui_but_find_old + * as long as old/new buttons are aligned. */ if (LIKELY(*but_old_p && ui_but_equals_old(but, *but_old_p))) { oldbut = *but_old_p; } @@ -897,6 +897,12 @@ bool UI_but_active_only_ex( } } if ((activate == true) || (found == false)) { + /* There might still be another active button. */ + uiBut *old_active = ui_region_find_active_but(region); + if (old_active) { + ui_but_active_free(C, old_active); + } + ui_but_activate_event((bContext *)C, region, but); } else if ((found == true) && (isactive == false)) { @@ -1491,7 +1497,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block) continue; } } - else if (but->dt != UI_EMBOSS_PULLDOWN) { + else if (but->emboss != UI_EMBOSS_PULLDOWN) { continue; } @@ -1505,10 +1511,10 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block) } } -void ui_but_override_flag(uiBut *but) +void ui_but_override_flag(Main *bmain, uiBut *but) { const uint override_status = RNA_property_override_library_status( - &but->rnapoin, but->rnaprop, but->rnaindex); + bmain, &but->rnapoin, but->rnaprop, but->rnaindex); if (override_status & RNA_OVERRIDE_STATUS_OVERRIDDEN) { but->flag |= UI_BUT_OVERRIDEN; @@ -1738,6 +1744,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x wmWindow *window = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); ARegion *region = CTX_wm_region(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); uiBut *but; BLI_assert(block->active); @@ -1766,8 +1773,10 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x } } - ui_but_anim_flag(but, (scene) ? scene->r.cfra : 0.0f); - ui_but_override_flag(but); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( + depsgraph, (scene) ? scene->r.cfra : 0.0f); + ui_but_anim_flag(but, &anim_eval_context); + ui_but_override_flag(CTX_data_main(C), but); if (UI_but_is_decorator(but)) { ui_but_anim_decorate_update_from_flag((uiButDecorator *)but); } @@ -2314,7 +2323,7 @@ bool ui_but_is_rna_valid(uiBut *but) } /** - * Checks if the button supports ctrl+mousewheel cycling + * Checks if the button supports cycling next/previous menu items (ctrl+mouse-wheel). */ bool ui_but_supports_cycling(const uiBut *but) { @@ -2804,25 +2813,39 @@ char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) return str; } -static bool ui_set_but_string_eval_num_unit(bContext *C, - uiBut *but, - const char *str, - double *r_value) +/** + * Report a generic error prefix when evaluating a string with #BPY_execute_string_as_number + * as the Python error on it's own doesn't provide enough context. + */ +#define UI_NUMBER_EVAL_ERROR_PREFIX IFACE_("Error evaluating number, see Info editor for details") + +static bool ui_number_from_string_units( + bContext *C, const char *str, const int unit_type, const UnitSettings *unit, double *r_value) +{ + return user_string_to_number(C, str, unit, unit_type, UI_NUMBER_EVAL_ERROR_PREFIX, r_value); +} + +static bool ui_number_from_string_units_with_but(bContext *C, + const char *str, + const uiBut *but, + double *r_value) { + const int unit_type = RNA_SUBTYPE_UNIT_VALUE(UI_but_unit_type_get(but)); const UnitSettings *unit = but->block->unit; - int type = RNA_SUBTYPE_UNIT_VALUE(UI_but_unit_type_get(but)); - return user_string_to_number(C, str, unit, type, r_value); + return ui_number_from_string_units(C, str, unit_type, unit, r_value); } static bool ui_number_from_string(bContext *C, const char *str, double *r_value) { + bool ok; #ifdef WITH_PYTHON - return BPY_execute_string_as_number(C, NULL, str, true, r_value); + ok = BPY_execute_string_as_number(C, NULL, str, UI_NUMBER_EVAL_ERROR_PREFIX, r_value); #else UNUSED_VARS(C); *r_value = atof(str); - return true; + ok = true; #endif + return ok; } static bool ui_number_from_string_factor(bContext *C, const char *str, double *r_value) @@ -2856,7 +2879,7 @@ static bool ui_number_from_string_percentage(bContext *C, const char *str, doubl return ui_number_from_string(C, str, r_value); } -bool ui_but_string_set_eval_num(bContext *C, uiBut *but, const char *str, double *r_value) +bool ui_but_string_eval_number(bContext *C, const uiBut *but, const char *str, double *r_value) { if (str[0] == '\0') { *r_value = 0.0; @@ -2870,7 +2893,7 @@ bool ui_but_string_set_eval_num(bContext *C, uiBut *but, const char *str, double if (ui_but_is_float(but)) { if (ui_but_is_unit(but)) { - return ui_set_but_string_eval_num_unit(C, but, str, r_value); + return ui_number_from_string_units_with_but(C, str, but, r_value); } if (subtype == PROP_FACTOR) { return ui_number_from_string_factor(C, str, r_value); @@ -3014,7 +3037,7 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) /* number editing */ double value; - if (ui_but_string_set_eval_num(C, but, str, &value) == false) { + if (ui_but_string_eval_number(C, but, str, &value) == false) { WM_report_banner_show(); return false; } @@ -3086,8 +3109,38 @@ static double soft_range_round_down(double value, double max) return newmax; } +void ui_but_range_set_hard(uiBut *but) +{ + if (but->rnaprop) { + const PropertyType type = RNA_property_type(but->rnaprop); + double hardmin, hardmax; + + /* clamp button range to something reasonable in case + * we get -inf/inf from RNA properties */ + if (type == PROP_INT) { + int imin, imax; + + RNA_property_int_range(&but->rnapoin, but->rnaprop, &imin, &imax); + hardmin = (imin == INT_MIN) ? -1e4 : imin; + hardmax = (imin == INT_MAX) ? 1e4 : imax; + } + else if (type == PROP_FLOAT) { + float fmin, fmax; + + RNA_property_float_range(&but->rnapoin, but->rnaprop, &fmin, &fmax); + hardmin = (fmin == -FLT_MAX) ? (float)-1e4 : fmin; + hardmax = (fmax == FLT_MAX) ? (float)1e4 : fmax; + } + else { + return; + } + but->hardmin = hardmin; + but->hardmax = hardmax; + } +} + /* note: this could be split up into functions which handle arrays and not */ -static void ui_set_but_soft_range(uiBut *but) +void ui_but_range_set_soft(uiBut *but) { /* ideally we would not limit this but practically, its more than * enough worst case is very long vectors wont use a smart soft-range @@ -3364,7 +3417,7 @@ void UI_block_region_set(uiBlock *block, ARegion *region) block->oldblock = oldblock; } -uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, short dt) +uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, char emboss) { uiBlock *block; wmWindow *window; @@ -3375,7 +3428,7 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, sh block = MEM_callocN(sizeof(uiBlock), "uiBlock"); block->active = 1; - block->dt = dt; + block->emboss = emboss; block->evil_C = (void *)C; /* XXX */ if (scn) { @@ -3414,12 +3467,12 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, sh char UI_block_emboss_get(uiBlock *block) { - return block->dt; + return block->emboss; } -void UI_block_emboss_set(uiBlock *block, char dt) +void UI_block_emboss_set(uiBlock *block, char emboss) { - block->dt = dt; + block->emboss = emboss; } void UI_block_theme_style_set(uiBlock *block, char theme_style) @@ -3507,7 +3560,7 @@ static void ui_but_update_ex(uiBut *but, const bool validate) /* only update soft range while not editing */ if (!ui_but_is_editing(but)) { if ((but->rnaprop != NULL) || (but->poin && (but->pointype & UI_BUT_POIN_TYPES))) { - ui_set_but_soft_range(but); + ui_but_range_set_soft(but); } } @@ -3892,7 +3945,7 @@ static uiBut *ui_def_but(uiBlock *block, but->tip = tip; but->disabled_info = block->lockstr; - but->dt = block->dt; + but->emboss = block->emboss; but->pie_dir = UI_RADIAL_NONE; but->block = block; /* pointer back, used for frontbuffer status, and picker */ @@ -4426,7 +4479,7 @@ static uiBut *ui_def_but_rna(uiBlock *block, } if (type == UI_BTYPE_MENU) { - if (but->dt == UI_EMBOSS_PULLDOWN) { + if (but->emboss == UI_EMBOSS_PULLDOWN) { ui_but_submenu_enable(block, but); } } @@ -6383,7 +6436,7 @@ uiBut *uiDefHotKeyevtButS(uiBlock *block, short width, short height, short *keypoin, - short *modkeypoin, + const short *modkeypoin, const char *tip) { uiBut *but = ui_def_but(block, @@ -6553,7 +6606,8 @@ static void operator_enum_search_update_fn(const struct bContext *C, /* note: need to give the index rather than the * identifier because the enum can be freed */ if (BLI_strcasestr(item->name, str)) { - if (!UI_search_item_add(items, item->name, POINTER_FROM_INT(item->value), item->icon, 0)) { + if (!UI_search_item_add( + items, item->name, POINTER_FROM_INT(item->value), item->icon, 0, 0)) { break; } } |