diff options
Diffstat (limited to 'source/blender/editors/interface')
4 files changed, 34 insertions, 28 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index bc1133313ee..8d803ef130a 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1246,12 +1246,10 @@ int ui_is_but_float(uiBut *but) int ui_is_but_unit(uiBut *but) { Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); - int unit_type; - - if(but->rnaprop==NULL) - return 0; + int unit_type= uiButGetUnitType(but); - unit_type = RNA_SUBTYPE_UNIT(RNA_property_subtype(but->rnaprop)); + if(unit_type == PROP_UNIT_NONE) + return 0; #if 1 // removed so angle buttons get correct snapping if (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION) @@ -1267,9 +1265,6 @@ int ui_is_but_unit(uiBut *but) return 0; } - if(unit_type == PROP_UNIT_NONE) - return 0; - return 1; } @@ -1449,18 +1444,18 @@ int ui_get_but_string_max_length(uiBut *but) static double ui_get_but_scale_unit(uiBut *but, double value) { Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); - int subtype= RNA_SUBTYPE_UNIT(RNA_property_subtype(but->rnaprop)); + int unit_type= uiButGetUnitType(but); - if(subtype == PROP_UNIT_LENGTH) { + if(unit_type == PROP_UNIT_LENGTH) { return value * scene->unit.scale_length; } - else if(subtype == PROP_UNIT_AREA) { + else if(unit_type == PROP_UNIT_AREA) { return value * pow(scene->unit.scale_length, 2); } - else if(subtype == PROP_UNIT_VOLUME) { + else if(unit_type == PROP_UNIT_VOLUME) { return value * pow(scene->unit.scale_length, 3); } - else if(subtype == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */ + else if(unit_type == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */ return FRA2TIME(value); } else { @@ -1472,14 +1467,14 @@ static double ui_get_but_scale_unit(uiBut *but, double value) void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen) { if(ui_is_but_unit(but)) { - int unit_type= RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop)); + int unit_type= uiButGetUnitType(but); char *orig_str; Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); orig_str= MEM_callocN(sizeof(char)*maxlen + 1, "textedit sub str"); memcpy(orig_str, str, maxlen); - bUnit_ToUnitAltName(str, maxlen, orig_str, scene->unit.system, unit_type); + bUnit_ToUnitAltName(str, maxlen, orig_str, scene->unit.system, unit_type>>16); MEM_freeN(orig_str); } @@ -1489,7 +1484,7 @@ static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double va { Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); int do_split= scene->unit.flag & USER_UNIT_OPT_SPLIT; - int unit_type= RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop)); + int unit_type= uiButGetUnitType(but); int precision= but->a2; if(scene->unit.scale_length<0.0001) scene->unit.scale_length= 1.0; // XXX do_versions @@ -1498,13 +1493,13 @@ static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double va if(precision>4) precision= 4; else if(precision==0) precision= 2; - bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, scene->unit.system, unit_type, do_split, pad); + bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, scene->unit.system, unit_type>>16, do_split, pad); } static float ui_get_but_step_unit(uiBut *but, float step_default) { Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); - int unit_type= RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop)); + int unit_type= uiButGetUnitType(but)>>16; float step; step = bUnit_ClosestScalar(ui_get_but_scale_unit(but, step_default), scene->unit.system, unit_type); @@ -1655,19 +1650,14 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str) #ifdef WITH_PYTHON { char str_unit_convert[256]; - int unit_type; + int unit_type= uiButGetUnitType(but); Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); - if(but->rnaprop) - unit_type= RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop)); - else - unit_type= 0; - BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); if(ui_is_but_unit(but)) { /* 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); + 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_eval_button(C, str_unit_convert, &value)) { @@ -3183,6 +3173,21 @@ PointerRNA *uiButGetOperatorPtrRNA(uiBut *but) return but->opptr; } +void uiButSetUnitType(uiBut *but, const int unit_type) +{ + but->unit_type= (unsigned char)(unit_type>>16); +} + +int uiButGetUnitType(uiBut *but) +{ + if(but->rnaprop) { + return RNA_property_subtype(but->rnaprop); + } + else { + return ((int)but->unit_type)<<16; + } +} + void uiBlockSetHandleFunc(uiBlock *block, uiBlockHandleFunc func, void *arg) { block->handle_func= func; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 66ea2ebc265..499d1d62c76 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -2210,7 +2210,7 @@ static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, floa if(ui_is_but_unit(but)) { Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); - int unit_type = RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop)); + int unit_type= uiButGetUnitType(but)>>16; if(bUnit_IsValid(scene->unit.system, unit_type)) { fac= (float)bUnit_BaseScalar(scene->unit.system, unit_type); diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 0573026bf56..a7c03a6b95d 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -209,7 +209,8 @@ struct uiBut { BIFIconID icon; char lock; char dt; - short changed; /* could be made into a single flag */ + char changed; /* could be made into a single flag */ + unsigned char unit_type; /* so buttons can support unit systems which are not RNA */ short modifier_key; short iconadd; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index df2ebd44c9c..2230042fb1f 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -384,7 +384,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) } if(but->rnaprop) { - int unit_type = RNA_SUBTYPE_UNIT(RNA_property_subtype(but->rnaprop)); + int unit_type= uiButGetUnitType(but); if (unit_type == PROP_UNIT_ROTATION) { if (RNA_property_type(but->rnaprop) == PROP_FLOAT) { |