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