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