[Bf-committers] Menu code bug/weirdness

bf-committers@blender.org bf-committers@blender.org
Sat, 21 Feb 2004 04:33:08 -0600


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

Chris Want wrote:
> Looks like I've been thwarted by my old nemesis, interface.c!
> 
> I was adding some code that alphabetizes the bone
> parent menu (as requested by many), and having completed
> the task, I discovered that the rendering of the menu is
> quite screwy.
> 
I did this for vertex groups and also fixed the problem in
interface.c.  I've been meaning to send a patch for these to
the list, but felt I wanted a more general solution for this,
one that would catch the bones too.  I've attatched my patch
for these.  The change for interface.c is a one liner.

I've been using this code since just after Christmas and haven't
noticed any problems.

As far as the more general solution, I was hoping at some point
to maybe add a flag to these menus that would sort them
automatically.  Putting code like I did in buttons_editing.c to
sort the vertex group entries just seemed like a hack.

--
Todd Koeckeritz, zaz@visi.com

Surfin' the Web with an ActiveX enabled browser is kindof like having
to worry about getting shot everytime you knock on a door.

--------------060103030904040307070507
Content-Type: text/x-patch;
 name="sorted-vgroup-menu.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="sorted-vgroup-menu.patch"

Index: source/blender/src/interface.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface.c,v
retrieving revision 1.105
diff -u -r1.105 interface.c
--- source/blender/src/interface.c	28 Jan 2004 12:20:19 -0000	1.105
+++ source/blender/src/interface.c	21 Feb 2004 10:31:42 -0000
@@ -890,7 +890,7 @@
 	for(a=0; a<md->nitems; a++) {
 		
 		x1= but->x1 + width*((int)(md->nitems-a-1)/rows);
-		y1= but->y1 - boxh*(a%rows) + (rows-1)*boxh; 
+		y1= but->y1 - boxh*(rows - ((md->nitems - a - 1)%rows)) + (rows*boxh);
 
 		if (strcmp(md->items[md->nitems-a-1].str, "%l")==0) {
 			uiDefBut(block, SEPR, B_NOP, "", x1, y1,(short)(width-(rows>1)), (short)(boxh-1), NULL, 0.0, 0.0, 0, 0, "");
Index: source/blender/src/buttons_editing.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons_editing.c,v
retrieving revision 1.36
diff -u -r1.36 buttons_editing.c
--- source/blender/src/buttons_editing.c	29 Jan 2004 00:47:35 -0000	1.36
+++ source/blender/src/buttons_editing.c	21 Feb 2004 10:31:43 -0000
@@ -1846,14 +1846,26 @@
 		if (!defCount) min=0;
 		else min=1;
 		
-		s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
+		char	(*qsort_ptr) [32] = NULL;
+
+		if (defCount > 0) {
+		  qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr [0]), "qsort_ptr");
+		  for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
+		    snprintf (qsort_ptr [index - 1], sizeof (qsort_ptr [0]), "%s%%x%d|", dg->name, index);
+		  }
+
+		  qsort (qsort_ptr, defCount, sizeof (qsort_ptr [0]), strcmp);
+		}
 
-		for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
-			int cnt= sprintf (s, "%s%%x%d|", dg->name, index);
-			
+		s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
+		for (index = 0; index < defCount; index++) {
+			int cnt= sprintf (s, "%s", qsort_ptr [index]);
 			if (cnt>0) s+= cnt;
 		}
-		
+
+		if (qsort_ptr)
+		  MEM_freeN (qsort_ptr);
+
 		uiBlockBeginAlign(block);
 		if (defCount) uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr,	143, 132,18,21, &ob->actdef, min, defCount, 0, 0, "Browses available vertex groups");
 

--------------060103030904040307070507--