Cleanup: Declare variables where initialized
Also reduce the scope of some variable declarations. This also allows making some variables constant.
This commit is contained in:
parent
6b32de4d9f
commit
a4aa94c41c
Notes:
blender-bot
2023-10-18 15:23:11 +02:00
Referenced by commit27bcbf19ed
, Fix possible un-initialized variable use in UI code Referenced by commit29a85682a0
, Fix stack use after scope error after recent cleanup
|
@ -312,16 +312,13 @@ static bool ui_layout_variable_size(uiLayout *layout)
|
|||
/* estimated size of text + icon */
|
||||
static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool compact)
|
||||
{
|
||||
bool variable;
|
||||
const int unit_x = UI_UNIT_X * (layout->scale[0] ? layout->scale[0] : 1.0f);
|
||||
|
||||
if (icon && !name[0]) {
|
||||
return unit_x; /* icon only */
|
||||
}
|
||||
|
||||
variable = ui_layout_variable_size(layout);
|
||||
|
||||
if (variable) {
|
||||
if (ui_layout_variable_size(layout)) {
|
||||
if (!icon && !name[0]) {
|
||||
return unit_x; /* No icon or name. */
|
||||
}
|
||||
|
@ -510,7 +507,6 @@ int uiLayoutGetLocalDir(const uiLayout *layout)
|
|||
static uiLayout *ui_item_local_sublayout(uiLayout *test, uiLayout *layout, bool align)
|
||||
{
|
||||
uiLayout *sub;
|
||||
|
||||
if (uiLayoutGetLocalDir(test) == UI_LAYOUT_HORIZONTAL) {
|
||||
sub = uiLayoutRow(layout, align);
|
||||
}
|
||||
|
@ -569,17 +565,12 @@ static void ui_item_array(uiLayout *layout,
|
|||
bool show_text)
|
||||
{
|
||||
const uiStyle *style = layout->root->style;
|
||||
uiBut *but;
|
||||
PropertyType type;
|
||||
PropertySubType subtype;
|
||||
uiLayout *sub;
|
||||
uint a, b;
|
||||
|
||||
/* retrieve type and subtype */
|
||||
type = RNA_property_type(prop);
|
||||
subtype = RNA_property_subtype(prop);
|
||||
const PropertyType type = RNA_property_type(prop);
|
||||
const PropertySubType subtype = RNA_property_subtype(prop);
|
||||
|
||||
sub = ui_item_local_sublayout(layout, layout, 1);
|
||||
uiLayout *sub = ui_item_local_sublayout(layout, layout, 1);
|
||||
UI_block_layout_set_current(block, sub);
|
||||
|
||||
/* create label */
|
||||
|
@ -590,17 +581,15 @@ static void ui_item_array(uiLayout *layout,
|
|||
/* create buttons */
|
||||
if (type == PROP_BOOLEAN && ELEM(subtype, PROP_LAYER, PROP_LAYER_MEMBER)) {
|
||||
/* special check for layer layout */
|
||||
int butw, buth, unit;
|
||||
const int cols = (len >= 20) ? 2 : 1;
|
||||
const uint colbuts = len / (2 * cols);
|
||||
const int colbuts = len / (2 * cols);
|
||||
uint layer_used = 0;
|
||||
uint layer_active = 0;
|
||||
|
||||
UI_block_layout_set_current(block, uiLayoutAbsolute(layout, false));
|
||||
|
||||
unit = UI_UNIT_X * 0.75;
|
||||
butw = unit;
|
||||
buth = unit;
|
||||
const int butw = UI_UNIT_X * 0.75;
|
||||
const int buth = UI_UNIT_X * 0.75;
|
||||
|
||||
if (ptr->type == &RNA_Armature) {
|
||||
bArmature *arm = ptr->data;
|
||||
|
@ -619,10 +608,10 @@ static void ui_item_array(uiLayout *layout,
|
|||
}
|
||||
}
|
||||
|
||||
for (b = 0; b < cols; b++) {
|
||||
for (int b = 0; b < cols; b++) {
|
||||
UI_block_align_begin(block);
|
||||
|
||||
for (a = 0; a < colbuts; a++) {
|
||||
for (int a = 0; a < colbuts; a++) {
|
||||
const int layer_num = a + b * colbuts;
|
||||
const uint layer_flag = (1u << layer_num);
|
||||
|
||||
|
@ -638,13 +627,13 @@ static void ui_item_array(uiLayout *layout,
|
|||
icon = ICON_BLANK1;
|
||||
}
|
||||
|
||||
but = uiDefAutoButR(
|
||||
uiBut *but = uiDefAutoButR(
|
||||
block, ptr, prop, layer_num, "", icon, x + butw * a, y + buth, butw, buth);
|
||||
if (subtype == PROP_LAYER_MEMBER) {
|
||||
UI_but_func_set(but, ui_layer_but_cb, but, POINTER_FROM_INT(layer_num));
|
||||
}
|
||||
}
|
||||
for (a = 0; a < colbuts; a++) {
|
||||
for (int a = 0; a < colbuts; a++) {
|
||||
const int layer_num = a + len / 2 + b * colbuts;
|
||||
const uint layer_flag = (1u << layer_num);
|
||||
|
||||
|
@ -660,7 +649,8 @@ static void ui_item_array(uiLayout *layout,
|
|||
icon = ICON_BLANK1;
|
||||
}
|
||||
|
||||
but = uiDefAutoButR(block, ptr, prop, layer_num, "", icon, x + butw * a, y, butw, buth);
|
||||
uiBut *but = uiDefAutoButR(
|
||||
block, ptr, prop, layer_num, "", icon, x + butw * a, y, butw, buth);
|
||||
if (subtype == PROP_LAYER_MEMBER) {
|
||||
UI_but_func_set(but, ui_layer_but_cb, but, POINTER_FROM_INT(layer_num));
|
||||
}
|
||||
|
@ -685,20 +675,20 @@ static void ui_item_array(uiLayout *layout,
|
|||
w /= dim_size[0];
|
||||
/* h /= dim_size[1]; */ /* UNUSED */
|
||||
|
||||
for (a = 0; a < len; a++) {
|
||||
for (int a = 0; a < len; a++) {
|
||||
col = a % dim_size[0];
|
||||
row = a / dim_size[0];
|
||||
|
||||
but = uiDefAutoButR(block,
|
||||
ptr,
|
||||
prop,
|
||||
a,
|
||||
"",
|
||||
ICON_NONE,
|
||||
x + w * col,
|
||||
y + (dim_size[1] * UI_UNIT_Y) - (row * UI_UNIT_Y),
|
||||
w,
|
||||
UI_UNIT_Y);
|
||||
uiBut *but = uiDefAutoButR(block,
|
||||
ptr,
|
||||
prop,
|
||||
a,
|
||||
"",
|
||||
ICON_NONE,
|
||||
x + w * col,
|
||||
y + (dim_size[1] * UI_UNIT_Y) - (row * UI_UNIT_Y),
|
||||
w,
|
||||
UI_UNIT_Y);
|
||||
if (slider && but->type == UI_BTYPE_NUM) {
|
||||
uiButNumber *number_but = (uiButNumber *)but;
|
||||
|
||||
|
@ -734,8 +724,6 @@ static void ui_item_array(uiLayout *layout,
|
|||
uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, 0, 0, w, UI_UNIT_Y);
|
||||
}
|
||||
else {
|
||||
bool *boolarr = NULL;
|
||||
|
||||
/* even if 'expand' is fale, expanding anyway */
|
||||
|
||||
/* layout for known array subtypes */
|
||||
|
@ -748,6 +736,7 @@ static void ui_item_array(uiLayout *layout,
|
|||
}
|
||||
|
||||
/* show checkboxes for rna on a non-emboss block (menu for eg) */
|
||||
bool *boolarr = NULL;
|
||||
if (type == PROP_BOOLEAN &&
|
||||
ELEM(layout->root->block->emboss, UI_EMBOSS_NONE, UI_EMBOSS_PULLDOWN)) {
|
||||
boolarr = MEM_callocN(sizeof(bool) * len, __func__);
|
||||
|
@ -755,9 +744,7 @@ static void ui_item_array(uiLayout *layout,
|
|||
}
|
||||
|
||||
const char *str_buf = show_text ? str : "";
|
||||
for (a = 0; a < len; a++) {
|
||||
int width_item;
|
||||
|
||||
for (int a = 0; a < len; a++) {
|
||||
if (!icon_only && show_text) {
|
||||
str[0] = RNA_property_array_item_char(prop, a);
|
||||
}
|
||||
|
@ -765,11 +752,12 @@ static void ui_item_array(uiLayout *layout,
|
|||
icon = boolarr[a] ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
|
||||
}
|
||||
|
||||
width_item = ((compact && type == PROP_BOOLEAN) ?
|
||||
min_ii(w, ui_text_icon_width(layout, str_buf, icon, false)) :
|
||||
w);
|
||||
const int width_item = ((compact && type == PROP_BOOLEAN) ?
|
||||
min_ii(w, ui_text_icon_width(layout, str_buf, icon, false)) :
|
||||
w);
|
||||
|
||||
but = uiDefAutoButR(block, ptr, prop, a, str_buf, icon, 0, 0, width_item, UI_UNIT_Y);
|
||||
uiBut *but = uiDefAutoButR(
|
||||
block, ptr, prop, a, str_buf, icon, 0, 0, width_item, UI_UNIT_Y);
|
||||
if (slider && but->type == UI_BTYPE_NUM) {
|
||||
uiButNumber *number_but = (uiButNumber *)but;
|
||||
|
||||
|
@ -832,7 +820,6 @@ static void ui_item_enum_expand_elem_exec(uiLayout *layout,
|
|||
const int itemw = ui_text_icon_width(block->curlayout, icon_only ? "" : name, icon, 0);
|
||||
|
||||
uiBut *but;
|
||||
|
||||
if (icon && name[0] && !icon_only) {
|
||||
but = uiDefIconTextButR_prop(
|
||||
block, but_type, 0, icon, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL);
|
||||
|
@ -886,13 +873,12 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
|
|||
* - mont29
|
||||
*/
|
||||
|
||||
const EnumPropertyItem *item, *item_array;
|
||||
bool free;
|
||||
|
||||
BLI_assert(RNA_property_type(prop) == PROP_ENUM);
|
||||
|
||||
uiLayout *layout_radial = NULL;
|
||||
const bool radial = (layout->root->type == UI_LAYOUT_PIEMENU);
|
||||
|
||||
bool free;
|
||||
const EnumPropertyItem *item_array;
|
||||
if (radial) {
|
||||
RNA_property_enum_items_gettexted_all(block->evil_C, ptr, prop, &item_array, NULL, &free);
|
||||
}
|
||||
|
@ -901,6 +887,7 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
|
|||
}
|
||||
|
||||
/* we dont want nested rows, cols in menus */
|
||||
uiLayout *layout_radial = NULL;
|
||||
if (radial) {
|
||||
if (layout->root->layout == layout) {
|
||||
layout_radial = uiLayoutRadial(layout);
|
||||
|
@ -921,7 +908,7 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
|
|||
UI_block_layout_set_current(block, ui_item_local_sublayout(layout, layout, 1));
|
||||
}
|
||||
|
||||
for (item = item_array; item->identifier; item++) {
|
||||
for (const EnumPropertyItem *item = item_array; item->identifier; item++) {
|
||||
const bool is_first = item == item_array;
|
||||
|
||||
if (!item->identifier[0]) {
|
||||
|
@ -1016,9 +1003,6 @@ static uiBut *ui_item_with_label(uiLayout *layout,
|
|||
int flag)
|
||||
{
|
||||
uiLayout *sub = layout;
|
||||
uiBut *but = NULL;
|
||||
PropertyType type;
|
||||
PropertySubType subtype;
|
||||
int prop_but_width = w_hint;
|
||||
#ifdef UI_PROP_DECORATE
|
||||
uiLayout *layout_prop_decorate = NULL;
|
||||
|
@ -1047,7 +1031,6 @@ static uiBut *ui_item_with_label(uiLayout *layout,
|
|||
#endif
|
||||
{
|
||||
int w_label;
|
||||
|
||||
if (ui_layout_variable_size(layout)) {
|
||||
/* w_hint is width for label in this case.
|
||||
* Use a default width for property button(s) */
|
||||
|
@ -1061,9 +1044,10 @@ static uiBut *ui_item_with_label(uiLayout *layout,
|
|||
}
|
||||
}
|
||||
|
||||
type = RNA_property_type(prop);
|
||||
subtype = RNA_property_subtype(prop);
|
||||
const PropertyType type = RNA_property_type(prop);
|
||||
const PropertySubType subtype = RNA_property_subtype(prop);
|
||||
|
||||
uiBut *but;
|
||||
if (subtype == PROP_FILEPATH || subtype == PROP_DIRPATH) {
|
||||
UI_block_layout_set_current(block, uiLayoutRow(sub, true));
|
||||
but = uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, prop_but_width - UI_UNIT_X, h);
|
||||
|
@ -1204,8 +1188,6 @@ static void ui_but_tip_from_enum_item(uiBut *but, const EnumPropertyItem *item)
|
|||
static void ui_item_disabled(uiLayout *layout, const char *name)
|
||||
{
|
||||
uiBlock *block = layout->root->block;
|
||||
uiBut *but;
|
||||
int w;
|
||||
|
||||
UI_block_layout_set_current(block, layout);
|
||||
|
||||
|
@ -1213,9 +1195,10 @@ static void ui_item_disabled(uiLayout *layout, const char *name)
|
|||
name = "";
|
||||
}
|
||||
|
||||
w = ui_text_icon_width(layout, name, 0, 0);
|
||||
const int w = ui_text_icon_width(layout, name, 0, 0);
|
||||
|
||||
but = uiDefBut(block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
|
||||
uiBut *but = uiDefBut(
|
||||
block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
|
||||
UI_but_disable(but, "");
|
||||
}
|
||||
|
||||
|
@ -1235,8 +1218,6 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout,
|
|||
{
|
||||
/* Take care to fill 'r_opptr' whatever happens. */
|
||||
uiBlock *block = layout->root->block;
|
||||
uiBut *but;
|
||||
int w;
|
||||
|
||||
if (!name) {
|
||||
if (ot && ot->srna && (flag & UI_ITEM_R_ICON_ONLY) == 0) {
|
||||
|
@ -1254,7 +1235,7 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout,
|
|||
/* create button */
|
||||
UI_block_layout_set_current(block, layout);
|
||||
|
||||
w = ui_text_icon_width(layout, name, icon, 0);
|
||||
const int w = ui_text_icon_width(layout, name, icon, 0);
|
||||
|
||||
const int prev_emboss = layout->emboss;
|
||||
if (flag & UI_ITEM_R_NO_BG) {
|
||||
|
@ -1262,6 +1243,7 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout,
|
|||
}
|
||||
|
||||
/* create the button */
|
||||
uiBut *but;
|
||||
if (icon) {
|
||||
if (name[0]) {
|
||||
but = uiDefIconTextButO_ptr(
|
||||
|
@ -1409,11 +1391,11 @@ static const char *ui_menu_enumpropname(uiLayout *layout,
|
|||
PropertyRNA *prop,
|
||||
int retval)
|
||||
{
|
||||
const EnumPropertyItem *item;
|
||||
bool free;
|
||||
const char *name;
|
||||
|
||||
const EnumPropertyItem *item;
|
||||
RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, NULL, &free);
|
||||
|
||||
const char *name;
|
||||
if (RNA_enum_name(item, retval, &name)) {
|
||||
name = CTX_IFACE_(RNA_property_translation_context(prop), name);
|
||||
}
|
||||
|
@ -1436,14 +1418,10 @@ void uiItemEnumO_ptr(uiLayout *layout,
|
|||
int value)
|
||||
{
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
|
||||
if ((prop = RNA_struct_find_property(&ptr, propname))) {
|
||||
/* pass */
|
||||
}
|
||||
else {
|
||||
PropertyRNA *prop = RNA_struct_find_property(&ptr, propname);
|
||||
if (prop == NULL) {
|
||||
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
|
||||
return;
|
||||
}
|
||||
|
@ -1502,7 +1480,6 @@ void uiItemsFullEnumO_items(uiLayout *layout,
|
|||
}
|
||||
|
||||
uiLayout *target, *split = NULL;
|
||||
const EnumPropertyItem *item;
|
||||
uiBlock *block = layout->root->block;
|
||||
const bool radial = ui_layout_is_radial(layout);
|
||||
|
||||
|
@ -1534,10 +1511,9 @@ void uiItemsFullEnumO_items(uiLayout *layout,
|
|||
target = uiLayoutColumn(split, layout->align);
|
||||
}
|
||||
|
||||
int i;
|
||||
bool last_iter = false;
|
||||
|
||||
for (i = 1, item = item_array; item->identifier && !last_iter; i++, item++) {
|
||||
const EnumPropertyItem *item = item_array;
|
||||
for (int i = 1; item->identifier && !last_iter; i++, item++) {
|
||||
/* handle oversized pies */
|
||||
if (radial && (totitem > PIE_MAX_ITEMS) && (i >= PIE_MAX_ITEMS)) {
|
||||
if (item->name) { /* only visible items */
|
||||
|
@ -1566,7 +1542,6 @@ void uiItemsFullEnumO_items(uiLayout *layout,
|
|||
|
||||
if (item->identifier[0]) {
|
||||
PointerRNA tptr;
|
||||
|
||||
WM_operator_properties_create_ptr(&tptr, ot);
|
||||
if (properties) {
|
||||
if (tptr.data) {
|
||||
|
@ -1589,8 +1564,6 @@ void uiItemsFullEnumO_items(uiLayout *layout,
|
|||
}
|
||||
else {
|
||||
if (item->name) {
|
||||
uiBut *but;
|
||||
|
||||
if (item != item_array && !radial && split != NULL) {
|
||||
target = uiLayoutColumn(split, layout->align);
|
||||
|
||||
|
@ -1598,6 +1571,7 @@ void uiItemsFullEnumO_items(uiLayout *layout,
|
|||
block->flag |= UI_BLOCK_NO_FLIP;
|
||||
}
|
||||
|
||||
uiBut *but;
|
||||
if (item->icon || radial) {
|
||||
uiItemL(target, item->name, item->icon);
|
||||
|
||||
|
@ -1647,24 +1621,22 @@ void uiItemsFullEnumO(uiLayout *layout,
|
|||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
||||
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
uiBlock *block = layout->root->block;
|
||||
|
||||
if (!ot || !ot->srna) {
|
||||
ui_item_disabled(layout, opname);
|
||||
RNA_warning("%s '%s'", ot ? "unknown operator" : "operator missing srna", opname);
|
||||
return;
|
||||
}
|
||||
|
||||
PointerRNA ptr;
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
/* so the context is passed to itemf functions (some need it) */
|
||||
WM_operator_properties_sanitize(&ptr, false);
|
||||
prop = RNA_struct_find_property(&ptr, propname);
|
||||
PropertyRNA *prop = RNA_struct_find_property(&ptr, propname);
|
||||
|
||||
/* don't let bad properties slip through */
|
||||
BLI_assert((prop == NULL) || (RNA_property_type(prop) == PROP_ENUM));
|
||||
|
||||
uiBlock *block = layout->root->block;
|
||||
if (prop && RNA_property_type(prop) == PROP_ENUM) {
|
||||
const EnumPropertyItem *item_array = NULL;
|
||||
int totitem;
|
||||
|
@ -1721,18 +1693,14 @@ void uiItemEnumO_value(uiLayout *layout,
|
|||
int value)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
|
||||
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
||||
|
||||
PointerRNA ptr;
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
|
||||
/* enum lookup */
|
||||
if ((prop = RNA_struct_find_property(&ptr, propname))) {
|
||||
/* pass */
|
||||
}
|
||||
else {
|
||||
PropertyRNA *prop = RNA_struct_find_property(&ptr, propname);
|
||||
if (prop == NULL) {
|
||||
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
|
||||
return;
|
||||
}
|
||||
|
@ -1755,39 +1723,36 @@ void uiItemEnumO_string(uiLayout *layout,
|
|||
const char *value_str)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
|
||||
const EnumPropertyItem *item;
|
||||
int value;
|
||||
bool free;
|
||||
|
||||
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
||||
|
||||
PointerRNA ptr;
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
|
||||
/* enum lookup */
|
||||
if ((prop = RNA_struct_find_property(&ptr, propname))) {
|
||||
/* no need for translations here */
|
||||
RNA_property_enum_items(layout->root->block->evil_C, &ptr, prop, &item, NULL, &free);
|
||||
if (item == NULL || RNA_enum_value_from_id(item, value_str, &value) == 0) {
|
||||
if (free) {
|
||||
MEM_freeN((void *)item);
|
||||
}
|
||||
RNA_warning(
|
||||
"%s.%s, enum %s not found", RNA_struct_identifier(ptr.type), propname, value_str);
|
||||
return;
|
||||
}
|
||||
PropertyRNA *prop = RNA_struct_find_property(&ptr, propname);
|
||||
if (prop == NULL) {
|
||||
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
|
||||
return;
|
||||
}
|
||||
|
||||
/* enum lookup */
|
||||
/* no need for translations here */
|
||||
const EnumPropertyItem *item;
|
||||
bool free;
|
||||
RNA_property_enum_items(layout->root->block->evil_C, &ptr, prop, &item, NULL, &free);
|
||||
|
||||
int value;
|
||||
if (item == NULL || RNA_enum_value_from_id(item, value_str, &value) == 0) {
|
||||
if (free) {
|
||||
MEM_freeN((void *)item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
|
||||
RNA_warning("%s.%s, enum %s not found", RNA_struct_identifier(ptr.type), propname, value_str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (free) {
|
||||
MEM_freeN((void *)item);
|
||||
}
|
||||
|
||||
RNA_property_enum_set(&ptr, prop, value);
|
||||
|
||||
/* same as uiItemEnumO */
|
||||
|
@ -1806,10 +1771,9 @@ void uiItemBooleanO(uiLayout *layout,
|
|||
int value)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
||||
PointerRNA ptr;
|
||||
|
||||
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
||||
|
||||
PointerRNA ptr;
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
RNA_boolean_set(&ptr, propname, value);
|
||||
|
||||
|
@ -1824,10 +1788,9 @@ void uiItemIntO(uiLayout *layout,
|
|||
int value)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
||||
PointerRNA ptr;
|
||||
|
||||
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
||||
|
||||
PointerRNA ptr;
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
RNA_int_set(&ptr, propname, value);
|
||||
|
||||
|
@ -1842,10 +1805,10 @@ void uiItemFloatO(uiLayout *layout,
|
|||
float value)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
||||
PointerRNA ptr;
|
||||
|
||||
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
||||
|
||||
PointerRNA ptr;
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
RNA_float_set(&ptr, propname, value);
|
||||
|
||||
|
@ -1860,10 +1823,10 @@ void uiItemStringO(uiLayout *layout,
|
|||
const char *value)
|
||||
{
|
||||
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
||||
PointerRNA ptr;
|
||||
|
||||
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
||||
|
||||
PointerRNA ptr;
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
RNA_string_set(&ptr, propname, value);
|
||||
|
||||
|
@ -1888,16 +1851,14 @@ static void ui_item_rna_size(uiLayout *layout,
|
|||
int *r_w,
|
||||
int *r_h)
|
||||
{
|
||||
PropertyType type;
|
||||
PropertySubType subtype;
|
||||
int len, w = 0, h;
|
||||
bool is_checkbox_only = false;
|
||||
int w = 0, h;
|
||||
|
||||
/* arbitrary extended width by type */
|
||||
type = RNA_property_type(prop);
|
||||
subtype = RNA_property_subtype(prop);
|
||||
len = RNA_property_array_length(ptr, prop);
|
||||
PropertyType type = RNA_property_type(prop);
|
||||
PropertySubType subtype = RNA_property_subtype(prop);
|
||||
const int len = RNA_property_array_length(ptr, prop);
|
||||
|
||||
bool is_checkbox_only = false;
|
||||
if (!name[0] && !icon_only) {
|
||||
if (ELEM(type, PROP_STRING, PROP_POINTER)) {
|
||||
name = "non-empty text";
|
||||
|
@ -1911,12 +1872,12 @@ static void ui_item_rna_size(uiLayout *layout,
|
|||
}
|
||||
else if (type == PROP_ENUM) {
|
||||
/* Find the longest enum item name, instead of using a dummy text! */
|
||||
const EnumPropertyItem *item, *item_array;
|
||||
const EnumPropertyItem *item_array;
|
||||
bool free;
|
||||
|
||||
RNA_property_enum_items_gettexted(
|
||||
layout->root->block->evil_C, ptr, prop, &item_array, NULL, &free);
|
||||
for (item = item_array; item->identifier; item++) {
|
||||
|
||||
for (const EnumPropertyItem *item = item_array; item->identifier; item++) {
|
||||
if (item->identifier[0]) {
|
||||
w = max_ii(w, ui_text_icon_width(layout, item->name, item->icon, compact));
|
||||
}
|
||||
|
@ -2606,10 +2567,6 @@ void uiItemEnumR_string_prop(uiLayout *layout,
|
|||
const char *name,
|
||||
int icon)
|
||||
{
|
||||
const EnumPropertyItem *item;
|
||||
int ivalue, a;
|
||||
bool free;
|
||||
|
||||
if (UNLIKELY(RNA_property_type(prop) != PROP_ENUM)) {
|
||||
const char *propname = RNA_property_identifier(prop);
|
||||
ui_item_disabled(layout, propname);
|
||||
|
@ -2617,8 +2574,11 @@ void uiItemEnumR_string_prop(uiLayout *layout,
|
|||
return;
|
||||
}
|
||||
|
||||
const EnumPropertyItem *item;
|
||||
bool free;
|
||||
RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, NULL, &free);
|
||||
|
||||
int ivalue;
|
||||
if (!RNA_enum_value_from_id(item, value, &ivalue)) {
|
||||
const char *propname = RNA_property_identifier(prop);
|
||||
if (free) {
|
||||
|
@ -2629,7 +2589,7 @@ void uiItemEnumR_string_prop(uiLayout *layout,
|
|||
return;
|
||||
}
|
||||
|
||||
for (a = 0; item[a].identifier; a++) {
|
||||
for (int a = 0; item[a].identifier; a++) {
|
||||
if (item[a].identifier[0] == '\0') {
|
||||
/* Skip enum item separators. */
|
||||
continue;
|
||||
|
@ -2669,11 +2629,9 @@ void uiItemEnumR_string(uiLayout *layout,
|
|||
|
||||
void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
uiBlock *block = layout->root->block;
|
||||
uiBut *bt;
|
||||
|
||||
prop = RNA_struct_find_property(ptr, propname);
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
|
||||
|
||||
if (!prop) {
|
||||
ui_item_disabled(layout, propname);
|
||||
|
@ -2686,12 +2644,12 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname
|
|||
return;
|
||||
}
|
||||
|
||||
const EnumPropertyItem *item;
|
||||
int totitem;
|
||||
bool free;
|
||||
uiLayout *split = uiLayoutSplit(layout, 0.0f, false);
|
||||
uiLayout *column = uiLayoutColumn(split, false);
|
||||
|
||||
int totitem;
|
||||
const EnumPropertyItem *item;
|
||||
bool free;
|
||||
RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item, &totitem, &free);
|
||||
|
||||
for (int i = 0; i < totitem; i++) {
|
||||
|
@ -2708,7 +2666,7 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname
|
|||
}
|
||||
|
||||
uiItemL(column, item[i].name, ICON_NONE);
|
||||
bt = block->buttons.last;
|
||||
uiBut *bt = block->buttons.last;
|
||||
bt->drawflag = UI_BUT_TEXT_LEFT;
|
||||
|
||||
ui_but_tip_from_enum_item(bt, &item[i]);
|
||||
|
@ -2731,8 +2689,6 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname
|
|||
|
||||
static void search_id_collection(StructRNA *ptype, PointerRNA *r_ptr, PropertyRNA **r_prop)
|
||||
{
|
||||
StructRNA *srna;
|
||||
|
||||
/* look for collection property in Main */
|
||||
/* Note: using global Main is OK-ish here, UI shall not access other Mains anyay... */
|
||||
RNA_main_pointer_create(G_MAIN, r_ptr);
|
||||
|
@ -2742,7 +2698,7 @@ static void search_id_collection(StructRNA *ptype, PointerRNA *r_ptr, PropertyRN
|
|||
RNA_STRUCT_BEGIN (r_ptr, iprop) {
|
||||
/* if it's a collection and has same pointer type, we've got it */
|
||||
if (RNA_property_type(iprop) == PROP_COLLECTION) {
|
||||
srna = RNA_property_pointer_type(r_ptr, iprop);
|
||||
StructRNA *srna = RNA_property_pointer_type(r_ptr, iprop);
|
||||
|
||||
if (ptype == srna) {
|
||||
*r_prop = iprop;
|
||||
|
@ -2766,13 +2722,11 @@ static void ui_rna_collection_search_arg_free_fn(void *ptr)
|
|||
uiBut *ui_but_add_search(
|
||||
uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop)
|
||||
{
|
||||
StructRNA *ptype;
|
||||
PointerRNA sptr;
|
||||
|
||||
/* for ID's we do automatic lookup */
|
||||
if (!searchprop) {
|
||||
if (RNA_property_type(prop) == PROP_POINTER) {
|
||||
ptype = RNA_property_pointer_type(ptr, prop);
|
||||
StructRNA *ptype = RNA_property_pointer_type(ptr, prop);
|
||||
PointerRNA sptr;
|
||||
search_id_collection(ptype, &sptr, &searchprop);
|
||||
searchptr = &sptr;
|
||||
}
|
||||
|
@ -2833,17 +2787,11 @@ void uiItemPointerR_prop(uiLayout *layout,
|
|||
const char *name,
|
||||
int icon)
|
||||
{
|
||||
PropertyType type;
|
||||
uiBut *but;
|
||||
uiBlock *block;
|
||||
StructRNA *icontype;
|
||||
int w, h;
|
||||
char namestr[UI_MAX_NAME_STR];
|
||||
const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0);
|
||||
|
||||
layout_root_new_button_group(layout->root);
|
||||
|
||||
type = RNA_property_type(prop);
|
||||
const PropertyType type = RNA_property_type(prop);
|
||||
if (!ELEM(type, PROP_POINTER, PROP_STRING, PROP_ENUM)) {
|
||||
RNA_warning("Property %s.%s must be a pointer, string or enum",
|
||||
RNA_struct_identifier(ptr->type),
|
||||
|
@ -2859,6 +2807,7 @@ void uiItemPointerR_prop(uiLayout *layout,
|
|||
|
||||
/* get icon & name */
|
||||
if (icon == ICON_NONE) {
|
||||
StructRNA *icontype;
|
||||
if (type == PROP_POINTER) {
|
||||
icontype = RNA_property_pointer_type(ptr, prop);
|
||||
}
|
||||
|
@ -2872,16 +2821,18 @@ void uiItemPointerR_prop(uiLayout *layout,
|
|||
name = RNA_property_ui_name(prop);
|
||||
}
|
||||
|
||||
char namestr[UI_MAX_NAME_STR];
|
||||
if (use_prop_sep == false) {
|
||||
name = ui_item_name_add_colon(name, namestr);
|
||||
}
|
||||
|
||||
/* create button */
|
||||
block = uiLayoutGetBlock(layout);
|
||||
uiBlock *block = uiLayoutGetBlock(layout);
|
||||
|
||||
int w, h;
|
||||
ui_item_rna_size(layout, name, icon, ptr, prop, 0, 0, false, &w, &h);
|
||||
w += UI_UNIT_X; /* X icon needs more space */
|
||||
but = ui_item_with_label(layout, block, name, icon, ptr, prop, 0, 0, 0, w, h, 0);
|
||||
uiBut *but = ui_item_with_label(layout, block, name, icon, ptr, prop, 0, 0, 0, w, h, 0);
|
||||
|
||||
ui_but_add_search(but, ptr, prop, searchptr, searchprop);
|
||||
}
|
||||
|
@ -2894,15 +2845,13 @@ void uiItemPointerR(uiLayout *layout,
|
|||
const char *name,
|
||||
int icon)
|
||||
{
|
||||
PropertyRNA *prop, *searchprop;
|
||||
|
||||
/* validate arguments */
|
||||
prop = RNA_struct_find_property(ptr, propname);
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
|
||||
if (!prop) {
|
||||
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
||||
return;
|
||||
}
|
||||
searchprop = RNA_struct_find_property(searchptr, searchpropname);
|
||||
PropertyRNA *searchprop = RNA_struct_find_property(searchptr, searchpropname);
|
||||
if (!searchprop) {
|
||||
RNA_warning("search collection property not found: %s.%s",
|
||||
RNA_struct_identifier(searchptr->type),
|
||||
|
@ -2944,8 +2893,6 @@ static uiBut *ui_item_menu(uiLayout *layout,
|
|||
{
|
||||
uiBlock *block = layout->root->block;
|
||||
uiLayout *heading_layout = ui_layout_heading_find(layout);
|
||||
uiBut *but;
|
||||
int w, h;
|
||||
|
||||
UI_block_layout_set_current(block, layout);
|
||||
layout_root_new_button_group(layout->root);
|
||||
|
@ -2957,8 +2904,8 @@ static uiBut *ui_item_menu(uiLayout *layout,
|
|||
icon = ICON_BLANK1;
|
||||
}
|
||||
|
||||
w = ui_text_icon_width(layout, name, icon, 1);
|
||||
h = UI_UNIT_Y;
|
||||
int w = ui_text_icon_width(layout, name, icon, 1);
|
||||
int h = UI_UNIT_Y;
|
||||
|
||||
if (layout->root->type == UI_LAYOUT_HEADER) { /* ugly .. */
|
||||
if (icon == ICON_NONE && force_menu) {
|
||||
|
@ -2978,6 +2925,7 @@ static uiBut *ui_item_menu(uiLayout *layout,
|
|||
ui_layout_heading_label_add(layout, heading_layout, true, true);
|
||||
}
|
||||
|
||||
uiBut *but;
|
||||
if (name[0] && icon) {
|
||||
but = uiDefIconTextMenuBut(block, func, arg, icon, name, 0, 0, w, h, tip);
|
||||
}
|
||||
|
@ -3058,10 +3006,9 @@ void uiItemMContents(uiLayout *layout, const char *menuname)
|
|||
void uiItemDecoratorR_prop(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index)
|
||||
{
|
||||
uiBlock *block = layout->root->block;
|
||||
uiLayout *col;
|
||||
|
||||
UI_block_layout_set_current(block, layout);
|
||||
col = uiLayoutColumn(layout, false);
|
||||
uiLayout *col = uiLayoutColumn(layout, false);
|
||||
col->space = 0;
|
||||
col->emboss = UI_EMBOSS_NONE;
|
||||
|
||||
|
@ -3212,8 +3159,6 @@ void uiItemPopoverPanelFromGroup(uiLayout *layout,
|
|||
static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon)
|
||||
{
|
||||
uiBlock *block = layout->root->block;
|
||||
uiBut *but;
|
||||
int w;
|
||||
|
||||
UI_block_layout_set_current(block, layout);
|
||||
layout_root_new_button_group(layout->root);
|
||||
|
@ -3225,8 +3170,9 @@ static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon)
|
|||
icon = ICON_BLANK1;
|
||||
}
|
||||
|
||||
w = ui_text_icon_width(layout, name, icon, 0);
|
||||
const int w = ui_text_icon_width(layout, name, icon, 0);
|
||||
|
||||
uiBut *but;
|
||||
if (icon && name[0]) {
|
||||
but = uiDefIconTextBut(
|
||||
block, UI_BTYPE_LABEL, 0, icon, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, NULL);
|
||||
|
@ -3342,7 +3288,6 @@ void uiItemV(uiLayout *layout, const char *name, int icon, int argval)
|
|||
/* label */
|
||||
uiBlock *block = layout->root->block;
|
||||
int *retvalue = (block->handle) ? &block->handle->retvalue : NULL;
|
||||
int w;
|
||||
|
||||
UI_block_layout_set_current(block, layout);
|
||||
|
||||
|
@ -3353,7 +3298,7 @@ void uiItemV(uiLayout *layout, const char *name, int icon, int argval)
|
|||
icon = ICON_BLANK1;
|
||||
}
|
||||
|
||||
w = ui_text_icon_width(layout, name, icon, 0);
|
||||
const int w = ui_text_icon_width(layout, name, icon, 0);
|
||||
|
||||
if (icon && name[0]) {
|
||||
uiDefIconTextButI(block,
|
||||
|
@ -3501,9 +3446,6 @@ void uiItemMenuEnumO_ptr(uiLayout *layout,
|
|||
const char *name,
|
||||
int icon)
|
||||
{
|
||||
MenuItemLevel *lvl;
|
||||
uiBut *but;
|
||||
|
||||
/* Caller must check */
|
||||
BLI_assert(ot->srna != NULL);
|
||||
|
||||
|
@ -3515,12 +3457,12 @@ void uiItemMenuEnumO_ptr(uiLayout *layout,
|
|||
icon = ICON_BLANK1;
|
||||
}
|
||||
|
||||
lvl = MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel");
|
||||
MenuItemLevel *lvl = MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel");
|
||||
BLI_strncpy(lvl->opname, ot->idname, sizeof(lvl->opname));
|
||||
BLI_strncpy(lvl->propname, propname, sizeof(lvl->propname));
|
||||
lvl->opcontext = layout->root->opcontext;
|
||||
|
||||
but = ui_item_menu(layout, name, icon, menu_item_enum_opname_menu, NULL, lvl, NULL, true);
|
||||
uiBut *but = ui_item_menu(layout, name, icon, menu_item_enum_opname_menu, NULL, lvl, NULL, true);
|
||||
|
||||
/* add hotkey here, lower UI code can't detect it */
|
||||
if ((layout->root->block->flag & UI_BLOCK_LOOP) && (ot->prop && ot->invoke)) {
|
||||
|
@ -3591,9 +3533,7 @@ void uiItemMenuEnumR_prop(
|
|||
void uiItemMenuEnumR(
|
||||
uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name, int icon)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
prop = RNA_struct_find_property(ptr, propname);
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
|
||||
if (!prop) {
|
||||
ui_item_disabled(layout, propname);
|
||||
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
||||
|
|
Loading…
Reference in New Issue