[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26507] trunk/blender/source/blender/ editors/interface: Fix #20502: add constraint (with targets) menu has no last used memory.

Brecht Van Lommel brecht at blender.org
Mon Feb 1 12:13:55 CET 2010


Revision: 26507
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26507
Author:   blendix
Date:     2010-02-01 12:13:55 +0100 (Mon, 01 Feb 2010)

Log Message:
-----------
Fix #20502: add constraint (with targets) menu has no last used memory.

The last click button memory can now deal with menus with varying amounts
of menu entries and multi column layouts.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_regions.c

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2010-02-01 10:51:34 UTC (rev 26506)
+++ trunk/blender/source/blender/editors/interface/interface.c	2010-02-01 11:13:55 UTC (rev 26507)
@@ -344,8 +344,8 @@
 static void ui_popup_bounds_block(const bContext *C, uiBlock *block, int bounds_calc)
 {
 	wmWindow *window= CTX_wm_window(C);
-	int startx, starty, endx, endy, width, height;
-	int oldbounds, mx, my, xmax, ymax;
+	int startx, starty, endx, endy, width, height, oldwidth, oldheight;
+	int oldbounds, xmax, ymax;
 
 	oldbounds= block->bounds;
 
@@ -354,9 +354,9 @@
 	
 	wm_window_get_size(window, &xmax, &ymax);
 
-	mx= window->eventstate->x + block->minx + block->mx;
-	my= window->eventstate->y + block->miny + block->my;
-	
+	oldwidth= block->maxx - block->minx;
+	oldheight= block->maxy - block->miny;
+
 	/* first we ensure wide enough text bounds */
 	if(bounds_calc==UI_BLOCK_BOUNDS_POPUP_MENU) {
 		if(block->flag & UI_BLOCK_LOOP) {
@@ -373,8 +373,10 @@
 	width= block->maxx - block->minx;
 	height= block->maxy - block->miny;
 
-	startx= mx-(0.8*(width));
-	starty= my;
+	/* offset block based on mouse position, user offset is scaled
+	   along in case we resized the block in ui_text_bounds_block */
+	startx= window->eventstate->x + block->minx + (block->mx*width)/oldwidth;
+	starty= window->eventstate->y + block->miny + (block->my*height)/oldheight;
 	
 	if(startx<10)
 		startx= 10;

Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c	2010-02-01 10:51:34 UTC (rev 26506)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c	2010-02-01 11:13:55 UTC (rev 26507)
@@ -1875,6 +1875,19 @@
 
 /************************ Popup Menu Memory ****************************/
 
+static int ui_popup_string_hash(char *str)
+{
+	/* sometimes button contains hotkey, sometimes not, strip for proper compare */
+	int hash;
+	char *delimit= strchr(str, '|');
+
+	if(delimit) *delimit= 0;
+	hash= BLI_ghashutil_strhash(str);
+	if(delimit) *delimit= '|';
+
+	return hash;
+}
+
 static int ui_popup_menu_hash(char *str)
 {
 	return BLI_ghashutil_strhash(str);
@@ -1883,7 +1896,7 @@
 /* but == NULL read, otherwise set */
 uiBut *ui_popup_menu_memory(uiBlock *block, uiBut *but)
 {
-	static char mem[256], first=1;
+	static int mem[256], first=1;
 	int hash= block->puphash;
 	
 	if(first) {
@@ -1894,12 +1907,16 @@
 
 	if(but) {
 		/* set */
-		mem[hash & 255 ]= BLI_findindex(&block->buttons, but);
+		mem[hash & 255 ]= ui_popup_string_hash(but->str);
 		return NULL;
 	}
 	else {
 		/* get */
-		return BLI_findlink(&block->buttons, mem[hash & 255]);
+		for(but=block->buttons.first; but; but=but->next)
+			if(ui_popup_string_hash(but->str) == mem[hash & 255])
+				return but;
+
+		return NULL;
 	}
 }
 
@@ -1924,7 +1941,7 @@
 	ScrArea *sa;
 	ARegion *ar;
 	uiPopupMenu *pup= arg_pup;
-	int offset, direction, minwidth, flip;
+	int offset[2], direction, minwidth, width, height, flip;
 
 	if(pup->menu_func) {
 		pup->block->handle= handle;
@@ -1960,7 +1977,7 @@
 
 	block->direction= direction;
 
-	uiBlockLayoutResolve(block, NULL, NULL);
+	uiBlockLayoutResolve(block, &width, &height);
 
 	uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT);
 	
@@ -1969,17 +1986,27 @@
 		uiBlockSetDirection(block, direction);
 
 		/* offset the mouse position, possibly based on earlier selection */
-		offset= 1.5*MENU_BUTTON_HEIGHT;
+		if((block->flag & UI_BLOCK_POPUP_MEMORY) &&
+			(bt= ui_popup_menu_memory(block, NULL))) {
+			/* position mouse on last clicked item, at 0.8*width of the
+			   button, so it doesn't overlap the text too much, also note
+			   the offset is negative because we are inverse moving the
+			   block to be under the mouse */
+			offset[0]= -(bt->x1 + 0.8f*(bt->x2 - bt->x1));
+			offset[1]= -(bt->y1 + 0.5f*MENU_BUTTON_HEIGHT);
+		}
+		else {
+			/* position mouse at 0.8*width of the button and below the tile
+			   on the first item */
+			offset[0]= 0;
+			for(bt=block->buttons.first; bt; bt=bt->next)
+				offset[0]= MIN2(offset[0], -(bt->x1 + 0.8f*(bt->x2 - bt->x1)));
 
-		if(block->flag & UI_BLOCK_POPUP_MEMORY) {
-			bt= ui_popup_menu_memory(block, NULL);
-
-			if(bt)
-				offset= -bt->y1 - 0.5f*MENU_BUTTON_HEIGHT;
+			offset[1]= 1.5*MENU_BUTTON_HEIGHT;
 		}
 
 		block->minbounds= minwidth;
-		uiMenuPopupBoundsBlock(block, 1, 20, offset);
+		uiMenuPopupBoundsBlock(block, 1, offset[0], offset[1]);
 	}
 	else {
 		/* for a header menu we set the direction automatic */





More information about the Bf-blender-cvs mailing list