Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r--source/blender/editors/interface/interface_templates.c204
1 files changed, 84 insertions, 120 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 8b3f2bf4100..8f1d57b28ed 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1486,93 +1486,63 @@ void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname)
/************************* List Template **************************/
-#if 0
-typedef struct ListItem {
- PointerRNA ptr;
- PropertyRNA *prop;
- PropertyRNA *activeprop;
-
- PointerRNA activeptr;
- int activei;
-
- int selected;
-} ListItem;
-
-static void list_item_cb(bContext *C, void *arg_item, void *arg_unused)
-{
- ListItem *item= (ListItem*)arg_item;
- PropertyType activetype;
- char *activename;
-
- if(item->selected) {
- activetype= RNA_property_type(item->activeprop);
-
- if(activetype == PROP_POINTER)
- RNA_property_pointer_set(&item->ptr, item->activeprop, item->activeptr);
- else if(activetype == PROP_INT)
- RNA_property_int_set(&item->ptr, item->activeprop, item->activei);
- else if(activetype == PROP_STRING) {
- activename= RNA_struct_name_get_alloc(&item->activeptr, NULL, 0);
- RNA_property_string_set(&item->ptr, item->activeprop, activename);
- MEM_freeN(activename);
- }
- }
-}
-#endif
-
-ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, char *activepropname, int rows, int columns, int compact)
+ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, PointerRNA *activeptr, char *activepropname, int rows, int columns, int compact)
{
CollectionPointerLink *link;
- PropertyRNA *prop, *activeprop;
+ PropertyRNA *prop= NULL, *activeprop;
PropertyType type, activetype;
- PointerRNA activeptr;
uiLayout *box, *row, *col;
uiBlock *block;
uiBut *but;
+ Panel *pa;
ListBase lb;
- char *name, *activename= NULL, str[32];
- int i= 1, activei= 0, len, items, found;
- static int scroll = 1;
+ char *name, str[32];
+ int i= 0, activei= 0, len, items, found, min, max;
lb.first= lb.last= NULL;
/* validate arguments */
- if(!ptr->data)
+ block= uiLayoutGetBlock(layout);
+ pa= block->panel;
+
+ if(!pa) {
+ printf("uiTemplateList: only works inside a panel.\n");
return lb;
-
- prop= RNA_struct_find_property(ptr, propname);
- if(!prop) {
- printf("uiTemplateList: property not found: %s\n", propname);
+ }
+
+ if(!activeptr->data)
return lb;
+
+ if(ptr->data) {
+ prop= RNA_struct_find_property(ptr, propname);
+ if(!prop) {
+ printf("uiTemplateList: property not found: %s\n", propname);
+ return lb;
+ }
}
- activeprop= RNA_struct_find_property(ptr, activepropname);
+ activeprop= RNA_struct_find_property(activeptr, activepropname);
if(!activeprop) {
printf("uiTemplateList: property not found: %s\n", activepropname);
return lb;
}
- type= RNA_property_type(prop);
- if(type != PROP_COLLECTION) {
- printf("uiTemplateList: expected collection property.\n");
- return lb;
+ if(prop) {
+ type= RNA_property_type(prop);
+ if(type != PROP_COLLECTION) {
+ printf("uiTemplateList: expected collection property.\n");
+ return lb;
+ }
}
activetype= RNA_property_type(activeprop);
- if(!ELEM3(activetype, PROP_POINTER, PROP_INT, PROP_STRING)) {
- printf("uiTemplateList: expected pointer, integer or string property.\n");
+ if(activetype != PROP_INT) {
+ printf("uiTemplateList: expected integer property.\n");
return lb;
}
/* get active data */
- if(activetype == PROP_POINTER)
- activeptr= RNA_property_pointer_get(ptr, activeprop);
- else if(activetype == PROP_INT)
- activei= RNA_property_int_get(ptr, activeprop);
- else if(activetype == PROP_STRING)
- activename= RNA_property_string_get_alloc(ptr, activeprop, NULL, 0);
-
- block= uiLayoutGetBlock(layout);
+ activei= RNA_property_int_get(activeptr, activeprop);
if(compact) {
/* compact layout */
@@ -1580,111 +1550,105 @@ ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, char
row= uiLayoutRow(layout, 1);
- RNA_PROP_BEGIN(ptr, itemptr, prop) {
- if(activetype == PROP_POINTER)
- found= (activeptr.data == itemptr.data);
- else if(activetype == PROP_INT)
+ if(ptr->data && prop) {
+ /* create list items */
+ RNA_PROP_BEGIN(ptr, itemptr, prop) {
found= (activei == i);
- else if(activetype == PROP_STRING)
- found= (strcmp(activename, name) == 0);
-
- if(found) {
- name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
- if(name) {
- uiItemL(row, name, RNA_struct_ui_icon(itemptr.type));
- MEM_freeN(name);
+
+ if(found) {
+ /* create button */
+ name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
+ if(name) {
+ uiItemL(row, name, RNA_struct_ui_icon(itemptr.type));
+ MEM_freeN(name);
+ }
+
+ /* add to list to return */
+ link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return");
+ link->ptr= itemptr;
+ BLI_addtail(&lb, link);
}
- link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return");
- link->ptr= itemptr;
- BLI_addtail(&lb, link);
+ i++;
}
-
- i++;
+ RNA_PROP_END;
}
- RNA_PROP_END;
- if(i == 1)
+ /* if not found, add in dummy button */
+ if(i == 0)
uiItemL(row, "", 0);
- sprintf(str, "%d :", i-1);
- but= uiDefIconTextButR(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, ptr, activepropname, 0, 0, 0, 0, 0, "");
- if(i == 1)
+ /* next/prev button */
+ sprintf(str, "%d :", i);
+ but= uiDefIconTextButR(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activepropname, 0, 0, 0, 0, 0, "");
+ if(i == 0)
uiButSetFlag(but, UI_BUT_DISABLED);
}
else {
+ /* default rows/columns */
if(rows == 0)
rows= 5;
if(columns == 0)
columns= 1;
- items= rows*columns;
-
+ /* layout */
box= uiLayoutBox(layout);
row= uiLayoutRow(box, 0);
col = uiLayoutColumn(row, 1);
uiBlockSetEmboss(block, UI_EMBOSSN);
- len= RNA_property_collection_length(ptr, prop);
- scroll= MIN2(scroll, len-items+1);
- scroll= MAX2(scroll, 1);
+ /* init numbers */
+ RNA_property_int_range(activeptr, activeprop, &min, &max);
- RNA_PROP_BEGIN(ptr, itemptr, prop) {
- if(i >= scroll && i<scroll+items) {
- name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
+ len= max - min + 1;
+ items= rows*columns;
- if(name) {
-#if 0
- ListItem *item= MEM_callocN(sizeof(ListItem), "uiTemplateList ListItem");
-
- item->ptr= *ptr;
- item->prop= prop;
- item->activeprop= activeprop;
- item->activeptr= itemptr;
- item->activei= i;
-
- if(activetype == PROP_POINTER)
- item->selected= (activeptr.data == itemptr.data)? i: -1;
- else if(activetype == PROP_INT)
- item->selected= (activei == i)? i: -1;
- else if(activetype == PROP_STRING)
- item->selected= (strcmp(activename, name) == 0)? i: -1;
-#endif
+ pa->list_scroll= MIN2(pa->list_scroll, len-items);
+ pa->list_scroll= MAX2(pa->list_scroll, 0);
- //but= uiDefIconTextButI(block, ROW, 0, RNA_struct_ui_icon(itemptr.type), name, 0,0,UI_UNIT_X*10,UI_UNIT_Y, &item->selected, 0, i, 0, 0, "");
- but= uiDefIconTextButR(block, ROW, 0, RNA_struct_ui_icon(itemptr.type), name, 0,0,UI_UNIT_X*10,UI_UNIT_Y, ptr, activepropname, 0/*&item->selected*/, 0, i, 0, 0, "");
- uiButSetFlag(but, UI_ICON_LEFT|UI_TEXT_LEFT);
- //uiButSetNFunc(but, list_item_cb, item, NULL);
+ if(ptr->data && prop) {
+ /* create list items */
+ RNA_PROP_BEGIN(ptr, itemptr, prop) {
+ if(i >= pa->list_scroll && i<pa->list_scroll+items) {
+ name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
- MEM_freeN(name);
+ if(name) {
+ /* create button */
+ but= uiDefIconTextButR(block, ROW, 0, RNA_struct_ui_icon(itemptr.type), name, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
+ uiButSetFlag(but, UI_ICON_LEFT|UI_TEXT_LEFT);
+ MEM_freeN(name);
+ }
+
+ /* add to list to return */
link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return");
link->ptr= itemptr;
BLI_addtail(&lb, link);
}
- }
- i++;
+ i++;
+ }
+ RNA_PROP_END;
}
- RNA_PROP_END;
- while(i < scroll+items) {
- if(i >= scroll)
+ /* add dummy buttons to fill space */
+ while(i < pa->list_scroll+items) {
+ if(i >= pa->list_scroll)
uiItemL(col, "", 0);
i++;
}
uiBlockSetEmboss(block, UI_EMBOSS);
+ /* add scrollbar */
if(len > items) {
col= uiLayoutColumn(row, 0);
- uiDefButI(block, SCROLL, 0, "", 0,0,UI_UNIT_X*0.75,UI_UNIT_Y*items, &scroll, 1, len-items+1, items, 0, "");
+ uiDefButI(block, SCROLL, 0, "", 0,0,UI_UNIT_X*0.75,UI_UNIT_Y*items, &pa->list_scroll, 0, len-items, items, 0, "");
}
-
- //uiDefButI(block, SCROLL, 0, "", 0,0,UI_UNIT_X*15,UI_UNIT_Y*0.75, &scroll, 1, 16-5, 5, 0, "");
}
+ /* return items in list */
return lb;
}