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