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