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