Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_utils.c
| Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | switch (RNA_property_type(prop)) { | ||||
| case PROP_BOOLEAN: | case PROP_BOOLEAN: | ||||
| { | { | ||||
| int arraylen = RNA_property_array_length(ptr, prop); | int arraylen = RNA_property_array_length(ptr, prop); | ||||
| if (arraylen && index == -1) | if (arraylen && index == -1) | ||||
| return NULL; | return NULL; | ||||
| if (icon && name && name[0] == '\0') | if (icon && name && name[0] == '\0') | ||||
| but = uiDefIconButR_prop(block, ICONTOG, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| else if (icon) | else if (icon) | ||||
| but = uiDefIconTextButR_prop(block, ICONTOG, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefIconTextButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| else | else | ||||
| but = uiDefButR_prop(block, OPTION, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefButR_prop(block, UI_BTYPE_CHECKBOX, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| break; | break; | ||||
| } | } | ||||
| case PROP_INT: | case PROP_INT: | ||||
| case PROP_FLOAT: | case PROP_FLOAT: | ||||
| { | { | ||||
| int arraylen = RNA_property_array_length(ptr, prop); | int arraylen = RNA_property_array_length(ptr, prop); | ||||
| if (arraylen && index == -1) { | if (arraylen && index == -1) { | ||||
| if (ELEM(RNA_property_subtype(prop), PROP_COLOR, PROP_COLOR_GAMMA)) | if (ELEM(RNA_property_subtype(prop), PROP_COLOR, PROP_COLOR_GAMMA)) | ||||
| but = uiDefButR_prop(block, COLOR, 0, name, x1, y1, x2, y2, ptr, prop, -1, 0, 0, -1, -1, NULL); | but = uiDefButR_prop(block, UI_BTYPE_COLOR, 0, name, x1, y1, x2, y2, ptr, prop, -1, 0, 0, -1, -1, NULL); | ||||
| } | } | ||||
| else if (RNA_property_subtype(prop) == PROP_PERCENTAGE || RNA_property_subtype(prop) == PROP_FACTOR) | else if (RNA_property_subtype(prop) == PROP_PERCENTAGE || RNA_property_subtype(prop) == PROP_FACTOR) | ||||
| but = uiDefButR_prop(block, NUMSLI, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefButR_prop(block, UI_BTYPE_NUM_SLIDER, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| else | else | ||||
| but = uiDefButR_prop(block, NUM, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefButR_prop(block, UI_BTYPE_NUM, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| break; | break; | ||||
| } | } | ||||
| case PROP_ENUM: | case PROP_ENUM: | ||||
| if (icon && name && name[0] == '\0') | if (icon && name && name[0] == '\0') | ||||
| but = uiDefIconButR_prop(block, MENU, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefIconButR_prop(block, UI_BTYPE_MENU, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| else if (icon) | else if (icon) | ||||
| but = uiDefIconTextButR_prop(block, MENU, 0, icon, NULL, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefIconTextButR_prop(block, UI_BTYPE_MENU, 0, icon, NULL, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| else | else | ||||
| but = uiDefButR_prop(block, MENU, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefButR_prop(block, UI_BTYPE_MENU, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| break; | break; | ||||
| case PROP_STRING: | case PROP_STRING: | ||||
| if (icon && name && name[0] == '\0') | if (icon && name && name[0] == '\0') | ||||
| but = uiDefIconButR_prop(block, TEX, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefIconButR_prop(block, UI_BTYPE_TEXT, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| else if (icon) | else if (icon) | ||||
| but = uiDefIconTextButR_prop(block, TEX, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefIconTextButR_prop(block, UI_BTYPE_TEXT, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| else | else | ||||
| but = uiDefButR_prop(block, TEX, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefButR_prop(block, UI_BTYPE_TEXT, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| break; | break; | ||||
| case PROP_POINTER: | case PROP_POINTER: | ||||
| { | { | ||||
| PointerRNA pptr; | PointerRNA pptr; | ||||
| pptr = RNA_property_pointer_get(ptr, prop); | pptr = RNA_property_pointer_get(ptr, prop); | ||||
| if (!pptr.type) | if (!pptr.type) | ||||
| pptr.type = RNA_property_pointer_type(ptr, prop); | pptr.type = RNA_property_pointer_type(ptr, prop); | ||||
| icon = RNA_struct_ui_icon(pptr.type); | icon = RNA_struct_ui_icon(pptr.type); | ||||
| if (icon == ICON_DOT) | if (icon == ICON_DOT) | ||||
| icon = 0; | icon = 0; | ||||
| but = uiDefIconTextButR_prop(block, SEARCH_MENU, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | but = uiDefIconTextButR_prop(block, UI_BTYPE_SEARCH_MENU, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); | ||||
| break; | break; | ||||
| } | } | ||||
| case PROP_COLLECTION: | case PROP_COLLECTION: | ||||
| { | { | ||||
| char text[256]; | char text[256]; | ||||
| BLI_snprintf(text, sizeof(text), IFACE_("%d items"), RNA_property_collection_length(ptr, prop)); | BLI_snprintf(text, sizeof(text), IFACE_("%d items"), RNA_property_collection_length(ptr, prop)); | ||||
| but = uiDefBut(block, LABEL, 0, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, NULL); | but = uiDefBut(block, UI_BTYPE_LABEL, 0, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, NULL); | ||||
| uiButSetFlag(but, UI_BUT_DISABLED); | UI_but_flag_enable(but, UI_BUT_DISABLED); | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| but = NULL; | but = NULL; | ||||
| break; | break; | ||||
| } | } | ||||
| return but; | return but; | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | int uiDefAutoButsRNA(uiLayout *layout, PointerRNA *ptr, | ||||
| } | } | ||||
| RNA_STRUCT_END; | RNA_STRUCT_END; | ||||
| return tot; | return tot; | ||||
| } | } | ||||
| /***************************** ID Utilities *******************************/ | /***************************** ID Utilities *******************************/ | ||||
| int uiIconFromID(ID *id) | int UI_icon_from_id(ID *id) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| short idcode; | short idcode; | ||||
| if (id == NULL) | if (id == NULL) | ||||
| return ICON_NONE; | return ICON_NONE; | ||||
| idcode = GS(id->name); | idcode = GS(id->name); | ||||
| /* exception for objects */ | /* exception for objects */ | ||||
| if (idcode == ID_OB) { | if (idcode == ID_OB) { | ||||
| ob = (Object *)id; | ob = (Object *)id; | ||||
| if (ob->type == OB_EMPTY) | if (ob->type == OB_EMPTY) | ||||
| return ICON_EMPTY_DATA; | return ICON_EMPTY_DATA; | ||||
| else | else | ||||
| return uiIconFromID(ob->data); | return UI_icon_from_id(ob->data); | ||||
| } | } | ||||
| /* otherwise get it through RNA, creating the pointer | /* otherwise get it through RNA, creating the pointer | ||||
| * will set the right type, also with subclassing */ | * will set the right type, also with subclassing */ | ||||
| RNA_id_pointer_create(id, &ptr); | RNA_id_pointer_create(id, &ptr); | ||||
| return (ptr.type) ? RNA_struct_ui_icon(ptr.type) : ICON_NONE; | return (ptr.type) ? RNA_struct_ui_icon(ptr.type) : ICON_NONE; | ||||
| } | } | ||||
| /* see: report_type_str */ | /* see: report_type_str */ | ||||
| int uiIconFromReportType(int type) | int UI_icon_from_report_type(int type) | ||||
| { | { | ||||
| if (type & RPT_ERROR_ALL) | if (type & RPT_ERROR_ALL) | ||||
| return ICON_ERROR; | return ICON_ERROR; | ||||
| else if (type & RPT_WARNING_ALL) | else if (type & RPT_WARNING_ALL) | ||||
| return ICON_ERROR; | return ICON_ERROR; | ||||
| else if (type & RPT_INFO_ALL) | else if (type & RPT_INFO_ALL) | ||||
| return ICON_INFO; | return ICON_INFO; | ||||
| else | else | ||||
| return ICON_NONE; | return ICON_NONE; | ||||
| } | } | ||||
| /********************************** Misc **************************************/ | /********************************** Misc **************************************/ | ||||
| /** | /** | ||||
| * Returns the best "UI" precision for given floating value, so that e.g. 10.000001 rather gets drawn as '10'... | * Returns the best "UI" precision for given floating value, so that e.g. 10.000001 rather gets drawn as '10'... | ||||
| */ | */ | ||||
| int uiFloatPrecisionCalc(int prec, double value) | int UI_calc_float_precision(int prec, double value) | ||||
| { | { | ||||
| static const double pow10_neg[UI_PRECISION_FLOAT_MAX + 1] = {1e0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7}; | static const double pow10_neg[UI_PRECISION_FLOAT_MAX + 1] = {1e0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7}; | ||||
| static const double max_pow = 10000000.0; /* pow(10, UI_PRECISION_FLOAT_MAX) */ | static const double max_pow = 10000000.0; /* pow(10, UI_PRECISION_FLOAT_MAX) */ | ||||
| BLI_assert(prec <= UI_PRECISION_FLOAT_MAX); | BLI_assert(prec <= UI_PRECISION_FLOAT_MAX); | ||||
| BLI_assert(fabs(pow10_neg[prec] - pow(10, -prec)) < 1e-16); | BLI_assert(fabs(pow10_neg[prec] - pow(10, -prec)) < 1e-16); | ||||
| /* check on the number of decimal places need to display the number, this is so 0.00001 is not displayed as 0.00, | /* check on the number of decimal places need to display the number, this is so 0.00001 is not displayed as 0.00, | ||||
| ▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines | |||||