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