[Bf-committers] Select menu Alt+RMB in obj mode

Campbell Barton cbarton at metavr.com
Sun Oct 3 15:48:33 CEST 2004


Subject says it all. :)



-- 
Campbell J Barton

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241

-------------- next part --------------
Index: source/blender/src/editview.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/editview.c,v
retrieving revision 1.38
diff -u -r1.38 editview.c
--- source/blender/src/editview.c	1 Oct 2004 14:48:12 -0000	1.38
+++ source/blender/src/editview.c	3 Oct 2004 12:45:53 -0000
@@ -853,19 +853,34 @@
 	}
 }
 
+/* The max number of menu items in an object select menu */
+#define SEL_MENU_SIZE 22
+
 void mouse_select(void)
 {
 	Base *base, *startbase=NULL, *basact=NULL, *oldbasact=NULL;
+	
+	/* Vars for object selection menu */
+	Base  *baseList[SEL_MENU_SIZE]; /*baseList is used to store all possible bases to bring up a menu */
+	short baseCount = 0;
+	/* menuText should be the initial size of text (18 atm) + ( SEL_MENU_SIZE * 26)  
+	26 being the longest possible length for a menu item */
+	char menuText[512] = "Select Object%t"; 
+	char menuIndexChar[2];
+	/*end select menu */
+	
 	unsigned int buffer[MAXPICKBUF];
-	int temp, a, dist=100;
+	int temp, a, dist=1000;
 	short hits, mval[2];
 
+	
 	/* always start list from basact */
 	startbase=  FIRSTBASE;
 	if(BASACT && BASACT->next) startbase= BASACT->next;
 
 	getmouseco_areawin(mval);
-
+	
+	/* This block uses the controle key to make the object selected by its centre point rather then its contentse*/
 	if(G.obedit==0 && (G.qual & LR_CTRLKEY)) {
 
 		base= startbase;
@@ -878,8 +893,28 @@
 				temp= abs(base->sx -mval[0]) + abs(base->sy -mval[1]);
 				if(base==BASACT) temp+=10;
 				if(temp<dist ) {
-					basact= base;
+					
 					dist= temp;
+					
+					
+					/* Generate menu text */
+					if (G.qual & LR_ALTKEY) {
+						if (baseCount < SEL_MENU_SIZE) {
+							baseList[baseCount] = base;
+							strcat(menuText, "|"); /* Seperate menu items */
+							sprintf(menuIndexChar, "%d", baseCount+1); /* Turn Base count into a string */
+							strcat(menuText, base->object->id.name+2); /*Object name*/
+							strcat(menuText, "%x");
+							strcat(menuText, menuIndexChar);						
+						
+							baseCount++;
+						} /* end generating menu*/
+					} else { /* no altkey, no menu */
+						basact= base; /*  No menu so we need to do this now */
+					}
+					
+					
+					
 				}
 			}
 			base= base->next;
@@ -887,9 +922,27 @@
 			if(base==0) base= FIRSTBASE;
 			if(base==startbase) break;
 		}
-
+		
+		if (G.qual & LR_ALTKEY) {
+			/* USE MENU IF MORE THEN 1 ITEM ARE UNDER THE MOUSE*/
+			if (baseCount == 1) { /* Only 1 item, dont bother with a menu */
+				base = baseList[0];
+				basact = base;			
+			} else { /* We have more then 1 item under the mouse cursor */
+		
+				baseCount = pupmenu(menuText);
+		
+				if (baseCount != -1) { /* If nothing is selected then dont do anything */
+					base = baseList[baseCount-1];
+					basact = base;
+					} else {
+						return; /* No menu item selected so give up now */
+					}
+			}
+		} /*end altkey/menu option*/
+		
 		/* complete redraw when: */
-		if(G.f & (G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT+G_WEIGHTPAINT)) allqueue(REDRAWVIEW3D, 1);
+		if(G.f & (G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT+G_WEIGHTPAINT)) allqueue(REDRAWVIEW3D, 0);
 		
 	}
 	else {
@@ -903,15 +956,59 @@
 				if(base->lay & G.vd->lay) {
 					for(a=0; a<hits; a++) {
 						/* index was converted */
-						if(base->selcol==buffer[ (4 * a) + 3 ]) basact= base;
+						if(base->selcol==buffer[ (4 * a) + 3 ]) {
+							
+							
+							
+							/* Generate menu text */
+							if (G.qual & LR_ALTKEY) {
+								if (baseCount < SEL_MENU_SIZE) {
+									baseList[baseCount] = base;
+									strcat(menuText, "|"); /* Seperate menu items */
+									sprintf(menuIndexChar, "%d", baseCount+1); /* Turn Base count into a string */
+									strcat(menuText, base->object->id.name+2); /*Object name*/
+									strcat(menuText, "%x");
+									strcat(menuText, menuIndexChar);						
+									baseCount++;
+								} /* end generating menu*/
+							} else { /* no altkey, no menu */
+								basact= base;  /*  No menu so we need to do this now */
+							}
+							
+							
+						}
 					}
 				}
-				if(basact) break;
+				
+				/* Act normaly if Menu isnt being used */
+				if (!(G.qual & LR_ALTKEY)) {
+					if(basact) break; /*  No menu so we need to do this now */
+				}
 				
 				base= base->next;
 				if(base==0) base= FIRSTBASE;
 				if(base==startbase) break;
 			}
+			
+			
+			/* Menu only if the altkey is pressed */
+			if (G.qual & LR_ALTKEY) {
+				/* USE MENU IF MORE THEN 1 ITEM ARE UNDER THE MOUSE*/
+				if (baseCount == 1) { /* Only 1 item, dont bother with a menu */
+				base = baseList[0];
+				basact = base;			
+				} else { /* We have more then 1 item under the mouse cursor */
+					baseCount = pupmenu(menuText);
+				
+					if (baseCount != -1) { /* If nothing is selected then dont do anything */
+						base = baseList[baseCount-1];
+						basact = base;
+					} else {
+						return; /* No menu item selected so give up now */
+					}
+				}
+			} /*end altkey/menu option*/
+			
 		}
 	}
 	


More information about the Bf-committers mailing list