diff options
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r-- | source/blender/editors/interface/interface.c | 135 |
1 files changed, 73 insertions, 62 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index fd082c34238..57f45059865 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -502,10 +502,10 @@ void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block) return; for(but=block->buttons.first; but; but=but->next) { - if(but->opname) { + if(but->optype) { prop= (but->opptr)? but->opptr->data: NULL; - if(WM_key_event_operator_string(C, but->opname, but->opcontext, prop, buf, sizeof(buf))) { + if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) { butstr= MEM_mallocN(strlen(but->str)+strlen(buf)+2, "menu_block_set_keymaps"); strcpy(butstr, but->str); strcat(butstr, "|"); @@ -535,8 +535,8 @@ void uiEndBlock(const bContext *C, uiBlock *block) ui_check_but(but); /* temp? Proper check for greying out */ - if(but->opname) { - wmOperatorType *ot= WM_operatortype_find(but->opname); + if(but->optype) { + wmOperatorType *ot= but->optype; if(ot==NULL || (ot->poll && ot->poll((bContext *)C)==0)) { but->flag |= UI_BUT_DISABLED; but->lock = 1; @@ -559,6 +559,8 @@ void uiEndBlock(const bContext *C, uiBlock *block) } /* handle pending stuff */ + if(block->layout) uiBlockLayoutResolve(C, block, NULL, NULL); + ui_block_do_align(block); if(block->flag & UI_BLOCK_LOOP) ui_menu_block_set_keymaps(C, block); /* after keymaps! */ @@ -598,7 +600,7 @@ static void ui_but_to_pixelrect(rcti *rect, const ARegion *ar, uiBlock *block, u getsizex= ar->winx; getsizey= ar->winy; - + gx= (but?but->x1:block->minx) + (block->panel?block->panel->ofsx:0.0f); gy= (but?but->y1:block->miny) + (block->panel?block->panel->ofsy:0.0f); @@ -1716,21 +1718,18 @@ void uiFreeInactiveBlocks(const bContext *C, ListBase *lb) } } -uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, short dt) +void uiBlockSetRegion(uiBlock *block, ARegion *region) { ListBase *lb; - uiBlock *block, *oldblock= NULL; - wmWindow *window; - int getsizex, getsizey; + uiBlock *oldblock= NULL; - window= CTX_wm_window(C); lb= ®ion->uiblocks; /* each listbase only has one block with this name, free block * if is already there so it can be rebuilt from scratch */ if(lb) { for (oldblock= lb->first; oldblock; oldblock= oldblock->next) - if (BLI_streq(oldblock->name, name)) + if (BLI_streq(oldblock->name, block->name)) break; if (oldblock) { @@ -1738,20 +1737,32 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, shor oldblock->panel= NULL; } } - - block= MEM_callocN(sizeof(uiBlock), "uiBlock"); + block->oldblock= oldblock; - block->active= 1; - block->dt= dt; /* at the beginning of the list! for dynamical menus/blocks */ if(lb) BLI_addhead(lb, block); +} + +uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, short dt) +{ + uiBlock *block; + wmWindow *window; + int getsizex, getsizey; + window= CTX_wm_window(C); + + block= MEM_callocN(sizeof(uiBlock), "uiBlock"); + block->active= 1; + block->dt= dt; BLI_strncpy(block->name, name, sizeof(block->name)); + if(region) + uiBlockSetRegion(block, region); + /* window matrix and aspect */ - if(region->swinid) { + if(region && region->swinid) { wm_subwindow_getmatrix(window, region->swinid, block->winmat); wm_subwindow_getsize(window, region->swinid, &getsizex, &getsizey); @@ -1952,7 +1963,9 @@ void uiBlockBeginAlign(uiBlock *block) if(block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block); block->flag |= UI_BUT_ALIGN_DOWN; - /* buttons declared after this call will this align flag */ + block->alignnr++; + + /* buttons declared after this call will get this align nr */ // XXX flag? } static int buts_are_horiz(uiBut *but1, uiBut *but2) @@ -1968,36 +1981,33 @@ static int buts_are_horiz(uiBut *but1, uiBut *but2) void uiBlockEndAlign(uiBlock *block) { + block->flag &= ~UI_BUT_ALIGN; // all 4 flags +} + +static void ui_block_do_align_but(uiBlock *block, uiBut *first, int nr) +{ uiBut *prev, *but=NULL, *next; int flag= 0, cols=0, rows=0; - /* auto align: - - go back to first button of align start (ALIGN_DOWN) - - compare triples, and define flags - */ - prev= block->buttons.last; - while(prev) { - if( (prev->flag & UI_BUT_ALIGN_DOWN)) but= prev; - else break; - - if(but && but->next) { + /* auto align */ + + for(but=first; but && but->alignnr == nr; but=but->next) { + if(but->next && but->next->alignnr == nr) { if(buts_are_horiz(but, but->next)) cols++; else rows++; } - - prev= prev->prev; } - if(but==NULL) return; - + /* rows==0: 1 row, cols==0: 1 collumn */ /* note; how it uses 'flag' in loop below (either set it, or OR it) is confusing */ - prev= NULL; - while(but) { + for(but=first, prev=NULL; but && but->alignnr == nr; prev=but, but=but->next) { next= but->next; - + if(next && next->alignnr != nr) + next= NULL; + /* clear old flag */ - but->flag &= ~UI_BUT_ALIGN_DOWN; + but->flag &= ~UI_BUT_ALIGN; if(flag==0) { /* first case */ if(next) { @@ -2030,11 +2040,11 @@ void uiBlockEndAlign(uiBlock *block) /* exception case: bottom row */ if(rows>0) { uiBut *bt= but; - while(bt) { - if(bt->next && buts_are_horiz(bt, bt->next)==0 ) break; + while(bt && bt->alignnr == nr) { + if(bt->next && bt->next->alignnr == nr && buts_are_horiz(bt, bt->next)==0 ) break; bt= bt->next; } - if(bt==0) flag= UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT; + if(bt==0 || bt->alignnr != nr) flag= UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT; } } else flag |= UI_BUT_ALIGN_LEFT; @@ -2086,35 +2096,30 @@ void uiBlockEndAlign(uiBlock *block) } } } - - prev= but; - but= next; } - - block->flag &= ~UI_BUT_ALIGN; // all 4 flags } -#if 0 -static void uiBlockEndAligno(uiBlock *block) +void ui_block_do_align(uiBlock *block) { uiBut *but; - - /* correct last defined button */ - but= block->buttons.last; - if(but) { - /* vertical align case */ - if( (block->flag & UI_BUT_ALIGN) == (UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_DOWN) ) { - but->flag &= ~UI_BUT_ALIGN_DOWN; - } - /* horizontal align case */ - if( (block->flag & UI_BUT_ALIGN) == (UI_BUT_ALIGN_LEFT|UI_BUT_ALIGN_RIGHT) ) { - but->flag &= ~UI_BUT_ALIGN_RIGHT; + int nr; + + /* align buttons with same align nr */ + for(but=block->buttons.first; but;) { + if(but->alignnr) { + nr= but->alignnr; + ui_block_do_align_but(block, but, nr); + + /* skip with same number */ + for(; but && but->alignnr == nr; but=but->next); + + if(!but) + break; } - /* else do nothing, manually provided flags */ + else + but= but->next; } - block->flag &= ~UI_BUT_ALIGN; // all 4 flags } -#endif /* ui_def_but is the function that draws many button types @@ -2171,6 +2176,9 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, char *str, short but->aspect= 1.0f; //XXX block->aspect; but->block= block; // pointer back, used for frontbuffer status, and picker + if(block->flag & UI_BUT_ALIGN) + but->alignnr= block->alignnr; + but->func= block->func; but->func_arg1= block->func_arg1; but->func_arg2= block->func_arg2; @@ -2217,6 +2225,9 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, char *str, short } else BLI_addtail(&block->buttons, but); + + if(block->curlayout) + ui_layout_add_but(block->curlayout, but); return but; } @@ -2374,7 +2385,7 @@ uiBut *ui_def_but_operator(uiBlock *block, int type, char *opname, int opcontext } but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, NULL, 0, 0, 0, 0, tip); - but->opname= opname; + but->optype= ot; but->opcontext= opcontext; if(!ot) { @@ -2894,9 +2905,9 @@ int uiButGetRetVal(uiBut *but) PointerRNA *uiButGetOperatorPtrRNA(uiBut *but) { - if(but->opname && !but->opptr) { + if(but->optype && !but->opptr) { but->opptr= MEM_callocN(sizeof(PointerRNA), "uiButOpPtr"); - WM_operator_properties_create(but->opptr, but->opname); + WM_operator_properties_create(but->opptr, but->optype->idname); } return but->opptr; |