[Bf-committers] Patch- 3d view Object sel menu

Campbell Barton bf-committers@blender.org
Sun, 18 Jul 2004 18:14:58 +1000


This is a multi-part message in MIME format.
--------------030001060703080308020804
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi all
This patch pops up a menu of all objects under the mouse and Alt+RMP
I quite like it for large scenes where you have meny objects.

- Cam

--------------030001060703080308020804
Content-Type: text/plain;
 name="bf_obj_sel_menu.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="bf_obj_sel_menu.txt"

Index: source/blender/src/editview.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/editview.c,v
retrieving revision 1.25
diff -u -r1.25 editview.c
--- source/blender/src/editview.c	16 Jul 2004 01:34:19 -0000	1.25
+++ source/blender/src/editview.c	18 Jul 2004 07:52:34 -0000
@@ -539,6 +539,9 @@
 	}
 }
 
+/* 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;
@@ -546,6 +549,14 @@
 	int temp, a, dist=100;
 	short hits, mval[2];
 
+  /* menuText should be the initial size of text (22 atm) + ( SEL_MENU_SIZE * 26)  
+	26 being the longest possible length for a menu item */
+	char menuText[512] = "Select Object%t"; 
+	char menuIndexChar[2];
+  short baseCount = 0;
+  Base  *baseList[SEL_MENU_SIZE]; /* baseList is used to store all possible bases to bring up a menu */
+	/*end select menu */
+  
 	/* always start list from basact */
 	startbase=  FIRSTBASE;
 	if(BASACT && BASACT->next) startbase= BASACT->next;
@@ -589,15 +600,55 @@
 				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*/
+			
 		}
 	}
 	
Index: source/blender/src/header_view3d.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/header_view3d.c,v
retrieving revision 1.59
diff -u -r1.59 header_view3d.c
--- source/blender/src/header_view3d.c	16 Jul 2004 02:10:52 -0000	1.59
+++ source/blender/src/header_view3d.c	18 Jul 2004 07:52:39 -0000
@@ -1041,6 +1041,24 @@
 		case 4: /* Select Same UV */
 			get_same_uv();
 			break;
+		case 5: /* Select Same Material */
+			get_same_mat();
+			break;
+		case 6: /* Select Same Mode */
+			get_same_mode();
+			break;
+		case 7: /* Select Same Normal */
+			get_same_normal();
+			break;
+		case 8: /* Select Same Area */
+			get_same_area();
+			break;
+		case 9: /* Select Same Vert colour */
+			get_same_vcol();
+			break;
+		case 10: /* Select Same Vert colour */
+			get_same_uvco();
+			break;
 	}
 	allqueue(REDRAWVIEW3D, 0);
 }
@@ -1059,7 +1077,16 @@
 	
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A",				0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Inverse",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
-	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same UV",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
+
+	uiDefBut(block, SEPR, 0, "",				0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same UV Image",                0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same Material",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same Mode",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same Normal",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same Area",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same Vert Col",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same UV Coords",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
 
 	if(curarea->headertype==HEADERTOP) {
 		uiBlockSetDirection(block, UI_DOWN);
@@ -1072,6 +1099,7 @@
 	uiTextBoundsBlock(block, 50);
 	return block;
 }
+
 
 void do_view3d_edit_snapmenu(void *arg, int event)
 {

--------------030001060703080308020804--