diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-07-21 05:26:17 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-07-21 05:26:17 +0400 |
commit | a78ef19054af921c536f647bd84ed9fd2636bfe0 (patch) | |
tree | 47e5912921bf0b17832495d9eb525f75427de2b1 | |
parent | f682de6fd2b4b64bc405f36f68c4024797b84492 (diff) |
2.5: UI
* List template visual changes. Items now look different,
and it expands to size 5 as more items are added.
* Added LISTROW and LISTBOX elements. The former is like
a typical ROW button, but looks diffrent. The latter
looks like a BOUNDBOX, and has no extra features yet.
* Fix some glColor3ubv warnings with casting, did not find
a nicer way.
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 19 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 7 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_draw.c | 12 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 21 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 32 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 8 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 100 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 76 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_userdef_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 75 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui_api.c | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_userdef.c | 6 |
13 files changed, 287 insertions, 84 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 66089272737..2fec61fda3c 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -30,6 +30,8 @@ #ifndef UI_INTERFACE_H #define UI_INTERFACE_H +#include "RNA_types.h" + /* Struct Declarations */ struct ID; @@ -201,7 +203,9 @@ typedef struct uiLayout uiLayout; #define SEARCH_MENU (40<<9) #define BUT_EXTRA (41<<9) #define HSVCIRCLE (42<<9) -#define BUTTYPE (63<<9) +#define LISTBOX (43<<9) +#define LISTROW (44<<9) +#define BUTTYPE (63<<9) /* Drawing * @@ -588,7 +592,6 @@ void uiLayoutSetKeepAspect(uiLayout *layout, int keepaspect); void uiLayoutSetScaleX(uiLayout *layout, float scale); void uiLayoutSetScaleY(uiLayout *layout, float scale); - int uiLayoutGetOperatorContext(uiLayout *layout); int uiLayoutGetActive(uiLayout *layout); int uiLayoutGetEnabled(uiLayout *layout); @@ -597,12 +600,14 @@ int uiLayoutGetAlignment(uiLayout *layout); int uiLayoutGetKeepAspect(uiLayout *layout); float uiLayoutGetScaleX(uiLayout *layout); float uiLayoutGetScaleY(uiLayout *layout); +ListBase *uiLayoutBoxGetList(uiLayout *layout); /* layout specifiers */ uiLayout *uiLayoutRow(uiLayout *layout, int align); uiLayout *uiLayoutColumn(uiLayout *layout, int align); uiLayout *uiLayoutColumnFlow(uiLayout *layout, int number, int align); uiLayout *uiLayoutBox(uiLayout *layout); +uiLayout *uiLayoutListBox(uiLayout *layout); uiLayout *uiLayoutFree(uiLayout *layout, int align); uiLayout *uiLayoutSplit(uiLayout *layout, float percentage); @@ -619,11 +624,19 @@ void uiTemplateColorRamp(uiLayout *layout, struct ColorBand *coba, int expand); void uiTemplateCurveMapping(uiLayout *layout, struct CurveMapping *cumap, int type); void uiTemplateLayers(uiLayout *layout, struct PointerRNA *ptr, char *propname); void uiTemplateImageLayers(uiLayout *layout, struct bContext *C, struct Image *ima, struct ImageUser *iuser); -ListBase uiTemplateList(uiLayout *layout, struct PointerRNA *ptr, char *propname, struct PointerRNA *activeptr, char *activeprop, int rows, int columns, int compact); void uiTemplateRunningJobs(uiLayout *layout, struct bContext *C); void uiTemplateOperatorSearch(uiLayout *layout); void uiTemplateHeader3D(uiLayout *layout, struct bContext *C); +typedef struct uiListItem { + struct uiListItem *next, *prev; + + struct PointerRNA data; + uiLayout *layout; +} uiListItem; + +ListBase uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname, struct PointerRNA *activeptr, char *activeprop, int rows, int type); + /* items */ void uiItemO(uiLayout *layout, char *name, int icon, char *opname); void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value); diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 9ded2ec9eb8..27561f42b8a 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -720,6 +720,7 @@ static void ui_is_but_sel(uiBut *but) if(value==0.0) push= 1; break; case ROW: + case LISTROW: if(value == but->hardmax) push= 1; break; case COL: @@ -2149,7 +2150,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, freestr= 1; } - else if(type == ROW && proptype == PROP_ENUM) { + else if(ELEM(type, ROW, LISTROW) && proptype == PROP_ENUM) { EnumPropertyItem *item; int i, totitem, free; @@ -2202,7 +2203,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, RNA_property_int_range(ptr, prop, &hardmin, &hardmax); RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step); - if(type != ROW && min == max) { + if(!ELEM(type, ROW, LISTROW) && min == max) { min= hardmin; max= hardmax; } @@ -2217,7 +2218,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, RNA_property_float_range(ptr, prop, &hardmin, &hardmax); RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision); - if(type != ROW && min == max) { + if(!ELEM(type, ROW, LISTROW) && min == max) { min= hardmin; max= hardmax; } diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 8400fee0c55..cded4753f61 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -788,7 +788,7 @@ void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect) glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff); /* backdrop */ - glColor3ubv(wcol->inner); + glColor3ubv((unsigned char*)wcol->inner); uiSetRoundBox(15); gl_round_box(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f); @@ -852,7 +852,7 @@ void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect) /* AA circle */ glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH ); - glColor3ubv(wcol->inner); + glColor3ubv((unsigned char*)wcol->inner); glutil_draw_lined_arc(0.0f, M_PI*2.0, 100.0f, 32); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH ); @@ -926,14 +926,14 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect if(cumap->flag & CUMA_DO_CLIP) { glColor3ubvShade(wcol->inner, -20); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); - glColor3ubv(wcol->inner); + glColor3ubv((unsigned char*)wcol->inner); glRectf(rect->xmin + zoomx*(cumap->clipr.xmin-offsx), rect->ymin + zoomy*(cumap->clipr.ymin-offsy), rect->xmin + zoomx*(cumap->clipr.xmax-offsx), rect->ymin + zoomy*(cumap->clipr.ymax-offsy)); } else { - glColor3ubv(wcol->inner); + glColor3ubv((unsigned char*)wcol->inner); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); } @@ -989,7 +989,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect }*/ /* the curve */ - glColor3ubv(wcol->item); + glColor3ubv((unsigned char*)wcol->item); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBegin(GL_LINE_STRIP); @@ -1043,7 +1043,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); /* outline */ - glColor3ubv(wcol->outline); + glColor3ubv((unsigned char*)wcol->outline); fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 0fbfeffba0d..442d472a47a 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -188,7 +188,7 @@ static uiBut *ui_but_prev(uiBut *but) { while(but->prev) { but= but->prev; - if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but; + if(!ELEM4(but->type, LABEL, SEPR, ROUNDBOX, LISTBOX)) return but; } return NULL; } @@ -197,7 +197,7 @@ static uiBut *ui_but_next(uiBut *but) { while(but->next) { but= but->next; - if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but; + if(!ELEM4(but->type, LABEL, SEPR, ROUNDBOX, LISTBOX)) return but; } return NULL; } @@ -208,7 +208,7 @@ static uiBut *ui_but_first(uiBlock *block) but= block->buttons.first; while(but) { - if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but; + if(!ELEM4(but->type, LABEL, SEPR, ROUNDBOX, LISTBOX)) return but; but= but->next; } return NULL; @@ -220,7 +220,7 @@ static uiBut *ui_but_last(uiBlock *block) but= block->buttons.last; while(but) { - if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but; + if(!ELEM4(but->type, LABEL, SEPR, ROUNDBOX, LISTBOX)) return but; but= but->prev; } return NULL; @@ -284,7 +284,7 @@ static void ui_apply_autokey_undo(bContext *C, uiBut *but) uiAfterFunc *after; char *str= NULL; - if ELEM5(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX); + if ELEM6(but->type, BLOCK, BUT, LABEL, PULLDOWN, ROUNDBOX, LISTBOX); else { /* define which string to use for undo */ if ELEM(but->type, LINK, INLINK) str= "Add button link"; @@ -449,7 +449,7 @@ static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleBu /* states of other row buttons */ for(bt= block->buttons.first; bt; bt= bt->next) - if(bt!=but && bt->poin==but->poin && bt->type==ROW) + if(bt!=but && bt->poin==but->poin && ELEM(bt->type, ROW, LISTROW)) ui_check_but(bt); ui_apply_but_func(C, but); @@ -782,6 +782,7 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut ui_apply_but_TOG(C, block, but, data); break; case ROW: + case LISTROW: ui_apply_but_ROW(C, block, but, data); break; case SCROLL: @@ -1392,7 +1393,7 @@ static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonDa uiBut *but; /* label and roundbox can overlap real buttons (backdrops...) */ - if(actbut->type==LABEL && actbut->type==ROUNDBOX) + if(ELEM4(actbut->type, LABEL, SEPR, ROUNDBOX, LISTBOX)) return; for(but= actbut->next; but; but= but->next) { @@ -1416,7 +1417,7 @@ static void ui_textedit_prev_but(uiBlock *block, uiBut *actbut, uiHandleButtonDa uiBut *but; /* label and roundbox can overlap real buttons (backdrops...) */ - if(actbut->type==LABEL && actbut->type==ROUNDBOX) + if(ELEM4(actbut->type, LABEL, SEPR, ROUNDBOX, LISTBOX)) return; for(but= actbut->prev; but; but= but->prev) { @@ -3183,9 +3184,11 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) retval= ui_do_but_SLI(C, block, but, data, event); break; case ROUNDBOX: + case LISTBOX: case LABEL: case TOG3: case ROW: + case LISTROW: retval= ui_do_but_EXIT(C, but, data, event); break; case TEX: @@ -3331,7 +3334,7 @@ static uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y) ui_window_to_block(ar, block, &mx, &my); for(but=block->buttons.first; but; but= but->next) { - if(ELEM3(but->type, LABEL, ROUNDBOX, SEPR)) + if(ELEM4(but->type, LABEL, ROUNDBOX, SEPR, LISTBOX)) continue; if(but->flag & UI_HIDDEN) continue; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 5760a28cb5c..70d60502ac4 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -84,7 +84,8 @@ typedef enum { UI_WTYPE_RGB_PICKER, UI_WTYPE_NORMAL, UI_WTYPE_BOX, - UI_WTYPE_SCROLL + UI_WTYPE_SCROLL, + UI_WTYPE_LISTITEM } uiWidgetTypeEnum; diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 284da29f0d2..07fe2686317 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -148,6 +148,7 @@ typedef struct uiLayoutItemFlow { typedef struct uiLayoutItemBx { uiLayout litem; uiBut *roundbox; + ListBase items; } uiLayoutItemBx; typedef struct uiLayoutItemSplt { @@ -218,7 +219,7 @@ static int ui_text_icon_width(uiLayout *layout, char *name, int icon) { int variable = ui_layout_vary_direction(layout) == UI_ITEM_VARY_X; - if(icon && strcmp(name, "") == 0) + if(icon && !name[0]) return UI_UNIT_X; /* icon only */ else if(icon) return (variable)? UI_GetStringWidth(name) + 4 + UI_UNIT_X: 10*UI_UNIT_X; /* icon + text */ @@ -723,15 +724,17 @@ static void ui_item_rna_size(uiLayout *layout, char *name, int icon, PropertyRNA subtype= RNA_property_subtype(prop); len= RNA_property_array_length(prop); - if(ELEM(type, PROP_STRING, PROP_POINTER) && strcmp(name, "") == 0) + if(ELEM(type, PROP_STRING, PROP_POINTER) && !name[0]) name= "non-empty"; + else if(type == PROP_BOOLEAN && !name[0]) + icon= ICON_DOT; w= ui_text_icon_width(layout, name, icon); h= UI_UNIT_Y; /* increase height for arrays */ if(index == RNA_NO_INDEX && len > 0) { - if(strcmp(name, "") == 0 && icon == 0) + if(!name[0] && icon == 0) h= 0; if(type == PROP_BOOLEAN && len == 20) @@ -1808,7 +1811,7 @@ uiLayout *uiLayoutColumnFlow(uiLayout *layout, int number, int align) return &flow->litem; } -uiLayout *uiLayoutBox(uiLayout *layout) +static uiLayout *ui_layout_box(uiLayout *layout, int type) { uiLayoutItemBx *box; @@ -1823,11 +1826,27 @@ uiLayout *uiLayoutBox(uiLayout *layout) uiBlockSetCurLayout(layout->root->block, &box->litem); - box->roundbox= uiDefBut(layout->root->block, ROUNDBOX, 0, "", 0, 0, 0, 0, NULL, 0.0, 0.0, 0, 0, ""); + box->roundbox= uiDefBut(layout->root->block, type, 0, "", 0, 0, 0, 0, NULL, 0.0, 0.0, 0, 0, ""); return &box->litem; } +uiLayout *uiLayoutBox(uiLayout *layout) +{ + return ui_layout_box(layout, ROUNDBOX); +} + +uiLayout *uiLayoutListBox(uiLayout *layout) +{ + return ui_layout_box(layout, LISTBOX); +} + +ListBase *uiLayoutBoxGetList(uiLayout *layout) +{ + uiLayoutItemBx *box= (uiLayoutItemBx*)layout; + return &box->items; +} + uiLayout *uiLayoutFree(uiLayout *layout, int align) { uiLayout *litem; @@ -2132,6 +2151,9 @@ static void ui_layout_free(uiLayout *layout) ui_layout_free((uiLayout*)item); } + if(layout->item.type == ITEM_LAYOUT_BOX) + BLI_freelistN(&((uiLayoutItemBx*)layout)->items); + MEM_freeN(layout); } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 6faa658c3d0..e2c97e4f05e 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -93,7 +93,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->paneltitle.uifont_id= UIFONT_DEFAULT; style->paneltitle.points= 12; - style->paneltitle.kerning= 0; + style->paneltitle.kerning= 1; style->paneltitle.shadow= 5; style->paneltitle.shadx= 2; style->paneltitle.shady= -2; @@ -102,7 +102,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->grouplabel.uifont_id= UIFONT_DEFAULT; style->grouplabel.points= 12; - style->grouplabel.kerning= 0; + style->grouplabel.kerning= 1; style->grouplabel.shadow= 3; style->grouplabel.shadx= 1; style->grouplabel.shady= -1; @@ -110,7 +110,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->widgetlabel.uifont_id= UIFONT_DEFAULT; style->widgetlabel.points= 11; - style->widgetlabel.kerning= 0; + style->widgetlabel.kerning= 1; style->widgetlabel.shadow= 3; style->widgetlabel.shadx= 1; style->widgetlabel.shady= -1; @@ -119,7 +119,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->widget.uifont_id= UIFONT_DEFAULT; style->widget.points= 11; - style->widget.kerning= 0; + style->widget.kerning= 1; style->widget.shadowalpha= 0.25f; style->columnspace= 5; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 512d279cc37..f34774b0516 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -99,11 +99,12 @@ static void id_search_cb(const struct bContext *C, void *arg_template, char *str /* ID listbase */ for(id= lb->first; id; id= id->next) { - iconid= ui_id_icon_get(scene, id); + if(BLI_strcasestr(id->name+2, str)) { + iconid= ui_id_icon_get(scene, id); - if(BLI_strcasestr(id->name+2, str)) if(!uiSearchItemAdd(items, id->name+2, id, iconid)) break; + } } } @@ -1296,17 +1297,36 @@ void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname) /************************* List Template **************************/ -ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, PointerRNA *activeptr, char *activepropname, int rows, int columns, int compact) +#if 0 +static void list_item_add(ListBase *lb, ListBase *itemlb, uiLayout *layout, PointerRNA *data) { CollectionPointerLink *link; + uiListItem *item; + + /* add to list to store in box */ + item= MEM_callocN(sizeof(uiListItem), "uiListItem"); + item->layout= layout; + item->data= *data; + BLI_addtail(itemlb, item); + + /* add to list to return from function */ + link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return"); + RNA_pointer_create(NULL, &RNA_UIListItem, item, &link->ptr); + BLI_addtail(lb, link); +} +#endif + +ListBase uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, PointerRNA *activeptr, char *activepropname, int rows, int listtype) +{ + //Scene *scene= CTX_data_scene(C); PropertyRNA *prop= NULL, *activeprop; PropertyType type, activetype; StructRNA *ptype; - uiLayout *box, *row, *col; + uiLayout *box, *row, *col, *subrow; uiBlock *block; uiBut *but; Panel *pa; - ListBase lb; + ListBase lb, *itemlb; char *name, str[32]; int icon=0, i= 0, activei= 0, len, items, found, min, max; @@ -1361,7 +1381,39 @@ ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, Point /* get active data */ activei= RNA_property_int_get(activeptr, activeprop); - if(compact) { + if(listtype == 'i') { + box= uiLayoutListBox(layout); + col= uiLayoutColumn(box, 1); + row= uiLayoutRow(col, 0); + + itemlb= uiLayoutBoxGetList(box); + + if(ptr->data && prop) { + /* create list items */ + RNA_PROP_BEGIN(ptr, itemptr, prop) { + /* create button */ + if(i == 9) + row= uiLayoutRow(col, 0); + + if(RNA_struct_is_a(itemptr.type, &RNA_TextureSlot)) { +#if 0 + MTex *mtex= itemptr.data; + + if(mtex && mtex->tex) + icon= ui_id_icon_get(scene, &mtex->tex->id); +#endif + } + + uiDefIconButR(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, ""); + + //list_item_add(&lb, itemlb, uiLayoutRow(row, 1), &itemptr); + + i++; + } + RNA_PROP_END; + } + } + else if(listtype == 'c') { /* compact layout */ found= 0; @@ -1381,9 +1433,7 @@ ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, Point MEM_freeN(name); /* add to list to return */ - link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return"); - link->ptr= itemptr; - BLI_addtail(&lb, link); + //list_item_add(&lb, itemlb, uiLayoutRow(row, 1), &itemptr); } i++; @@ -1402,45 +1452,53 @@ ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, Point uiButSetFlag(but, UI_BUT_DISABLED); } else { - /* default rows/columns */ + /* default rows */ if(rows == 0) rows= 5; - if(columns == 0) - columns= 1; /* layout */ - box= uiLayoutBox(layout); + box= uiLayoutListBox(layout); row= uiLayoutRow(box, 0); col = uiLayoutColumn(row, 1); - uiBlockSetEmboss(block, UI_EMBOSSN); - /* init numbers */ RNA_property_int_range(activeptr, activeprop, &min, &max); len= max - min + 1; - items= rows*columns; + items= CLAMPIS(len, rows, 5); pa->list_scroll= MIN2(pa->list_scroll, len-items); pa->list_scroll= MAX2(pa->list_scroll, 0); + itemlb= uiLayoutBoxGetList(box); + 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); + subrow= uiLayoutRow(col, 0); + /* create button */ - but= uiDefIconTextButR(block, ROW, 0, icon, (name)? name: "", 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, ""); + if(!icon || icon == ICON_DOT) + but= uiDefButR(block, LISTROW, 0, (name)? name: "", 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, ""); + else + but= uiDefIconTextButR(block, LISTROW, 0, icon, (name)? 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); + /* XXX hardcoded */ + if(itemptr.type == &RNA_MeshTextureFaceLayer || itemptr.type == &RNA_MeshColorLayer) { + uiBlockSetEmboss(block, UI_EMBOSSN); + uiItemR(subrow, "", ICON_SCENE, &itemptr, "active_render", 0, 0, 0); + uiBlockSetEmboss(block, UI_EMBOSS); + } + if(name) MEM_freeN(name); /* add to list to return */ - link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return"); - link->ptr= itemptr; - BLI_addtail(&lb, link); + //list_item_add(&lb, itemlb, subrow, &itemptr); } i++; @@ -1455,8 +1513,6 @@ ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, Point i++; } - uiBlockSetEmboss(block, UI_EMBOSS); - /* add scrollbar */ if(len > items) { col= uiLayoutColumn(row, 0); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index afb7e74daff..97c2bb55a69 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -536,7 +536,7 @@ static void shadecolors4(char *coltop, char *coldown, char *color, short shadeto static void round_box_shade_col4(char *col1, char *col2, float fac) { int faci, facm; - char col[4]; + unsigned char col[4]; faci= floor(255.1f*fac); facm= 255-faci; @@ -575,7 +575,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) if(wcol->shaded==0) { /* filled center, solid */ - glColor4ubv(wcol->inner); + glColor4ubv((unsigned char*)wcol->inner); glBegin(GL_POLYGON); for(a=0; a<wtb->totvert; a++) glVertex2fv(wtb->inner_v[a]); @@ -682,7 +682,7 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, int blend, rcti *rect) height= ICON_HEIGHT; /* calculate blend color */ - if ELEM3(but->type, TOG, ROW, TOGN) { + if ELEM4(but->type, TOG, ROW, TOGN, LISTROW) { if(but->flag & UI_SELECT); else if(but->flag & UI_ACTIVE); else blend= -60; @@ -806,7 +806,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b but->drawstr[selend_tmp]= ch; - glColor3ubv(wcol->item); + glColor3ubv((unsigned char*)wcol->item); glRects(rect->xmin+selsta_draw+1, rect->ymin+2, rect->xmin+selwidth_draw+1, rect->ymax-2); } } else { @@ -838,7 +838,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b if(cpoin) *cpoin= 0; } - glColor3ubv(wcol->text); + glColor3ubv((unsigned char*)wcol->text); uiStyleFontDraw(fstyle, rect, but->drawstr+but->ofs); /* part text right aligned */ @@ -1123,6 +1123,19 @@ static struct uiWidgetColors wcol_scroll= { 10, -20 }; +static struct uiWidgetColors wcol_list_item= { + {0, 0, 0, 255}, + {0, 0, 0, 0}, + {86, 128, 194, 255}, + {0, 0, 0, 255}, + + {0, 0, 0, 255}, + {0, 0, 0, 255}, + + 0, + 0, 0 +}; + /* free wcol struct to play with */ static struct uiWidgetColors wcol_tmp= { {0, 0, 0, 255}, @@ -1155,6 +1168,7 @@ void ui_widget_color_init(ThemeUI *tui) tui->wcol_menu_item= wcol_menu_item; tui->wcol_box= wcol_box; tui->wcol_scroll= wcol_scroll; + tui->wcol_list_item= wcol_list_item; tui->wcol_state= wcol_state; } @@ -1724,7 +1738,7 @@ static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat { rcti rect1; double value; - float fac, size; + float fac, size, min; int horizontal; /* calculate slider part */ @@ -1743,11 +1757,35 @@ static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat fac= (rect->xmax - rect->xmin)/(size); rect1.xmin= rect1.xmin + ceil(fac*(value - but->softmin)); rect1.xmax= rect1.xmin + ceil(fac*(but->a1 - but->softmin)); + + /* ensure minimium size */ + min= rect->ymax - rect->ymin; + + if(rect1.xmax - rect1.xmin < min) { + rect1.xmax= rect1.xmin + min; + + if(rect1.xmax > rect->xmax) { + rect1.xmax= rect->xmax; + rect1.xmin= MAX2(rect1.xmax - min, rect->xmin); + } + } } else { fac= (rect->ymax - rect->ymin)/(size); rect1.ymax= rect1.ymax - ceil(fac*(value - but->softmin)); rect1.ymin= rect1.ymax - ceil(fac*(but->a1 - but->softmin)); + + /* ensure minimium size */ + min= rect->xmax - rect->xmin; + + if(rect1.ymax - rect1.ymin < min) { + rect1.ymax= rect1.ymin + min; + + if(rect1.ymax > rect->ymax) { + rect1.ymax= rect->ymax; + rect1.ymin= MAX2(rect1.ymax - min, rect->ymin); + } + } } if(state & UI_SELECT) @@ -1755,7 +1793,6 @@ static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat else state= 0; uiWidgetScrollDraw(wcol, rect, &rect1, state); - } static void widget_link(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) @@ -1918,6 +1955,18 @@ static void widget_menu_itembut(uiWidgetColors *wcol, rcti *rect, int state, int widgetbase_draw(&wtb, wcol); } +static void widget_list_itembut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) +{ + uiWidgetBase wtb; + + widget_init(&wtb); + + /* rounded, but no outline */ + wtb.outline= 0; + round_box_edges(&wtb, 15, rect, 4.0f); + + widgetbase_draw(&wtb, wcol); +} static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) { @@ -2067,7 +2116,6 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type) case UI_WTYPE_OPTION: wt.wcol_theme= &btheme->tui.wcol_option; wt.draw= widget_optionbut; - wt.state= widget_state_label; break; case UI_WTYPE_RADIO: @@ -2161,6 +2209,11 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type) wt.state= widget_state_nothing; wt.custom= widget_scroll; break; + + case UI_WTYPE_LISTITEM: + wt.wcol_theme= &btheme->tui.wcol_list_item; + wt.draw= widget_list_itembut; + break; } return &wt; @@ -2268,6 +2321,10 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct case ROW: wt= widget_type(UI_WTYPE_RADIO); break; + + case LISTROW: + wt= widget_type(UI_WTYPE_LISTITEM); + break; case TEX: wt= widget_type(UI_WTYPE_NAME); @@ -2315,6 +2372,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct break; case ROUNDBOX: + case LISTBOX: wt= widget_type(UI_WTYPE_BOX); break; @@ -2437,7 +2495,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, char *name, int iconid, rect->xmax -= BLF_width(cpoin+1) + 10; } - glColor3ubv(wt->wcol.text); + glColor3ubv((unsigned char*)wt->wcol.text); uiStyleFontDraw(fstyle, rect, name); /* part text right aligned */ diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 4fab0de1f0a..d8a943e1656 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -139,7 +139,7 @@ typedef struct ThemeUI { uiWidgetColors wcol_radio, wcol_option, wcol_toggle; uiWidgetColors wcol_num, wcol_numslider; uiWidgetColors wcol_menu, wcol_pulldown, wcol_menu_back, wcol_menu_item; - uiWidgetColors wcol_box, wcol_scroll; + uiWidgetColors wcol_box, wcol_scroll, wcol_list_item; uiWidgetStateColors wcol_state; diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index e83557957f6..8a51a5f4142 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -199,7 +199,7 @@ static StructRNA *rna_Panel_register(const bContext *C, ReportList *reports, voi return pt->py_srna; } -static StructRNA* rna_Panel_refine(struct PointerRNA *ptr) +static StructRNA* rna_Panel_refine(PointerRNA *ptr) { Panel *hdr= (Panel*)ptr->data; return (hdr->type && hdr->type->py_srna)? hdr->type->py_srna: &RNA_Panel; @@ -290,7 +290,7 @@ static StructRNA *rna_Header_register(const bContext *C, ReportList *reports, vo return ht->py_srna; } -static StructRNA* rna_Header_refine(struct PointerRNA *htr) +static StructRNA* rna_Header_refine(PointerRNA *htr) { Header *hdr= (Header*)htr->data; return (hdr->type && hdr->type->py_srna)? hdr->type->py_srna: &RNA_Header; @@ -405,92 +405,108 @@ static StructRNA *rna_Menu_register(const bContext *C, ReportList *reports, void return mt->py_srna; } -static StructRNA* rna_Menu_refine(struct PointerRNA *mtr) +static StructRNA* rna_Menu_refine(PointerRNA *mtr) { Menu *hdr= (Menu*)mtr->data; return (hdr->type && hdr->type->py_srna)? hdr->type->py_srna: &RNA_Menu; } -static int rna_UILayout_active_get(struct PointerRNA *ptr) +static int rna_UILayout_active_get(PointerRNA *ptr) { return uiLayoutGetActive(ptr->data); } -static void rna_UILayout_active_set(struct PointerRNA *ptr, int value) +static void rna_UILayout_active_set(PointerRNA *ptr, int value) { uiLayoutSetActive(ptr->data, value); } -static void rna_UILayout_op_context_set(struct PointerRNA *ptr, int value) +static void rna_UILayout_op_context_set(PointerRNA *ptr, int value) { uiLayoutSetOperatorContext(ptr->data, value); } -static int rna_UILayout_op_context_get(struct PointerRNA *ptr) +static int rna_UILayout_op_context_get(PointerRNA *ptr) { return uiLayoutGetOperatorContext(ptr->data); } -static int rna_UILayout_enabled_get(struct PointerRNA *ptr) +static int rna_UILayout_enabled_get(PointerRNA *ptr) { return uiLayoutGetEnabled(ptr->data); } -static void rna_UILayout_enabled_set(struct PointerRNA *ptr, int value) +static void rna_UILayout_enabled_set(PointerRNA *ptr, int value) { uiLayoutSetEnabled(ptr->data, value); } -static int rna_UILayout_red_alert_get(struct PointerRNA *ptr) +#if 0 +static int rna_UILayout_red_alert_get(PointerRNA *ptr) { return uiLayoutGetRedAlert(ptr->data); } -static void rna_UILayout_red_alert_set(struct PointerRNA *ptr, int value) +static void rna_UILayout_red_alert_set(PointerRNA *ptr, int value) { uiLayoutSetRedAlert(ptr->data, value); } -static int rna_UILayout_keep_aspect_get(struct PointerRNA *ptr) +static int rna_UILayout_keep_aspect_get(PointerRNA *ptr) { return uiLayoutGetKeepAspect(ptr->data); } -static void rna_UILayout_keep_aspect_set(struct PointerRNA *ptr, int value) +static void rna_UILayout_keep_aspect_set(PointerRNA *ptr, int value) { uiLayoutSetKeepAspect(ptr->data, value); } +#endif -static int rna_UILayout_alignment_get(struct PointerRNA *ptr) +static int rna_UILayout_alignment_get(PointerRNA *ptr) { return uiLayoutGetAlignment(ptr->data); } -static void rna_UILayout_alignment_set(struct PointerRNA *ptr, int value) +static void rna_UILayout_alignment_set(PointerRNA *ptr, int value) { uiLayoutSetAlignment(ptr->data, value); } -static float rna_UILayout_scale_x_get(struct PointerRNA *ptr) +static float rna_UILayout_scale_x_get(PointerRNA *ptr) { return uiLayoutGetScaleX(ptr->data); } -static void rna_UILayout_scale_x_set(struct PointerRNA *ptr, float value) +static void rna_UILayout_scale_x_set(PointerRNA *ptr, float value) { uiLayoutSetScaleX(ptr->data, value); } -static float rna_UILayout_scale_y_get(struct PointerRNA *ptr) +static float rna_UILayout_scale_y_get(PointerRNA *ptr) { return uiLayoutGetScaleY(ptr->data); } -static void rna_UILayout_scale_y_set(struct PointerRNA *ptr, float value) +static void rna_UILayout_scale_y_set(PointerRNA *ptr, float value) { uiLayoutSetScaleY(ptr->data, value); } +static PointerRNA rna_UIListItem_layout_get(PointerRNA *ptr) +{ + uiListItem *item= (uiListItem*)ptr->data; + PointerRNA newptr; + RNA_pointer_create(NULL, &RNA_UILayout, item->layout, &newptr); + return newptr; +} + +static PointerRNA rna_UIListItem_data_get(PointerRNA *ptr) +{ + uiListItem *item= (uiListItem*)ptr->data; + return item->data; +} + #else // RNA_RUNTIME static void rna_def_ui_layout(BlenderRNA *brna) @@ -516,6 +532,8 @@ static void rna_def_ui_layout(BlenderRNA *brna) {WM_OP_EXEC_AREA, "EXEC_AREA", 0, "Exec Area", ""}, {WM_OP_EXEC_SCREEN, "EXEC_SCREEN", 0, "Exec Screen", ""}, {0, NULL, 0, NULL, NULL}}; + + /* layout */ srna= RNA_def_struct(brna, "UILayout", NULL); RNA_def_struct_sdna(srna, "uiLayout"); @@ -531,15 +549,19 @@ static void rna_def_ui_layout(BlenderRNA *brna) prop= RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_UILayout_enabled_get", "rna_UILayout_enabled_set"); +#if 0 prop= RNA_def_property(srna, "red_alert", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_UILayout_red_alert_get", "rna_UILayout_red_alert_set"); +#endif prop= RNA_def_property(srna, "alignment", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, alignment_items); RNA_def_property_enum_funcs(prop, "rna_UILayout_alignment_get", "rna_UILayout_alignment_set", NULL); +#if 0 prop= RNA_def_property(srna, "keep_aspect", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_UILayout_keep_aspect_get", "rna_UILayout_keep_aspect_set"); +#endif prop= RNA_def_property(srna, "scale_x", PROP_FLOAT, PROP_UNSIGNED); RNA_def_property_float_funcs(prop, "rna_UILayout_scale_x_get", "rna_UILayout_scale_x_set", NULL); @@ -548,6 +570,21 @@ static void rna_def_ui_layout(BlenderRNA *brna) RNA_def_property_float_funcs(prop, "rna_UILayout_scale_y_get", "rna_UILayout_scale_y_set", NULL); RNA_api_ui_layout(srna); + + /* list item */ + + srna= RNA_def_struct(brna, "UIListItem", NULL); + RNA_def_struct_ui_text(srna, "UI List Item", "User interface list."); + + prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "UILayout"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, "rna_UIListItem_layout_get", NULL, NULL); + + prop= RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "AnyType"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, "rna_UIListItem_data_get", NULL, NULL); } static void rna_def_panel(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 404befc9bb2..e89e633acbe 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -86,6 +86,12 @@ void RNA_api_ui_layout(StructRNA *srna) {'v', "VECTOR", 0, "Vector", ""}, {'c', "COLOR", 0, "Color", ""}, {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem list_type_items[] = { + {0, "DEFAULT", 0, "None", ""}, + {'c', "COMPACT", 0, "Compact", ""}, + {'i', "ICONS", 0, "Icons", ""}, + {0, NULL, 0, NULL, NULL}}; /* simple layout specifiers */ func= RNA_def_function(srna, "row", "uiLayoutRow"); @@ -258,14 +264,14 @@ void RNA_api_ui_layout(StructRNA *srna) RNA_def_property_flag(parm, PROP_REQUIRED); func= RNA_def_function(srna, "template_list", "uiTemplateList"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); api_ui_item_rna_common(func); parm= RNA_def_pointer(func, "active_data", "AnyType", "", "Data from which to take property for the active element."); RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR); parm= RNA_def_string(func, "active_property", "", 0, "", "Identifier of property in data, for the active element."); RNA_def_property_flag(parm, PROP_REQUIRED); parm= RNA_def_int(func, "rows", 5, 0, INT_MAX, "", "Number of rows to display.", 0, INT_MAX); - parm= RNA_def_int(func, "columns", 5, 0, INT_MAX, "", "Number of columns to display.", 0, INT_MAX); - parm= RNA_def_boolean(func, "compact", 0, "", "Use compact, single row list template."); + parm= RNA_def_enum(func, "type", list_type_items, 0, "Type", "Type of list to use."); parm= RNA_def_collection(func, "items", 0, "", "Items visible in the list."); RNA_def_function_return(func, parm); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 5235883e408..f9aa27fcdbd 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -410,6 +410,12 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Scroll Widget Colors", ""); RNA_def_property_update(prop, NC_WINDOW, NULL); + prop= RNA_def_property(srna, "wcol_list_item", PROP_POINTER, PROP_NEVER_NULL); + RNA_def_property_pointer_sdna(prop, NULL, "wcol_list_item"); + RNA_def_property_struct_type(prop, "ThemeWidgetColors"); + RNA_def_property_ui_text(prop, "List Item Colors", ""); + RNA_def_property_update(prop, NC_WINDOW, NULL); + prop= RNA_def_property(srna, "wcol_state", PROP_POINTER, PROP_NEVER_NULL); RNA_def_property_pointer_sdna(prop, NULL, "wcol_state"); RNA_def_property_struct_type(prop, "ThemeWidgetStateColors"); |