diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-02-04 14:52:16 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-02-04 14:52:16 +0300 |
commit | df7e7660325611847721768fb7d082e7d5f2736c (patch) | |
tree | a13434a5824a3f55c46f6d876275f864647c0f95 /source/blender/editors/interface/interface_regions.c | |
parent | 0341e762b28f732dd2913ebec48405f7718a4617 (diff) |
UI
* Changed uiPupMenuOperator usage to uiPupMenuBegin/End (simpler,
no need to build a string). Also made transform orientation and
subdiv type enums instead of ints for this.
* Added an icon argument to many of the uiMenu calls, and added a
uiMenuItemIntO.
* Move auto rna button creation out of outliner code, now is
uiDefAutoButR for individual buttons and uiDefAutoButsRNA for a
whole block.
* Implemented uiPupBlock(O). Pressing F6 gives a menu with the
properties of the last operator to test. I tried to make a redo
last operator out of this but couldn't get the context correct
for the operator to repeat in. Further the popup block also has
some issues getting closed while editing buttons.
* Fix uiAfterFunc memory leak on Ctrl+Q quit.
* Fix handling of RNA number button dragging and sliding for RNA
buttons with range -inf/inf.
Diffstat (limited to 'source/blender/editors/interface/interface_regions.c')
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 113 |
1 files changed, 64 insertions, 49 deletions
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 09bbbb9ea60..ffd742098de 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1657,13 +1657,14 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, #define MENU_ITEM_OPNAME 2 #define MENU_ITEM_OPNAME_BOOL 3 #define MENU_ITEM_OPNAME_ENUM 4 -#define MENU_ITEM_OPNAME_FLOAT 5 -#define MENU_ITEM_RNA_BOOL 6 -#define MENU_ITEM_RNA_ENUM 7 -#define MENU_ITEM_LEVEL 8 -#define MENU_ITEM_LEVEL_OPNAME_ENUM 9 -#define MENU_ITEM_LEVEL_RNA_ENUM 10 -#define MENU_ITEM_SEPARATOR 11 +#define MENU_ITEM_OPNAME_INT 5 +#define MENU_ITEM_OPNAME_FLOAT 6 +#define MENU_ITEM_RNA_BOOL 7 +#define MENU_ITEM_RNA_ENUM 8 +#define MENU_ITEM_LEVEL 9 +#define MENU_ITEM_LEVEL_OPNAME_ENUM 10 +#define MENU_ITEM_LEVEL_RNA_ENUM 11 +#define MENU_ITEM_SEPARATOR 12 struct uiMenuItem { struct uiMenuItem *next, *prev; @@ -1675,7 +1676,7 @@ struct uiMenuItem { char *opname; /* static string */ char *propname; /* static string */ - int retval, enumval, boolval; + int retval, enumval, boolval, intval; float fltval; int opcontext; uiMenuHandleFunc eventfunc; @@ -1762,15 +1763,15 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, block->themecol= TH_MENU_ITEM; block->direction= UI_DOWN; - width= 50; // fixed with, uiPopupBoundsBlock will compute actual width + width= 50; // fixed with, uiMenuPopupBoundsBlock will compute actual width for(item= head->items.first; item; item= item->next) { if(0) height+= PUP_LABELH; // XXX sepr line else height+= MENU_BUTTON_HEIGHT; } - startx= info->mx; - starty= info->my-height+MENU_BUTTON_HEIGHT/2; + startx= 0; + starty= 0; /* here we go! */ if(head->name[0]) { @@ -1836,6 +1837,12 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, y1 -= MENU_BUTTON_HEIGHT; } + else if(item->type==MENU_ITEM_OPNAME_INT) { + but= uiDefIconTextButO(block, BUTM, item->opname, head->opcontext, item->icon, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, ""); + RNA_int_set(uiButGetOperatorPtrRNA(but), item->propname, item->intval); + + y1 -= MENU_BUTTON_HEIGHT; + } else if(item->type==MENU_ITEM_OPNAME_FLOAT) { but= uiDefIconTextButO(block, BUTM, item->opname, item->opcontext, item->icon, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, ""); RNA_float_set(uiButGetOperatorPtrRNA(but), item->propname, item->fltval); @@ -1890,7 +1897,8 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT|UI_BLOCK_RET_1); uiBlockSetDirection(block, UI_DOWN); - uiPopupBoundsBlock(block, 1); + /* here we set an offset for the mouse position */ + uiMenuPopupBoundsBlock(block, 1, 0, -height+MENU_BUTTON_HEIGHT/2); } else { /* for a header menu we set the direction automatic */ @@ -1985,18 +1993,18 @@ void uiMenuItemVal(uiMenuItem *head, const char *name, int icon, int argval) } /* regular operator item */ -void uiMenuItemO(uiMenuItem *head, char *name, int icon) +void uiMenuItemO(uiMenuItem *head, int icon, char *opname) { - uiMenuItem *item= ui_menu_add_item(head, name, icon, 0); + uiMenuItem *item= ui_menu_add_item(head, "", icon, 0); - item->opname= name; // static! + item->opname= opname; // static! item->type = MENU_ITEM_OPNAME; } /* single operator item with property */ -void uiMenuItemEnumO(uiMenuItem *head, char *opname, char *propname, int value) +void uiMenuItemEnumO(uiMenuItem *head, int icon, char *opname, char *propname, int value) { - uiMenuItem *item= ui_menu_add_item(head, "", 0, 0); + uiMenuItem *item= ui_menu_add_item(head, "", icon, 0); item->opname= opname; // static! item->propname= propname; // static! @@ -2005,9 +2013,20 @@ void uiMenuItemEnumO(uiMenuItem *head, char *opname, char *propname, int value) } /* single operator item with property */ -void uiMenuItemFloatO(uiMenuItem *head, const char *name, char *opname, char *propname, float value) +void uiMenuItemIntO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, int value) { - uiMenuItem *item= ui_menu_add_item(head, name, 0, 0); + uiMenuItem *item= ui_menu_add_item(head, name, icon, 0); + + item->opname= opname; // static! + item->propname= propname; // static! + item->intval= value; + item->type = MENU_ITEM_OPNAME_INT; +} + +/* single operator item with property */ +void uiMenuItemFloatO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, float value) +{ + uiMenuItem *item= ui_menu_add_item(head, name, icon, 0); item->opname= opname; // static! item->propname= propname; // static! @@ -2016,9 +2035,9 @@ void uiMenuItemFloatO(uiMenuItem *head, const char *name, char *opname, char *pr } /* single operator item with property */ -void uiMenuItemBooleanO(uiMenuItem *head, char *opname, char *propname, int value) +void uiMenuItemBooleanO(uiMenuItem *head, int icon, char *opname, char *propname, int value) { - uiMenuItem *item= ui_menu_add_item(head, "", 0, 0); + uiMenuItem *item= ui_menu_add_item(head, "", icon, 0); item->opname= opname; // static! item->propname= propname; // static! @@ -2046,7 +2065,7 @@ void uiMenuItemsEnumO(uiMenuItem *head, char *opname, char *propname) RNA_property_enum_items(&ptr, prop, &item, &totitem); for (i=0; i<totitem; i++) - uiMenuItemEnumO(head, opname, propname, item[i].value); + uiMenuItemEnumO(head, 0, opname, propname, item[i].value); } } @@ -2142,12 +2161,13 @@ void uiMenuSeparator(uiMenuItem *head) /*************************** Popup Menu API **************************/ /* only return handler, and set optional title */ -uiMenuItem *uiPupMenuBegin(const char *title) +uiMenuItem *uiPupMenuBegin(const char *title, int icon) { uiMenuItem *item= MEM_callocN(sizeof(uiMenuItem), "menu start"); item->type = MENU_ITEM_TITLE; item->opcontext= WM_OP_EXEC_REGION_WIN; + item->icon= icon; /* NULL is no title */ if(title) @@ -2179,32 +2199,6 @@ void uiPupMenuEnd(bContext *C, uiMenuItem *head) MEM_freeN(head); } -/* This one will set enum propname, call operator and register it, and free the operator itself, - call it in op->invoke with returning OPERATOR_RUNNING_MODAL */ -/* Note: propname has to be static */ -void uiPupMenuOperator(bContext *C, int maxrow, wmOperator *op, const char *propname, char *str) -{ - wmWindow *window= CTX_wm_window(C); - uiPupMenuInfo info; - uiPopupBlockHandle *menu; - - memset(&info, 0, sizeof(info)); - info.mx= window->eventstate->x; - info.my= window->eventstate->y; - info.maxrow= maxrow; - info.instr= str; - - menu= ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PUPMENU, &info); - menu->popup= 1; - - UI_add_popup_handlers(&window->handlers, menu); - WM_event_add_mousemove(C); - - menu->op_arg= op; - menu->propname= propname; -} - - /* this one only to be called with operatortype name option */ void uiPupMenu(bContext *C, int maxrow, uiMenuHandleFunc func, void *arg, char *str, ...) { @@ -2339,3 +2333,24 @@ void uiPupMenuReports(bContext *C, ReportList *reports) BLI_dynstr_free(ds); } +/*************************** Popup Block API **************************/ + +void uiPupBlockO(bContext *C, uiBlockCreateFunc func, void *arg, char *opname, int opcontext) +{ + wmWindow *window= CTX_wm_window(C); + uiPopupBlockHandle *handle; + + handle= ui_popup_block_create(C, NULL, NULL, func, NULL, arg); + handle->popup= 1; + handle->opname= opname; + handle->opcontext= opcontext; + + UI_add_popup_handlers(&window->handlers, handle); + WM_event_add_mousemove(C); +} + +void uiPupBlock(bContext *C, uiBlockCreateFunc func, void *arg) +{ + uiPupBlockO(C, func, arg, NULL, 0); +} + |