The patch to pre-emptify the queues for 'clever numbuts' didn't check for
[blender.git] / source / blender / src / toolbox.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #define PY_TOOLBOX 1
34
35 #include <math.h>
36 #include <ctype.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <stdarg.h>
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #ifndef WIN32
46 #include <unistd.h>
47 #else
48 #include <io.h>
49 #endif   
50
51 #include <fcntl.h>
52 #include "MEM_guardedalloc.h"
53
54 #include "BMF_Api.h"
55 #include "BIF_language.h"
56 #include "BIF_resources.h"
57
58 #include "DNA_group_types.h"
59 #include "DNA_image_types.h"
60 #include "DNA_lamp_types.h"
61 #include "DNA_mesh_types.h"
62 #include "DNA_object_types.h"
63 #include "DNA_screen_types.h"
64 #include "DNA_scene_types.h"
65 #include "DNA_userdef_types.h"
66 #include "DNA_view3d_types.h"
67
68 #include "BLI_blenlib.h"
69 #include "BLI_arithb.h"
70
71 #include "BKE_displist.h"
72 #include "BKE_depsgraph.h"
73 #include "BKE_global.h"
74 #include "BKE_library.h"
75 #include "BKE_mesh.h"
76 #include "BKE_main.h"
77 #include "BKE_plugin_types.h"
78 #include "BKE_utildefines.h"
79
80 #include "BIF_editnla.h"
81 #include "BIF_editarmature.h"
82 #include "BIF_editdeform.h"
83 #include "BIF_editfont.h"
84 #include "BIF_editmesh.h"
85 #include "BIF_editseq.h"
86 #include "BIF_editlattice.h"
87 #include "BIF_editsima.h"
88 #include "BIF_editoops.h"
89 #include "BIF_editview.h"
90 #include "BIF_gl.h"
91 #include "BIF_graphics.h"
92 #include "BIF_imasel.h"
93 #include "BIF_interface.h"
94 #include "BIF_mainqueue.h"
95 #include "BIF_mywindow.h"
96 #include "BIF_renderwin.h"
97 #include "BIF_screen.h"
98 #include "BIF_space.h"
99 #include "BIF_toolbox.h"
100 #include "BIF_tbcallback.h"
101 #include "BIF_transform.h"
102
103 #include "BDR_editobject.h"
104 #include "BDR_editcurve.h"
105 #include "BDR_editmball.h"
106
107 #include "BSE_editipo.h"
108 #include "BSE_filesel.h"
109 #include "BSE_edit.h"
110 #include "BSE_headerbuttons.h"
111
112 #include "IMB_imbuf.h"
113
114 #include "mydevice.h"
115 #include "blendef.h"
116
117 static int tbx1, tbx2, tby1, tby2, tbfontyofs, tbmain=0;
118 static int tbmemx=TBOXX/2, tbmemy=(TBOXEL-0.5)*TBOXH, tboldwin, addmode= 0;
119 static int oldcursor;
120
121         /* variables per item */
122 static char *tbstr, *tbstr1, *keystr;   
123 static void (*tbfunc)(int);
124 static int tbval;
125
126 /* prototypes ----------------------- */
127 TBcallback *callback_dummy(int level, int entry);
128
129
130 /* *********** PC PATCH ************* */
131
132 void ColorFunc(int i)
133 {
134         if(i==TBOXBLACK) glColor3ub(0, 0, 0);
135         else if(i==TBOXWHITE) glColor3ub(240, 240, 240);
136         else if(i==TBOXGREY) glColor3ub(160, 160, 160);
137         else glColor3ub(0, 0, 0);
138 }
139
140 /* ********************* PYTHON TOOLBOX CALLBACK ************************* */
141
142 #ifdef PY_TOOLBOX 
143 /* see bpython/intern/py_toolbox.c */
144
145 /* moved to BIF_toolbox.h */
146 /* typedef char** (*tbox_callback)(int, int); */
147
148 TBcallback *callback_dummy(int level, int entry)
149 {
150         return NULL;
151 }       
152
153 /* callback func ptr for py_toolbox */
154 Tbox_callbackfunc g_toolbox_menucallback = &callback_dummy;
155
156 void tboxSetCallback(Tbox_callbackfunc f)
157 {
158         g_toolbox_menucallback = f;
159 }
160
161 #endif
162
163 /* ********************* TOOLBOX ITEMS ************************* */
164
165 void tbox_setinfo(int x, int y)
166 {
167         /* dependant of tbmain vars are set */
168         tbstr= 0;
169         tbstr1= 0;
170         tbfunc= 0;
171         tbval= 0;
172         keystr = NULL;
173
174 /* main menu entries: defined in BIF_toolbox.h */
175         
176         if(x==0) {
177                 switch(y) {
178                         case TBOX_MAIN_FILE:            tbstr= "FILE";          break;
179                         case TBOX_MAIN_EDIT:            tbstr= "EDIT";          break;
180                         case TBOX_MAIN_ADD:             
181                                 if (addmode==OB_MESH) tbstr= "  MESH";
182                                 else if(addmode==OB_CURVE) tbstr= "  CURVE";
183                                 else if(addmode==OB_SURF) tbstr= "  SURF";
184                                 else if(addmode==OB_MBALL) tbstr= "  META";
185                                 else tbstr= "ADD";
186                                 break;
187                         case TBOX_MAIN_OBJECT1:         tbstr= "OBJECT";        break;
188                         case TBOX_MAIN_OBJECT2:         tbstr= "OBJECT";        break;
189                         case TBOX_MAIN_MESH:            tbstr= "MESH";          break;
190                         case TBOX_MAIN_CURVE:           tbstr= "CURVE";         break;
191                         case TBOX_MAIN_KEY:                     tbstr= "KEY";           break;
192                         case TBOX_MAIN_RENDER:          tbstr= "RENDER";        break;
193                         case TBOX_MAIN_VIEW:            tbstr= "VIEW";          break;
194                         case TBOX_MAIN_SEQ:             tbstr= "SEQUENCE";      break;
195 #ifdef PY_TOOLBOX
196                         case TBOX_MAIN_PYTOOL:          
197                         {
198                                 if (g_toolbox_menucallback(0, 0)) // valid callback?
199                                         tbstr= "PYTOOL";        
200                                 break;
201                         }
202 #endif
203                 }
204         }
205         
206 /* TOPICS */
207         else {
208                 
209                 
210 /* FILE TOPICS */
211                 if(tbmain==TBOX_MAIN_FILE) {
212                         switch(y) {
213                                 case 0: tbstr= "New";                           tbstr1= "c|x";          keystr= "Ctrl X";       break;
214                                 case 1: tbstr= "Open";                          tbstr1= "F1";           keystr= "F1";           break;
215                                 case 2: tbstr= "Reopen Last";           tbstr1= "c|o";          keystr= "Ctrl O";       break;
216                                 case 3: tbstr= "Append";                        tbstr1= "shift+F1";     keystr= "Shift F1";     break;
217                                 case 4: tbstr= "";                                      tbstr1= "";                     keystr= "";                     break;
218                                 case 5: tbstr= "Save As";                       tbstr1= "F2";           keystr= "F2";           break;
219                                 case 6: tbstr= "Save";                          tbstr1= "c|w";          keystr= "Ctrl W";       break;
220                                 case 7: tbstr= "";                                      tbstr1= "";                     keystr= "";                     break;
221                                 case 8: tbstr= "Save Image";            tbstr1= "F3";           keystr= "F3";           break;
222                                 case 9: tbstr= "Save VRML";                     tbstr1= "c|F2";         keystr= "Ctrl F2";      break;
223                                 case 10: tbstr= "Save DXF";                     tbstr1= "shift+F2";     keystr= "Shift F2";     break;
224                                 case 11: tbstr= "Save VideoScape";      tbstr1= "a|w";          keystr= "Alt W";        break;
225                                 case 12: tbstr= "Save UserPrefs";       tbstr1= "c|u";          keystr= "Ctrl U";       break;
226                                 case 13: tbstr= "Quit";                         tbstr1= "q";            keystr= "Q";            break;
227                         }
228                 }
229
230 /* EDIT TOPICS */
231                 if(tbmain==TBOX_MAIN_EDIT) {
232                         switch(y) {
233                                 case 0: tbstr= "(De)Select All";        tbstr1= "a";    keystr= "A";            break;
234                                 case 1: tbstr= "Border Select";         tbstr1= "b";    keystr= "B";            break;
235                                 case 2: tbstr= "Select Linked";         tbstr1= "l";    keystr= "L";            break;
236                                 case 3: tbstr= "Hide Selected";         tbstr1= "h";    keystr= "H";            break;
237                                 case 4: tbstr= "Duplicate";                     tbstr1= "D";    keystr= "Shift D";      break;
238                                 case 5: tbstr= "Delete";                        tbstr1= "x";    keystr= "X";            break;
239                                 case 6: tbstr= "Edit Mode";                     tbstr1= "Tab";  keystr= "Tab";          break;
240                                 case 7: tbstr= "Grabber";                       tbstr1= "g";    keystr= "G";            break;
241                                 case 8: tbstr= "Rotate";                        tbstr1= "r";    keystr= "R";            break;
242                                 case 9: tbstr= "Scale";                         tbstr1= "s";    keystr= "S";            break;
243                                 case 10: tbstr= "Shrink/Fatten";        tbstr1= "a|s";  keystr= "Alt S";        break;
244                                 case 11: tbstr= "Shear";                        tbstr1= "c|s";  keystr= "Ctrl S";       break;
245                                 case 12: tbstr= "Warp/Bend";            tbstr1= "W";    keystr= "Shift W";      break;
246                                 case 13: tbstr= "Snap Menu";            tbstr1= "S";    keystr= "Shift S";      break;
247                         }
248                 }
249
250 /* ADD TOPICS */
251                 if(tbmain==TBOX_MAIN_ADD) {
252
253                         if(addmode==0) {
254                                 switch(y) {
255                                         case 0: tbstr= "Mesh";          tbstr1= ">>";   keystr= ">>";   tbval=OB_MESH;                                                                          break;
256                                         case 1: tbstr= "Curve";         tbstr1= ">>";   keystr= ">>";   tbval=OB_CURVE;                                                                         break;
257                                         case 2: tbstr= "Surface";       tbstr1= ">>";   keystr= ">>";   tbval=OB_SURF;                                                                          break;
258                                         case 3: tbstr= "Meta";          tbstr1= ">>";   keystr= ">>";   tbval=OB_MBALL;                                                                         break;
259                                         case 4: tbstr= "Text";          tbstr1= "";             keystr= "";             tbval=OB_FONT;  tbfunc= add_primitiveFont;                      break;
260                                         case 5: tbstr= "Empty";         tbstr1= "A";    keystr= "";             tbval=OB_EMPTY;                                                                         break;
261                                         case 6: tbstr= "";                      tbstr1= "";             keystr= "";             tbval=0;                                                                                        break;
262                                         case 7: tbstr= "Camera";        tbstr1= "A";    keystr= "";             tbval=OB_CAMERA;                                                                        break;
263                                         case 8: tbstr= "Lamp";          tbstr1= "A";    keystr= "";             tbval=OB_LAMP;                                                                          break;
264                                         case 9: tbstr= "Armature";      tbstr1= "";             keystr= "";             tbval=OB_ARMATURE;      tbfunc=add_primitiveArmature;   break;
265                                         case 10: tbstr= "";                     tbstr1= "";             keystr= "";             tbval=0;                                                                                        break;
266                                         case 11: tbstr= "Lattice";      tbstr1= "A";    keystr= "";             tbval=OB_LATTICE;                                                                       break;
267                                         case 12: tbstr= "";                     tbstr1= "";             keystr= "";             tbval=0;                                                                                        break;
268                                         case 13: tbstr= "";                     tbstr1= "";             keystr= "";             tbval=0;                                                                                        break;
269                                 }
270                                 if(tbstr1 && tbstr1[0]=='A') tbfunc= (void (*)(int))add_object_draw;
271                         }
272                         else if(addmode==OB_MESH) {             
273                                 switch(y) {
274                                         case 0: tbstr= ">Plane";        tbstr1= "A";    keystr= "";             tbval=0;        break;
275                                         case 1: tbstr= ">Cube";         tbstr1= "A";    keystr= "";             tbval=1;        break;
276                                         case 2: tbstr= ">Circle";       tbstr1= "A";    keystr= "";             tbval=4;        break;
277                                         case 3: tbstr= ">UVsphere";     tbstr1= "A";    keystr= "";             tbval=11;       break;
278                                         case 4: tbstr= ">Icosphere";tbstr1= "A";        keystr= "";             tbval=12;       break;
279                                         case 5: tbstr= ">Cylinder";     tbstr1= "A";    keystr= "";             tbval=5;        break;
280                                         case 6: tbstr= ">Tube";         tbstr1= "A";    keystr= "";             tbval=6;        break;
281                                         case 7: tbstr= ">Cone";         tbstr1= "A";    keystr= "";             tbval=7;        break;
282                                         case 8: tbstr= ">";                     tbstr1= "";             keystr= "";                                     break;
283                                         case 9: tbstr= ">Grid";         tbstr1= "A";    keystr= "";             tbval=10;       break;
284                                         case 13: tbstr= ">Monkey";      tbstr1= "A";    keystr= "";             tbval=13;       break;
285                                 }
286                                 if(tbstr1 && tbstr1[0]=='A') tbfunc= add_primitiveMesh;
287                         }
288                         else if(addmode==OB_SURF) {
289                                 switch(y) {
290                                         case 0: tbstr= ">Curve";        tbstr1= "A";    keystr= "";             tbval=0; break;
291                                         case 1: tbstr= ">Circle";       tbstr1= "A";    keystr= "";             tbval=1; break;
292                                         case 2: tbstr= ">Surface";      tbstr1= "A";    keystr= "";             tbval=2; break;
293                                         case 3: tbstr= ">Tube";         tbstr1= "A";    keystr= "";             tbval=3; break;
294                                         case 4: tbstr= ">Sphere";       tbstr1= "A";    keystr= "";             tbval=4; break;
295                                         case 5: tbstr= ">Donut";        tbstr1= "A";    keystr= "";             tbval=5; break;
296                                 }
297                                 if(tbstr1 && tbstr1[0]=='A') tbfunc= add_primitiveNurb;
298                         }
299 /*                      else if (addmode==OB_ARMATURE){
300                                 switch(y) {
301                                         case 0: tbstr= ">Bone";         tbstr1= "A";    keystr= "";             tbval=0; break;
302                                         case 1: tbstr= ">Hand";         tbstr1= "A";    keystr= "";             tbval=1; break;
303                                         case 2: tbstr= ">Biped";        tbstr1= "A";    keystr= "";             tbval=2; break;
304                                 }
305                                 if(tbstr1 && tbstr1[0]=='A') tbfunc= add_primitiveArmature;     
306                         }
307 */
308                         else if(addmode==OB_CURVE) {
309                                 switch(y) {
310                                         case 0: tbstr= ">Bezier Curve";         tbstr1= "A";    keystr= "";     tbval=10;       break;
311                                         case 1: tbstr= ">Bezier Circle";        tbstr1= "A";    keystr= "";     tbval=11;       break;
312                                         case 2: tbstr= ">";                                     tbstr1= "";             keystr= "";                             break;
313                                         case 3: tbstr= ">Nurbs Curve";          tbstr1= "A";    keystr= "";     tbval=40;       break;
314                                         case 4: tbstr= ">Nurbs Circle";         tbstr1= "A";    keystr= "";     tbval=41;       break;
315                                         case 5: tbstr= ">";                                     tbstr1= "";             keystr= "";                             break;
316                                         case 6: tbstr= ">Path";                         tbstr1= "A";    keystr= "";     tbval=46;       break;
317                                 }
318                                 if(tbstr1 && tbstr1[0]=='A') tbfunc= add_primitiveCurve;
319                         }
320                         else if(addmode==OB_MBALL) {
321                                 switch(y) {
322                                         case 0: tbstr= "Ball";                  tbstr1= "A";    tbval=1; break;
323                                         case 1: tbstr= "Tube";                  tbstr1= "A";    tbval=2; break;
324                                         case 2: tbstr= "Plane";                 tbstr1= "A";    tbval=3; break;
325                                         case 3: tbstr= "Elipsoid";              tbstr1= "A";    tbval=4; break;
326                                         case 4: tbstr= "Cube";                  tbstr1= "A";    tbval=5; break;
327                                         case 5: tbstr= "";                      tbstr1= "";             break;
328                                         case 6: tbstr= "";                      tbstr1= "";             break;
329                                         case 7: tbstr= "";                      tbstr1= "";             break;
330                                         case 8: tbstr= "";                      tbstr1= "";             break;
331                                         case 9: tbstr= "";                      tbstr1= "";             break;
332                                         case 10: tbstr= "";                     tbstr1= "";             break;
333                                         case 11: tbstr= "Duplicate";tbstr1= "D";        break;
334                                 }
335                                 if(tbstr1 && tbstr1[0]=='A') tbfunc= add_primitiveMball;
336                         }
337                 }
338                 
339 /* OB TOPICS 1 */
340                 else if(tbmain==TBOX_MAIN_OBJECT1) {
341                         switch(y) {
342                                 case 0: tbstr= "Clear Size";            tbstr1= "a|s";  keystr= "Alt S";        break;
343                                 case 1: tbstr= "Clear Rotation";        tbstr1= "a|r";  keystr= "Alt R";        break;
344                                 case 2: tbstr= "Clear Location";        tbstr1= "a|g";  keystr= "Alt G";        break;
345                                 case 3: tbstr= "Clear Origin";          tbstr1= "a|o";  keystr= "Alt O";        break;
346                                 case 4: tbstr= "Make Parent";           tbstr1= "c|p";  keystr= "Ctrl P";       break;
347                                 case 5: tbstr= "Clear Parent";          tbstr1= "a|p";  keystr= "Alt P";        break;
348 /*      Unkown what tbstr1 should be...
349                                 case 6: tbstr= "MkVert Parent";         tbstr1= "c|a|p";        keystr= "Ctrl Alt P";   break;
350 */
351                                 case 7: tbstr= "Make Track";            tbstr1= "c|t";  keystr= "Ctrl T";       break;
352                                 case 8: tbstr= "Clear Track";           tbstr1= "a|t";  keystr= "Alt T";        break;
353 /*                              case 9: tbstr= "";                                      tbstr1= "";             keystr= "";                     break; */
354                                 case 10: tbstr= "Image Displist";       tbstr1= "c|d";  keystr= "Ctrl D";       break;
355                                 case 11: tbstr= "Image Aspect";         tbstr1= "a|v";  keystr= "Alt V";        break;
356                                 case 12: tbstr= "Vect Paint";           tbstr1= "v";    keystr= "V";    break;
357                         }
358                 }
359                 
360 /* OB TOPICS 2 */
361                 else if(tbmain==TBOX_MAIN_OBJECT2) {
362                         switch(y) {
363                                 case 0: tbstr= "Edit Mode";                     tbstr1= "Tab";  keystr= "Tab";                  break;
364                                 case 1: tbstr= "Move To Layer";         tbstr1= "m";    keystr= "M";                    break;
365                                 case 2: tbstr= "Delete";                        tbstr1= "x";    keystr= "X";                    break;
366                                 case 3: tbstr= "Delete All";            tbstr1= "c|x";  keystr= "Ctrl X";               break;
367                                 case 4: tbstr= "Apply Size/Rot";        tbstr1= "c|a";  keystr= "Ctrl A";               break;
368                                 case 5: tbstr= "Apply Deform";          tbstr1= "c|A";  keystr= "Ctrl Shift A"; break;
369                                 case 6: tbstr= "Join";                          tbstr1= "c|j";  keystr= "Ctrl J";               break;
370                                 case 7: tbstr= "Make Local";            tbstr1= "l";    keystr= "L";                    break;
371                                 case 8: tbstr= "Select Linked";         tbstr1= "L";    keystr= "Shift L";              break;
372                                 case 9: tbstr= "Make Links";            tbstr1= "c|l";  keystr= "Ctrl L";               break;
373                                 case 10: tbstr= "Copy Menu";            tbstr1= "c|c";  keystr= "Ctrl C";               break;
374                                 case 11: tbstr= "Convert Menu";         tbstr1= "a|c";  keystr= "Alt C";                break;
375                                 case 12: tbstr= "Boolean Op";           tbstr1= "w";    keystr= "W";            break;
376                         }
377                 }
378
379 /* mesh TOPICS */
380                 else if(tbmain==TBOX_MAIN_MESH) {
381                         switch(y) {
382                                 case 0: tbstr= "Select Linked";         tbstr1= "l";    keystr= "L";            break;
383                                 case 1: tbstr= "Deselect Linked";       tbstr1= "L";    keystr= "Shift L";      break;
384                                 case 2: tbstr= "Extrude";                       tbstr1= "e";    keystr= "E";            break;
385                                 case 3: tbstr= "Delete Menu";           tbstr1= "x";    keystr= "X";            break;
386                                 case 4: tbstr= "Make edge/face";        tbstr1= "f";    keystr= "F";            break;
387                                 case 5: tbstr= "Fill";                          tbstr1= "F";    keystr= "Shift F";      break;
388                                 case 6: tbstr= "Split";                         tbstr1= "y";    keystr= "Y";            break;
389                                 case 7: tbstr= "Undo/reload";           tbstr1= "u";    keystr= "U";            break;
390                                 case 8: tbstr= "Calc Normals";          tbstr1= "c|n";  keystr= "Ctrl N";       break;
391                                 case 9: tbstr= "Separate";                      tbstr1= "p";    keystr= "P";            break;
392                                 case 10: tbstr= "Write Videosc";        tbstr1= "a|w";  keystr= "Alt W";        break;
393 /*                              case 11: tbstr= "";                                     tbstr1= "";             keystr= "";                     break; */
394                         }
395                 }
396         
397 /* CURVE TOPICS */
398                 else if(tbmain==TBOX_MAIN_CURVE) {
399                         switch(y) {
400                                 case 0: tbstr= "Select Linked";         tbstr1= "l";    keystr= "L";            break;
401                                 case 1: tbstr= "Deselect Linked";       tbstr1= "L";    keystr= "Shift L";      break;
402                                 case 2: tbstr= "Extrude";                       tbstr1= "e";    keystr= "E";            break;
403                                 case 3: tbstr= "Delete Menu";           tbstr1= "x";    keystr= "X";            break;
404                                 case 4: tbstr= "Make Segment";          tbstr1= "f";    keystr= "F";            break;
405                                 case 5: tbstr= "Cyclic";                        tbstr1= "c";    keystr= "C";            break;
406 /*                              case 6: tbstr= "";                                      tbstr1= "";             keystr= "";                     break; */
407                                 case 7: tbstr= "Select Row";            tbstr1= "R";    keystr= "Shift R";      break;
408                                 case 8: tbstr= "Calc Handle";           tbstr1= "h";    keystr= "H";            break;
409                                 case 9: tbstr= "Auto Handle";           tbstr1= "H";    keystr= "Shift H";      break;
410                                 case 10: tbstr= "Vect Handle";          tbstr1= "v";    keystr= "V";            break;
411                                 case 11: tbstr= "Specials";                     tbstr1= "w";    keystr= "W";            break;
412                         }
413                 }
414         
415 /* KEY TOPICS */
416                 else if(tbmain==TBOX_MAIN_KEY) {
417                         switch(y) {
418                                 case 0: tbstr= "Insert";        tbstr1= "i";            keystr= "I";            break;
419                                 case 1: tbstr= "Show";          tbstr1= "k";            keystr= "K";            break;
420                                 case 2: tbstr= "Next";          tbstr1= "PageUp";       keystr= "PgUp";         break;
421                                 case 3: tbstr= "Prev";          tbstr1= "PageDn";       keystr= "PgDn";         break;
422                                 case 4: tbstr= "Show+Sel";      tbstr1= "K";            keystr= "Shift K";      break;
423 /*                              case 5: tbstr= "";                      tbstr1= "";                     keystr= "";                     break;
424                                 case 6: tbstr= "";                      tbstr1= "";                     keystr= "";                     break;
425                                 case 7: tbstr= "";                      tbstr1= "";                     keystr= "";                     break;
426                                 case 8: tbstr= "";                      tbstr1= "";                     keystr= "";                     break;
427                                 case 9: tbstr= "";                      tbstr1= "";                     keystr= "";                     break;
428                                 case 10: tbstr= "";                     tbstr1= "";                     keystr= "";                     break;
429                                 case 11: tbstr= "";                     tbstr1= "";                     keystr= "";                     break; */
430                         }
431                 }
432 /* SEQUENCER TOPICS */
433                 else if(tbmain==TBOX_MAIN_SEQ) {
434                         switch(y) {
435                                 case 0: tbstr= "Add Strip";  tbstr1= "A"; keystr= "Shift A"; break;
436                                 case 1: tbstr= "Change Str"; tbstr1= "c"; keystr= "C";       break;
437                                 case 2: tbstr= "Delete Str"; tbstr1= "x"; keystr= "X";       break;
438                                 case 3: tbstr= "Make Meta";  tbstr1= "m"; keystr= "M";       break;
439                                 case 4: tbstr= "Str Params"; tbstr1= "n"; keystr= "N";       break;
440                         }
441                 }
442
443 /* RENDER TOPICS */
444                 else if(tbmain==TBOX_MAIN_RENDER) {
445                         switch(y) {
446                                 case 0: tbstr= "Render Window"; tbstr1= "F11";  keystr= "F11";          break;
447                                 case 1: tbstr= "Render";                tbstr1= "F12";  keystr= "F12";          break;
448                                 case 2: tbstr= "Set Border";    tbstr1= "B";    keystr= "Shift B";      break;
449                                 case 3: tbstr= "Image Zoom";    tbstr1= "z";    keystr= "Z";            break;
450 /*                              case 4: tbstr= "";                              tbstr1= "";             keystr= "";                     break;
451                                 case 5: tbstr= "";                              tbstr1= "";             keystr= "";                     break;
452                                 case 6: tbstr= "";                              tbstr1= "";             keystr= "";                     break;
453                                 case 7: tbstr= "";                              tbstr1= "";             keystr= "";                     break;
454                                 case 8: tbstr= "";                              tbstr1= "";             keystr= "";                     break;
455                                 case 9: tbstr= "";                              tbstr1= "";             keystr= "";                     break;
456                                 case 10: tbstr= "";                             tbstr1= "";             keystr= "";                     break;
457                                 case 11: tbstr= "";                             tbstr1= "";             keystr= "";                     break; */
458                         }
459                 }
460         
461 /* VIEW TOPICS */
462                 else if(tbmain==TBOX_MAIN_VIEW) {
463                         switch(y) {
464 /*                              case 0: tbstr= "";              tbstr1= "";     break;
465                                 case 1: tbstr= "";              tbstr1= "";     break;
466                                 case 2: tbstr= "";              tbstr1= "";     break;
467                                 case 3: tbstr= "";              tbstr1= "";     break; */
468                                 case 4: tbstr= "Centre";                tbstr1= "c";    keystr= "C";            break;
469                                 case 5: tbstr= "Home";                  tbstr1= "C";    keystr= "Shift C";      break;
470 /*                              case 6: tbstr= "";              tbstr1= "";     break;
471                                 case 7: tbstr= "";              tbstr1= "";     break;
472                                 case 8: tbstr= "";              tbstr1= "";     break;*/
473                                 case 9: tbstr= "Z-Buffer";              tbstr1= "z";    keystr= "Z";            break;
474 /*                              case 10: tbstr= "";             tbstr1= "";     break;
475                                 case 11: tbstr= "";             tbstr1= "";     break;*/
476                         }
477                 }
478 #ifdef PY_TOOLBOX
479                 else if(tbmain==TBOX_MAIN_PYTOOL) {
480                         TBcallback *t= g_toolbox_menucallback(0, y); // call python menu constructor
481                         if (t) { 
482                                 tbstr = t->desc; 
483                                 keystr = t->key;
484                                 tbfunc = t->cb;
485                                 tbval = t->val;
486                         }
487                 }
488 #endif
489         }
490 }
491
492 /* ******************** INIT ************************** */
493
494 void bgnpupdraw(int startx, int starty, int endx, int endy)
495 {
496         #if defined(__sgi) || defined(__sun__) || defined( __sun ) || defined (__sparc) || defined (__sparc__)
497
498         /* this is a dirty patch: XgetImage gets sometimes the backbuffer */
499         my_get_frontbuffer_image(0, 0, 1, 1);
500         my_put_frontbuffer_image();
501         #endif
502
503         tboldwin= mywinget();
504
505         mywinset(G.curscreen->mainwin);
506         
507         /* tinsy bit larger, 1 pixel on the rand */
508         
509         glReadBuffer(GL_FRONT);
510         glDrawBuffer(GL_FRONT);
511
512         glFlush();
513
514         my_get_frontbuffer_image(startx-1, starty-4, endx-startx+5, endy-starty+6);
515
516         oldcursor= get_cursor();
517         set_cursor(CURSOR_STD);
518         
519         tbfontyofs= (TBOXH-11)/2 +1;    /* ypos text in toolbox */
520 }
521
522 void endpupdraw(void)
523 {
524         glFlush();
525         my_put_frontbuffer_image();
526         
527         if(tboldwin) {
528                 mywinset(tboldwin);
529                 set_cursor(oldcursor);
530         }
531
532         glReadBuffer(GL_BACK);
533         glDrawBuffer(GL_BACK);
534 }
535
536 /* ********************************************** */
537
538 void asciitoraw(int ch, unsigned short *event, unsigned short *qual)
539 {
540         if( isalpha(ch)==0 ) return;
541         
542         if( isupper(ch) ) {
543                 *qual= LEFTSHIFTKEY;
544                 ch= tolower(ch);
545         }
546         
547         switch(ch) {
548         case 'a': *event= AKEY; break;
549         case 'b': *event= BKEY; break;
550         case 'c': *event= CKEY; break;
551         case 'd': *event= DKEY; break;
552         case 'e': *event= EKEY; break;
553         case 'f': *event= FKEY; break;
554         case 'g': *event= GKEY; break;
555         case 'h': *event= HKEY; break;
556         case 'i': *event= IKEY; break;
557         case 'j': *event= JKEY; break;
558         case 'k': *event= KKEY; break;
559         case 'l': *event= LKEY; break;
560         case 'm': *event= MKEY; break;
561         case 'n': *event= NKEY; break;
562         case 'o': *event= OKEY; break;
563         case 'p': *event= PKEY; break;
564         case 'q': *event= QKEY; break;
565         case 'r': *event= RKEY; break;
566         case 's': *event= SKEY; break;
567         case 't': *event= TKEY; break;
568         case 'u': *event= UKEY; break;
569         case 'v': *event= VKEY; break;
570         case 'w': *event= WKEY; break;
571         case 'x': *event= XKEY; break;
572         case 'y': *event= YKEY; break;
573         case 'z': *event= ZKEY; break;
574         }
575 }
576
577 void tbox_execute(void)
578 {
579         /* if tbfunc: call function */
580         /* if tbstr1 is a string: put value tbval in queue */
581         unsigned short event=0;
582         unsigned short qual1=0, qual2=0;
583
584         /* needed to check for valid selected objects */
585         Base *base=NULL;
586         Object *ob=NULL;
587
588         base= BASACT;
589         if (base) ob= base->object;
590
591         if(tbfunc) {
592                 tbfunc(tbval);
593         }
594         else if(tbstr1) {
595                 if(strcmp(tbstr1, "Tab")==0) {
596                         event= TABKEY;
597                 }
598                 else if(strcmp(tbstr1, "PageUp")==0) {
599                         event= PAGEUPKEY;
600                 }
601                 else if(strcmp(tbstr1, "PageDn")==0) {
602                         event= PAGEDOWNKEY;
603                 }
604                 else if(strcmp(tbstr1, "shift+F1")==0) {
605                         qual1= LEFTSHIFTKEY;
606                         event= F1KEY;
607                 }
608                 else if(strcmp(tbstr1, "shift+F2")==0) {
609                         qual1= LEFTSHIFTKEY;
610                         event= F2KEY;
611                 }
612                 /* ctrl-s (Shear): switch into editmode ### */
613                 else if(strcmp(tbstr1, "c|s")==0) {
614                         /* check that a valid object is selected to prevent crash */
615                         if(!ob) error("Only selected objects can be sheared");
616                         else if ((ob->type==OB_LAMP) || (ob->type==OB_EMPTY) || (ob->type==OB_FONT) || (ob->type==OB_CAMERA)) {
617                                 error("Only editable 3D objects can be sheared");
618                         }
619                         else if ((base->lay & G.vd->lay)==0) {
620                                 error("Only objects on visible layers can be sheared");
621                         }
622                         else {
623                                 if (!G.obedit) {
624                                         enter_editmode();
625                                         /* ### put these into a deselectall_gen() */
626                                         if(G.obedit->type==OB_MESH) deselectall_mesh();
627                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
628                                         else if(G.obedit->type==OB_MBALL) deselectall_mball();
629                                         else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
630                                         /* ### */
631                                 }
632                                 qual1 = LEFTCTRLKEY;
633                                 event = SKEY;
634                         }
635                 }
636                 else if(strcmp(tbstr1, "W")==0) {
637                         if (!ob) error ("Only selected objects can be warped");
638                         /* check that a valid object is selected to prevent crash */
639                         else if ((ob->type==OB_LAMP) || (ob->type==OB_EMPTY) || (ob->type==OB_FONT) || (ob->type==OB_CAMERA)) {
640                                 error("Only editable 3D objects can be warped");
641                         }
642                         else if ((base->lay & G.vd->lay)==0) {
643                                 error("Only objects on visible layers can be warped");
644                         }
645                         else {
646                                 if (!G.obedit) {
647                                         enter_editmode();
648                                         /* ### put these into a deselectall_gen() */
649                                         if(G.obedit->type==OB_MESH) deselectall_mesh();
650                                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) deselectall_nurb();
651                                         else if(G.obedit->type==OB_MBALL) deselectall_mball();
652                                         else if(G.obedit->type==OB_LATTICE) deselectall_Latt();
653                                         /* ### */
654                                 }
655                                 qual1 = LEFTSHIFTKEY;
656                                 event = WKEY;
657                         }
658                 }
659
660                 else if(strlen(tbstr1)<4 || (strlen(tbstr1)==4 && tbstr1[2]=='F')) {
661                                 
662                         if(tbstr1[1]=='|') {
663                                 if(tbstr1[0]=='c') qual1= LEFTCTRLKEY;
664                                 else if(tbstr1[0]=='a') qual1= LEFTALTKEY;
665                                 
666                                 if (tbstr1[2]=='F') {
667                                         switch(tbstr1[3]) {
668                                         case '1': event= F1KEY; break;
669                                         case '2': event= F2KEY; break;
670                                         case '3': event= F3KEY; break;
671                                         case '4': event= F4KEY; break;
672                                         case '5': event= F5KEY; break;
673                                         case '6': event= F6KEY; break;
674                                         case '7': event= F7KEY; break;
675                                         case '8': event= F8KEY; break;
676                                         case '9': event= F9KEY; break;
677                                         }
678                                 }
679                                 else asciitoraw(tbstr1[2], &event, &qual2);
680                         }
681                         else if(tbstr1[1]==0) {
682                                 asciitoraw(tbstr1[0], &event, &qual2);
683                         }
684                         else if(tbstr1[0]=='F') {
685                                 event= atoi(tbstr1+1);
686                                 switch(event) {
687                                         case 1: event= F1KEY; break;
688                                         case 2: event= F2KEY; break;
689                                         case 3: event= F3KEY; break;
690                                         case 4: event= F4KEY; break;
691                                         case 5: event= F5KEY; break;
692                                         case 6: event= F6KEY; break;
693                                         case 7: event= F7KEY; break;
694                                         case 8: event= F8KEY; break;
695                                         case 9: event= F9KEY; break;
696                                         case 10: event= F10KEY; break;
697                                         case 11: event= F11KEY; break;
698                                         case 12: event= F12KEY; break;
699                                 }
700                         }
701                 }
702                 
703                 if(event) {
704                         if(qual1) mainqenter(qual1, 1);
705                         if(qual2) mainqenter(qual2, 1);
706                         mainqenter(event, 1);
707                         mainqenter(event, 0);
708                         mainqenter(EXECUTE, 1);
709                         if(qual1) mainqenter(qual1, 0);
710                         if(qual2) mainqenter(qual2, 0);
711                 }
712         }
713         
714 }
715
716 void tbox_getmouse(mval)
717 short *mval;
718 {
719
720         getmouseco_sc(mval);
721
722 }
723
724 void tbox_setmain(int val)
725 {
726         tbmain= val;
727
728         if(tbmain==0 && G.obedit) {
729                 addmode= G.obedit->type;
730         }
731 }
732
733 void bgntoolbox(void)
734 {
735         short xmax, ymax, mval[2];
736         
737         xmax = G.curscreen->sizex;
738         ymax = G.curscreen->sizey;
739
740         tbox_getmouse(mval);
741         
742         if(mval[0]<95) mval[0]= 95;
743         if(mval[0]>xmax-95) mval[0]= xmax-95;
744
745         warp_pointer(mval[0], mval[1]);
746
747         tbx1= mval[0]-tbmemx;
748         tby1= mval[1]-tbmemy;
749         if(tbx1<10) tbx1= 10;
750         if(tby1<10) tby1= 10;
751         
752         tbx2= tbx1+TBOXX;
753         tby2= tby1+TBOXY;
754         if(tbx2>xmax) {
755                 tbx2= xmax-10;
756                 tbx1= tbx2-TBOXX;
757         }
758         if(tby2>ymax) {
759                 tby2= ymax-10;
760                 tby1= tby2-TBOXY;
761         }
762
763         bgnpupdraw(tbx1, tby1, tbx2, tby2);
764 }
765
766 void endtoolbox(void)
767 {
768         short mval[2];
769         
770         tbox_getmouse(mval);
771         if(mval[0]>tbx1 && mval[0]<tbx2)
772                 if(mval[1]>tby1 && mval[1]<tby2) {
773                         tbmemx= mval[0]-(tbx1);
774                         tbmemy= mval[1]-(tby1);
775         }
776         
777         endpupdraw();
778 }
779
780
781 void tbox_embossbox(short x1, short y1, short x2, short y2, short type) 
782 /* type: 0=menu, 1=menusel, 2=topic, 3=topicsel */
783 {
784         
785         if(type==0) {
786                 glColor3ub(160, 160, 160);
787                 glRects(x1+1, y1+1, x2-1, y2-1);
788         }
789         if(type==1) {
790                 glColor3ub(50, 50, 100);
791                 glRects(x1+1, y1+1, x2-1, y2-1);
792         }
793         if(type==2) {
794                 glColor3ub(190, 190, 190);
795                 glRects(x1+1, y1+1, x2-1, y2-1);
796         }
797         if(type==3) {
798                 cpack(0xc07070);
799                 glRects(x1+1, y1+1, x2-1, y2-1);
800         }
801         
802         if(type & 1) cpack(0xFFFFFF);
803         else cpack(0x0);
804 }
805
806
807 void tbox_drawelem_body( int x, int y, int type)
808 {
809         int x1 = 0, y1, x2 = 0, y2;
810         
811         if(x==0) {
812                 x1= tbx1; x2= tbx1+TBOXXL;
813         }
814         else if(x==1) {
815                 x1= tbx1+TBOXXL;
816                 x2= x1+ TBOXXR-1;
817         }
818         
819         y1= tby1+ (TBOXEL-y-1)*TBOXH;
820         y2= y1+TBOXH-1;
821         
822         tbox_embossbox(x1, y1, x2, y2, type);
823         
824 }
825
826 void tbox_drawelem_text( int x, int y, int type)
827 {
828         int x1 = 0, y1, x2 = 0, y2, len1, len2;
829         
830         if(x==0) {
831                 x1= tbx1; x2= tbx1+TBOXXL;
832         }
833         else if(x==1) {
834                 x1= tbx1+TBOXXL;
835                 x2= x1+ TBOXXR-1;
836         }
837         
838         y1= tby1+ (TBOXEL-y-1)*TBOXH;
839         y2= y1+TBOXH-1;
840         
841         if(type==0 || type==2) {
842                 ColorFunc(TBOXBLACK);
843         }
844         else {
845                 glColor3ub(240, 240, 240);
846         }
847         
848         /* text */
849         tbox_setinfo(x, y);
850         if(tbstr && tbstr[0]) {
851                 len1= 5+BMF_GetStringWidth(G.font, tbstr);
852                 if(keystr) len2= 5+BMF_GetStringWidth(G.font, keystr); else len2= 0;
853                 
854                 while(len1>0 && (len1+len2+5>x2-x1) ) {
855                         tbstr[strlen(tbstr)-1]= 0;
856                         len1= BMF_GetStringWidth(G.font, tbstr);
857                 }
858                 
859                 glRasterPos2i(x1+5, y1+tbfontyofs);
860                 BIF_DrawString(G.font, tbstr, (U.transopts & USER_TR_MENUS));
861                 
862                 if(keystr && keystr[0]) {
863                         if(type & 1) {
864                                 ColorFunc(TBOXBLACK);
865         
866                                 glRecti(x2-len2-2,  y1+2,  x2-3,  y2-2);
867                                 ColorFunc(TBOXWHITE);
868                                 glRasterPos2i(x2-len2,  y1+tbfontyofs);
869                                 BIF_DrawString(G.font, keystr, (U.transopts & USER_TR_MENUS));
870                         }
871                         else {
872                                 ColorFunc(TBOXBLACK);
873                                 glRasterPos2i(x2-len2,  y1+tbfontyofs);
874                                 BIF_DrawString(G.font, keystr, (U.transopts & USER_TR_MENUS));
875                         }
876                 }
877         }
878 }
879
880
881 void tbox_drawelem(x, y, type)
882 int x, y, type; 
883 {
884         /* type: 0=menu, 1=menusel, 2=topic, 3=topicsel */
885
886         tbox_drawelem_body(x, y, type);
887         tbox_drawelem_text(x, y, type);
888         
889 }
890
891 void tbox_getactive(x, y)
892 int *x, *y;
893 {
894         short mval[2];
895         
896         tbox_getmouse(mval);
897         
898         mval[0]-=tbx1;
899         if(mval[0]<TBOXXL) *x= 0;
900         else *x= 1;
901         
902         *y= mval[1]-tby1;
903         *y/= TBOXH;
904         *y= TBOXEL- *y-1;
905         if(*y<0) *y= 0;
906         if(*y>TBOXEL-1) *y= TBOXEL-1;
907         
908 }
909
910 void drawtoolbox(void)
911 {
912         int x, y, actx, acty, type;
913
914         tbox_getactive(&actx, &acty);
915
916         /* background */
917         for(x=0; x<2; x++) {
918                 
919                 for(y=0; y<TBOXEL; y++) {
920                         
921                         if(x==0) type= 0; 
922                         else type= 2;
923                         
924                         if(actx==x && acty==y) type++;
925                         if(type==0) {
926                                 if(tbmain==y) type= 1;
927                         }
928                         
929                         tbox_drawelem_body(x, y, type);
930                         
931                 }
932         }
933
934         /* text */
935         for(x=0; x<2; x++) {
936                 
937                 for(y=0; y<TBOXEL; y++) {
938                         
939                         if(x==0) type= 0; 
940                         else type= 2;
941                         
942                         if(actx==x && acty==y) type++;
943                         if(type==0) {
944                                 if(tbmain==y) type= 1;
945                         }
946                         
947                         tbox_drawelem_text(x, y, type);
948                         
949                 }
950         }
951         glFlush();              /* for geforce, to show it in the frontbuffer */
952
953 }
954
955
956 void toolbox(void)
957 {
958         int actx, acty, y;
959         unsigned short event;
960         short val, mval[2], xo= -1, yo=0;
961         
962         bgntoolbox();
963         glColor3ub(0xB0, 0xB0, 0xB0);
964         uiDrawMenuBox((float)tbx1, (float)tby1-1, (float)tbx2, (float)tby2, 0);
965         drawtoolbox();
966         
967         /* 
968          *      The active window will be put back in the queue.
969          */
970
971         while(1) {
972                 event= extern_qread(&val);
973                 if(event) {
974                         switch(event) {
975                                 case LEFTMOUSE: case MIDDLEMOUSE: case RIGHTMOUSE: case RETKEY: case PADENTER:
976                                         if(val==1) {
977                                                 tbox_getactive(&actx, &acty);
978                                                 tbox_setinfo(actx, acty);
979                                                 
980                                                 if(event==RIGHTMOUSE) {
981                                                         if(addmode) {
982                                                                 addmode= 0;
983                                                                 drawtoolbox();
984                                                         }
985                                                 }
986                                                 else if(tbstr1 && tbstr1[0]=='>') {
987                                                         addmode= tbval;
988                                                         drawtoolbox();
989                                                 }
990                                                 else {
991                                                         endtoolbox();
992                                                         tbox_execute();
993                                                         return;
994                                                 }
995                                         }
996                                         break;
997                                 case ESCKEY:
998                                         /* alt keys: to prevent conflicts with over-draw and stow/push/pop at sgis */
999 #ifndef MAART
1000 /* Temporary for making screen dumps (Alt+PrtSc) */
1001                                 case LEFTALTKEY:
1002                                 case RIGHTALTKEY:
1003 #endif /* MAART */
1004                                         if(val) endtoolbox();
1005                                         return;
1006                         }
1007                 }
1008                 
1009                 tbox_getmouse(mval);
1010                 if(mval[0]<tbx1-10 || mval[0]>tbx2+10 || mval[1]<tby1-10 || mval[1]>tby2+10) break;
1011                 
1012                 tbox_getactive(&actx, &acty);
1013                 
1014                 /* mouse handling and redraw */
1015                 if(xo!=actx || yo!=acty) {
1016                         if(actx==0) {
1017                                 if (acty==0) addmode=0;
1018                                 
1019                                 tbox_drawelem(0, tbmain, 0);
1020                                 tbox_drawelem(0, acty, 1);
1021                                 
1022                                 tbmain= acty;
1023                                 addmode= 0;
1024                                 for(y=0; y<TBOXEL; y++) tbox_drawelem(1, y, 2);
1025                         }
1026                         else if(xo> -1) {
1027                                 if(xo==0) tbox_drawelem(xo, yo, 1);
1028                                 else tbox_drawelem(xo, yo, 2);
1029                                 tbox_drawelem(actx, acty, 3);
1030                         }
1031                         
1032                         glFlush();              /* for geforce, to show it in the frontbuffer */
1033                         
1034                         xo= actx;
1035                         yo= acty;
1036                 }
1037         }
1038
1039         endtoolbox();
1040 }
1041
1042 /* ************************************  */
1043
1044 /* this va_ stuff allows printf() style codes in these menus */
1045
1046 static int vconfirm(char *title, char *itemfmt, va_list ap)
1047 {
1048         char *s, buf[512];
1049
1050         s= buf;
1051         if (title) s+= sprintf(s, "%s%%t|", title);
1052         vsprintf(s, itemfmt, ap);
1053         
1054         return (pupmenu(buf)>=0);
1055 }
1056
1057 static int confirm(char *title, char *itemfmt, ...)
1058 {
1059         va_list ap;
1060         int ret;
1061         
1062         va_start(ap, itemfmt);
1063         ret= vconfirm(title, itemfmt, ap);
1064         va_end(ap);
1065         
1066         return ret;
1067 }
1068
1069 int okee(char *str, ...)
1070 {
1071         va_list ap;
1072         int ret;
1073         char titlestr[256];
1074         
1075         sprintf(titlestr, "OK? %%i%d", ICON_HELP);
1076         
1077         va_start(ap, str);
1078         ret= vconfirm(titlestr, str, ap);
1079         va_end(ap);
1080         
1081         return ret;
1082 }
1083
1084 void notice(char *str, ...)
1085 {
1086         va_list ap;
1087         
1088         va_start(ap, str);
1089         vconfirm(NULL, str, ap);
1090         va_end(ap);
1091 }
1092
1093 void error(char *fmt, ...)
1094 {
1095         va_list ap;
1096         char nfmt[256];
1097         char titlestr[256];
1098         
1099         sprintf(titlestr, "Error %%i%d", ICON_ERROR);
1100         
1101         sprintf(nfmt, "%s", fmt);
1102         
1103         va_start(ap, fmt);
1104         if (G.background || !G.curscreen || (G.rendering)) {
1105                 vprintf(nfmt, ap);
1106                 printf("\n");
1107         } else {
1108                 vconfirm(titlestr, nfmt, ap);
1109         }
1110         va_end(ap);
1111 }
1112
1113 int saveover(char *file)
1114 {
1115         return (!BLI_exists(file) || confirm("Save over", file));
1116 }
1117
1118 /* ****************** EXTRA STUFF **************** */
1119
1120 short button(short *var, short min, short max, char *str)
1121 {
1122         uiBlock *block;
1123         ListBase listb={0, 0};
1124         short x1,y1;
1125         short mval[2], ret=0;
1126
1127         if(min>max) min= max;
1128
1129         getmouseco_sc(mval);
1130         
1131         if(mval[0]<150) mval[0]=150;
1132         if(mval[1]<30) mval[1]=30;
1133         if(mval[0]>G.curscreen->sizex) mval[0]= G.curscreen->sizex-10;
1134         if(mval[1]>G.curscreen->sizey) mval[1]= G.curscreen->sizey-10;
1135
1136         block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
1137         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_ENTER_OK);
1138
1139         x1=mval[0]-150; 
1140         y1=mval[1]-20; 
1141         
1142         uiDefButS(block, NUM, 0, str,   (short)(x1+5),(short)(y1+10),125,20, var,(float)min,(float)max, 0, 0, "");
1143         uiDefBut(block, BUT, 1, "OK",   (short)(x1+136),(short)(y1+10),25,20, NULL, 0, 0, 0, 0, "");
1144
1145         uiBoundsBlock(block, 5);
1146
1147         ret= uiDoBlocks(&listb, 0);
1148
1149         if(ret==UI_RETURN_OK) return 1;
1150         return 0;
1151 }
1152
1153 short sbutton(char *var, float min, float max, char *str)
1154 {
1155         uiBlock *block;
1156         ListBase listb={0, 0};
1157         short x1,y1;
1158         short mval[2], ret=0;
1159
1160         if(min>max) min= max;
1161
1162         getmouseco_sc(mval);
1163         
1164         if(mval[0]<150) mval[0]=150;
1165         if(mval[1]<30) mval[1]=30;
1166         if(mval[0]>G.curscreen->sizex) mval[0]= G.curscreen->sizex-10;
1167         if(mval[1]>G.curscreen->sizey) mval[1]= G.curscreen->sizey-10;
1168
1169         block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
1170         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_ENTER_OK);
1171
1172         x1=mval[0]-150; 
1173         y1=mval[1]-20; 
1174         
1175         uiDefButC(block, TEX, 0, str,   x1+5,y1+10,125,20, var,(float)min,(float)max, 0, 0, "");
1176         uiDefBut(block, BUT, 1, "OK",   x1+136,y1+10,25,20, NULL, 0, 0, 0, 0, "");
1177
1178         uiBoundsBlock(block, 5);
1179
1180         ret= uiDoBlocks(&listb, 0);
1181
1182         if(ret==UI_RETURN_OK) return 1;
1183         return 0;
1184 }
1185
1186 short fbutton(float *var, float min, float max, float a1, float a2, char *str)
1187 {
1188         uiBlock *block;
1189         ListBase listb={0, 0};
1190         short x1,y1;
1191         short mval[2], ret=0;
1192
1193         if(min>max) min= max;
1194
1195         getmouseco_sc(mval);
1196         
1197         if(mval[0]<150) mval[0]=150;
1198         if(mval[1]<30) mval[1]=30;
1199         if(mval[0]>G.curscreen->sizex) mval[0]= G.curscreen->sizex-10;
1200         if(mval[1]>G.curscreen->sizey) mval[1]= G.curscreen->sizey-10;
1201
1202         block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
1203         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
1204
1205         x1=mval[0]-150; 
1206         y1=mval[1]-20; 
1207         
1208         uiDefButF(block, NUM, 0, str,(short)(x1+5),(short)(y1+10),125,20, var, min, max, a1, a2, "");
1209         uiDefBut(block, BUT, 1, "OK",(short)(x1+136),(short)(y1+10), 35, 20, NULL, 0, 0, 0, 0, "");
1210
1211         uiBoundsBlock(block, 2);
1212
1213         ret= uiDoBlocks(&listb, 0);
1214
1215         if(ret==UI_RETURN_OK) return 1;
1216         return 0;
1217 }
1218
1219 int movetolayer_buts(unsigned int *lay)
1220 {
1221         uiBlock *block;
1222         ListBase listb={0, 0};
1223         int dx, dy, a, x1, y1, sizex=160, sizey=30;
1224         short pivot[2], mval[2], ret=0;
1225         
1226         if(G.vd->localview) {
1227                 error("Not in localview ");
1228                 return ret;
1229         }
1230
1231         getmouseco_sc(mval);
1232
1233         pivot[0]= CLAMPIS(mval[0], (sizex+10), G.curscreen->sizex-30);
1234         pivot[1]= CLAMPIS(mval[1], (sizey/2)+10, G.curscreen->sizey-(sizey/2)-10);
1235         
1236         if (pivot[0]!=mval[0] || pivot[1]!=mval[1])
1237                 warp_pointer(pivot[0], pivot[1]);
1238
1239         mywinset(G.curscreen->mainwin);
1240         
1241         x1= pivot[0]-sizex+10; 
1242         y1= pivot[1]-sizey/2; 
1243
1244         block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
1245         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT|UI_BLOCK_ENTER_OK);
1246         
1247         dx= (sizex-5)/12;
1248         dy= sizey/2;
1249         
1250         /* buttons have 0 as return event, to prevent menu to close on hotkeys */
1251         
1252         uiBlockBeginAlign(block);
1253         for(a=0; a<5; a++) 
1254                 uiDefButBitI(block, TOGR, 1<<a, 0, "",(short)(x1+a*dx),(short)(y1+dy),(short)dx,(short)dy, lay, 0, 0, 0, 0, "");
1255         for(a=0; a<5; a++) 
1256                 uiDefButBitI(block, TOGR, 1<<(a+10), 0, "",(short)(x1+a*dx),(short)y1,(short)dx,(short)dy, lay, 0, 0, 0, 0, "");
1257         x1+= 5;
1258         
1259         uiBlockBeginAlign(block);
1260         for(a=5; a<10; a++) 
1261                 uiDefButBitI(block, TOGR, 1<<a, 0, "",(short)(x1+a*dx),(short)(y1+dy),(short)dx,(short)dy, lay, 0, 0, 0, 0, "");
1262         for(a=5; a<10; a++) 
1263                 uiDefButBitI(block, TOGR, 1<<(a+10), 0, "",(short)(x1+a*dx),(short)y1,(short)dx,(short)dy, lay, 0, 0, 0, 0, "");
1264         uiBlockEndAlign(block);
1265
1266         x1-= 5;
1267         uiDefBut(block, BUT, 1, "OK", (short)(x1+10*dx+10), (short)y1, (short)(3*dx), (short)(2*dy), NULL, 0, 0, 0, 0, "");
1268
1269         uiBoundsBlock(block, 2);
1270
1271         ret= uiDoBlocks(&listb, 0);
1272
1273         if(ret==UI_RETURN_OK) return 1;
1274         return 0;
1275 }
1276
1277 int movetolayer_short_buts(short *lay)
1278 {
1279         uiBlock *block;
1280         ListBase listb={0, 0};
1281         int dx, dy, a, x1, y1, sizex=120, sizey=30;
1282         short pivot[2], mval[2], ret=0;
1283         
1284         getmouseco_sc(mval);
1285         
1286         pivot[0]= CLAMPIS(mval[0], (sizex+10), G.curscreen->sizex-30);
1287         pivot[1]= CLAMPIS(mval[1], (sizey/2)+10, G.curscreen->sizey-(sizey/2)-10);
1288         
1289         if (pivot[0]!=mval[0] || pivot[1]!=mval[1])
1290                 warp_pointer(pivot[0], pivot[1]);
1291         
1292         mywinset(G.curscreen->mainwin);
1293         
1294         x1= pivot[0]-sizex+10; 
1295         y1= pivot[1]-sizey/2; 
1296         
1297         block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
1298         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT|UI_BLOCK_ENTER_OK);
1299         
1300         dx= (sizex-5)/10;
1301         dy= sizey/2;
1302         
1303         /* buttons have 0 as return event, to prevent menu to close on hotkeys */
1304         
1305         uiBlockBeginAlign(block);
1306         for(a=0; a<8; a++) 
1307                 uiDefButBitS(block, TOGR, 1<<a, 0, "",(short)(x1+a*dx),(short)(y1+dy),(short)dx,(short)dy, lay, 0, 0, 0, 0, "");
1308         for(a=0; a<8; a++) 
1309                 uiDefButBitS(block, TOGR, 1<<(a+8), 0, "",(short)(x1+a*dx),(short)y1,(short)dx,(short)dy, lay, 0, 0, 0, 0, "");
1310         
1311         uiBlockEndAlign(block);
1312         
1313         x1-= 5;
1314         uiDefBut(block, BUT, 1, "OK", (short)(x1+8*dx+10), (short)y1, (short)(3*dx), (short)(2*dy), NULL, 0, 0, 0, 0, "");
1315         
1316         uiBoundsBlock(block, 2);
1317         
1318         ret= uiDoBlocks(&listb, 0);
1319         
1320         if(ret==UI_RETURN_OK) return 1;
1321         return 0;
1322 }
1323
1324
1325
1326 /* ********************** CLEVER_NUMBUTS ******************** */
1327
1328 #define MAXNUMBUTS      24
1329
1330 VarStruct numbuts[MAXNUMBUTS];
1331 void *numbpoin[MAXNUMBUTS];
1332 int numbdata[MAXNUMBUTS];
1333
1334 void draw_numbuts_tip(char *str, int x1, int y1, int x2, int y2)
1335 {
1336         static char *last=0;    /* avoid ugly updates! */
1337         int temp;
1338         
1339         if(str==last) return;
1340         last= str;
1341         if(str==0) return;
1342
1343         glColor3ub(160, 160, 160); /* MGREY */
1344         glRecti(x1+4,  y2-36,  x2-4,  y2-16);
1345
1346         cpack(0x0);
1347
1348         temp= 0;
1349         while( BIF_GetStringWidth(G.fonts, str+temp, (U.transopts & USER_TR_BUTTONS))>(x2 - x1-24)) temp++;
1350         glRasterPos2i(x1+16, y2-30);
1351         BIF_DrawString(G.fonts, str+temp, (U.transopts & USER_TR_BUTTONS));
1352 }
1353
1354 int do_clever_numbuts(char *name, int tot, int winevent)
1355 {
1356         ListBase listb= {NULL, NULL};
1357         uiBlock *block;
1358         VarStruct *varstr;
1359         int a, sizex, sizey, x1, y2;
1360         short mval[2], event;
1361         
1362         /* Clear all events so tooltips work, this is not ideal and
1363         only needed because calls from the menu still have some events
1364         left over when do_clever_numbuts is called.
1365         Calls from keyshortcuts do not have this problem.*/
1366         ScrArea *sa;
1367         BWinEvent temp_bevt;
1368         for (sa= G.curscreen->areabase.first; sa; sa= sa->next) {
1369                 if(sa->win) {
1370                         while( bwin_qread( sa->win, &temp_bevt ) ) {}
1371                 }
1372                 if(sa->headwin) {
1373                         while( bwin_qread( sa->headwin, &temp_bevt ) ) {}
1374                 }
1375         }
1376         /* Done clearing events */
1377         
1378         
1379         if(tot<=0 || tot>MAXNUMBUTS) return 0;
1380
1381         getmouseco_sc(mval);
1382
1383         /* size */
1384         sizex= 235;
1385         sizey= 30+20*(tot+1);
1386         
1387         /* center */
1388         if(mval[0]<sizex/2) mval[0]=sizex/2;
1389         if(mval[1]<sizey/2) mval[1]=sizey/2;
1390         if(mval[0]>G.curscreen->sizex -sizex/2) mval[0]= G.curscreen->sizex -sizex/2;
1391         if(mval[1]>G.curscreen->sizey -sizey/2) mval[1]= G.curscreen->sizey -sizey/2;
1392
1393         mywinset(G.curscreen->mainwin);
1394         
1395         x1= mval[0]-sizex/2; 
1396         y2= mval[1]+sizey/2;
1397         
1398         block= uiNewBlock(&listb, "numbuts", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
1399         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_ENTER_OK);
1400         
1401         /* WATCH IT: TEX BUTTON EXCEPTION */
1402         /* WARNING: ONLY A SINGLE BIT-BUTTON POSSIBLE: WE WORK AT COPIED DATA! */
1403         
1404         BIF_ThemeColor(TH_MENU_TEXT); /* makes text readable on dark theme */
1405         
1406         uiDefBut(block, LABEL, 0, name, (short)(x1+15), (short)(y2-35), (short)(sizex-60), 19, 0, 1.0, 0.0, 0, 0, ""); 
1407         
1408         /*
1409         if(name[0]=='A' && name[7]=='O') {
1410                 y2 -= 20;
1411                 uiDefBut(block, LABEL, 0, "Rotations in degrees!",      (short)(x1+15), (short)(y2-35), (short)(sizex-60), 19, 0, 0.0, 0.0, 0, 0, "");
1412         }*/
1413         
1414         uiBlockBeginAlign(block);
1415         varstr= &numbuts[0];
1416         for(a=0; a<tot; a++, varstr++) {
1417                 
1418                 if(varstr->type==TEX) {
1419                         uiDefBut(block, TEX, 0, varstr->name,(short)(x1+15),(short)(y2-55-20*a),(short)(sizex-60), 19, numbpoin[a], varstr->min, varstr->max, 0, 0, varstr->tip);
1420                 }
1421                 else  {
1422                         
1423                         if(varstr->type==LABEL) /* dont include the label when rounding the buttons */
1424                                 uiBlockEndAlign(block);
1425                         
1426                         uiDefBut(block, varstr->type, 0, varstr->name,(short)(x1+15),(short)(y2-55-20*a), (short)(sizex-60), 19, &(numbdata[a]), varstr->min, varstr->max, 100, 0, varstr->tip);
1427                         
1428                         if(varstr->type==LABEL)
1429                                 uiBlockBeginAlign(block);
1430                 }
1431
1432                 
1433         }
1434         uiBlockEndAlign(block);
1435
1436         uiDefBut(block, BUT, 4000, "OK", (short)(x1+sizex-40),(short)(y2-35-20*a), 25, (short)(sizey-50), 0, 0, 0, 0, 0, "OK: Assign Values");
1437         
1438         uiBoundsBlock(block, 5);
1439
1440         event= uiDoBlocks(&listb, 0);
1441
1442         areawinset(curarea->win);
1443         
1444         if(event & UI_RETURN_OK) {
1445                 
1446                 varstr= &numbuts[0];
1447                 for(a=0; a<tot; a++, varstr++) {
1448                         if(varstr->type==TEX);
1449                         else if ELEM( (varstr->type & BUTPOIN), FLO, INT ) memcpy(numbpoin[a], numbdata+a, 4);
1450                         else if((varstr->type & BUTPOIN)==SHO ) *((short *)(numbpoin[a]))= *( (short *)(numbdata+a));
1451                         
1452                         /*
1453                         if( strncmp(varstr->name, "Rot", 3)==0 ) {
1454                                 float *fp;
1455                                 
1456                                 fp= numbpoin[a];
1457                                 fp[0]= M_PI*fp[0]/180.0;
1458                         }*/
1459                 }
1460                 
1461                 if(winevent) {
1462                         ScrArea *sa;
1463                 
1464                         sa= G.curscreen->areabase.first;
1465                         while(sa) {
1466                                 if(sa->spacetype==curarea->spacetype) addqueue(sa->win, winevent, 1);
1467                                 sa= sa->next;
1468                         }
1469                 }
1470                 
1471                 return 1;
1472         }
1473         return 0;
1474 }
1475
1476 void add_numbut(int nr, int type, char *str, float min, float max, void *poin, char *tip)
1477 {
1478         if(nr>=MAXNUMBUTS) return;
1479
1480         numbuts[nr].type= type;
1481         strcpy(numbuts[nr].name, str);
1482         numbuts[nr].min= min;
1483         numbuts[nr].max= max;
1484         if(tip) 
1485                 strcpy(numbuts[nr].tip, tip);
1486         else
1487                 strcpy(numbuts[nr].tip, "");
1488         
1489         
1490         /*WATCH: TEX BUTTON EXCEPTION */
1491         
1492         numbpoin[nr]= poin;
1493         
1494         if ELEM( (type & BUTPOIN), FLO, INT ) memcpy(numbdata+nr, poin, 4);
1495         if((type & BUTPOIN)==SHO ) *((short *)(numbdata+nr))= *( (short *)poin);
1496         
1497         /* if( strncmp(numbuts[nr].name, "Rot", 3)==0 ) {
1498                 float *fp;
1499                 
1500                 fp= (float *)(numbdata+nr);
1501                 fp[0]= 180.0*fp[0]/M_PI;
1502         } */
1503
1504 }
1505
1506 void clever_numbuts(void)
1507 {
1508         
1509         if(curarea->spacetype==SPACE_VIEW3D) {
1510                 // panel now
1511         }
1512         else if(curarea->spacetype==SPACE_NLA){
1513                 // panel now
1514         }
1515         else if(curarea->spacetype==SPACE_IPO) {
1516                 // panel now
1517         }
1518         else if(curarea->spacetype==SPACE_SEQ) {
1519                 // panel now
1520         }
1521         else if(curarea->spacetype==SPACE_IMAGE) {
1522                 // panel now
1523         }
1524         else if(curarea->spacetype==SPACE_IMASEL) {
1525                 clever_numbuts_imasel();
1526         }
1527         else if(curarea->spacetype==SPACE_OOPS) {
1528                 clever_numbuts_oops();
1529         }
1530         else if(curarea->spacetype==SPACE_ACTION){
1531                 // in its own queue
1532         }
1533         else if(curarea->spacetype==SPACE_FILE) {
1534                 clever_numbuts_filesel();
1535         }
1536 }
1537
1538
1539 void replace_names_but(void)
1540 {
1541         Image *ima= G.main->image.first;
1542         short len, tot=0;
1543         char old[64], new[64], temp[80];
1544         
1545         strcpy(old, "/");
1546         strcpy(new, "/");
1547         
1548         add_numbut(0, TEX, "Old:", 0, 63, old, 0);
1549         add_numbut(1, TEX, "New:", 0, 63, new, 0);
1550
1551         if (do_clever_numbuts("Replace image name", 2, REDRAW) ) {
1552                 
1553                 len= strlen(old);
1554                 
1555                 while(ima) {
1556                         
1557                         if(strncmp(old, ima->name, len)==0) {
1558                                 
1559                                 strcpy(temp, new);
1560                                 strcat(temp, ima->name+len);
1561                                 BLI_strncpy(ima->name, temp, sizeof(ima->name));
1562                                 
1563                                 if(ima->ibuf) IMB_freeImBuf(ima->ibuf);
1564                                 ima->ibuf= 0;
1565                                 ima->ok= 1;
1566                                 
1567                                 tot++;
1568                         }
1569                         
1570                         ima= ima->id.next;
1571                 }
1572
1573                 notice("Replaced %d names", tot);
1574         }
1575         
1576 }
1577
1578
1579 /* ********************** NEW TOOLBOX ********************** */
1580
1581 ListBase tb_listb= {NULL, NULL};
1582
1583 #define TB_TAB  256
1584 #define TB_ALT  512
1585 #define TB_CTRL 1024
1586 #define TB_PAD  2048
1587 #define TB_SHIFT 4096
1588
1589 typedef struct TBitem {
1590         int icon;
1591         char *name;
1592         int retval;
1593         void *poin;
1594 } TBitem;
1595
1596 static void tb_do_hotkey(void *arg, int event)
1597 {
1598         unsigned short i, key=0;
1599         unsigned short qual[] = { 0,0,0,0 };
1600         
1601         if(event & TB_CTRL) {
1602                 qual[0] = LEFTCTRLKEY;
1603                 event &= ~TB_CTRL;
1604         }
1605         if(event & TB_ALT) {
1606                 qual[1] = LEFTALTKEY;
1607                 event &= ~TB_ALT;
1608         }
1609         if(event & TB_SHIFT) {
1610                 qual[2] = LEFTSHIFTKEY;
1611                 event &= ~TB_SHIFT;
1612         }
1613         
1614         if(event & TB_TAB) key= TABKEY;
1615         else if(event & TB_PAD) {
1616                 event &= ~TB_PAD;
1617                 switch(event) {
1618                 case '0': key= PAD0; break;
1619                 case '5': key= PAD5; break;
1620                 case '/': key= PADSLASHKEY; break;
1621                 case '.': key= PADPERIOD; break;
1622                 case '*': key= PADASTERKEY; break;
1623                 case 'h': key= HOMEKEY; break;
1624                 case 'u': key= PAGEUPKEY; break;
1625                 case 'd': key= PAGEDOWNKEY; break;
1626                 }
1627         }
1628         else asciitoraw(event, &key, &qual[3]);
1629
1630         for (i=0;i<4;i++)
1631         {
1632                 if(qual[i]) mainqenter(qual[i], 1);
1633         }
1634         mainqenter(key, 1);
1635         mainqenter(key, 0);
1636         mainqenter(EXECUTE, 1);
1637
1638         for (i=0;i<4;i++)
1639         {
1640                 if(qual[i]) mainqenter(qual[i], 0);
1641         }
1642 }
1643
1644 /* *************Select ********** */
1645
1646 static TBitem tb_object_select_layer1_5[]= {
1647 {       0, "1",         1, NULL},
1648 {       0, "2",         2, NULL},
1649 {       0, "3",         3, NULL},
1650 {       0, "4",         4, NULL},
1651 {       0, "5",         5, NULL},
1652 {  -1, "",              0, do_view3d_select_object_layermenu}};
1653
1654 static TBitem tb_object_select_layer6_10[]= {
1655 {       0, "6",         6, NULL},
1656 {       0, "7",         7, NULL},
1657 {       0, "8",         8, NULL},
1658 {       0, "9",         9, NULL},
1659 {       0, "10",        10, NULL},
1660 {  -1, "",              0, do_view3d_select_object_layermenu}};
1661
1662 static TBitem tb_object_select_layer11_15[]= {
1663 {       0, "11",        11, NULL},
1664 {       0, "12",        12, NULL},
1665 {       0, "13",        13, NULL},
1666 {       0, "14",        14, NULL},
1667 {       0, "15",        15, NULL},
1668 {  -1, "",              0, do_view3d_select_object_layermenu}};
1669
1670 static TBitem tb_object_select_layer16_20[]= {
1671 {       0, "16",        16, NULL},
1672 {       0, "17",        17, NULL},
1673 {       0, "18",        18, NULL},
1674 {       0, "19",        19, NULL},
1675 {       0, "20",        20, NULL},
1676 {  -1, "",              0, do_view3d_select_object_layermenu}};
1677
1678 static TBitem tb_object_select_layer[]= {
1679 {       0, "Layers 1-5",        0,              tb_object_select_layer1_5},
1680 {       0, "Layers 6-10",       0,              tb_object_select_layer6_10},
1681 {       0, "Layers 11-15",      0,              tb_object_select_layer11_15},
1682 {       0, "Layers 16-20",      0,              tb_object_select_layer16_20},
1683 {  -1, "",                      0, tb_do_hotkey}};
1684
1685 static TBitem tb_object_select_type[]= {
1686 {       0, "Mesh",              1, NULL},
1687 {       0, "Curve",     2, NULL},
1688 {       0, "Surface",   3, NULL},
1689 {       0, "Meta",              4, NULL},
1690 {       0, "SEPR",              0, NULL},
1691 {       0, "Armature",  5, NULL},
1692 {       0, "Lattice",   6, NULL},
1693 {       0, "Text",              7, NULL},
1694 {       0, "Empty",     8, NULL},
1695 {       0, "SEPR",              0, NULL},
1696 {       0, "Camera",    9, NULL},
1697 {       0, "Lamp",              10, NULL},
1698 {  -1, "",                      0, do_view3d_select_object_typemenu}};
1699
1700 static TBitem tb_object_select_linked[]= {
1701 {       0, "Object Ipo|Shift L, 1",     1, NULL},
1702 {       0, "ObData|Shift L, 2",         2, NULL},
1703 {       0, "Material|Shift L, 3",       3, NULL},
1704 {       0, "Texture|Shift L, 4",        4, NULL},
1705 {  -1, "",                      0, do_view3d_select_object_linkedmenu}};
1706
1707 static TBitem tb_object_select_grouped[]= {
1708 {       0, "Children|Shift G, 1",       1, NULL},
1709 {       0, "Immediate Children|Shift G, 2",     2, NULL},
1710 {       0, "Parent|Shift G, 3",         3, NULL},
1711 {       0, "Objects on Shared Layers|Shift G, 4",       4, NULL},
1712 {  -1, "",                      0, do_view3d_select_object_groupedmenu}};
1713
1714 static TBitem tb_object_select[]= {
1715 {       0, "Border Select|B",   0, NULL},
1716 {       0, "SEPR",                              0, NULL},
1717 {       0, "Select/Deselect All|A",     1, NULL},
1718 {       0, "Inverse",                   2, NULL},
1719 {       0, "Select All by Layer",       0,              tb_object_select_layer},
1720 {       0, "Select All by Type",        0,              tb_object_select_type},
1721 {       0, "SEPR",                              0, NULL},
1722 {       0, "Linked",    0,      tb_object_select_linked},
1723 {       0, "Grouped",   0,      tb_object_select_grouped},
1724 {  -1, "",                      0, do_view3d_select_objectmenu}};
1725
1726 static TBitem tb_mesh_select[]= {
1727 {       0, "Border Select|B",               0, NULL},
1728 {       0, "SEPR",                          0, NULL},
1729 {       0, "(De)select All|A",              2, NULL},
1730 {       0, "Inverse",                       3, NULL},
1731 {       0, "SEPR",                          0, NULL},
1732 {       0, "Random...",                             5, NULL},
1733 {       0, "Non-Manifold|Shift Ctrl Alt M", 9, NULL},
1734 {       0, "Sharp Edges|Shift Ctrl Alt S", 14, NULL},
1735 {       0, "Linked Flat Faces|Shift Ctrl Alt F", 15, NULL},
1736 {       0, "Triangles|Shift Ctrl Alt 3",    11, NULL},
1737 {       0, "Quads|Shift Ctrl Alt 4",        12, NULL},
1738 {       0, "Non-Triangles/Quads|Shift Ctrl Alt 5", 13, NULL},
1739 {       0, "SEPR",                          0, NULL},
1740 {       0, "More|Ctrl NumPad +",            7, NULL},
1741 {       0, "Less|Ctrl NumPad -",            8, NULL},
1742 {       0, "SEPR",                          0, NULL},
1743 {       0, "Linked Vertices|Ctrl L",        4, NULL},
1744 {  -1, "",                      0, do_view3d_select_meshmenu}};
1745
1746
1747 static TBitem tb_curve_select[]= {
1748 {       0, "Border Select|B",   0, NULL},
1749 {       0, "SEPR",                              0, NULL},
1750 {       0, "(De)select All|A",  2, NULL},
1751 {       0, "Inverse",                   3, NULL},
1752 {       0, "Row|Shift R",                       5, NULL},
1753 {  -1, "",                              0, do_view3d_select_curvemenu}};
1754
1755 static TBitem tb__select[]= {
1756 {       0, "Border Select|B",   'b', NULL},
1757 {       0, "(De)select All|A",  'a', NULL},
1758 {  -1, "",                      0, tb_do_hotkey}};
1759
1760
1761 /* *************Edit ********** */
1762
1763 static TBitem tb_edit[]= {
1764 {       0, "Exit Editmode|Tab",         TB_TAB, NULL},
1765 {  -1, "",                      0, tb_do_hotkey}};
1766
1767 static TBitem tb_curve_edit_seg[]= {
1768 {       0, "Subdivide|W, 1",            0, NULL},
1769 {       0, "Switch Direction|W, 2",     1, NULL},
1770 {  -1, "",                      0, do_view3d_edit_curve_segmentsmenu}};
1771
1772 static TBitem tb_curve_edit_cv[]= {
1773 {       0, "Tilt|T",    't', NULL},
1774 {       0, "Clear Tilt|Alt T",                  TB_ALT|'t', NULL},
1775 {       0, "Separate|P",        'p', NULL},
1776 {       0, "SEPR",                                                              0, NULL},
1777 {       0, "Automatic|Shift H",                 'H', NULL},
1778 {       0, "Toggle Free/Aligned|H",     'h', NULL},
1779 {       0, "Vector|V",                                  'v', NULL},
1780 {       0, "SEPR",                                                              0, NULL},
1781 {       0, "Make Vertex Parent|Ctrl P", TB_CTRL|'p', NULL},
1782 {       0, "Add Hook|Ctrl H",                   TB_CTRL|'h', NULL},
1783 {  -1, "",                      0, tb_do_hotkey}};
1784
1785
1786 static TBitem tb_curve_edit[]= {
1787 {       0, "Exit Editmode|Tab",         TB_TAB, NULL},
1788 {       0, "SEPR",                                                              0, NULL},
1789 {       0, "Extrude|E",                 'e',            NULL},
1790 {       0, "Duplicate|Shift D", 'D',            NULL},
1791 {       0, "Make Segment|F",    'f',            NULL},
1792 {       0, "Toggle Cyclic|C",   'c',            NULL},
1793 {       0, "Delete...|X",               'x',            NULL},
1794 {       0, "SEPR",                                                              0, NULL},
1795 {       0, "Control Points",    0,              tb_curve_edit_cv},
1796 {       0, "Segments",  0,              tb_curve_edit_seg},
1797 {  -1, "",                      0, tb_do_hotkey}};
1798
1799
1800 static TBitem tb_mesh_edit_vertex[]= {
1801 {       0, "Merge...|Alt M",            5, NULL},
1802 {       0, "Rip|V",                                     7, NULL},
1803 {       0, "Split|Y",                           4,              NULL},
1804 {       0, "Separate|P",                        3,              NULL},
1805 {       0, "SEPR",                                      0, NULL},
1806 {       0, "Smooth|W, 0",                       2, NULL},
1807 {       0, "Remove Doubles|W, 5",                       1, NULL},
1808 {       0, "SEPR",                                      0, NULL},
1809 {       0, "Make Vertex Parent|Ctrl P",         0, NULL},
1810 {       0, "Add Hook|Ctrl H",           6, NULL},
1811 {  -1, "",                      0, do_view3d_edit_mesh_verticesmenu}};
1812
1813 static TBitem tb_mesh_edit_edge[]= {
1814 {       0, "Make Edge/Face|F",                  5,              NULL},
1815 {       0, "SEPR",                                              0, NULL},
1816 {       0, "Bevel|W, Alt 1",                                    6,              NULL},
1817 {       0, "Loop Subdivide|Ctrl R",             4,              NULL},
1818 {       0, "Knife Subdivide...|Shift K",        3,              NULL},
1819 {       0, "SEPR",                                                              0, NULL},
1820 {       0, "Subdivide|W, 1",                    2,              NULL},
1821 {       0, "Subdivide Fractal|W, 2",    1,              NULL},
1822 {       0, "Subdivide Smooth|W, 3",             0,              NULL},
1823 {       0, "SEPR",                                                              0, NULL},
1824 {       0, "Mark Seam|Ctrl E",                  7,              NULL},
1825 {       0, "Clear Seam|Ctrl E",                 8,              NULL},
1826 {       0, "SEPR",                                                              0, NULL},
1827 {       0, "Crease SubSurf|Shift E",    9,              NULL},
1828 {       0, "SEPR",                                                              0, NULL},
1829 {       0, "Rotate Edge CW|Ctrl E",     10,             NULL},
1830 {       0, "Rotate Edge CCW|Ctrl E",    11,             NULL},
1831 {       0, "SEPR",                                                              0, NULL},
1832 {       0, "Slide Edge|Ctrl E", 12,             NULL},
1833 {       0, "Delete Edge Loop|X",        13,             NULL},
1834 {  -1, "",                      0, do_view3d_edit_mesh_edgesmenu}};
1835
1836 static TBitem tb_mesh_edit_face[]= {
1837 {       0, "Make Edge/Face|F",                  5,              NULL},
1838 {       0, "Fill|Shift F",                              0,              NULL},
1839 {       0, "Beautify Fill|Alt F",                       1,              NULL},
1840 {       0, "SEPR",                                      0, NULL},
1841 {       0, "Convert to Triangles|Ctrl T",       2,              NULL},
1842 {       0, "Convert to Quads|Alt J",            3,              NULL},
1843 {       0, "Flip Triangle Edges|Ctrl F",        4,              NULL},
1844 {       0, "Set Smooth|W, Alt 4",       6,              NULL},
1845 {       0, "Set Solid|W, Alt 5",        7,              NULL},
1846 {  -1, "",                      0, do_view3d_edit_mesh_facesmenu}};
1847
1848
1849 static TBitem tb_mesh_edit_normal[]= {
1850 {       0, "Recalculate Outside|Ctrl N",        2,              NULL},
1851 {       0, "Recalculate Inside|Ctrl Shift N",   1,              NULL},
1852 {       0, "SEPR",                                      0, NULL},
1853 {       0, "Flip|W, 9",                                 0,              NULL},
1854 {  -1, "",                      0, do_view3d_edit_mesh_normalsmenu}};
1855
1856 static TBitem tb_mesh_edit[]= {
1857 {       0, "Exit Editmode|Tab",         TB_TAB, NULL},
1858 {       0, "Undo|U",                    'u',            NULL},
1859 {       0, "Redo|Shift U",              'U',            NULL},
1860 {       0, "SEPR",                              0,                      NULL},
1861 {       0, "Extrude|E",                 'e',            NULL},
1862 {       0, "Duplicate|Shift D", 'D',            NULL},
1863 {       0, "Delete...|X",               'x',            NULL},
1864 {       0, "SEPR",                              0,                      NULL},
1865 {       0, "Vertices",          0,              tb_mesh_edit_vertex},
1866 {       0, "Edges",             0,              tb_mesh_edit_edge},
1867 {       0, "Faces",             0,              tb_mesh_edit_face},
1868 {       0, "Normals",           0,              tb_mesh_edit_normal},
1869 {  -1, "",                      0, tb_do_hotkey}};
1870
1871
1872 static TBitem tb_object_ipo[]= {
1873 {       0, "Show/Hide",         'k', NULL},
1874 {       0, "Select Next",       TB_PAD|'u', NULL},
1875 {       0, "Select Prev",       TB_PAD|'d', NULL},
1876 {  -1, "",                      0, tb_do_hotkey}};
1877
1878
1879 static TBitem tb_object_edit[]= {
1880 {       0, "Enter Editmode|Tab",        TB_TAB, NULL},
1881 {       0, "SEPR",                                                              0, NULL},
1882 {       0, "Duplicate|Shift D",                 'D',            NULL},
1883 {       0, "Duplicate Linked|Alt D",    TB_ALT|'d', NULL},
1884 {       0, "Delete|X",                                  'x',            NULL},
1885 {       0, "SEPR",                                                              0, NULL},
1886 {       0, "Object Keys",       0, tb_object_ipo},
1887 {  -1, "",                      0, tb_do_hotkey}};
1888
1889
1890 /* ************* Type  ********** */
1891
1892 static TBitem tb_obdata_hide[]= {
1893 {       0, "Show Hidden|Alt H",                 TB_ALT|'h',             NULL},
1894 {       0, "Hide Selected|H",                   'h',            NULL},
1895 {       0, "Hide Deselected|Shift H",   'H',            NULL},
1896 {  -1, "",                      0, tb_do_hotkey}};
1897
1898 static void tb_do_mesh(void *arg, int event){
1899         switch(event) {
1900         case 1: common_insertkey(); break;
1901         case 2: G.f ^= G_DRAWEDGES; break;
1902         case 3: G.f ^= G_DRAWFACES; break;
1903         case 4: G.f ^= G_DRAWNORMALS; break;
1904         case 5: flip_subdivison(OBACT, -1); break;
1905         }
1906         addqueue(curarea->win, REDRAW, 1);
1907 }
1908
1909 static TBitem tb_mesh[]= {
1910 {       0, "Insert Keyframe|I",                 1,              NULL},
1911 {       0, "SEPR",                                              0, NULL},
1912 {       0, "Show/Hide Edges",                   2,              NULL},
1913 {       0, "Show/Hide Faces",                   3,              NULL},
1914 {       0, "Show/Hide Normals",                 4,              NULL},
1915 {       0, "SEPR",                                              0,      NULL},
1916 {       0, "Subdivision Surface",               5,              NULL},
1917 {       0, "SEPR",                                              0, NULL},
1918 {       0, "Show/Hide Vertices",        0,              tb_obdata_hide},
1919 {  -1, "",                      0, tb_do_mesh}};
1920
1921 static TBitem tb_curve_hide[]= {
1922 {       0, "Show Hidden|Alt H",                 10,             NULL},
1923 {       0, "Hide Selected|H",                   11,             NULL},
1924 {  -1, "",                      0, do_view3d_edit_curve_showhidemenu}};
1925
1926
1927 static TBitem tb_curve[]= {
1928 {       0, "Insert Keyframe|I",                 'i',            NULL},
1929 {       0, "SEPR",                                              0, NULL},
1930 {       0, "Show/Hide Points",  0,              tb_curve_hide},
1931 {  -1, "",                      0, tb_do_hotkey}};
1932
1933 static TBitem tb_obdata[]= {
1934 {       0, "Duplicate|Shift D",                 'D',            NULL},
1935 {       0, "Delete|X",                                  'x',            NULL},
1936 {  -1, "",                      0, tb_do_hotkey}};
1937
1938 static TBitem tb_object_parent[]= {
1939 {       0, "Make Parent...|Ctrl P",             TB_CTRL|'p', NULL},
1940 {       0, "Clear Parent...|Alt P",             TB_ALT|'p', NULL},
1941 {  -1, "",                      0, tb_do_hotkey}};
1942
1943 static TBitem tb_object_track[]= {
1944 {       0, "Make Track|Ctrl T",                 TB_CTRL|'t', NULL},
1945 {       0, "Clear Track|Alt T",                 TB_ALT|'t', NULL},
1946 {  -1, "",                      0, tb_do_hotkey}};
1947
1948 static TBitem tb_object[]= {
1949 {       0, "Insert Keyframe|I",                 'i',            NULL},
1950 {       0, "SEPR",                                                              0, NULL},
1951 {       0, "Make Links...|Ctrl L",              TB_CTRL|'l', NULL},
1952 {       0, "Make Single User...|U",     'u',            NULL},
1953 {       0, "Copy Attributes...|Ctrl C", TB_CTRL|'c', NULL},
1954 {       0, "SEPR",                                                              0, NULL},
1955 {       0, "Parent",    0,              tb_object_parent},
1956 {       0, "Track",     0,              tb_object_track},
1957 {       0, "SEPR",                                                              0, NULL},
1958 {       0, "Boolean Operation|W",       'w', NULL},
1959 {       0, "Join Objects...|Ctrl J",    TB_CTRL|'j', NULL},
1960 {       0, "Convert Object Type...|Alt C",      TB_ALT|'c', NULL},
1961 {       0, "SEPR",                                                              0, NULL},
1962 {       0, "Move to Layer...|M",                'm', NULL},
1963 {  -1, "",                      0, tb_do_hotkey}};
1964
1965
1966 /* *************VIEW ********** */
1967
1968 static void tb_do_view_dt(void *arg, int event){
1969         G.vd->drawtype= event;
1970         addqueue(curarea->win, REDRAW, 1);
1971 }
1972
1973 static TBitem tb_view_dt[]= {
1974 {       ICON_BBOX, "Bounding Box",      1, NULL},
1975 {       ICON_WIRE, "Wireframe|Z",       2, NULL},
1976 {       ICON_SOLID, "Solid|Z",          3, NULL},
1977 {       ICON_SMOOTH, "Shaded|Shift Z",          4, NULL},
1978 {       ICON_POTATO, "Textured|Alt Z",  5, NULL},
1979 {  -1, "",                      0, tb_do_view_dt}};
1980
1981 static TBitem tb_view_alignview[]= {
1982 {       0, "Centre View to Cursor|C",           'c', NULL},
1983 {       0, "Align Active Camera to View|Ctrl Alt NumPad 0",
1984 TB_CTRL|TB_ALT|TB_PAD|'0', NULL}, 
1985 {       0, "Align View to Selected|NumPad *",           TB_PAD|'*', NULL},
1986 {  -1, "",                      0, tb_do_hotkey}};
1987
1988 static TBitem tb_view[]= {
1989 {       0, "Viewport Shading",                  0, tb_view_dt},
1990 {       0, "SEPR",                                              0, NULL},
1991 {       0, "Ortho/Perspective|NumPad 5",        TB_PAD|'5', NULL},
1992 {       0, "Local/Global View|NumPad /",        TB_PAD|'/', NULL},
1993 {       0, "SEPR",                                              0, NULL},
1994 {       0, "Align View",                        0, tb_view_alignview},
1995 {       0, "SEPR",              0, NULL},
1996 {       0, "View Selected|NumPad .",    TB_PAD|'.', NULL},
1997 {       0, "View All|Home",             TB_PAD|'h', NULL},
1998 {       0, "SEPR",              0, NULL},
1999 {       0, "Play Back Animation|Alt A", TB_ALT|'a', NULL},
2000 {       0, "Camera Fly Mode|Shift F", TB_SHIFT|'f', NULL},
2001 {  -1, "",                      0, tb_do_hotkey}};
2002
2003
2004 /* *************TRANSFORM ********** */
2005
2006 static TBitem tb_transform_moveaxis[]= {
2007 {       0, "X Global|G, X",     0, NULL},
2008 {       0, "Y Global|G, Y",     1, NULL},
2009 {       0, "Z Global|G, Z",     2, NULL},
2010 {       0, "SEPR",                                      0, NULL},
2011 {       0, "X Local|G, X, X",   3, NULL},
2012 {       0, "Y Local|G, Y, Y",   4, NULL},
2013 {       0, "Z Local|G, Z, Z",   5, NULL},
2014 {  -1, "",                      0, do_view3d_transform_moveaxismenu}};
2015
2016 static TBitem tb_transform_rotateaxis[]= {
2017 {       0, "X Global|R, X",     0, NULL},
2018 {       0, "Y Global|R, Y",     1, NULL},
2019 {       0, "Z Global|R, Z",     2, NULL},
2020 {       0, "SEPR",                                      0, NULL},
2021 {       0, "X Local|R, X, X",   3, NULL},
2022 {       0, "Y Local|R, Y, Y",   4, NULL},
2023 {       0, "Z Local|R, Z, Z",   5, NULL},
2024 {  -1, "",                      0, do_view3d_transform_rotateaxismenu}};
2025
2026 static TBitem tb_transform_scaleaxis[]= {
2027 {       0, "X Global|S, X",     0, NULL},
2028 {       0, "Y Global|S, Y",     1, NULL},
2029 {       0, "Z Global|S, Z",     2, NULL},
2030 {       0, "SEPR",                                      0, NULL},
2031 {       0, "X Local|S, X, X",   3, NULL},
2032 {       0, "Y Local|S, Y, Y",   4, NULL},
2033 {       0, "Z Local|S, Z, Z",   5, NULL},
2034 {  -1, "",                      0, do_view3d_transform_scaleaxismenu}};
2035
2036 static void tb_do_transform_clearapply(void *arg, int event)
2037 {
2038         Object *ob;
2039         ob= OBACT;
2040         
2041         switch(event)
2042         {
2043             case 0: /* clear location */
2044                         clear_object('g');
2045                         break;
2046                 case 1: /* clear rotation */
2047                         clear_object('r');
2048                         break;
2049                 case 2: /* clear size */
2050                         clear_object('s');
2051                         break;
2052                 case 3: /* apply size/rotation */
2053                         apply_object();
2054                         break;
2055                 case 4: /* apply deformation */
2056                         object_apply_deform(ob);
2057                         break;
2058                 case 5: /* make duplicates real */
2059                         if (ob->transflag & OB_DUPLI) make_duplilist_real();
2060                         else error("The active object does not have dupliverts");
2061                         break;
2062         }
2063 }
2064
2065 static TBitem tb_transform_clearapply[]= {
2066 {       0, "Clear Location|Alt G",              0, NULL},
2067 {       0, "Clear Rotation|Alt R",              1, NULL},
2068 {       0, "Clear Size|Alt S",                  2, NULL},
2069 {       0, "SEPR",                                      0, NULL},
2070 {       0, "Apply Size/Rotation|Ctrl A", 3, NULL},
2071 {       0, "Apply Deformation|Shift Ctrl A", 4, NULL},
2072 {       0, "Make Duplicates Real|Shift Ctrl A", 5, NULL},
2073 {  -1, "",                      0, tb_do_transform_clearapply}};
2074
2075 static TBitem tb_transform_snap[]= {
2076 {       0, "Selection -> Grid|Shift S, 1",              1, NULL},
2077 {       0, "Selection -> Cursor|Shift S, 2",    2, NULL},
2078 {       0, "Cursor -> Grid|Shift S, 3",                 3, NULL},
2079 {       0, "Cursor -> Selection|Shift S, 4", 4, NULL},
2080 {       0, "Selection -> Center|Shift S, 5", 5, NULL},
2081 {  -1, "",                      0, do_view3d_edit_snapmenu}};
2082
2083 static void tb_do_transform(void *arg, int event)
2084 {
2085         switch(event)
2086         {
2087                 case 0: /* Grab/move */
2088                         initTransform(TFM_TRANSLATION, CTX_NONE);
2089                         Transform();
2090                         break;
2091                 case 1: /* Rotate */
2092                         initTransform(TFM_ROTATION, CTX_NONE);
2093                         Transform();
2094                         break;
2095                 case 2: /* Scale */
2096                         initTransform(TFM_RESIZE,CTX_NONE);
2097                         Transform();
2098                         break;
2099                 case 3: /* transform properties */
2100                         add_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_UNSTOW);
2101                         break;
2102                 case 4: /* snap */
2103                         snapmenu();
2104                         break;
2105                 case 5: /* Shrink/Fatten Along Normals */
2106                         initTransform(TFM_SHRINKFATTEN, CTX_NONE);
2107                         Transform();
2108                         break;
2109                 case 6: /* Shear */
2110                         initTransform(TFM_SHEAR, CTX_NONE);
2111                         Transform();
2112                         break;
2113                 case 7: /* Warp */
2114                         initTransform(TFM_WARP, CTX_NONE);
2115                         Transform();
2116                         break;
2117                 case 8: /* proportional edit (toggle) */
2118                         if(G.scene->proportional) G.scene->proportional= 0;
2119                         else G.scene->proportional= 1;
2120                         break;
2121                 case 10:
2122                         docentre(0);
2123                         break;
2124                 case 11:
2125                         docentre_new();
2126                         break;
2127                 case 12:
2128                         docentre_cursor();
2129                         break;
2130         }
2131         allqueue(REDRAWVIEW3D, 0);
2132 }
2133
2134 static TBitem tb_transform_object_mirror[]= {
2135 {       0, "X Local|Ctrl M, 1",         1, NULL},
2136 {       0, "Y Local|Ctrl M, 2",         2, NULL},
2137 {       0, "Z Local|Ctrl M, 3",         3, NULL},
2138 {  -1, "",                      0, do_view3d_object_mirrormenu}};
2139
2140 static TBitem tb_transform[]= {
2141 {       0, "Grab/Move|G",       0, NULL},
2142 {       0, "Grab/Move on Axis| ",       0, tb_transform_moveaxis},
2143 {       0, "Rotate|R",          1, NULL},
2144 {       0, "Rotate on Axis",    0, tb_transform_rotateaxis},
2145 {       0, "Scale|S",           2, NULL},
2146 {       0, "Scale on Axis",     0, tb_transform_scaleaxis},
2147 {       0, "SEPR",                                      0, NULL},
2148 {       0, "ObData to Center",          10, NULL},
2149 {       0, "Center New",                        11, NULL},
2150 {       0, "Center Cursor",                     12, NULL},
2151 {       0, "SEPR",                                      0, NULL},
2152 {       ICON_MENU_PANEL, "Properties|N", 3, NULL},
2153 {       0, "SEPR",                                      0, NULL},
2154 {       0, "Mirror",    0, tb_transform_object_mirror},
2155 {       0, "SEPR",                                      0, NULL},
2156 {       0, "Snap",              0, tb_transform_snap},
2157 {       0, "SEPR",                                      0, NULL},
2158 {       0, "Clear/Apply",       0, tb_transform_clearapply},
2159 {  -1, "",                      0, tb_do_transform}};
2160
2161 static TBitem tb_transform_edit_mirror[]= {
2162 {       0, "X Global|Ctrl M, 1",        1, NULL},
2163 {       0, "Y Global|Ctrl M, 2",        2, NULL},
2164 {       0, "Z Global|Ctrl M, 3",        3, NULL},
2165 {       0, "SEPR",                                      0, NULL},
2166 {       0, "X Local|Ctrl M, 4",         4, NULL},
2167 {       0, "Y Local|Ctrl M, 5",         5, NULL},
2168 {       0, "Z Local|Ctrl M, 6",         6, NULL},
2169 {       0, "SEPR",                                      0, NULL},
2170 {       0, "X View|Ctrl M, 7",  7, NULL},
2171 {       0, "Y View|Ctrl M, 8",  8, NULL},
2172 {       0, "Z View|Ctrl M, 9",  9, NULL},
2173 {  -1, "",                      0, do_view3d_edit_mirrormenu}};
2174
2175 static TBitem tb_transform_editmode1[]= {
2176 {       0, "Grab/Move|G",       0, NULL},
2177 {       0, "Grab/Move on Axis| ",       0, tb_transform_moveaxis},
2178 {       0, "Rotate|R",          1, NULL},
2179 {       0, "Rotate on Axis",    0, tb_transform_rotateaxis},
2180 {       0, "Scale|S",           2, NULL},
2181 {       0, "Scale on Axis",     0, tb_transform_scaleaxis},
2182 {       0, "SEPR",                                      0, NULL},
2183 {       0, "Shrink/Fatten|Alt S", 5, NULL},
2184 {       0, "Shear|Ctrl S", 6, NULL},
2185 {       0, "Warp|Shift W",      7, NULL},
2186 {       0, "SEPR",                                      0, NULL},
2187 {       0, "ObData to Center",          10, NULL},
2188 {       0, "SEPR",                                      0, NULL},
2189 {       ICON_MENU_PANEL, "Properties|N", 3, NULL},
2190 {       0, "SEPR",                                      0, NULL},
2191 {       0, "Mirror",    0, tb_transform_edit_mirror},
2192 {       0, "SEPR",                                      0, NULL},
2193 {       0, "Snap",              0, tb_transform_snap},
2194 {       0, "SEPR",                                      0, NULL},
2195 {       0, "Proportional Edit|O",       8,              NULL},
2196 {  -1, "",                      0, tb_do_transform}};
2197
2198
2199 static TBitem tb_transform_editmode2[]= {
2200 {       0, "Grab/Move|G",       0, NULL},
2201 {       0, "Grab/Move on Axis| ",       0, tb_transform_moveaxis},
2202 {       0, "Rotate|R",          1, NULL},
2203 {       0, "Rotate on Axis",    0, tb_transform_rotateaxis},
2204 {       0, "Scale|S",           2, NULL},
2205 {       0, "Scale on Axis",     0, tb_transform_scaleaxis},
2206 {       0, "SEPR",                                      0, NULL},
2207 {       ICON_MENU_PANEL, "Properties|N", 3, NULL},
2208 {       0, "Snap",              0, tb_transform_snap},
2209 {  -1, "",                      0, tb_do_transform}};
2210
2211
2212 /* *************ADD ********** */
2213
2214 static TBitem addmenu_mesh[]= {
2215 {       0, "Plane",     0, NULL},
2216 {       0, "Cube",              1, NULL},
2217 {       0, "Circle",    2, NULL},
2218 {       0, "UVsphere",  3, NULL},
2219 {       0, "Icosphere", 4, NULL},
2220 {       0, "Cylinder",  5, NULL},
2221 {       0, "Tube",              6, NULL},
2222 {       0, "Cone",              7, NULL},
2223 {       0, "SEPR",              0, NULL},
2224 {       0, "Grid",              8, NULL},
2225 {       0, "Monkey",    9, NULL},
2226 {  -1, "",                      0, do_info_add_meshmenu}};
2227
2228 static TBitem addmenu_curve[]= {
2229 {       0, "Bezier Curve",      0, NULL},
2230 {       0, "Bezier Circle", 1, NULL},
2231 {       0, "NURBS Curve",       2, NULL},
2232 {       0, "NURBS Circle",      3, NULL},
2233 {       0, "Path",                      4, NULL},
2234 {  -1, "",                      0, do_info_add_curvemenu}};
2235
2236 static TBitem addmenu_surf[]= {
2237 {       0, "NURBS Curve",       0, NULL},
2238 {       0, "NURBS Circle",      1, NULL},
2239 {       0, "NURBS Surface", 2, NULL},
2240 {       0, "NURBS Tube",        3, NULL},
2241 {       0, "NURBS Sphere",      4, NULL},
2242 {       0, "NURBS Donut",       5, NULL},
2243 {  -1, "",                      0, do_info_add_surfacemenu}};
2244
2245 static TBitem addmenu_meta[]= {
2246 {       0, "Meta Ball",         0, NULL},
2247 {       0, "Meta Tube",         1, NULL},
2248 {       0, "Meta Plane",        2, NULL},
2249 {       0, "Meta Ellipsoid", 3, NULL},
2250 {       0, "Meta Cube",         4, NULL},
2251 {  -1, "",                      0, do_info_add_metamenu}};
2252
2253 static TBitem addmenu_lamp[]= {
2254 {       0, "Lamp",      0, NULL},
2255 {       0, "Sun",       1, NULL},
2256 {       0, "Spot",      2, NULL},
2257 {       0, "Hemi", 3, NULL},
2258 {       0, "Area",      4, NULL},
2259 {  -1, "",                      0, do_info_add_lampmenu}};
2260
2261 static TBitem addmenu_YF_lamp[]= {
2262 {       0, "Lamp",      0, NULL},
2263 {       0, "Sun",       1, NULL},
2264 {       0, "Spot",      2, NULL},
2265 {       0, "Hemi", 3, NULL},
2266 {       0, "Area",      4, NULL},
2267 {       0, "Photon",    5, NULL},
2268 {  -1, "",                      0, do_info_add_lampmenu}};
2269
2270
2271 static TBitem addmenu_armature[]= {
2272 {       0, "Bone",      8, NULL},
2273 {  -1, "",                      0, do_info_addmenu}};
2274
2275 /* dynamic items */
2276 #define TB_ADD_GROUP    7
2277 #define TB_ADD_LAMP             10
2278
2279 static TBitem tb_add[]= {
2280 {       0, "Mesh",              0, addmenu_mesh},
2281 {       0, "Curve",     1, addmenu_curve},
2282 {       0, "Surface",   2, addmenu_surf},
2283 {       0, "Meta",      3, addmenu_meta},
2284 {       0, "Text",              4, NULL},
2285 {       0, "Empty",     5, NULL},
2286 {       0, "SEPR",              0, NULL},
2287 {       0, "Group",     10, NULL},
2288 {       0, "SEPR",              0, NULL},
2289 {       0, "Camera",    6, NULL},
2290 {       0, "Lamp",              7, addmenu_lamp},
2291 {       0, "SEPR",              0, NULL},
2292 {       0, "Armature",  8, NULL},
2293 {       0, "Lattice",   9, NULL},
2294 {  -1, "",                      0, do_info_addmenu}};
2295
2296 static TBitem tb_empty[]= {
2297 {       0, "Nothing...",        0, NULL},
2298 {  -1, "",              0, NULL}};
2299
2300
2301 /* *************RENDER ********** */
2302
2303 static void tb_do_render(void *arg, int event){
2304         switch(event)
2305         {
2306                 case 1: /* set render border */
2307                         set_render_border();
2308                         break;
2309                 case 2: /* render */
2310                         BIF_do_render(0);
2311                         break;
2312                 case 3: /* render anim */
2313                         BIF_do_render(1);
2314                         break;
2315                 case 4: /* render anim */
2316                         if(G.scene->r.scemode & R_PASSEPARTOUT) G.scene->r.scemode &= ~R_PASSEPARTOUT;
2317                         else G.scene->r.scemode |= R_PASSEPARTOUT;
2318                         allqueue(REDRAWVIEW3D, 0);
2319                         break;
2320         }
2321 }
2322
2323 static TBitem tb_render[]= {
2324         {       0, "Passepartout",                      4, NULL},
2325         {       0, "Set Border",                        1, NULL},
2326         {       0, "SEPR",              0, NULL},
2327         {       0, "Render|F12",                        2, NULL},
2328         {       0, "Anim",                                      3, NULL},
2329         {  -1, "",                      0, tb_do_render}};
2330
2331
2332 static uiBlock *tb_makemenu(void *arg)
2333 {
2334         static int counter=0;
2335         TBitem *item= arg, *itemt;
2336         uiBlock *block;
2337         int yco= 0;
2338         char str[10];
2339         
2340         if(arg==NULL) return NULL;
2341         
2342         sprintf(str, "tb %d", counter++);
2343         block= uiNewBlock(&tb_listb, str, UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2344         uiBlockSetCol(block, TH_MENU_ITEM);
2345
2346         // last item has do_menu func, has to be stored in each button
2347         itemt= item;
2348         while(itemt->icon != -1) itemt++;
2349         uiBlockSetButmFunc(block, itemt->poin, NULL);
2350
2351         // now make the buttons
2352         while(item->icon != -1) {
2353
2354                 if(strcmp(item->name, "SEPR")==0) {
2355                         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 50, 6, NULL, 0.0, 0.0, 0, 0, "");
2356                 }
2357                 else if(item->icon) {
2358                         uiDefIconTextBut(block, BUTM, 1, item->icon, item->name, 0, yco-=20, 80, 19, NULL, 0.0, 0.0, 0, item->retval, "");
2359                 }
2360                 else if(item->poin) {
2361                         uiDefIconTextBlockBut(block, tb_makemenu, item->poin, ICON_RIGHTARROW_THIN, item->name, 0, yco-=20, 80, 19, "");
2362                 }
2363                 else {
2364                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, item->name, 0, yco-=20, 80, 19, NULL, 0.0, 0.0, 0, item->retval, "");
2365                 }
2366                 item++;
2367         }
2368         uiTextBoundsBlock(block, 60);
2369         
2370         /* direction is also set in the function that calls this */
2371         if(U.uiflag & USER_PLAINMENUS)
2372                 uiBlockSetDirection(block, UI_RIGHT);
2373         else
2374                 uiBlockSetDirection(block, UI_RIGHT|UI_CENTRE);
2375
2376         return block;
2377 }
2378
2379 static int tb_mainx= 1234, tb_mainy= 0;
2380 static void store_main(void *arg1, void *arg2)
2381 {
2382         tb_mainx= (int)arg1;
2383         tb_mainy= (int)arg2;
2384 }
2385
2386 static void do_group_addmenu(void *arg, int event)
2387 {
2388         Object *ob;
2389         
2390         add_object_draw(OB_EMPTY);
2391         ob= OBACT;
2392         
2393         ob->dup_group= BLI_findlink(&G.main->group, event);
2394         if(ob->dup_group) {
2395                 id_us_plus((ID *)ob->dup_group);
2396                 ob->transflag |= OB_DUPLIGROUP;
2397                 DAG_scene_sort(G.scene);
2398         }
2399 }
2400                                                          
2401 /* example of dynamic toolbox sublevel */
2402 static TBitem *create_group_sublevel(void)
2403 {
2404         static TBitem addmenu[]= { {    0, "No Groups",         0, NULL}, {  -1, "",                    0, NULL}};
2405         TBitem *groupmenu;
2406         Group *group;
2407         int a;
2408         
2409         int tot= BLI_countlist(&G.main->group);
2410         
2411         if(tot==0) {
2412                 tb_add[TB_ADD_GROUP].poin= addmenu;
2413                 return NULL;
2414         }
2415         
2416         groupmenu= MEM_callocN(sizeof(TBitem)*(tot+1), "group menu");
2417         for(a=0, group= G.main->group.first; group; group= group->id.next, a++) {
2418                 groupmenu[a].name= group->id.name+2;
2419                 groupmenu[a].retval= a;
2420         }
2421         groupmenu[a].icon= -1;  /* end signal */
2422         groupmenu[a].name= "";
2423         groupmenu[a].retval= a;
2424         groupmenu[a].poin= do_group_addmenu;
2425         
2426         tb_add[TB_ADD_GROUP].poin= groupmenu;
2427         
2428         return groupmenu;
2429 }
2430
2431 void toolbox_n(void)
2432 {
2433         uiBlock *block;
2434         uiBut *but;
2435         TBitem *menu1=NULL, *menu2=NULL, *menu3=NULL; 
2436         TBitem *menu4=NULL, *menu5=NULL, *menu6=NULL;
2437         TBitem *menu7=NULL, *groupmenu;
2438         int dx=0;
2439         short event, mval[2], tot=0;
2440         char *str1=NULL, *str2=NULL, *str3=NULL, *str4=NULL, *str5=NULL, *str6=NULL, *str7=NULL;
2441         
2442         /* temporal too... when this flag is (was) saved, it should initialize OK */
2443         if(tb_mainx==1234) {
2444                 if(U.uiflag & USER_PLAINMENUS) {
2445                         tb_mainx= -32;
2446                         tb_mainy= -5;
2447                 } else {
2448                         tb_mainx= 0;
2449                         tb_mainy= -5;
2450                 }
2451         }
2452         
2453         mywinset(G.curscreen->mainwin); // we go to screenspace
2454         
2455         block= uiNewBlock(&tb_listb, "toolbox", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2456         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
2457         uiBlockSetCol(block, TH_MENU_ITEM);
2458         
2459         /* dynamic menu entries */
2460         groupmenu= create_group_sublevel();
2461         
2462         if (G.scene->r.renderer==R_YAFRAY)
2463                 tb_add[TB_ADD_LAMP].poin= addmenu_YF_lamp;
2464         else
2465                 tb_add[TB_ADD_LAMP].poin= addmenu_lamp;
2466         
2467         /* select context for main items */
2468         if(curarea->spacetype==SPACE_VIEW3D) {
2469
2470                 if(U.uiflag & USER_PLAINMENUS) {
2471                         menu1= tb_add; str1= "Add";
2472                         menu2= tb_object_edit; str2= "Edit";
2473                         menu3= tb_object_select; str3= "Select";
2474                         menu4= tb_transform; str4= "Transform";
2475                         menu5= tb_object; str5= "Object";
2476                         menu6= tb_view; str6= "View";
2477                         menu7= tb_render; str7= "Render";
2478
2479                         dx= 96;
2480                         tot= 7;
2481                 } else {
2482                         /* 3x2 layout menu */
2483                         menu1= tb_object; str1= "Object";
2484                         menu2= tb_add; str2= "Add";
2485                         menu3= tb_object_select; str3= "Select";
2486                         menu4= tb_object_edit; str4= "Edit";
2487                         menu5= tb_transform; str5= "Transform";
2488                         menu6= tb_view; str6= "View";
2489
2490                         dx= 64;
2491                         tot= 6;
2492                 }
2493                 
2494                 if(G.obedit) {
2495                         if(U.uiflag & USER_PLAINMENUS) {
2496                                 switch(G.obedit->type){
2497                                 case OB_MESH:
2498                                         menu1= addmenu_mesh;
2499                                         menu2= tb_mesh_edit;
2500                                         menu3= tb_mesh_select;
2501                                         menu4= tb_transform_editmode1;
2502                                         menu5= tb_mesh; str5= "Mesh";
2503                                 break;
2504                                 case OB_CURVE:
2505                                         menu1= addmenu_curve;
2506                                         menu2= tb_curve_edit;
2507                                         menu3= tb_curve_select;
2508                                         menu4= tb_transform_editmode1;
2509                                         menu5= tb_curve; str5= "Curve";
2510                                 break;
2511                                 case OB_SURF:
2512                                         menu1= addmenu_surf;
2513                                         menu2= tb_curve_edit;
2514                                         menu3= tb_curve_select;
2515                                         menu4= tb_transform_editmode1;
2516                                         menu5= tb_curve; str5= "Surface";
2517                                 break;
2518                                 case OB_MBALL:
2519                                         menu1= addmenu_meta;
2520                                         menu2= tb_edit;
2521                                         menu3= tb__select;
2522                                         menu4= tb_transform_editmode2;
2523                                         menu5= tb_obdata; str5= "Meta";
2524                                 break;
2525                                 case OB_ARMATURE:
2526                                         menu1= addmenu_armature;
2527                                         menu2= tb_edit;
2528                                         menu3= tb__select;
2529                                         menu4= tb_transform_editmode2;
2530                                         menu5= tb_obdata;str5= "Armature";
2531                                 break;
2532                                 case OB_LATTICE:
2533                                         menu1= tb_empty;
2534                                         menu2= tb_edit;
2535                                         menu3= tb__select;
2536                                         menu4= tb_transform_editmode1;
2537                                         menu5= tb_empty;str5= "Lattice";
2538                                 break;
2539                                 }
2540                         } else {
2541                                 if(G.obedit->type==OB_MESH) {
2542                                         menu1= tb_mesh; str1= "Mesh";
2543                                         menu2= addmenu_mesh; 
2544                                         menu3= tb_mesh_select;
2545                                         menu4= tb_mesh_edit; 
2546                                         menu5= tb_transform_editmode1;
2547                                 }
2548                                 else if(G.obedit->type==OB_CURVE) {
2549                                         menu1= tb_curve; str1= "Curve";
2550                                         menu2= addmenu_curve;
2551                                         menu3= tb_curve_select;
2552                                         menu4= tb_curve_edit;
2553                                         menu5= tb_transform_editmode1;
2554                                 }
2555                                 else if(G.obedit->type==OB_SURF) {
2556                                         menu1= tb_curve; str1= "Surface";
2557                                         menu2= addmenu_surf; 
2558                                         menu3= tb_curve_select;
2559                                         menu4= tb_curve_edit;
2560                                         menu5= tb_transform_editmode1;
2561                                 }
2562                                 else if(G.obedit->type==OB_MBALL) {
2563                                         menu1= tb_obdata; str1= "Meta";
2564                                         menu2= addmenu_meta;
2565                                         menu3= tb__select;
2566                                         menu4= tb_edit;
2567                                         menu5= tb_transform_editmode2;
2568                                 }
2569                                 else if(G.obedit->type==OB_ARMATURE) {
2570                                         menu1= tb_obdata;str1= "Armature";
2571                                         menu2= addmenu_armature;
2572                                         menu3= tb__select;
2573                                         menu4= tb_edit;
2574                                         menu5= tb_transform_editmode2;
2575                                 }
2576                                 else if(G.obedit->type==OB_LATTICE) {
2577                                         menu1= tb_empty;str1= "Lattice";
2578                                         menu2= tb_empty;
2579                                         menu3= tb__select;
2580                                         menu4= tb_edit;
2581                                         menu5= tb_transform_editmode1;
2582                                 }
2583                         }
2584                 }
2585                 else {
2586                 }
2587         }
2588         
2589         getmouseco_sc(mval);
2590         
2591         /* create the main buttons menu */
2592         if(tot==6) {
2593         
2594                 /* check if it fits */
2595                 if(mval[0]-1.5*dx+tb_mainx < 6) mval[0]= 6 + 1.5*dx -tb_mainx;
2596                 else if(mval[0]+1.5*dx+tb_mainx > G.curscreen->sizex-6) 
2597                         mval[0]= G.curscreen->sizex-6-1.5*dx-tb_mainx;
2598
2599                 if(mval[1]-20+tb_mainy < 6) mval[1]= 6+20 -tb_mainy;
2600                 else if(mval[1]+20+tb_mainy > G.curscreen->sizey-6) 
2601                         mval[1]= G.curscreen->sizey-6-20-tb_mainy;
2602         
2603                 but=uiDefBlockBut(block, tb_makemenu, menu1, str1,      mval[0]-(1.5*dx)+tb_mainx,mval[1]+tb_mainy, dx, 19, "");
2604                 uiButSetFlag(but, UI_MAKE_TOP|UI_MAKE_RIGHT);
2605                 uiButSetFunc(but, store_main, (void *)dx, (void *)-5);
2606
2607                 but=uiDefBlockBut(block, tb_makemenu, menu2, str2,      mval[0]-(0.5*dx)+tb_mainx,mval[1]+tb_mainy, dx, 19, "");
2608                 uiButSetFlag(but, UI_MAKE_TOP);
2609                 uiButSetFunc(but, store_main, (void *)0, (void *)-5);
2610
2611                 but=uiDefBlockBut(block, tb_makemenu, menu3, str3,      mval[0]+(0.5*dx)+tb_mainx,mval[1]+tb_mainy, dx, 19, "");
2612                 uiButSetFlag(but, UI_MAKE_TOP|UI_MAKE_LEFT);
2613                 uiButSetFunc(but, store_main, (void *)-dx, (void *)-5);
2614
2615                 but=uiDefBlockBut(block, tb_makemenu, menu4, str4,      mval[0]-(1.5*dx)+tb_mainx,mval[1]+tb_mainy-20, dx, 19, "");
2616                 uiButSetFlag(but, UI_MAKE_DOWN|UI_MAKE_RIGHT);
2617                 uiButSetFunc(but, store_main, (void *)dx, (void *)5);
2618
2619                 but=uiDefBlockBut(block, tb_makemenu, menu5, str5,      mval[0]-(0.5*dx)+tb_mainx,mval[1]+tb_mainy-20, dx, 19, "");
2620                 uiButSetFlag(but, UI_MAKE_DOWN);
2621                 uiButSetFunc(but, store_main, (void *)0, (void *)5);
2622
2623                 but=uiDefBlockBut(block, tb_makemenu, menu6, str6,      mval[0]+(0.5*dx)+tb_mainx,mval[1]+tb_mainy-20, dx, 19, "");
2624                 uiButSetFlag(but, UI_MAKE_DOWN|UI_MAKE_LEFT);
2625                 uiButSetFunc(but, store_main, (void *)-dx, (void *)5);
2626         } else if (tot==7) {
2627                 /* check if it fits, dubious */
2628                 if(mval[0]-0.25*dx+tb_mainx < 6) mval[0]= 6 + 0.25*dx -tb_mainx;
2629                 else if(mval[0]+0.25*dx+tb_mainx > G.curscreen->sizex-6)
2630                 mval[0]= G.curscreen->sizex-6-0.25*dx-tb_mainx;
2631
2632                 if(mval[1]-20+tb_mainy < 6) mval[1]= 6+20 -tb_mainy;
2633                 else if(mval[1]+20+tb_mainy > G.curscreen->sizey-6)
2634                         mval[1]= G.curscreen->sizey-6-20-tb_mainy;
2635
2636                 but=uiDefIconTextBlockBut(block, tb_makemenu, menu1, ICON_RIGHTARROW_THIN, str1, mval[0]+tb_mainx,mval[1]+tb_mainy, dx, 19, "");
2637                 uiButSetFlag(but, UI_MAKE_RIGHT);
2638                 uiButSetFunc(but, store_main, (void *)-32, (void *)-5);
2639
2640                 but=uiDefIconTextBlockBut(block, tb_makemenu, menu2, ICON_RIGHTARROW_THIN, str2, mval[0]+tb_mainx,mval[1]+tb_mainy-20, dx, 19, "");
2641                 uiButSetFlag(but, UI_MAKE_RIGHT);
2642                 uiButSetFunc(but, store_main, (void *)-32, (void *)15);
2643
2644                 but=uiDefIconTextBlockBut(block, tb_makemenu, menu3, ICON_RIGHTARROW_THIN, str3, mval[0]+tb_mainx,mval[1]+tb_mainy-40, dx, 19, "");
2645                 uiButSetFlag(but, UI_MAKE_RIGHT);
2646                 uiButSetFunc(but, store_main, (void *)-32, (void *)35);
2647
2648                 but=uiDefIconTextBlockBut(block, tb_makemenu, menu4, ICON_RIGHTARROW_THIN, str4, mval[0]+tb_mainx,mval[1]+tb_mainy-60, dx, 19, "");
2649                 uiButSetFlag(but, UI_MAKE_RIGHT);
2650                 uiButSetFunc(but, store_main, (void *)-32, (void *)55);
2651
2652                 but=uiDefIconTextBlockBut(block, tb_makemenu, menu5, ICON_RIGHTARROW_THIN, str5, mval[0]+tb_mainx,mval[1]+tb_mainy-80, dx, 19, "");
2653                 uiButSetFlag(but, UI_MAKE_RIGHT);
2654                 uiButSetFunc(but, store_main, (void *)-32, (void *)75);
2655
2656                 but=uiDefIconTextBlockBut(block, tb_makemenu, menu6, ICON_RIGHTARROW_THIN, str6, mval[0]+tb_mainx,mval[1]+tb_mainy-100, dx, 19, "");
2657                 uiButSetFlag(but, UI_MAKE_RIGHT);
2658                 uiButSetFunc(but, store_main, (void *)-32, (void *)95);
2659
2660                 but=uiDefIconTextBlockBut(block, tb_makemenu, menu7, ICON_RIGHTARROW_THIN, str7, mval[0]+tb_mainx,mval[1]+tb_mainy-120, dx, 19, "");
2661                 uiButSetFlag(but, UI_MAKE_RIGHT);
2662                 uiButSetFunc(but, store_main, (void *)-32, (void *)105);
2663         }
2664         
2665         uiBoundsBlock(block, 2);
2666         event= uiDoBlocks(&tb_listb, 0);
2667         
2668         if(groupmenu) MEM_freeN(groupmenu);
2669         
2670         mywinset(curarea->win);
2671 }
2672
2673 void toolbox_n_add(void)
2674 {
2675         reset_toolbox();
2676         toolbox_n();
2677 }
2678
2679 void reset_toolbox(void)
2680 {
2681         if(U.uiflag & USER_PLAINMENUS) {
2682                 tb_mainx= -32;
2683                 tb_mainy= -5;
2684         } else {
2685                 tb_mainx= 0;
2686                 tb_mainy= -5;
2687         }
2688 }