diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-04-18 07:27:15 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-04-18 07:27:15 +0400 |
commit | ea5baccbf8bfe737d6f5d4bd17faa2ff7ab9e8bd (patch) | |
tree | 71bfaff8317a6d79bc5bd0a1a910f161dcd135e4 /source/blender/editors | |
parent | 66bf6487dfc624c1423053cd570bbe720ae20cf2 (diff) |
fix for own mistake in recent commit: [#27000] Spotlight spot shape size, lamp object data - numerical entries are interpreted as radians though displayed in degrees in SVN 36199
now apply units after python evaluation for unit buttons.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/interface/interface.c | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 5b59baf9ea2..29e8bf756f3 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1541,6 +1541,52 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen) } } +#ifdef WITH_PYTHON + +static int ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char *str, double *value) +{ + char str_unit_convert[256]; + const int unit_type= uiButGetUnitType(but); + Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); + + BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); + + /* ugly, use the draw string to get the value, this could cause problems if it includes some text which resolves to a unit */ + bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type>>16); + + return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1); +} + +static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value) +{ + int ok= FALSE; + + if(str[0] != '\0') { + int is_unit_but= ui_is_but_unit(but); + /* only enable verbose if we won't run again with units */ + if(BPY_button_exec(C, str, value, is_unit_but==FALSE) != -1) { + /* if the value parsed ok without unit conversion this button may still need a unit multiplier */ + if(is_unit_but) { + char str_new[128]; + + BLI_snprintf(str_new, sizeof(str_new), "%f", *value); + ok= ui_set_but_string_eval_num_unit(C, but, str_new, value); + } + else { + ok= TRUE; /* parse normal string via py (no unit conversion needed) */ + } + } + else if(is_unit_but) { + /* parse failed, this is a unit but so run replacements and parse again */ + ok= ui_set_but_string_eval_num_unit(C, but, str, value); + } + } + + return ok; +} + +#endif // WITH_PYTHON + int ui_set_but_string(bContext *C, uiBut *but, const char *str) { if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) { @@ -1601,32 +1647,7 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str) double value; #ifdef WITH_PYTHON - int ok= FALSE; - - if(str[0] != '\0') { - int is_unit_but= ui_is_but_unit(but); - /* only enable verbose if we won't run again with units */ - if(BPY_button_exec(C, str, &value, is_unit_but==FALSE) != -1) { - ok= TRUE; /* parse normal string via py (no unit conversion needed) */ - } - else if(is_unit_but) { - /* parse failed, this is a unit but so run replacements and parse again */ - char str_unit_convert[256]; - const int unit_type= uiButGetUnitType(but); - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); - - BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); - - /* ugly, use the draw string to get the value, this could cause problems if it includes some text which resolves to a unit */ - bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type>>16); - - if(BPY_button_exec(C, str_unit_convert, &value, TRUE) != -1) { - ok= TRUE; - } - } - } - - if(ok == FALSE) { + if(ui_set_but_string_eval_num(C, but, str, &value) == FALSE) { return 0; } #else |