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:
authorTon Roosendaal <ton@blender.org>2004-10-01 11:51:12 +0400
committerTon Roosendaal <ton@blender.org>2004-10-01 11:51:12 +0400
commit19c2d34967fa64d5200e5ff381d198d12a3ba125 (patch)
tree4a91c8822c4add271f0a83572ac6cc10fcbd57f9 /source/blender/src/interface.c
parent820a83dda835c172a59c1ee474dc7a1205f36151 (diff)
- Improved memory system for pupmenu(), which now stores 255 entries max.
Meaning menus come back to previous selection almost always. Also fixed annoying bug that caused Mirror menu (M in editmode) to start at 2nd item - New hotkey (test :) CTRL+TAB in editmode gives (and shows!) current selectmode. I prefer this over cycling, since the menu is informing you what happens. - To enforce pupmenus to start at specific item, use pupmenu_set_active() - pupmenu_col() to be done
Diffstat (limited to 'source/blender/src/interface.c')
-rw-r--r--source/blender/src/interface.c81
1 files changed, 62 insertions, 19 deletions
diff --git a/source/blender/src/interface.c b/source/blender/src/interface.c
index 8926ba20185..635df026e11 100644
--- a/source/blender/src/interface.c
+++ b/source/blender/src/interface.c
@@ -4557,15 +4557,42 @@ void uiDefKeyevtButS(uiBlock *block, int retval, char *str, short x1, short y1,
/* ******************** PUPmenu ****************** */
+static int pupmenu_set= 0;
+
+void pupmenu_set_active(int val)
+{
+ pupmenu_set= val;
+}
+
+/* value== -1 read, otherwise set */
+static int pupmenu_memory(char *str, int value)
+{
+ static char mem[256], first=1;
+ int val=0, nr=0;
+
+ if(first) {
+ memset(mem, 0, 256);
+ first= 0;
+ }
+ while(str[nr]) {
+ val+= str[nr];
+ nr++;
+ }
+
+ if(value >= 0) mem[ val & 255 ]= value;
+ else return mem[ val & 255 ];
+
+ return 0;
+}
+
+#define PUP_LABELH 6
short pupmenu(char *instr)
{
uiBlock *block;
ListBase listb= {NULL, NULL};
int event;
- static int lastselected= 0;
- short width, height=0, mousexmove = 0, mouseymove, xmax, ymax, mval[2], val= -1;
+ short lastselected, width, height=0, mousexmove = 0, mouseymove, xmax, ymax, mval[2], val= -1;
short a, startx, starty, endx, endy, boxh=TBOXH, x1, y1;
- static char laststring[UI_MAX_NAME_STR];
MenuData *md;
/* block stuff first, need to know the font */
@@ -4584,7 +4611,7 @@ short pupmenu(char *instr)
xmax= BIF_GetStringWidth(uiBlockGetCurFont(block), md->items[a].str, (U.transopts && USER_TR_BUTTONS));
if(xmax>width) width= xmax;
- if( strcmp(name, "%l")==0) height+= 6;
+ if( strcmp(name, "%l")==0) height+= PUP_LABELH;
else height+= boxh;
}
@@ -4595,14 +4622,27 @@ short pupmenu(char *instr)
getmouseco_sc(mval);
- if(strncmp(laststring, instr, UI_MAX_NAME_STR-1)!=0) lastselected= 0;
- BLI_strncpy(laststring, instr, UI_MAX_NAME_STR);
-
+ /* set first item */
+ lastselected= 0;
+ if(pupmenu_set) {
+ lastselected= pupmenu_set-1;
+ pupmenu_set= 0;
+ }
+ else if(md->nitems>1) {
+ lastselected= pupmenu_memory(instr, -1);
+ }
+
startx= mval[0]-(0.8*(width));
+ starty= mval[1]-height+boxh/2;
if(lastselected>=0 && lastselected<md->nitems) {
- starty= mval[1]-height+boxh/2+lastselected*boxh;
+ for(a=0; a<md->nitems; a++) {
+ if(a==lastselected) break;
+ if( strcmp(md->items[a].str, "%l")==0) starty+= PUP_LABELH;
+ else starty+=boxh;
+ }
+
+ //starty= mval[1]-height+boxh/2+lastselected*boxh;
}
- else starty= mval[1]-height/2;
mouseymove= 0;
@@ -4635,20 +4675,20 @@ short pupmenu(char *instr)
if(md->title) {
uiBut *bt;
uiSetCurFont(block, UI_HELVB);
- bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+md->nitems*boxh), width, boxh, NULL, 0.0, 0.0, 0, 0, "");
+ bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+height), width, boxh, NULL, 0.0, 0.0, 0, 0, "");
bt->flag= UI_TEXT_LEFT;
uiSetCurFont(block, UI_HELV);
}
- y1= starty + boxh*(md->nitems-1);
+ y1= starty + height - boxh;
x1= startx;
for(a=0; a<md->nitems; a++) {
char *name= md->items[a].str;
if( strcmp(name, "%l")==0) {
- uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, 6, NULL, 0, 0.0, 0, 0, "");
- y1 -= 6;
+ uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
+ y1 -= PUP_LABELH;
}
else {
uiDefButS(block, BUTM, B_NOP, name, x1, y1, width, boxh-1, &val, (float) md->items[a].retval, 0.0, 0, 0, "");
@@ -4661,11 +4701,14 @@ short pupmenu(char *instr)
event= uiDoBlocks(&listb, 0);
/* calculate last selected */
- lastselected= 0;
- for(a=0; a<md->nitems; a++) {
- if(val==md->items[a].retval) lastselected= a;
+ if(event & UI_RETURN_OK) {
+ lastselected= 0;
+ for(a=0; a<md->nitems; a++) {
+ if(val==md->items[a].retval) lastselected= a;
+ }
+
+ pupmenu_memory(instr, lastselected);
}
-
menudata_free(md);
if(mouseymove && (event & UI_RETURN_OUT)==0) ui_warp_pointer(mousexmove, mouseymove);
@@ -4786,8 +4829,8 @@ short pupmenu_col(char *instr, int maxrow)
y1= starty - boxh*(a%rows) + (rows-1)*boxh;
if( strcmp(name, "%l")==0){
- uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, 6, NULL, 0, 0.0, 0, 0, "");
- y1 -= 6;
+ uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
+ y1 -= PUP_LABELH;
}
else {
uiDefButI(block, BUTM, B_NOP, name, x1, y1, width, boxh-1, &val, (float) md->items[a].retval, 0.0, 0, 0, "");