RNA
* Enums can now be dynamically created in the _itemf callback, using RNA_enum_item(s)_add, RNA_enum_item_end. All places asking for enum items now need to potentially free the items. * This callback now also gets context, this was added specifically for operators. This doesn't fit design well at all, needed to do some ugly hacks, but can't find a good solution at the moment. * All enums must have a default list of items too, even with an _itemf callback, for docs and fallback in case there is no context. * Used by MESH_OT_merge, MESH_OT_select_similar, TFM_OT_select_orientation. * Also changes some operator properties that were enums to booleas (unselected, deselect), to make them consistent with other ops.
This commit is contained in:
@@ -1112,7 +1112,7 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item
|
||||
switch(prop->type) {
|
||||
case PROP_ENUM: {
|
||||
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
|
||||
eprop->item= item;
|
||||
eprop->item= (EnumPropertyItem*)item;
|
||||
eprop->totitem= 0;
|
||||
for(i=0; item[i].identifier; i++) {
|
||||
eprop->totitem++;
|
||||
@@ -2262,3 +2262,37 @@ int rna_parameter_size(PropertyRNA *parm)
|
||||
return sizeof(void *);
|
||||
}
|
||||
|
||||
/* Dynamic Enums */
|
||||
|
||||
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item)
|
||||
{
|
||||
EnumPropertyItem *newitems;
|
||||
int tot= *totitem;
|
||||
|
||||
if(tot == 0) {
|
||||
*items= MEM_callocN(sizeof(EnumPropertyItem)*8, "RNA_enum_items_add");
|
||||
}
|
||||
else if(tot >= 8 && (tot&(tot-1)) == 0){
|
||||
/* power of two > 8 */
|
||||
newitems= MEM_callocN(sizeof(EnumPropertyItem)*tot*2, "RNA_enum_items_add");
|
||||
memcpy(newitems, *items, sizeof(EnumPropertyItem)*tot);
|
||||
MEM_freeN(*items);
|
||||
*items= newitems;
|
||||
}
|
||||
|
||||
(*items)[tot]= *item;
|
||||
*totitem= tot+1;
|
||||
}
|
||||
|
||||
void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item)
|
||||
{
|
||||
for(; item->identifier; item++)
|
||||
RNA_enum_item_add(items, totitem, item);
|
||||
}
|
||||
|
||||
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
|
||||
{
|
||||
static EnumPropertyItem empty = {0, NULL, 0, NULL, NULL};
|
||||
RNA_enum_item_add(items, totitem, &empty);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user