Revision: 20583 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20583 Author: ton Date: 2009-06-02 20:10:06 +0200 (Tue, 02 Jun 2009)
Log Message: ----------- 2.5 Part one of new text button type: SEARCH_MENU This opens a popup showing all matches for a typed string, nice for object names, materials, operators, and so on. Warning: Currently menu doesn't function yet! Only draws choices. As test I've added an operator search button in top bar. It only shows operators that can be used in this context now. Also that is part of the WIP, tomorrow more fun :) Modified Paths: -------------- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h branches/blender2.5/blender/source/blender/editors/interface/interface.c branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c branches/blender2.5/blender/source/blender/editors/interface/interface_style.c branches/blender2.5/blender/source/blender/editors/interface/interface_widgets.c branches/blender2.5/blender/source/blender/editors/screen/screen_ops.c branches/blender2.5/blender/source/blender/editors/space_info/info_header.c Modified: branches/blender2.5/blender/source/blender/editors/include/UI_interface.h =================================================================== --- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h 2009-06-02 17:05:19 UTC (rev 20582) +++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h 2009-06-02 18:10:06 UTC (rev 20583) @@ -177,20 +177,21 @@ #define INLINK (23<<9) #define KEYEVT (24<<9) #define ICONTEXTROW (25<<9) -#define HSVCUBE (26<<9) -#define PULLDOWN (27<<9) -#define ROUNDBOX (28<<9) -#define CHARTAB (29<<9) +#define HSVCUBE (26<<9) +#define PULLDOWN (27<<9) +#define ROUNDBOX (28<<9) +#define CHARTAB (29<<9) #define BUT_COLORBAND (30<<9) -#define BUT_NORMAL (31<<9) -#define BUT_CURVE (32<<9) +#define BUT_NORMAL (31<<9) +#define BUT_CURVE (32<<9) #define BUT_TOGDUAL (33<<9) -#define ICONTOGN (34<<9) -#define FTPREVIEW (35<<9) -#define NUMABS (36<<9) -#define TOGBUT (37<<9) -#define OPTION (38<<9) -#define OPTIONN (39<<9) +#define ICONTOGN (34<<9) +#define FTPREVIEW (35<<9) +#define NUMABS (36<<9) +#define TOGBUT (37<<9) +#define OPTION (38<<9) +#define OPTIONN (39<<9) +#define SEARCH_MENU (40<<9) #define BUTTYPE (63<<9) /* Drawing @@ -401,6 +402,8 @@ void uiDefKeyevtButS(uiBlock *block, int retval, char *str, short x1, short y1, short x2, short y2, short *spoin, char *tip); +uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxlen, short x1, short y1, short x2, short y2, char *tip); + void uiBlockPickerButtons(struct uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval); void uiBlockColorbandButtons(struct uiBlock *block, struct ColorBand *coba, struct rctf *butr, int event); @@ -425,16 +428,29 @@ * * uiButSetCompleteFunc is for tab completion. * + * uiButSearchFunc is for name buttons, showing a popup with matches + * * uiBlockSetFunc and uiButSetFunc are callbacks run when a button is used, * in case events, operators or RNA are not sufficient to handle the button. * * uiButSetNFunc will free the argument with MEM_freeN. */ +typedef struct uiSearchItems { + int maxitem, totitem, maxstrlen; + + char **names; + void **pointers; + +} uiSearchItems; + + typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2); typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2); typedef void (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg); +typedef void (*uiButSearchFunc)(const struct bContext *C, void *arg, char *str, uiSearchItems *items); typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event); + void uiBlockSetHandleFunc(uiBlock *block, uiBlockHandleFunc func, void *arg); void uiBlockSetButmFunc (uiBlock *block, uiMenuHandleFunc func, void *arg); @@ -443,6 +459,7 @@ void uiButSetNFunc (uiBut *but, uiButHandleNFunc func, void *argN, void *arg2); void uiButSetCompleteFunc(uiBut *but, uiButCompleteFunc func, void *arg); +void uiButSetSearchFunc (uiBut *but, uiButSearchFunc func, void *arg); void uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(struct bContext *C, uiBlock *block)); Modified: branches/blender2.5/blender/source/blender/editors/interface/interface.c =================================================================== --- branches/blender2.5/blender/source/blender/editors/interface/interface.c 2009-06-02 17:05:19 UTC (rev 20582) +++ branches/blender2.5/blender/source/blender/editors/interface/interface.c 2009-06-02 18:10:06 UTC (rev 20583) @@ -1359,7 +1359,7 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen) { - if(but->rnaprop && ELEM(but->type, TEX, IDPOIN)) { + if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) { PropertyType type; char *buf= NULL; @@ -1402,6 +1402,11 @@ BLI_strncpy(str, but->poin, maxlen); return; } + else if(but->type == SEARCH_MENU) { + /* string */ + BLI_strncpy(str, but->poin, maxlen); + return; + } else { /* number */ double value; @@ -1491,7 +1496,7 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str) { - if(but->rnaprop && ELEM(but->type, TEX, IDPOIN)) { + if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) { if(RNA_property_editable(&but->rnapoin, but->rnaprop)) { PropertyType type; @@ -1535,6 +1540,11 @@ BLI_strncpy(but->poin, str, but->hardmax); return 1; } + else if(but->type == SEARCH_MENU) { + /* string */ + BLI_strncpy(but->poin, str, but->hardmax); + return 1; + } else { double value; @@ -1817,11 +1827,11 @@ /* if something changed in the button */ double value; float okwidth; - int transopts= ui_translate_buttons(); +// int transopts= ui_translate_buttons(); ui_is_but_sel(but); - if(but->type==TEX || but->type==IDPOIN) transopts= 0; +// if(but->type==TEX || but->type==IDPOIN) transopts= 0; /* test for min and max, icon sliders, etc */ switch( but->type ) { @@ -1926,6 +1936,7 @@ case IDPOIN: case TEX: + case SEARCH_MENU: if(!but->editstr) { char str[UI_MAX_DRAW_STR]; @@ -3065,6 +3076,29 @@ ui_check_but(but); } +/* arg is pointer to string/name, use callbacks below to make this work */ +uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxlen, short x1, short y1, short x2, short y2, char *tip) +{ + uiBut *but= ui_def_but(block, SEARCH_MENU, retval, "", x1, y1, x2, y2, arg, 0.0, maxlen, 0.0, 0.0, tip); + + but->icon= (BIFIconID) icon; + but->flag|= UI_HAS_ICON; + + but->flag|= UI_ICON_LEFT|UI_TEXT_LEFT; + but->flag|= UI_ICON_SUBMENU; + + ui_check_but(but); + + return but; +} + +void uiButSetSearchFunc(uiBut *but, uiButSearchFunc func, void *arg) +{ + but->search_func= func; + but->search_arg= arg; +} + + /* Program Init/Exit */ void UI_init(void) Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c =================================================================== --- branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c 2009-06-02 17:05:19 UTC (rev 20582) +++ branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c 2009-06-02 18:10:06 UTC (rev 20583) @@ -127,6 +127,9 @@ /* menu open */ uiPopupBlockHandle *menu; int menuretval; + + /* search box */ + ARegion *searchbox; /* post activate */ uiButtonActivateType posttype; @@ -557,6 +560,7 @@ ui_apply_but_BUT(C, but, data); break; case TEX: + case SEARCH_MENU: ui_apply_but_TEX(C, but, data); break; case TOGBUT: @@ -1124,7 +1128,7 @@ return changed; } -static void ui_textedit_begin(uiBut *but, uiHandleButtonData *data) +static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) { if(data->str) { MEM_freeN(data->str); @@ -1146,14 +1150,24 @@ but->selsta= 0; but->selend= strlen(but->drawstr) - strlen(but->str); + /* optional searchbox */ + if(but->type==SEARCH_MENU) { + data->searchbox= ui_searchbox_create(C, data->region, but); + ui_searchbox_update(C, data->searchbox, but); + } + ui_check_but(but); } -static void ui_textedit_end(uiBut *but, uiHandleButtonData *data) +static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) { if(but) { but->editstr= 0; but->pos= -1; + + if(data->searchbox) + ui_searchbox_free(C, data->searchbox); + data->searchbox= NULL; } } @@ -1316,6 +1330,9 @@ if(changed) { if(data->interactive) ui_apply_button(C, block, but, data, 1); else ui_check_but(but); + + if(data->searchbox) + ui_searchbox_update(C, data->searchbox, but); } if(changed || (retval == WM_UI_HANDLER_BREAK)) @@ -2702,6 +2719,7 @@ break; case TEX: case IDPOIN: + case SEARCH_MENU: retval= ui_do_but_TEX(C, block, but, data, event); break; case MENU: @@ -2928,9 +2946,9 @@ /* text editing */ if(state == BUTTON_STATE_TEXT_EDITING && data->state != BUTTON_STATE_TEXT_SELECTING) - ui_textedit_begin(but, data); + ui_textedit_begin(C, but, data); else if(data->state == BUTTON_STATE_TEXT_EDITING && state != BUTTON_STATE_TEXT_SELECTING) - ui_textedit_end(but, data); + ui_textedit_end(C, but, data); /* number editing */ if(state == BUTTON_STATE_NUM_EDITING) Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h =================================================================== --- branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h 2009-06-02 17:05:19 UTC (rev 20582) +++ branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h 2009-06-02 18:10:06 UTC (rev 20583) @@ -176,6 +176,9 @@ uiButCompleteFunc autocomplete_func; void *autofunc_arg; + uiButSearchFunc search_func; + void *search_arg; + uiLink *link; char *tip, *lockstr; @@ -351,6 +354,10 @@ struct ARegion *ui_tooltip_create(struct bContext *C, struct ARegion *butregion, uiBut *but); void ui_tooltip_free(struct bContext *C, struct ARegion *ar); +ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBut *but); +void ui_searchbox_update(struct bContext *C, struct ARegion *ar, uiBut *but); +void ui_searchbox_free(struct bContext *C, struct ARegion *ar); + typedef uiBlock* (*uiBlockHandleCreateFunc)(struct bContext *C, struct uiPopupBlockHandle *handle, void *arg1); uiPopupBlockHandle *ui_popup_block_create(struct bContext *C, struct ARegion *butregion, uiBut *but, @@ -394,6 +401,8 @@ struct ThemeUI; void ui_widget_color_init(struct ThemeUI *tui); +void ui_draw_menu_item(struct uiFontStyle *fstyle, rcti *rect, char *name, int state); + /* interface_style.c */ void uiStyleInit(void); Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c =================================================================== --- branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c 2009-06-02 17:05:19 UTC (rev 20582) +++ branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c 2009-06-02 18:10:06 UTC (rev 20583) @@ -383,6 +383,182 @@ ui_remove_temporary_region(C, CTX_wm_screen(C), ar); } + +/************************* Creating Search Box **********************/ + + +typedef struct uiSearchboxData { + rcti bbox; + uiFontStyle fstyle; + uiSearchItems items; +} uiSearchboxData; + +#define SEARCH_ITEMS 10 + +/* ar is the search box itself */ +void ui_searchbox_update(bContext *C, ARegion *ar, uiBut *but) +{ + uiSearchboxData *data= ar->regiondata; + @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs