b32ad5ea201763df98c56bfead3e3a31af61f98a
[blender-staging.git] / source / blender / src / buttons.txt
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  * Everything for drawing buttons (and I do mean _everything_).
32  */
33
34
35 /* System includes ----------------------------------------------------- */
36
37 #include <time.h>
38 #include <math.h>
39 #include <stdlib.h>
40 #include <string.h>
41
42 #ifdef HAVE_CONFIG_H
43 #include <config.h>
44 #endif
45
46 #ifdef _WIN32
47 #include "BLI_winstuff.h"
48 #else
49 #include <unistd.h>
50 #endif
51 #include "MEM_guardedalloc.h"
52
53 #include "BMF_Api.h"
54
55 #include "IMB_imbuf_types.h"
56 #include "IMB_imbuf.h"
57
58 #include "BLI_blenlib.h"
59 #include "BLI_arithb.h"
60 #include "BLI_editVert.h"
61
62 #include "DNA_action_types.h"
63 #include "DNA_armature_types.h"
64 #include "DNA_camera_types.h"
65 #include "DNA_constraint_types.h"
66 #include "DNA_curve_types.h"
67 #include "DNA_effect_types.h"
68 #include "DNA_group_types.h"
69 #include "DNA_ika_types.h"
70 #include "DNA_image_types.h"
71 #include "DNA_key_types.h"
72 #include "DNA_lamp_types.h"
73 #include "DNA_lattice_types.h"
74 #include "DNA_material_types.h"
75 #include "DNA_meta_types.h"
76 #include "DNA_mesh_types.h"
77 #include "DNA_object_types.h"
78 #include "DNA_packedFile_types.h"
79 #include "DNA_radio_types.h"
80 #include "DNA_scene_types.h"
81 #include "DNA_screen_types.h"
82 #include "DNA_sound_types.h"
83 #include "DNA_space_types.h"
84 #include "DNA_texture_types.h"
85 #include "DNA_userdef_types.h"
86 #include "DNA_vfont_types.h"
87 #include "DNA_view3d_types.h"
88 #include "DNA_world_types.h"
89
90 #include "BKE_anim.h"
91 #include "BKE_armature.h"
92 #include "BKE_constraint.h"
93 #include "BKE_curve.h"
94 #include "BKE_displist.h"
95 #include "BKE_effect.h"
96 #include "BKE_font.h"
97 #include "BKE_global.h"
98 #include "BKE_ika.h"
99 #include "BKE_image.h"
100 #include "BKE_ipo.h"
101 #include "BKE_lattice.h"
102 #include "BKE_library.h"
103 #include "BKE_main.h"
104 #include "BKE_material.h"
105 #include "BKE_mball.h"
106 #include "BKE_mesh.h"
107 #include "BKE_object.h"
108 #include "BKE_packedFile.h"
109 #include "BKE_plugin_types.h"
110 #include "BKE_sound.h"
111 #include "BKE_texture.h"
112 #include "BKE_utildefines.h"
113 #include "BKE_writeavi.h"
114
115 /* Everything from source (BIF, BDR, BSE) ------------------------------ */ 
116
117 #include "BDR_drawobject.h"
118 #include "BDR_editcurve.h"
119 #include "BDR_editface.h"
120 #include "BDR_editobject.h"
121 #include "BDR_vpaint.h"
122
123 #include "BSE_drawview.h"
124 #include "BSE_editipo.h"
125 #include "BSE_edit.h"
126 #include "BSE_filesel.h"
127 #include "BSE_headerbuttons.h"
128 #include "BSE_trans_types.h"
129 #include "BSE_view.h"
130 #include "BSE_buttons.h"
131 #include "BSE_seqaudio.h"
132
133 #include "BIF_gl.h"
134 #include "BIF_editarmature.h"   
135 #include "BIF_editconstraint.h" 
136 #include "BIF_editdeform.h"
137 #include "BIF_editfont.h"
138 #include "BIF_editmesh.h"
139 #include "BIF_editsca.h"
140 #include "BIF_editsound.h"
141 #include "BIF_interface.h"
142 #include "BIF_mywindow.h"
143 #include "BIF_renderwin.h"
144 #include "BIF_resources.h"
145 #include "BIF_screen.h"
146 #include "BIF_scrarea.h"
147 #include "BIF_space.h"
148 #include "BIF_toets.h"
149 #include "BIF_toolbox.h"
150 #include "BIF_previewrender.h"
151 #include "BIF_writeimage.h"
152 #include "BIF_writeavicodec.h"
153 #ifdef WITH_QUICKTIME
154 #include "quicktime_export.h"
155 #endif
156
157 /* 'old' stuff": defines and types ------------------------------------- */
158 #include "blendef.h"
159 #include "interface.h"
160
161 /* old style modules --------------------------------------------------- */
162
163 #include "mydevice.h"
164
165 #include "render.h"
166 #include "radio.h"
167 #include "nla.h"                        /* For __NLA: Do not remove! */
168
169 /* Decimation includes. See LOD_DependKludge.h for enabling Decimation   */
170 #include "LOD_DependKludge.h"
171 #ifdef NAN_DECIMATION
172   #include "LOD_decimation.h"
173 #endif
174
175 /* own include --------------------------------------------------------- */
176 #include "BSE_buttons.h"
177
178 /* some dirt ... let the linker deal with it :( ------------------------ */
179 extern ListBase editNurb;  /* from editcurve */
180 extern VPaint Gvp;         /* from vpaint */
181
182 /* Local vars ---------------------------------------------------------- */
183 short bgpicmode=0, near=1000, far=1000;
184 short degr= 90, step= 9, turn= 1, editbutflag= 1;
185 float hspeed=0.1f, prspeed=0.0f, prlen=0.0f, doublimit= 0.001f;
186 int decim_faces=0;
187
188 #ifdef __NLA
189 float editbutvweight=1;
190 #endif
191 float extr_offs= 1.0, editbutweight=1.0, editbutsize=0.1, cumapsize= 1.0;
192 MTex emptytex;
193 char texstr[15][8]= {"None"  , "Clouds" , "Wood",
194                                          "Marble", "Magic"  , "Blend",
195                                          "Stucci", "Noise"  , "Image",
196                                          "Plugin", "EnvMap" , "",
197                                          ""      , ""       , ""};
198
199
200 /* Local functions ----------------------------------------------------- */
201
202 /* event for buttons (ROW) to indicate the backbuffer isn't OK (ogl) */
203 #define B_DIFF                  1       
204
205 /* *********************** */
206 #define B_VIEWBUTS              1100
207
208 #define B_LOADBGPIC             1001
209 #define B_BLENDBGPIC    1002
210 #define B_BGPICBROWSE   1003
211 #define B_BGPICTEX              1004
212 #define B_BGPICCLEAR    1005
213 #define B_BGPICTEXCLEAR 1006
214
215 /* *********************** */
216 #define B_LAMPBUTS              1200
217
218 #define B_LAMPREDRAW    1101
219 #define B_COLLAMP               1102
220 #define B_TEXCLEARLAMP  1103
221 #define B_SBUFF                 1104
222
223 /* *********************** */
224 #define B_MATBUTS               1300
225
226 #define B_MATCOL                1201
227 #define B_SPECCOL               1202
228 #define B_MIRCOL                1203
229 #define B_ACTCOL                1204
230 #define B_MATFROM               1205
231 #define B_MATPRV                1206
232 #define B_MTEXCOL               1207
233 #define B_TEXCLEAR              1208
234 #define B_MATPRV_DRAW   1209
235 #define B_MTEXPASTE             1210
236 #define B_MTEXCOPY              1211
237 #define B_MATLAY                1212
238
239 /* *********************** */
240 #define B_TEXBUTS               1400
241
242 #define B_TEXTYPE               1301
243 #define B_DEFTEXVAR             1302
244 #define B_LOADTEXIMA    1303
245 #define B_NAMEIMA               1304
246 #define B_TEXCHANNEL    1305
247 #define B_TEXREDR_PRV   1306
248 #define B_TEXIMABROWSE  1307
249 #define B_IMAPTEST              1308
250 #define B_RELOADIMA             1309
251 #define B_LOADPLUGIN    1310
252 #define B_NAMEPLUGIN    1311
253 #define B_COLORBAND             1312
254 #define B_ADDCOLORBAND  1313
255 #define B_DELCOLORBAND  1314
256 #define B_CALCCBAND             1315
257 #define B_CALCCBAND2    1316
258 #define B_DOCOLORBAND   1317
259 #define B_REDRAWCBAND   1318
260 #define B_BANDCOL               1319
261 #define B_LOADTEXIMA1   1320
262 #define B_PLUGBUT               1321
263
264 /* plugbut reserves 24 buttons at least! */
265
266 #define B_ENV_MAKE              1350
267 #define B_ENV_FREE              1351
268 #define B_ENV_DELETE    1352
269 #define B_ENV_SAVE              1353
270 #define B_ENV_OB                1354
271
272 #define B_PACKIMA               1355
273 #define B_TEXSETFRAMES  1356
274
275 #define B_ENV_FREE_ALL  1357
276
277 /* *********************** */
278 #define B_ANIMBUTS              1500
279
280 #define B_RECALCPATH    1401
281 #define B_MUL_IPO               1402
282 #define B_AUTOTIMEOFS   1403
283 #define B_FRAMEMAP              1404
284 #define B_NEWEFFECT             1405
285 #define B_PREVEFFECT    1406
286 #define B_NEXTEFFECT    1407
287 #define B_CHANGEEFFECT  1408
288 #define B_CALCEFFECT    1409
289 #define B_DELEFFECT             1410
290 #define B_RECALCAL              1411
291 #define B_SETSPEED              1412
292 #define B_PRINTSPEED    1413
293 #define B_PRINTLEN              1414
294 #define B_RELKEY                1415
295
296         /* this has MAX_EFFECT settings! Next free define is 1450... */
297 #define B_SELEFFECT     1430    
298
299
300 /* *********************** */
301 #define B_WORLDBUTS             1600
302
303 #define B_TEXCLEARWORLD 1501
304
305 /* *********************** */
306 #define B_RENDERBUTS    1700
307
308 #define B_FS_PIC                1601
309 #define B_FS_BACKBUF    1602
310
311 #define B_FS_FTYPE              1604
312 #define B_DORENDER              1605
313 #define B_DOANIM                1606
314 #define B_PLAYANIM              1607
315 #define B_PR_PAL                1608
316 #define B_PR_FULL               1609
317 #define B_PR_PRV                1610
318 #define B_PR_CDI                1611
319 #define B_PR_PAL169             1612
320 #define B_PR_D2MAC              1613
321 #define B_PR_MPEG               1614
322 #define B_REDRAWDISP    1615
323 #define B_SETBROWSE             1616
324 #define B_CLEARSET              1617
325 #define B_PR_PRESET             1618
326 #define B_PR_PANO               1619
327 #define B_PR_NTSC               1620
328
329 #define B_IS_FTYPE              1622
330 #define B_IS_BACKBUF    1623
331 #define B_PR_PC                 1624
332
333 #define B_PR_PANO360    1627
334 #define B_PR_HALFFIELDS 1628
335 #define B_NEWRENDERPIPE 1629
336 #define B_R_SCALE       1630
337 #define B_G_SCALE       1631
338 #define B_B_SCALE       1632
339 #define B_USE_R_SCALE   1633
340 #define B_USE_G_SCALE   1634
341 #define B_USE_B_SCALE   1635
342 #define B_EDGECOLSLI    1636
343 #define B_GAMMASLI      1637
344
345 #define B_FILETYPEMENU  1638
346 #define B_SELECTCODEC   1639
347 #define B_RTCHANGED             1640
348
349 #ifdef __NLA
350 /* *********************** */
351 enum {
352         B_ARMATUREBUTS  =       1800,
353         B_POSE                  =       1701
354 };
355 #endif
356
357 /* *********************** */
358 #define B_COMMONEDITBUTS        2049
359
360 #define B_MATWICH               2003
361 #define B_MATNEW                2004
362 #define B_MATDEL                2005
363 #define B_MATASS                2006
364 #define B_MATSEL                2007
365 #define B_MATDESEL              2008
366 #define B_HIDE                  2009
367 #define B_REVEAL                2010
368 #define B_SELSWAP               2011
369 #define B_SETSMOOTH             2012
370 #define B_SETSOLID              2013
371 #define B_AUTOTEX               2014
372 #define B_DOCENTRE              2015
373 #define B_DOCENTRENEW   2016
374 #define B_DOCENTRECURSOR        2017
375
376         /* 32 values! */
377 #define B_OBLAY                 2018
378
379 #define B_MESHBUTS              2100
380
381 #define B_FLIPNORM              2050
382 #define B_SPIN                  2051
383 #define B_SPINDUP               2052
384 #define B_EXTR                  2053
385 #define B_SCREW                 2054
386 #define B_EXTREP                2055
387 #define B_SPLIT                 2056
388 #define B_REMDOUB               2057
389 #define B_SUBDIV                2058
390 #define B_FRACSUBDIV    2059
391 #define B_XSORT                 2060
392 #define B_HASH                  2061
393 #define B_DELSTICKY             2062
394 #define B_DELVERTCOL    2063
395 #define B_MAKE_TFACES   2064
396 #define B_TOSPHERE              2065
397 #define B_DEL_TFACES    2066
398 #define B_NEWVGROUP             2067
399 #define B_DELVGROUP             2068
400 #define B_ASSIGNVGROUP  2069
401 #define B_REMOVEVGROUP  2070
402 #define B_SELVGROUP             2071    
403 #define B_DESELVGROUP   2072
404 #define B_DECIM_FACES   2073
405 #define B_DECIM_CANCEL  2074
406 #define B_DECIM_APPLY   2075
407 #define B_AUTOVGROUP    2076
408 #define B_SLOWERDRAW    2077
409 #define B_FASTERDRAW    2078
410 #define B_VERTEXNOISE   2079
411 #define B_VERTEXSMOOTH  2080
412 #define B_MAKESTICKY    2082
413 #define B_MAKEVERTCOL   2083
414
415 /* *********************** */
416 #define B_CURVEBUTS             2200
417
418 #define B_CONVERTPOLY   2101
419 #define B_CONVERTBEZ    2102
420 #define B_CONVERTBSPL   2103
421 #define B_CONVERTCARD   2104
422 #define B_CONVERTNURB   2105
423 #define B_UNIFU                 2106
424 #define B_ENDPU                 2107
425 #define B_BEZU                  2108
426 #define B_UNIFV                 2109
427 #define B_ENDPV                 2110
428 #define B_BEZV                  2111
429 #define B_SETWEIGHT             2112
430 #define B_SETW1                 2113
431 #define B_SETW2                 2114
432 #define B_SETW3                 2115
433 #define B_SETORDER              2116
434 #define B_MAKEDISP              2117
435 #define B_SUBDIVCURVE   2118
436 #define B_SPINNURB              2119
437 #define B_CU3D                  2120
438 #define B_SETRESOLU             2121
439 #define B_SETW4                 2122
440
441
442 /* *********************** */
443 #define B_FONTBUTS              2300
444
445 #define B_MAKEFONT              2201
446 #define B_TOUPPER               2202
447 #define B_SETFONT               2203
448 #define B_LOADFONT              2204
449 #define B_TEXTONCURVE   2205
450 #define B_PACKFONT              2206
451
452 /* *********************** */
453 #define B_IKABUTS               2400
454
455 #define B_IKASETREF             2301
456 #define B_IKARECALC             2302
457
458 /* *********************** */
459 #define B_CAMBUTS               2500
460
461 /* *********************** */
462 #define B_MBALLBUTS             2600
463
464 #define B_RECALCMBALL   2501
465
466 /* *********************** */
467 #define B_LATTBUTS              2700
468
469 #define B_RESIZELAT             2601
470 #define B_DRAWLAT               2602
471 #define B_LATTCHANGED   2603
472
473 /* *********************** */
474 #define B_GAMEBUTS              2800
475
476 /* in editsca.c */
477
478 /* *********************** */
479 #define B_FPAINTBUTS    2900
480
481 #define B_VPCOLSLI              2801
482 #define B_VPGAMMA               2802
483
484 #define B_COPY_TF_MODE  2804
485 #define B_COPY_TF_UV    2805
486 #define B_COPY_TF_COL   2806
487 #define B_REDR_3D_IMA   2807
488 #define B_SET_VCOL              2808
489
490 #define B_COPY_TF_TEX   2814
491 #define B_TFACE_HALO    2815
492 #define B_TFACE_BILLB   2816
493
494 #define B_SHOWTEX               2832
495 #define B_ASSIGNMESH    2833
496
497
498 /* *********************** */
499 #define B_RADIOBUTS             3000
500
501 #define B_RAD_GO                2901
502 #define B_RAD_INIT              2902
503 #define B_RAD_LIMITS    2903
504 #define B_RAD_FAC               2904
505 #define B_RAD_NODELIM   2905
506 #define B_RAD_NODEFILT  2906
507 #define B_RAD_FACEFILT  2907
508 #define B_RAD_ADD               2908
509 #define B_RAD_DELETE    2909
510 #define B_RAD_COLLECT   2910
511 #define B_RAD_SHOOTP    2911
512 #define B_RAD_SHOOTE    2912
513 #define B_RAD_REPLACE   2913
514 #define B_RAD_DRAW              2914
515 #define B_RAD_FREE              2915
516 #define B_RAD_ADDMESH   2916
517
518 /* *********************** */
519 #define B_SCRIPTBUTS    3100
520
521 #define B_SCRIPT_ADD    3001
522 #define B_SCRIPT_DEL    3002
523 #define B_SCRIPT_TYPE   3003
524
525 /* Scene script buttons */
526 #define B_SSCRIPT_ADD   3004
527 #define B_SSCRIPT_DEL   3005
528 #define B_SSCRIPT_TYPE  3006
529
530 /* *********************** */
531 #define B_SOUNDBUTS             3200
532 enum B_SOUND_BUTTONS {
533         B_SOUND_CHANGED = 3101,
534                 B_SOUND_REDRAW,
535                 B_SOUND_VOLUME,
536                 B_SOUND_PANNING,
537                 B_SOUND_PITCH,
538                 B_SOUND_LOAD_SAMPLE,
539                 B_SOUND_MENU_SAMPLE,
540                 B_SOUND_NAME_SAMPLE,
541                 B_SOUND_UNLINK_SAMPLE,
542                 B_SOUND_RELOAD_SAMPLE,
543                 B_SOUND_UNPACK_SAMPLE,
544                 B_SOUND_PLAY_SAMPLE,
545                 B_SOUND_COPY_SOUND,
546                 B_SOUND_LOOPSTART,
547                 B_SOUND_LOOPEND,
548                 B_SOUND_BIDIRECTIONAL,
549                 B_SOUND_RECALC,
550                 B_SOUND_RATECHANGED,
551                 B_SOUND_MIXDOWN
552 };
553
554 /* *********************** */
555 #define B_CONSTRAINTBUTS        3300
556 enum {
557         B_CONSTRAINT_REDRAW = 3201,
558         B_CONSTRAINT_ADD,
559         B_CONSTRAINT_DEL,
560         B_CONSTRAINT_TEST,
561         B_CONSTRAINT_CHANGETYPE,
562         B_CONSTRAINT_CHANGENAME,
563         B_CONSTRAINT_CHANGETARGET
564 };
565
566 /* *********************** */
567 /*  BUTTON BUT: > 4000     */
568 /*  BUTTON 4001-4032: layers */
569
570
571 static char *physics_pup(void)
572 {
573   /* the number needs to match defines in KX_PhysicsBlenderSceneConverter.cpp */
574   return "Physics %t|None %x1|Sumo %x2|"
575          "ODE %x3 |Dynamo %x4|";
576 }
577
578
579 static void draw_buttons_edge(int win, float x1)
580 {
581         float asp, winmat[4][4];
582         int w,h;
583
584         bwin_getsinglematrix(win, winmat);
585         bwin_getsize(win, &w, &h);
586         asp= (float)(2.0/(w*winmat[0][0]));
587
588         glColor3ub(0,0,0);
589         fdrawline(x1, -1000, x1, 2000);
590         glColor3ub(255,255,255);
591         fdrawline(x1+asp, -1000, x1+asp, 2000);
592 }
593
594 static int packdummy = 0;
595
596 void test_scriptpoin_but(char *name, ID **idpp)
597 {
598         ID *id;
599         
600         id= G.main->text.first;
601         while(id) {
602                 if( strcmp(name, id->name+2)==0 ) {
603                         *idpp= id;
604                         return;
605                 }
606                 id= id->next;
607         }
608         *idpp= 0;
609 }
610 #ifdef __NLA
611 void test_actionpoin_but(char *name, ID **idpp)
612 {
613         ID *id;
614         
615         id= G.main->action.first;
616         while(id) {
617                 if( strcmp(name, id->name+2)==0 ) {
618                         *idpp= id;
619                         return;
620                 }
621                 id= id->next;
622         }
623         *idpp= 0;
624 }
625 #endif
626
627 void test_obpoin_but(char *name, ID **idpp)
628 {
629         ID *id;
630         
631         if(idpp == (ID **)&(emptytex.object)) {
632                 error("You must add a Texture first!");
633                 *idpp= 0;
634                 return;
635         }
636         
637         id= G.main->object.first;
638         while(id) {
639                 if( strcmp(name, id->name+2)==0 ) {
640                         *idpp= id;
641                         return;
642                 }
643                 id= id->next;
644         }
645         *idpp= 0;
646 }
647
648 void test_obcurpoin_but(char *name, ID **idpp)
649 {
650         ID *id;
651         
652         if(idpp == (ID **)&(emptytex.object)) {
653                 error("You must add a Texture first!");
654                 *idpp= 0;
655                 return;
656         }
657         
658         id= G.main->object.first;
659         while(id) {
660                 if( strcmp(name, id->name+2)==0 ) {
661                         if (((Object *)id)->type != OB_CURVE) {
662                                 error ("Bevel object must be a Curve.");
663                                 break;
664                         } 
665                         *idpp= id;
666                         return;
667                 }
668                 id= id->next;
669         }
670         *idpp= 0;
671 }
672
673 void test_meshpoin_but(char *name, ID **idpp)
674 {
675         ID *id;
676
677         if( *idpp ) (*idpp)->us--;
678         
679         id= G.main->mesh.first;
680         while(id) {
681                 if( strcmp(name, id->name+2)==0 ) {
682                         *idpp= id;
683                         id_us_plus(id);
684                         return;
685                 }
686                 id= id->next;
687         }
688         *idpp= 0;
689 }
690
691 void test_matpoin_but(char *name, ID **idpp)
692 {
693         ID *id;
694
695         if( *idpp ) (*idpp)->us--;
696         
697         id= G.main->mat.first;
698         while(id) {
699                 if( strcmp(name, id->name+2)==0 ) {
700                         *idpp= id;
701                         id_us_plus(id);
702                         return;
703                 }
704                 id= id->next;
705         }
706         *idpp= 0;
707 }
708
709 void test_scenepoin_but(char *name, ID **idpp)
710 {
711         ID *id;
712         
713         if( *idpp ) (*idpp)->us--;
714         
715         id= G.main->scene.first;
716         while(id) {
717                 if( strcmp(name, id->name+2)==0 ) {
718                         *idpp= id;
719                         id_us_plus(id);
720                         return;
721                 }
722                 id= id->next;
723         }
724         *idpp= 0;
725 }
726
727
728
729 /* ************************************* */
730
731 static void do_common_editbuts(unsigned short event)
732 {
733         EditVlak *evl;
734         Base *base;
735         Object *ob;
736         Mesh *me;
737         Nurb *nu;
738         Curve *cu;
739         MFace *mface;
740         BezTriple *bezt;
741         BPoint *bp;
742         unsigned int local;
743         int a, bit, index= -1;
744
745         switch(event) {
746                 
747         case B_MATWICH:
748                 if(G.obedit && G.obedit->actcol>0) {
749                         if(G.obedit->type == OB_MESH) {
750                                 evl= G.edvl.first;
751                                 while(evl) {
752                                         if( vlakselectedAND(evl, 1) ) {
753                                                 if(index== -1) index= evl->mat_nr;
754                                                 else if(index!=evl->mat_nr) {
755                                                         error("Mixed colors");
756                                                         return;
757                                                 }
758                                         }
759                                         evl= evl->next;
760                                 }
761                         }
762                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
763                                 nu= editNurb.first;
764                                 while(nu) {
765                                         if( isNurbsel(nu) ) {
766                                                 if(index== -1) index= nu->mat_nr;
767                                                 else if(index!=nu->mat_nr) {
768                                                         error("Mixed colors");
769                                                         return;
770                                                 }
771                                         }
772                                         nu= nu->next;
773                                 }                               
774                         }
775                         if(index>=0) {
776                                 G.obedit->actcol= index+1;
777                                 scrarea_queue_winredraw(curarea);
778                         }
779                 }
780                 break;
781         case B_MATNEW:
782                 new_material_to_objectdata((G.scene->basact) ? (G.scene->basact->object) : 0);
783                 scrarea_queue_winredraw(curarea);
784                 allqueue(REDRAWVIEW3D_Z, 0);
785                 break;
786         case B_MATDEL:
787                 delete_material_index();
788                 scrarea_queue_winredraw(curarea);
789                 allqueue(REDRAWVIEW3D_Z, 0);
790                 break;
791         case B_MATASS:
792                 if(G.obedit && G.obedit->actcol>0) {
793                         if(G.obedit->type == OB_MESH) {
794                                 evl= G.edvl.first;
795                                 while(evl) {
796                                         if( vlakselectedAND(evl, 1) )
797                                                 evl->mat_nr= G.obedit->actcol-1;
798                                         evl= evl->next;
799                                 }
800                                 allqueue(REDRAWVIEW3D_Z, 0);
801                                 makeDispList(G.obedit);
802                         }
803                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
804                                 nu= editNurb.first;
805                                 while(nu) {
806                                         if( isNurbsel(nu) )
807                                                 nu->mat_nr= G.obedit->actcol-1;
808                                         nu= nu->next;
809                                 }
810                         }
811                 }
812                 break;
813         case B_MATSEL:
814         case B_MATDESEL:
815                 if(G.obedit) {
816                         if(G.obedit->type == OB_MESH) {
817                                 evl= G.edvl.first;
818                                 while(evl) {
819                                         if(evl->mat_nr== G.obedit->actcol-1) {
820                                                 if(event==B_MATSEL) {
821                                                         if(evl->v1->h==0) evl->v1->f |= 1;
822                                                         if(evl->v2->h==0) evl->v2->f |= 1;
823                                                         if(evl->v3->h==0) evl->v3->f |= 1;
824                                                         if(evl->v4 && evl->v4->h==0) evl->v4->f |= 1;
825                                                 }
826                                                 else {
827                                                         if(evl->v1->h==0) evl->v1->f &= ~1;
828                                                         if(evl->v2->h==0) evl->v2->f &= ~1;
829                                                         if(evl->v3->h==0) evl->v3->f &= ~1;
830                                                         if(evl->v4 && evl->v4->h==0) evl->v4->f &= ~1;
831                                                 }
832                                         }
833                                         evl= evl->next;
834                                 }
835                                 tekenvertices_ext( event==B_MATSEL );
836                         }
837                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
838                                 nu= editNurb.first;
839                                 while(nu) {
840                                         if(nu->mat_nr==G.obedit->actcol-1) {
841                                                 if(nu->bezt) {
842                                                         a= nu->pntsu;
843                                                         bezt= nu->bezt;
844                                                         while(a--) {
845                                                                 if(bezt->hide==0) {
846                                                                         if(event==B_MATSEL) {
847                                                                                 bezt->f1 |= 1;
848                                                                                 bezt->f2 |= 1;
849                                                                                 bezt->f3 |= 1;
850                                                                         }
851                                                                         else {
852                                                                                 bezt->f1 &= ~1;
853                                                                                 bezt->f2 &= ~1;
854                                                                                 bezt->f3 &= ~1;
855                                                                         }
856                                                                 }
857                                                                 bezt++;
858                                                         }
859                                                 }
860                                                 else if(nu->bp) {
861                                                         a= nu->pntsu*nu->pntsv;
862                                                         bp= nu->bp;
863                                                         while(a--) {
864                                                                 if(bp->hide==0) {
865                                                                         if(event==B_MATSEL) bp->f1 |= 1;
866                                                                         else bp->f1 &= ~1;
867                                                                 }
868                                                                 bp++;
869                                                         }
870                                                 }
871                                         }
872                                         nu= nu->next;
873                                 }
874                                 allqueue(REDRAWVIEW3D, 0);
875                         }
876                 }
877                 break;
878         case B_HIDE:
879                 if(G.obedit) {
880                         if(G.obedit->type == OB_MESH) hide_mesh(0);
881                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) hideNurb(0);
882                 }
883                 break;
884         case B_REVEAL:
885                 if(G.obedit) {
886                         if(G.obedit->type == OB_MESH) reveal_mesh();
887                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) revealNurb();
888                 }
889                 else if(G.f & G_FACESELECT) reveal_tface();
890                 
891                 break;
892         case B_SELSWAP:
893                 if(G.obedit) {
894                         if(G.obedit->type == OB_MESH) selectswap_mesh();
895                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) selectswapNurb();
896                 }
897                 break;
898         case B_AUTOTEX:
899                 ob= OBACT;
900                 if(ob && G.obedit==0) {
901                         if(ob->type==OB_MESH) tex_space_mesh(ob->data);
902                         else if(ob->type==OB_MBALL) ;
903                         else tex_space_curve(ob->data);
904                 }
905                 break;
906         case B_DOCENTRE:
907                 docentre();
908                 break;
909         case B_DOCENTRENEW:
910                 docentre_new();
911                 break;
912         case B_DOCENTRECURSOR:
913                 docentre_cursor();
914                 break;
915         case B_SETSMOOTH:
916         case B_SETSOLID:
917                 if(G.obedit) {
918                         if(G.obedit->type == OB_MESH) {
919                                 evl= G.edvl.first;
920                                 while(evl) {
921                                         if( vlakselectedAND(evl, 1) ) {
922                                                 if(event==B_SETSMOOTH) evl->flag |= ME_SMOOTH;
923                                                 else evl->flag &= ~ME_SMOOTH;
924                                         }
925                                         evl= evl->next;
926                                 }
927
928                                 makeDispList(G.obedit);
929                                 allqueue(REDRAWVIEW3D, 0);
930                         }
931                         else {
932                                 nu= editNurb.first;
933                                 while(nu) {
934                                         if(isNurbsel(nu)) {
935                                                 if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
936                                                 else nu->flag &= ~ME_SMOOTH;
937                                         }
938                                         nu= nu->next;
939                                 }
940                                 
941                         }
942                 }
943                 else {
944                         base= FIRSTBASE;
945                         while(base) {
946                                 if(TESTBASELIB(base)) {
947                                         if(base->object->type==OB_MESH) {
948                                                 me= base->object->data;
949                                                 mface= me->mface;
950                                                 for(a=0; a<me->totface; a++, mface++) {
951                                                         if(event==B_SETSMOOTH) mface->flag |= ME_SMOOTH;
952                                                         else mface->flag &= ~ME_SMOOTH;
953                                                 }
954
955                                                 makeDispList(base->object);
956                                         }
957                                         else if ELEM(base->object->type, OB_SURF, OB_CURVE) {
958                                                 cu= base->object->data;
959                                                 nu= cu->nurb.first;
960                                                 while(nu) {
961                                                         if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
962                                                         else nu->flag &= ~ME_SMOOTH;
963                                                         nu= nu->next;
964                                                 }
965                                         }
966                                 }
967                                 base= base->next;
968                         }
969                         allqueue(REDRAWVIEW3D, 0);
970                 }
971                 break;
972
973         default:
974                 if(event>=B_OBLAY && event<=B_OBLAY+31) {
975                         local= BASACT->lay & 0xFF000000;
976                         BASACT->lay -= local;
977                         if(BASACT->lay==0 || (G.qual & LR_SHIFTKEY)==0) {
978                                 bit= event-B_OBLAY;
979                                 BASACT->lay= 1<<bit;
980                                 scrarea_queue_winredraw(curarea);
981                         }
982                         BASACT->lay += local;
983                         /* optimal redraw */
984                         if( (OBACT->lay & G.vd->lay) && (BASACT->lay & G.vd->lay) );
985                         else if( (OBACT->lay & G.vd->lay)==0 && (BASACT->lay & G.vd->lay)==0 );
986                         else allqueue(REDRAWVIEW3D, 0);
987                         
988                         OBACT->lay= BASACT->lay;
989                 }
990         }
991
992 }
993
994 void common_editbuts(void)
995 {
996         Object *ob;
997         ID *id;
998         Material *ma;
999         uiBlock *block;
1000         void *poin;
1001         float min;
1002         int xco, a, dx, dy;
1003         char str[32];
1004         
1005         ob= OBACT;
1006         if(ob==0) return;
1007         
1008         sprintf(str, "buttonswin %d", curarea->win);
1009         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
1010
1011         /* LAYERS */
1012         xco= 291;
1013         dx= 32;
1014         dy= 30;
1015         for(a=0; a<10; a++) {
1016                 /* the (a+10) evaluates correctly because of
1017            precedence... brackets aren't a bad idea though */
1018                 uiDefButI(block, TOG|BIT|(a+10), B_OBLAY+a+10, "",      (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), &(BASACT->lay), 0, 0, 0, 0, "");
1019                 uiDefButI(block, TOG|BIT|a, B_OBLAY+a, "",(short)(xco+a*(dx/2)), (short)(180+dy/2), (short)(dx/2), (short)(1+dy/2), &(BASACT->lay), 0, 0, 0, 0, "");
1020                 if(a==4) xco+= 5;
1021         }
1022
1023         id= ob->data;
1024         if(id && id->lib) uiSetButLock(1, "Can't edit library data");
1025
1026         uiBlockSetCol(block, BUTGREY);
1027         uiDefBut(block, LABEL, 0, "Drawtype",                                           28,200,100,18, 0, 0, 0, 0, 0, "");
1028         uiDefButC(block, MENU, REDRAWVIEW3D, "Drawtype%t|Bounds %x1|Wire %x2|Solid %x3|Shaded %x4",     
1029                                                                                                                                 28,180,100,18, &ob->dt, 0, 0, 0, 0, "Sets the drawing type of the active object");
1030         uiDefBut(block, LABEL, 0, "Draw Extra",                                         28,160,100,18, 0, 0, 0, 0, 0, "");
1031         uiDefButC(block, TOG|BIT|0, REDRAWVIEW3D, "Bounds",             28, 140, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
1032         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder",
1033                                                                                                                                 28, 120, 100, 18, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
1034         uiDefButC(block, TOG|BIT|5, REDRAWVIEW3D, "Wire",               28, 100, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's wireframe in shaded drawing modes");
1035         uiDefButC(block, TOG|BIT|1, REDRAWVIEW3D, "Axis",               28, 80, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's centre and axis");
1036         uiDefButC(block, TOG|BIT|2, REDRAWVIEW3D, "TexSpace",   28, 60, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
1037         uiDefButC(block, TOG|BIT|3, REDRAWVIEW3D, "Name",               28, 40, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
1038         
1039         uiBlockSetCol(block, BUTGREY);
1040         
1041         /* material and select swap and hide */
1042         if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
1043                 
1044                         if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag );
1045                         else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag );
1046                         else poin= &( ((Curve *)ob->data)->texflag );
1047                         uiDefButI(block, TOG|BIT|0, B_AUTOTEX, "AutoTexSpace",  143,180,130,19, poin, 0, 0, 0, 0, "Adjusts active object's texture space automatically when transforming object");
1048
1049                 sprintf(str,"%d Mat:", ob->totcol);
1050                 if(ob->totcol) min= 1.0; else min= 0.0;
1051                 ma= give_current_material(ob, ob->actcol);
1052                 
1053                 if(ma) {
1054                         uiDefButF(block, COL, 0, "",                    291,123,24,30, &(ma->r), 0, 0, 0, 0, "");
1055                         uiDefBut(block, LABEL, 0, ma->id.name+2, 318,146, 103, 30, 0, 0, 0, 0, 0, "");
1056                 }
1057                 uiDefButC(block, NUM, B_REDR,   str,            318,123,103,30, &ob->actcol, min, (float)(ob->totcol), 0, 0, "Displays total number of material indices and the current index");
1058                 uiDefBut(block, BUT,B_MATWICH,  "?",            423,123,31,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces");
1059                 
1060                 uiBlockSetCol(block, BUTSALMON);
1061                 uiDefBut(block, BUT,B_MATNEW,   "New",          292,101,80,21, 0, 0, 0, 0, 0, "Adds a new Material index");
1062                 uiDefBut(block, BUT,B_MATDEL,   "Delete",       374,101,80,21, 0, 0, 0, 0, 0, "Deletes this Material index");
1063                 uiDefBut(block, BUT,B_MATASS,   "Assign",       291,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces");
1064
1065                 uiBlockSetCol(block, BUTGREY);
1066                 uiDefBut(block, BUT,B_MATSEL,   "Select",       292,76,79,22, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index");
1067                 uiDefBut(block, BUT,B_MATDESEL, "Deselect",     373,76,79,21, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber");
1068                 
1069                 if(ob->type!=OB_FONT) {
1070                         uiDefBut(block, BUT,B_HIDE,             "Hide",         1091,152,77,18, 0, 0, 0, 0, 0, "Hides selected faces");
1071                         uiDefBut(block, BUT,B_REVEAL,   "Reveal",       1171,152,86,18, 0, 0, 0, 0, 0, "Reveals selected faces");
1072                         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  1091,129,166,18, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
1073                 }
1074                 uiDefBut(block, BUT,B_SETSMOOTH,        "Set Smooth",   291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces");
1075                 uiDefBut(block, BUT,B_SETSOLID, "Set Solid",    373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces");
1076
1077         }
1078         
1079         if ELEM3(ob->type, OB_MESH, OB_SURF, OB_CURVE) {
1080                 uiBlockSetCol(block, BUTSALMON);
1081                 uiDefBut(block, BUT,B_DOCENTRE, "Centre",                               961, 115, 100, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
1082                 uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New",                        961, 95, 100, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data");
1083                 uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          961, 75, 100, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
1084         }
1085
1086         
1087         uiDrawBlock(block);
1088         
1089 }
1090
1091
1092
1093 /* *************************** MESH ******************************** */
1094
1095 #ifdef NAN_DECIMATION
1096
1097 static int decimate_count_tria(Object *ob)
1098 {
1099         int tottria;
1100         MFace *mface;
1101         Mesh *me;
1102         int a;
1103         
1104         me= ob->data;
1105         
1106         /* count number of trias, since decimator doesnt allow quads */
1107         tottria= 0;
1108         mface= me->mface;
1109         for(a=0; a<me->totface; a++, mface++) {
1110                 if(mface->v4) tottria++;
1111                 if(mface->v3) tottria++;                
1112         }
1113         
1114         return tottria;
1115 }
1116
1117 static void decimate_faces(void)
1118 {
1119         Object *ob;
1120         Mesh *me;
1121         MVert *mvert;
1122         MFace *mface;
1123         LOD_Decimation_Info lod; 
1124         float *vb=NULL;
1125         float *vnb=NULL;
1126         int *tib=NULL;
1127         int a, tottria;
1128         
1129         /* we assume the active object being decimated */
1130         ob= OBACT;
1131         if(ob==NULL || ob->type!=OB_MESH) return;
1132         me= ob->data;
1133
1134         /* add warning for vertex col and tfaces */
1135         if(me->tface || me->mcol) {
1136                 if(okee("This will remove UV coordinates and vertexcolors")==0) return;
1137                 if(me->tface) MEM_freeN(me->tface);
1138                 if(me->mcol) MEM_freeN(me->mcol);
1139                 me->tface= NULL;
1140                 me->mcol= NULL;
1141         }
1142         
1143         /* count number of trias, since decimator doesnt allow quads */
1144         tottria= decimate_count_tria(ob);
1145
1146         if(tottria<3) {
1147                 error("You must have more than 3 input faces selected.");
1148                 return;
1149         }
1150         /* allocate and init */
1151         lod.vertex_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "vertices");
1152         lod.vertex_normal_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "normals");
1153         lod.triangle_index_buffer= MEM_mallocN(3*sizeof(int)*tottria, "trias");
1154         lod.vertex_num= me->totvert;
1155         lod.face_num= tottria;
1156         
1157         /* fill vertex buffer */
1158         vb= lod.vertex_buffer;
1159         vnb= lod.vertex_normal_buffer;
1160         mvert= me->mvert;
1161         for(a=0; a<me->totvert; a++, mvert++, vb+=3, vnb+=3) {
1162                 VECCOPY(vb, mvert->co);
1163                 VECCOPY(vnb, mvert->no);
1164                 Normalise(vnb);
1165         }
1166         
1167         /* fill index buffer */
1168         mface= me->mface;
1169         tib= lod.triangle_index_buffer;
1170         for(a=0; a<me->totface; a++, mface++) {
1171                 if(mface->v4) {
1172                         tib[0]= mface->v1;
1173                         tib[1]= mface->v3;
1174                         tib[2]= mface->v4;
1175                         tib+= 3;
1176                 }
1177                 if(mface->v3) {
1178                         tib[0]= mface->v1;
1179                         tib[1]= mface->v2;
1180                         tib[2]= mface->v3;
1181                         tib+= 3;
1182                 }
1183         }
1184
1185         if(LOD_LoadMesh(&lod) ) {
1186                 if( LOD_PreprocessMesh(&lod) ) {
1187                         DispList *dl;
1188                         DispListMesh *dlm;
1189                         MFaceInt *mfaceint;
1190                         
1191                         /* we assume the decim_faces tells how much to reduce */
1192                         
1193                         while(lod.face_num > decim_faces) {
1194                                 if( LOD_CollapseEdge(&lod)==0) break;
1195                         }
1196
1197                         /* ok, put back the stuff in a displist */
1198                         freedisplist(&(ob->disp));
1199                         dl= MEM_callocN(sizeof(DispList), "disp");
1200                         BLI_addtail(&ob->disp, dl);
1201                         dl->type= DL_MESH;
1202                         dlm=dl->mesh= MEM_callocN(sizeof(DispListMesh), "dispmesh");
1203                         dlm->mvert= MEM_callocN(lod.vertex_num*sizeof(MVert), "mvert");
1204                         dlm->mface= MEM_callocN(lod.face_num*sizeof(MFaceInt), "mface");
1205                         dlm->totvert= lod.vertex_num;
1206                         dlm->totface= lod.face_num;
1207                         
1208                         mvert= dlm->mvert;
1209                         vb= lod.vertex_buffer;
1210                         for(a=0; a<lod.vertex_num; a++, vb+=3, mvert++) {
1211                                 VECCOPY(mvert->co, vb);
1212                         }
1213                         
1214                         mfaceint= dlm->mface;
1215                         tib= lod.triangle_index_buffer;
1216                         for(a=0; a<lod.face_num; a++, mfaceint++, tib+=3) {
1217                                 mfaceint->v1= tib[0];
1218                                 mfaceint->v2= tib[1];
1219                                 mfaceint->v3= tib[2];
1220                         }
1221                 }
1222                 else error("No memory");
1223
1224                 LOD_FreeDecimationData(&lod);
1225         }
1226         else error("No manifold Mesh");
1227         
1228         MEM_freeN(lod.vertex_buffer);
1229         MEM_freeN(lod.vertex_normal_buffer);
1230         MEM_freeN(lod.triangle_index_buffer);
1231         
1232         allqueue(REDRAWVIEW3D, 0);
1233 }
1234
1235
1236
1237 static void decimate_cancel(void)
1238 {
1239         Object *ob;
1240         
1241         ob= OBACT;
1242         if(ob) {
1243                 freedisplist(&ob->disp);
1244                 makeDispList(ob);
1245         }
1246         allqueue(REDRAWVIEW3D, 0);
1247 }
1248
1249 static void decimate_apply(void)
1250 {
1251         Object *ob;
1252         DispList *dl;
1253         DispListMesh *dlm;
1254         Mesh *me;
1255         MFace *mface;
1256         MFaceInt *mfaceint;
1257         int a;
1258         
1259         if(G.obedit) return;
1260         
1261         ob= OBACT;
1262         if(ob) {
1263                 dl= ob->disp.first;
1264                 if(dl && dl->mesh) {
1265                         dlm= dl->mesh;
1266                         me= ob->data;
1267                         
1268                         // vertices 
1269                         if(me->mvert) MEM_freeN(me->mvert);
1270                         me->mvert= dlm->mvert;
1271                         dlm->mvert= NULL;
1272                         me->totvert= dlm->totvert;
1273                         
1274                         // faces
1275                         if(me->mface) MEM_freeN(me->mface);
1276                         me->mface= MEM_callocN(dlm->totface*sizeof(MFace), "mface");
1277                         me->totface= dlm->totface;
1278                         mface= me->mface;
1279                         mfaceint= dlm->mface;
1280                         for(a=0; a<me->totface; a++, mface++, mfaceint++) {
1281                                 mface->v1= mfaceint->v1;
1282                                 mface->v2= mfaceint->v2;
1283                                 mface->v3= mfaceint->v3;
1284                                 test_index_mface(mface, 3);
1285                         }
1286                         
1287                         freedisplist(&ob->disp);
1288                         
1289                         G.obedit= ob;
1290                         make_editMesh();
1291                         load_editMesh();
1292                         free_editMesh();
1293                         G.obedit= NULL;
1294                         tex_space_mesh(me);
1295                 }
1296                 else error("Not a decimated Mesh");
1297         }
1298 }
1299
1300 #endif
1301
1302 void do_meshbuts(unsigned short event)
1303 {
1304         Object *ob;
1305         Mesh *me;
1306         float fac;
1307         short randfac;
1308
1309         ob= OBACT;
1310         if(ob && ob->type==OB_MESH) {
1311                 
1312                 me= get_mesh(ob);
1313                 if(me==0) return;
1314                 
1315                 switch(event) {
1316 #ifdef __NLA
1317                 case B_AUTOVGROUP:
1318                         if (!get_armature(ob->parent)){
1319                                 error ("Mesh must be the child of an armature");
1320                                 break;
1321                         }
1322                                 /* Verify that there are vertex groups for bones in armature */
1323                                 /* Remove selected vertices from all defgroups */
1324                                 /* Perform assignment for selected vertices */
1325
1326                         allqueue (REDRAWVIEW3D, 1);
1327                         break;
1328                 case B_NEWVGROUP:
1329                         add_defgroup (G.obedit);
1330                         scrarea_queue_winredraw(curarea);
1331                         break;
1332                 case B_DELVGROUP:
1333                         del_defgroup (G.obedit);
1334                         allqueue (REDRAWVIEW3D, 1);
1335                         break;
1336                 case B_ASSIGNVGROUP:
1337                         assign_verts_defgroup ();
1338                         allqueue (REDRAWVIEW3D, 1);
1339                         break;
1340                 case B_REMOVEVGROUP:
1341                         remove_verts_defgroup (0);
1342                         allqueue (REDRAWVIEW3D, 1);
1343                         break;
1344                 case B_SELVGROUP:
1345                         sel_verts_defgroup(1);
1346                         allqueue (REDRAWVIEW3D, 1);
1347                         break;
1348                 case B_DESELVGROUP:
1349                         sel_verts_defgroup(0);
1350                         allqueue (REDRAWVIEW3D, 1);
1351                         break;
1352 #endif
1353                 case B_DELSTICKY:
1354                 
1355                         if(me->msticky) MEM_freeN(me->msticky);
1356                         me->msticky= 0;
1357                         allqueue(REDRAWBUTSEDIT, 0);
1358                         break;
1359                 case B_MAKESTICKY:
1360                         make_sticky();
1361                         break;
1362                 case B_MAKEVERTCOL:
1363                         make_vertexcol();
1364                         break;
1365                 case B_DELVERTCOL:
1366                         if(me->mcol) MEM_freeN(me->mcol);
1367                         me->mcol= 0;
1368                         G.f &= ~G_VERTEXPAINT;
1369                         freedisplist(&(ob->disp));
1370                         allqueue(REDRAWBUTSEDIT, 0);
1371                         allqueue(REDRAWVIEW3D, 0);
1372                         break;
1373
1374                 case B_MAKE_TFACES:
1375                         make_tfaces(me);
1376                         allqueue(REDRAWBUTSEDIT, 0);
1377                         break;
1378
1379                 case B_DEL_TFACES:
1380                         if(me->tface) MEM_freeN(me->tface);
1381                         me->tface= 0;
1382                         G.f &= ~G_FACESELECT;
1383                         allqueue(REDRAWBUTSEDIT, 0);
1384                         allqueue(REDRAWVIEW3D, 0);
1385                         allqueue(REDRAWIMAGE, 0);
1386                         break;
1387                         
1388                 case B_FLIPNORM:
1389                         if(G.obedit) {
1390                                 flip_editnormals();
1391                         }
1392                         else flipnorm_mesh( get_mesh(ob) );
1393                         
1394                         allqueue(REDRAWVIEW3D, 0);
1395                         break;
1396
1397                 case B_DECIM_FACES:
1398                         decimate_faces();
1399                         break;
1400                 case B_DECIM_CANCEL:
1401                         decimate_cancel();
1402                         break;
1403                 case B_DECIM_APPLY:
1404                         decimate_apply();
1405                         break;
1406
1407                 case B_SLOWERDRAW:
1408                         slowerdraw();
1409                         break;
1410                 case B_FASTERDRAW:
1411                         fasterdraw();
1412                         break;
1413                 }
1414         }
1415         
1416         if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return;
1417         
1418         switch(event) {
1419         case B_SPIN:
1420                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 0);
1421                 break;
1422         case B_SPINDUP:
1423                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 1);
1424                 break;
1425         case B_EXTR:
1426                 G.f |= G_DISABLE_OK;
1427                 if( select_area(SPACE_VIEW3D)) extrude_mesh();
1428                 G.f -= G_DISABLE_OK;
1429                 break;
1430         case B_SCREW:
1431                 if( select_area(SPACE_VIEW3D)) screw_mesh(step, turn);
1432                 break;
1433         case B_EXTREP:
1434                 if( select_area(SPACE_VIEW3D)) extrude_repeat_mesh(step, extr_offs);
1435                 break;
1436         case B_SPLIT:
1437                 G.f |= G_DISABLE_OK;
1438                 split_mesh();
1439                 G.f -= G_DISABLE_OK;
1440                 break;
1441         case B_REMDOUB:
1442                 notice("Removed: %d", removedoublesflag(1, doublimit));
1443                 allqueue(REDRAWVIEW3D, 0);
1444                 break;
1445         case B_SUBDIV:
1446                 waitcursor(1);
1447                 subdivideflag(1, 0.0, editbutflag & B_BEAUTY);
1448                 countall();
1449                 waitcursor(0);
1450                 allqueue(REDRAWVIEW3D, 0);
1451                 break;
1452         case B_FRACSUBDIV:
1453                 randfac= 10;
1454                 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
1455                 waitcursor(1);
1456                 fac= -( (float)randfac )/100;
1457                 subdivideflag(1, fac, editbutflag & B_BEAUTY);
1458                 countall();
1459                 waitcursor(0);
1460                 allqueue(REDRAWVIEW3D, 0);
1461                 break;
1462         case B_XSORT:
1463                 if( select_area(SPACE_VIEW3D)) xsortvert_flag(1);
1464                 break;
1465         case B_HASH:
1466                 hashvert_flag(1);
1467                 break;
1468         case B_TOSPHERE:
1469                 vertices_to_sphere();
1470                 break;
1471         case B_VERTEXNOISE:
1472                 vertexnoise();
1473                 break;
1474         case B_VERTEXSMOOTH:
1475                 vertexsmooth();
1476                 break;
1477         }
1478         /* WATCH IT: previous events only in editmode! */
1479 }
1480
1481 static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
1482 {
1483         unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
1484 }
1485
1486 void meshbuts(void)
1487 {
1488         Object *ob;
1489         Mesh *me;
1490         uiBlock *block;
1491         uiBut *but;
1492         float val;
1493         char str[64];
1494 #ifdef __NLA
1495         int by;
1496         float   min;
1497         int     defCount;
1498         bDeformGroup    *defGroup;
1499 #endif
1500
1501         ob= OBACT;
1502         if(ob==0) return;
1503         
1504         sprintf(str, "editbuttonswin %d", curarea->win);
1505         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
1506
1507         me= get_mesh(ob);
1508         
1509         if(me) {
1510                 uiDefButS(block, TOG|BIT|1, REDRAWVIEW3D, "No V.Normal Flip",   143,160,130,18, &me->flag, 0, 0, 0, 0, "Disables flipping of vertexnormals during render");
1511                 uiBlockSetCol(block, BUTGREEN);
1512                 uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Auto Smooth",        143,140,130,18, &me->flag, 0, 0, 0, 0, "Treats all faces with angles less than Degr: as 'smooth' during render");
1513                 uiBlockSetCol(block, BUTGREY);
1514                 uiDefButS(block, NUM, B_DIFF, "Degr:",                                                  143, 120, 130, 18, &me->smoothresh, 1, 80, 0, 0, "Defines maximum angle between face normals that 'Auto Smooth' will operate on");
1515                 uiBlockSetCol(block, BUTGREEN);
1516                 uiDefButS(block, TOG|BIT|7, B_MAKEDISP, "SubSurf",      143,100,130,18, &me->flag, 0, 0, 0, 0, "Treats the active object as a Catmull-Clark Subdivision Surface");
1517                 uiBlockSetCol(block, BUTGREY);
1518                 uiDefButS(block, NUM, B_MAKEDISP, "Subdiv:",                    143, 80, 100, 18, &me->subdiv, 0, 12, 0, 0, "Defines the level of subdivision to display in real time interactively");
1519                 uiDefButS(block, NUM, B_MAKEDISP, "",                           243, 80, 30, 18, &me->subdivr, 0, 12, 0, 0, "Defines the level of subdivision to apply during rendering");
1520                 uiDefButS(block, TOG|BIT|2, REDRAWVIEW3D, "Double Sided",       1090,184,164,19, &me->flag, 0, 0, 0, 0, "Toggles selected faces as doublesided or single-sided");
1521                 
1522                 uiBlockSetCol(block, BUTSALMON);
1523                 
1524                 if(me->msticky) val= 1.0; else val= 0.0;
1525                 uiDefBut(block, LABEL, 0, "Sticky", 137,55,70,20, 0, val, 0, 0, 0, "");
1526                 if(me->msticky==0) {
1527                         uiDefBut(block, BUT, B_MAKESTICKY, "Make",      210,58,63,19, 0, 0, 0, 0, 0, "Creates Sticky coordinates for the active object from the current camera view background picture");
1528                 }
1529                 else uiDefBut(block, BUT, B_DELSTICKY, "Delete", 210,58,63,19, 0, 0, 0, 0, 0, "Deletes Sticky texture coordinates");
1530         
1531                 if(me->mcol) val= 1.0; else val= 0.0;
1532                 uiDefBut(block, LABEL, 0, "VertCol", 140,33,70,20, 0, val, 0, 0, 0, "");
1533                 if(me->mcol==0) {
1534                         uiDefBut(block, BUT, B_MAKEVERTCOL, "Make",     209,36,64,19, 0, 0, 0, 0, 0, "Enables vertex colour painting on active object");
1535                 }
1536                 else uiDefBut(block, BUT, B_DELVERTCOL, "Delete", 209,36,64,19, 0, 0, 0, 0, 0, "Deletes vertex colours on active object");
1537
1538                         if(me->tface) val= 1.0; else val= 0.0;
1539                         uiDefBut(block, LABEL, 0, "TexFace", 142,13,70,20, 0, val, 0, 0, 0, "");
1540                         if(me->tface==0) {
1541                                 uiDefBut(block, BUT, B_MAKE_TFACES, "Make",     209,14,64,20, 0, 0, 0, 0, 0, "Enables the active object's faces for UV coordinate mapping");
1542                         }
1543                         else uiDefBut(block, BUT, B_DEL_TFACES, "Delete", 209,14,64,20, 0, 0, 0, 0, 0, "Deletes UV coordinates for active object's faces");
1544                 
1545                 uiBlockSetCol(block, BUTGREY);
1546         
1547                 uiDefIDPoinBut(block, test_meshpoin_but, 0, "TexMesh: ",                477,185,249,19, &me->texcomesh, "Enter the name of a Meshblock");
1548         }               
1549         
1550
1551         /* EDIT */
1552                 
1553         if(me) {
1554 #ifdef NAN_DECIMATION
1555                 int tottria= decimate_count_tria(ob);
1556                 DispList *dl;
1557
1558                 // wacko, wait for new displist system (ton)
1559                 if( (dl=ob->disp.first) && dl->mesh);
1560                 else decim_faces= tottria;
1561
1562                 uiBlockSetCol(block, BUTPURPLE);
1563                 uiDefButI(block, NUMSLI,B_DECIM_FACES, "Decimator: ",   477,155,249,20, &decim_faces, 4.0, tottria, 10, 10, "Defines the number of triangular faces to decimate the active Mesh object to");
1564                 uiBlockSetCol(block, BUTSALMON);
1565                 uiDefBut(block, BUT,B_DECIM_CANCEL, "Cancel",   477,135,124,19, 0, 0, 0, 0, 0, "Restores the Mesh to its original number of faces");
1566                 uiDefBut(block, BUT,B_DECIM_APPLY, "Apply",             602,135,124,19, 0, 0, 0, 0, 0, "Applies the decimation to the active Mesh object");
1567 #endif
1568         
1569                 uiBlockSetCol(block, BUTSALMON);
1570                 uiDefBut(block, BUT,B_EXTR,"Extrude",   477,100,249,24, 0, 0, 0, 0, 0, "Converts selected edges to faces and selects the new vertices");
1571                 uiDefBut(block, BUT,B_SPINDUP,"Spin Dupe",      639,75,87,24, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a circle around the cursor in the indicated viewport");
1572                 uiDefBut(block, BUT,B_SPIN, "Spin",             558,75,78,24, 0, 0, 0, 0, 0, "Extrudes the selected vertices in a circle around the cursor in the indicated viewport");
1573                 uiDefBut(block, BUT,B_SCREW,"Screw",            477,75,79,24, 0, 0, 0, 0, 0, "Activates the screw tool");  // Bish - This could use some more definition
1574                 uiDefBut(block, BUT,B_EXTREP, "Extrude Dupe",477,15,128,19, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a straight line away from the current viewport");
1575         
1576                 uiBlockSetCol(block, BUTGREY);
1577                 uiDefButS(block, NUM, B_DIFF, "Degr:",          477,55,78,19, &degr,10.0,360.0, 0, 0, "Specifies the number of degrees 'Spin' revolves");
1578                 uiDefButS(block, NUM, B_DIFF, "Steps:",         558,55,78,19, &step,1.0,180.0, 0, 0, "Specifies the total number of 'Spin' slices");
1579                 uiDefButS(block, NUM, B_DIFF, "Turns:",         639,55,86,19, &turn,1.0,360.0, 0, 0, "Specifies the number of revolutions the screw turns");
1580                 uiDefButS(block, TOG|BIT|0, B_DIFF, "Clockwise",        639,35,86,19, &editbutflag, 0, 0, 0, 0, "Specifies the direction for 'Screw' and 'Spin'");
1581                 uiDefButS(block, TOG|BIT|1, B_DIFF, "Keep Original",    477,35,156,19, &editbutflag, 0, 0, 0, 0, "Keeps a copy of the original vertices and faces after executing tools");
1582                 uiDefButF(block, NUM, B_DIFF, "Offset:",                608,15,117,19, &extr_offs, 0.01, 10.0, 100, 0, "Sets the distance between each copy for 'Extrude Dupe'");
1583         }
1584
1585         by=206;
1586
1587         uiBlockSetCol(block, BUTGREEN);
1588         uiDefButS(block, TOG|BIT|2, 0, "Beauty",        847,by-=20,94,19, &editbutflag, 0, 0, 0, 0, "Causes 'Subdivide' to split faces in halves instead of quarters");
1589         uiBlockSetCol(block, BUTSALMON);
1590
1591         uiDefBut(block, BUT,B_SPLIT,"Split",                    847,by-=19,94,18, 0, 0, 0, 0, 0, "Separates selected faces from unselected faces");
1592         uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",     847,by-=19,94,18, 0, 0, 0, 0, 0, "Moves selected vertices outwards into a spherical shape");
1593         uiDefBut(block, BUT,B_SUBDIV,"Subdivide",       847,by-=19,94,18, 0, 0, 0, 0, 0, "Splits selected faces into halves or quarters");
1594         uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd",847,by-=19,94,18, 0, 0, 0, 0, 0, "Subdivides selected faces with a random factor");
1595         
1596         uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",                              847,by-=19,94,18, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
1597         uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",                            847,by-=19,94,18, 0, 0, 0, 0, 0, "Flattens angles of selected faces");
1598         uiDefBut(block, BUT,B_XSORT,"Xsort",                    847,by-=19,94,18, 0, 0, 0, 0, 0, "Sorts selected vertice data in the X direction");
1599         uiDefBut(block, BUT,B_HASH,"Hash",                      847,by-=19,94,18, 0, 0, 0, 0, 0, "Randomizes selected vertice sequence data");
1600
1601         uiBlockSetCol(block, BUTGREY);
1602         uiDefButF(block, NUM, B_DIFF, "Limit:",                 959,151,100,19, &doublimit, 0.0001, 1.0, 10, 0, "Specifies the max distance 'Rem Doubles' will consider vertices as 'doubled'");
1603
1604         uiBlockSetCol(block, BUTSALMON);
1605         
1606         uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    958,173,101,32, 0, 0, 0, 0, 0, "Removes duplicates from selected vertices");
1607
1608         uiDefBut(block, BUT,B_FLIPNORM,"Flip Normals",          961,55,100,19, 0, 0, 0, 0, 0, "Toggles the direction of the selected face's normals");
1609
1610         uiDefBut(block, BUT, B_SLOWERDRAW,"SlowerDraw",                 961,35,100,19, 0, 0, 0, 0, 0, "Displays the active object with all possible edges shown");
1611         uiDefBut(block, BUT, B_FASTERDRAW,"FasterDraw",                 961,15,100,19, 0, 0, 0, 0, 0, "Displays the active object faster by omitting some edges when drawing");
1612
1613 #ifdef __NLA
1614                 
1615                 /* Draw Vertex grouping buttons if we're in editmode*/
1616         if (ob){
1617                 char *s, *menustr;
1618                 bDeformGroup *dg;
1619                 int index;
1620                 
1621                 by = 210;
1622                 uiBlockSetCol(block, BUTGREY);
1623                 uiDefBut(block, LABEL,0,"Vertex Groups",                        740,by-=19,93,18, 0, 0, 0, 0, 0, "");
1624
1625                 defCount=BLI_countlist(&ob->defbase);
1626
1627                 if (!defCount)
1628                         min=0;
1629                 else
1630                         min=1;
1631                                 
1632 #if 0
1633                 sprintf (str, "%d Group:", defCount);
1634                 uiDefButS(block, NUM, REDRAWBUTSEDIT, str,      740, by-=22,93,18, &ob->actdef, min, defCount, 0, 0, "");
1635 #else
1636                 s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
1637
1638                 for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next){
1639                         int cnt= sprintf (s, "%s%%x%d|", dg->name, index);
1640                         
1641                         if (cnt>0)
1642                                 s+= cnt;
1643                 }
1644                 
1645                 by-=22;
1646                 if (defCount)
1647                         uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr, 740, by,18,18, &ob->actdef, min, defCount, 0, 0, "Browses available vertex groups");
1648                 MEM_freeN (menustr);
1649 #endif
1650                 if (ob->actdef){
1651                         defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
1652                         but= uiDefBut(block, TEX,REDRAWBUTSEDIT,"",                     758,by,93-18,18, defGroup->name, 0, 32, 0, 0, "Displays current vertex group name. Click to change. (Match bone name for deformation.)");
1653                         uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
1654                 }
1655                 uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          740, by-=22, 93, 18, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
1656
1657         }
1658                 
1659         if (G.obedit && G.obedit==ob){
1660
1661                 uiBlockSetCol(block, BUTSALMON);
1662 /*              uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assigns deformation groups"); */
1663                 uiDefBut(block, BUT,B_NEWVGROUP,"New",                          740,by-=22,45,18, 0, 0, 0, 0, 0, "Creates a new vertex group");
1664                 uiDefBut(block, BUT,B_DELVGROUP,"Delete",                       788,by,45,18, 0, 0, 0, 0, 0, "Removes the current vertex group");
1665
1666                 uiBlockSetCol(block, BUTSALMON);
1667                 uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",                    740,by-=22,93,18, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group");
1668                 uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",                    740,by-=22,93,18, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group");
1669
1670                 uiBlockSetCol(block, BUTGREY);
1671                 uiDefBut(block, BUT,B_SELVGROUP,"Select",                       740,by-=22,93,18, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group");
1672                 uiDefBut(block, BUT,B_DESELVGROUP,"Deselect",                   740,by-=22,93,18, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group");
1673
1674 }
1675 #endif
1676
1677         uiBlockSetCol(block, BUTGREY);
1678         uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",               1090, 90, 164, 19, &editbutsize, 0.001, 2.0, 10, 0, "Sets the length to use when displaying face normals");
1679         uiDefButI(block, TOG|BIT|6, REDRAWVIEW3D, "Draw Normals",       1090,70,164,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
1680         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces", 1090,50,164,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
1681         uiDefButI(block, TOG|BIT|18, REDRAWVIEW3D, "Draw Edges", 1090,30,164,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
1682         uiDefButI(block, TOG|BIT|11, 0, "All edges",                            1090,10,164,19, &G.f, 0, 0, 0, 0, "Displays all edges in object mode without optimization");
1683
1684         uiDrawBlock(block);
1685 }
1686
1687 // Bish made it to here. (reviewing tooltips)
1688
1689
1690 /* *************************** FONT ******************************** */
1691
1692 short give_vfontnr(VFont *vfont)
1693 {
1694         VFont *vf;
1695         short nr= 1;
1696
1697         vf= G.main->vfont.first;
1698         while(vf) {
1699                 if(vf==vfont) return nr;
1700                 nr++;
1701                 vf= vf->id.next;
1702         }
1703         return -1;
1704 }
1705
1706 VFont *give_vfontpointer(int nr)        /* nr= button */
1707 {
1708         VFont *vf;
1709         short tel= 1;
1710
1711         vf= G.main->vfont.first;
1712         while(vf) {
1713                 if(tel==nr) return vf;
1714                 tel++;
1715                 vf= vf->id.next;
1716         }
1717         return G.main->vfont.first;
1718 }
1719
1720 VFont *exist_vfont(char *str)
1721 {
1722         VFont *vf;
1723
1724         vf= G.main->vfont.first;
1725         while(vf) {
1726                 if(strcmp(vf->name, str)==0) return vf;
1727                 vf= vf->id.next;
1728         }
1729         return 0;
1730 }
1731
1732 static char *give_vfontbutstr(void)
1733 {
1734         VFont *vf;
1735         int len= 0;
1736         char *str, di[FILE_MAXDIR], fi[FILE_MAXFILE];
1737
1738         vf= G.main->vfont.first;
1739         while(vf) {
1740                 strcpy(di, vf->name);
1741                 BLI_splitdirstring(di, fi);
1742                 len+= strlen(fi)+4;
1743                 vf= vf->id.next;
1744         }
1745         
1746         str= MEM_callocN(len+21, "vfontbutstr");
1747         strcpy(str, "FONTS %t");
1748         vf= G.main->vfont.first;
1749         while(vf) {
1750                 
1751                 if(vf->id.us==0) strcat(str, "|0 ");
1752                 else strcat(str, "|   ");
1753                 
1754                 strcpy(di, vf->name);
1755                 BLI_splitdirstring(di, fi);
1756                 
1757                 strcat(str, fi);
1758                 vf= vf->id.next;
1759         }
1760         return str;
1761 }
1762
1763 void load_buts_vfont(char *name)
1764 {
1765         VFont *vf;
1766         Curve *cu;
1767         
1768         if(OBACT && OBACT->type==OB_FONT) cu= OBACT->data;
1769         else return;
1770         
1771         vf= exist_vfont(name);
1772         if(vf==0) {
1773                 vf= load_vfont(name);
1774                 if(vf==0) return;
1775         }
1776         else id_us_plus((ID *)vf);
1777         
1778         if(cu->vfont) cu->vfont->id.us--;
1779         cu->vfont= vf;
1780         
1781         text_to_curve(OBACT, 0);
1782         makeDispList(OBACT);
1783         allqueue(REDRAWVIEW3D, 0);
1784         allqueue(REDRAWBUTSEDIT, 0);
1785 }
1786
1787 void do_fontbuts(unsigned short event)
1788 {
1789         Curve *cu;
1790         VFont *vf;
1791         Object *ob;
1792         ScrArea *sa;
1793         char str[80];
1794         
1795         ob= OBACT;
1796         
1797         switch(event) {
1798         case B_MAKEFONT:
1799                 text_to_curve(ob, 0);
1800                 makeDispList(ob);
1801                 allqueue(REDRAWVIEW3D, 0);
1802                 break;
1803         case B_TOUPPER:
1804                 to_upper();
1805                 break;
1806         case B_LOADFONT:
1807                 vf= give_vfontpointer(G.buts->texnr);
1808                 if(vf && vf->id.prev!=vf->id.next) strcpy(str, vf->name);
1809                 else strcpy(str, U.fontdir);
1810                 
1811                 sa= closest_bigger_area();
1812                 areawinset(sa->win);
1813
1814                 activate_fileselect(FILE_SPECIAL, "SELECT FONT", str, load_buts_vfont);
1815
1816                 break;
1817         case B_PACKFONT:
1818                 if (ob) {
1819                         cu= ob->data;
1820                         if(cu && cu->vfont) {
1821                                 if (cu->vfont->packedfile) {
1822                                         if (G.fileflags & G_AUTOPACK) {
1823                                                 if (okee("Disable AutoPack ?")) {
1824                                                         G.fileflags &= ~G_AUTOPACK;
1825                                                 }
1826                                         }
1827                                         
1828                                         if ((G.fileflags & G_AUTOPACK) == 0) {
1829                                                 if (unpackVFont(cu->vfont, PF_ASK) == RET_OK) {
1830                                                         text_to_curve(ob, 0);
1831                                                         makeDispList(ob);
1832                                                         allqueue(REDRAWVIEW3D, 0);
1833                                                 }
1834                                         }
1835                                 } else {
1836                                         cu->vfont->packedfile = newPackedFile(cu->vfont->name);
1837                                 }
1838                         }
1839                 }
1840                 allqueue(REDRAWHEADERS, 0);
1841                 allqueue(REDRAWBUTSEDIT, 0);
1842                 break;
1843
1844         case B_SETFONT:
1845                 if(ob) {
1846                         cu= ob->data;
1847
1848                         vf= give_vfontpointer(G.buts->texnr);
1849                         if(vf) {
1850                                 id_us_plus((ID *)vf);
1851                                 cu->vfont->id.us--;
1852                                 cu->vfont= vf;
1853                                 text_to_curve(ob, 0);
1854                                 makeDispList(ob);
1855                                 allqueue(REDRAWVIEW3D, 0);
1856                                 allqueue(REDRAWBUTSEDIT, 0);
1857                         }
1858                 }       
1859                 break;
1860         case B_TEXTONCURVE:
1861                 if(ob) {
1862                         cu= ob->data;
1863                         if(cu->textoncurve && cu->textoncurve->type!=OB_CURVE) {
1864                                 error("Only Curve Objects");
1865                                 cu->textoncurve= 0;
1866                                 allqueue(REDRAWBUTSEDIT, 0);
1867                         }
1868                         text_to_curve(ob, 0);
1869                         makeDispList(ob);
1870                 }
1871         }
1872 }
1873
1874
1875
1876 void fontbuts(void)
1877 {
1878         Curve *cu;
1879         uiBlock *block;
1880         char *strp, str[64];
1881         
1882         if(OBACT==0) return;
1883
1884         sprintf(str, "editbuttonswin1 %d", curarea->win);
1885         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
1886
1887         cu= OBACT->data;
1888
1889         uiBlockSetCol(block, BUTGREEN);
1890         uiDefButS(block, ROW,B_MAKEFONT, "Left",                484,139,53,18, &cu->spacemode, 0.0,0.0, 0, 0, "");
1891         uiDefButS(block, ROW,B_MAKEFONT, "Middle",      604,139,61,18, &cu->spacemode, 0.0,1.0, 0, 0, "");
1892         uiDefButS(block, ROW,B_MAKEFONT, "Right",               540,139,62,18, &cu->spacemode, 0.0,2.0, 0, 0, "");
1893         uiDefButS(block, ROW,B_MAKEFONT, "Flush",               665,139,61,18, &cu->spacemode, 0.0,3.0, 0, 0, "");
1894
1895         uiBlockSetCol(block, BUTGREY);
1896
1897         uiDefIDPoinBut(block, test_obpoin_but, B_TEXTONCURVE, "TextOnCurve:",   484,115,243,19, &cu->textoncurve, "");
1898
1899         uiDefButF(block, NUM,B_MAKEFONT, "Size:",               482,56,121,19, &cu->fsize, 0.1,10.0, 10, 0, "");
1900         uiDefButF(block, NUM,B_MAKEFONT, "Linedist:",   605,56,121,19, &cu->linedist, 0.0,10.0, 10, 0, "");
1901         uiDefButF(block, NUM,B_MAKEFONT, "Spacing:",    482,34,121,19, &cu->spacing, 0.0,10.0, 10, 0, "");
1902         uiDefButF(block, NUM,B_MAKEFONT, "Y offset:",   605,34,121,19, &cu->yof, -50.0,50.0, 10, 0, "");
1903         uiDefButF(block, NUM,B_MAKEFONT, "Shear:",      482,12,121,19, &cu->shear, -1.0,1.0, 10, 0, "");
1904         uiDefButF(block, NUM,B_MAKEFONT, "X offset:",   605,12,121,19, &cu->xof, -50.0,50.0, 10, 0, "");
1905
1906         uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 752,192,164,19, cu->family, 0.0, 20.0, 0, 0, "");
1907
1908         uiBlockSetCol(block, BUTSALMON);
1909         uiDefBut(block, BUT, B_TOUPPER, "ToUpper",              623,163,103,23, 0, 0, 0, 0, 0, "");
1910         
1911         uiBlockSetCol(block, BUTGREY);
1912
1913         G.buts->texnr= give_vfontnr(cu->vfont);
1914         
1915         strp= give_vfontbutstr();
1916         
1917         uiDefButS(block, MENU, B_SETFONT, strp, 484,191,220,20, &G.buts->texnr, 0, 0, 0, 0, "");
1918         
1919         if (cu->vfont->packedfile) {
1920                 packdummy = 1;
1921         } else {
1922                 packdummy = 0;
1923         }
1924         
1925         uiBlockSetCol(block, BUTYELLOW);
1926         uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE,       706,191,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this Vectorfont");
1927         
1928         MEM_freeN(strp);
1929         
1930         uiBlockSetCol(block, BUTSALMON);
1931         uiDefBut(block, BUT,B_LOADFONT, "Load Font",    484,163,103,23, 0, 0, 0, 0, 0, "");
1932         
1933         uiDrawBlock(block);
1934 }
1935
1936 /* *************************** CURVE ******************************** */
1937
1938
1939 void do_curvebuts(unsigned short event)
1940 {
1941         extern Nurb *lastnu;
1942         Object *ob;
1943         Curve *cu;
1944         Nurb *nu;
1945         
1946         ob= OBACT;
1947         if(ob==0) return;
1948         
1949         switch(event) { 
1950
1951         case B_CONVERTPOLY:
1952         case B_CONVERTBEZ:
1953         case B_CONVERTBSPL:
1954         case B_CONVERTCARD:
1955         case B_CONVERTNURB:
1956                 if(G.obedit) {
1957                         setsplinetype(event-B_CONVERTPOLY);
1958                         makeDispList(G.obedit);
1959                         allqueue(REDRAWVIEW3D, 0);
1960                 }
1961                 break;
1962         case B_UNIFU:
1963         case B_ENDPU:
1964         case B_BEZU:
1965         case B_UNIFV:
1966         case B_ENDPV:
1967         case B_BEZV:
1968                 if(G.obedit) {
1969                         nu= editNurb.first;
1970                         while(nu) {
1971                                 if(isNurbsel(nu)) {
1972                                         if((nu->type & 7)==CU_NURBS) {
1973                                                 if(event<B_UNIFV) {
1974                                                         nu->flagu &= 1;
1975                                                         nu->flagu += ((event-B_UNIFU)<<1);
1976                                                         makeknots(nu, 1, nu->flagu>>1);
1977                                                 }
1978                                                 else if(nu->pntsv>1) {
1979                                                         nu->flagv &= 1;
1980                                                         nu->flagv += ((event-B_UNIFV)<<1);
1981                                                         makeknots(nu, 2, nu->flagv>>1);
1982                                                 }
1983                                         }
1984                                 }
1985                                 nu= nu->next;
1986                         }
1987                         makeDispList(G.obedit);
1988                         allqueue(REDRAWVIEW3D, 0);
1989                 }
1990                 break;
1991         case B_SETWEIGHT:
1992                 if(G.obedit) {
1993                         weightflagNurb(1, editbutweight, 0);
1994                         makeDispList(G.obedit);
1995                         allqueue(REDRAWVIEW3D, 0);
1996                 }
1997                 break;
1998         case B_SETW1:
1999                 editbutweight= 1.0;
2000                 scrarea_queue_winredraw(curarea);
2001                 break;
2002         case B_SETW2:
2003                 editbutweight= sqrt(2.0)/4.0;
2004                 scrarea_queue_winredraw(curarea);
2005                 break;
2006         case B_SETW3:
2007                 editbutweight= 0.25;
2008                 scrarea_queue_winredraw(curarea);
2009                 break;
2010         case B_SETW4:
2011                 editbutweight= sqrt(0.5);
2012                 scrarea_queue_winredraw(curarea);
2013                 break;
2014         case B_SETORDER:
2015                 if(G.obedit) {
2016                         nu= lastnu;
2017                         if(nu && (nu->type & 7)==CU_NURBS ) {
2018                                 if(nu->orderu>nu->pntsu) {
2019                                         nu->orderu= nu->pntsu;
2020                                         scrarea_queue_winredraw(curarea);
2021                                 }
2022                                 makeknots(nu, 1, nu->flagu>>1);
2023                                 if(nu->orderv>nu->pntsv) {
2024                                         nu->orderv= nu->pntsv;
2025                                         scrarea_queue_winredraw(curarea);
2026                                 }
2027                                 makeknots(nu, 2, nu->flagv>>1);
2028                         }
2029                         makeDispList(G.obedit);
2030                         allqueue(REDRAWVIEW3D, 0);
2031                 }
2032                 break;
2033         case B_MAKEDISP:
2034                 if(ob->type==OB_FONT) text_to_curve(ob, 0);
2035                 makeDispList(ob);
2036                 allqueue(REDRAWVIEW3D, 0);
2037                 allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
2038                 break;
2039         
2040         case B_SUBDIVCURVE:
2041                 subdivideNurb();
2042                 break;
2043         case B_SPINNURB:
2044                 /* bad bad bad!!! use brackets!!! In case you wondered:
2045                   {==,!=} goes before & goes before || */
2046                 if( (G.obedit==0) || 
2047                     (G.obedit->type!=OB_SURF) || 
2048                         ((G.obedit->lay & G.vd->lay) == 0) ) return;
2049                 spinNurb(0, 0);
2050                 countall();
2051                 makeDispList(G.obedit);
2052                 allqueue(REDRAWVIEW3D, 0);
2053                 break;
2054         case B_CU3D:        /* allow 3D curve */
2055                 if(G.obedit) {
2056                         cu= G.obedit->data;
2057                         nu= editNurb.first;
2058                         while(nu) {
2059                                 nu->type &= ~CU_2D;
2060                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
2061                                 test2DNurb(nu);
2062                                 nu= nu->next;
2063                         }
2064                 }
2065                 if(ob->type==OB_CURVE) {
2066                         cu= ob->data;
2067                         nu= cu->nurb.first;
2068                         while(nu) {
2069                                 nu->type &= ~CU_2D;
2070                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
2071                                 test2DNurb(nu);
2072                                 nu= nu->next;
2073                         }
2074                 }
2075                 break;
2076         case B_SETRESOLU:
2077                 if(ob->type==OB_CURVE) {
2078                         cu= ob->data;
2079                         if(ob==G.obedit) nu= editNurb.first;
2080                         else nu= cu->nurb.first;
2081                         
2082                         while(nu) {
2083                                 nu->resolu= cu->resolu;
2084                                 nu= nu->next;
2085                         }
2086                 }
2087                 else if(ob->type==OB_FONT) text_to_curve(ob, 0);
2088                 
2089                 makeDispList(ob);
2090                 allqueue(REDRAWVIEW3D, 0);
2091
2092                 break;
2093         }
2094 }
2095
2096 void curvebuts(void)
2097 {
2098         Object *ob;
2099         Curve *cu;
2100         Nurb *nu;
2101         extern Nurb *lastnu;
2102         uiBlock *block;
2103         short *sp;
2104         char str[64];
2105         
2106         ob= OBACT;
2107         if(ob==0) return;
2108
2109         sprintf(str, "editbuttonswin %d", curarea->win);
2110         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2111
2112         cu= ob->data;
2113
2114         if(ob->type==OB_CURVE || ob->type==OB_SURF) {
2115                 uiBlockSetCol(block, BUTSALMON);
2116                 uiDefBut(block, LABEL, 0, "Convert",    463,173,72, 18, 0, 0, 0, 0, 0, "");
2117                 uiDefBut(block, BUT,B_CONVERTPOLY,"Poly",               467,152,72, 18, 0, 0, 0, 0, 0, "");
2118                 uiDefBut(block, BUT,B_CONVERTBEZ,"Bezier",      467,132,72, 18, 0, 0, 0, 0, 0, "");
2119                 uiDefBut(block, BUT,B_CONVERTBSPL,"Bspline",    467,112,72, 18, 0, 0, 0, 0, 0, "");
2120                 uiDefBut(block, BUT,B_CONVERTCARD,"Cardinal",   467,92,72, 18, 0, 0, 0, 0, 0, "");
2121                 uiDefBut(block, BUT,B_CONVERTNURB,"Nurb",               467,72,72, 18, 0, 0, 0, 0, 0, "");
2122         
2123                 uiDefBut(block, LABEL, 0, "Make Knots",562,173,102, 18, 0, 0, 0, 0, 0, "");
2124                 uiDefBut(block, BUT,B_UNIFU,"Uniform U",        565,152,102, 18, 0, 0, 0, 0, 0, "");
2125                 uiDefBut(block, BUT,B_ENDPU,"Endpoint U",       565,132,102, 18, 0, 0, 0, 0, 0, "");
2126                 uiDefBut(block, BUT,B_BEZU,"Bezier U",  565,112,102, 18, 0, 0, 0, 0, 0, "");
2127                 uiDefBut(block, BUT,B_UNIFV,"V",                670,152,50, 18, 0, 0, 0, 0, 0, "");
2128                 uiDefBut(block, BUT,B_ENDPV,"V",                670,132,50, 18, 0, 0, 0, 0, 0, "");
2129                 uiDefBut(block, BUT,B_BEZV,"V",         670,112,50, 18, 0, 0, 0, 0, 0, "");
2130         
2131                 uiDefBut(block, BUT,B_SETWEIGHT,"Set Weight",   465,11,95,49, 0, 0, 0, 0, 0, "");
2132                 uiBlockSetCol(block, BUTGREY);
2133                 uiDefButF(block, NUM,0,"Weight:",       564,36,102,22, &editbutweight, 0.01, 10.0, 10, 0, "");
2134                 uiDefBut(block, BUT,B_SETW1,"1.0",              669,36,50,22, 0, 0, 0, 0, 0, "");
2135                 uiDefBut(block, BUT,B_SETW2,"sqrt(2)/4",        564,11,57,20, 0, 0, 0, 0, 0, "");
2136                 uiDefBut(block, BUT,B_SETW3,"0.25",             621,11,43,20, 0, 0, 0, 0, 0, "");
2137                 uiDefBut(block, BUT,B_SETW4,"sqrt(0.5)",        664,11,57,20, 0, 0, 0, 0, 0, "");
2138                 
2139                 if(ob==G.obedit) {
2140                         nu= lastnu;
2141                         if(nu==NULL) nu= editNurb.first;
2142                         if(nu) {
2143                                 sp= &(nu->orderu); 
2144                                 uiDefButS(block, NUM, B_SETORDER, "Order U:", 565,91,102, 18, sp, 2.0, 6.0, 0, 0, "");
2145                                 sp= &(nu->orderv); 
2146                                 uiDefButS(block, NUM, B_SETORDER, "V:",  670,91,50, 18, sp, 2.0, 6.0, 0, 0, "");
2147                                 sp= &(nu->resolu); 
2148                                 uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 18, sp, 1.0, 128.0, 0, 0, "");
2149                                 sp= &(nu->resolv); 
2150                                 uiDefButS(block, NUM, B_MAKEDISP, "V:", 670,70,50, 18, sp, 1.0, 128.0, 0, 0, "");
2151                         }
2152                 }
2153
2154                 uiBlockSetCol(block, BUTSALMON);
2155                 uiDefBut(block, BUT, B_SUBDIVCURVE, "Subdivide",        1092,105,165,20, 0, 0, 0, 0, 0, "");
2156         }
2157
2158         if(ob->type==OB_SURF) {
2159                 uiDefBut(block, BUT, B_SPINNURB, "Spin",        808,92,101,36, 0, 0, 0, 0, 0, "");
2160
2161                 uiBlockSetCol(block, BUTGREY);
2162                 uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                                       143,160,130,18, &cu->flag, 0, 0, 0, 0, "");
2163                 uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "No Puno Flip",       143,140,130,18, &cu->flag, 0, 0, 0, 0, "");
2164         }
2165         else {
2166
2167                 uiBlockSetCol(block, BUTGREY);
2168                 uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                       143,160,130,18, &cu->flag, 0, 0, 0, 0, "");
2169                 
2170                 uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 752,163,132,21, &cu->resolu, 1.0, 128.0, 0, 0, "");
2171                 uiBlockSetCol(block, BUTSALMON);
2172                 uiDefBut(block, BUT, B_SETRESOLU, "Set",                                887,163,29,21, 0, 0, 0, 0, 0, "");
2173                 
2174                 uiBlockSetCol(block, BUTGREY);
2175                 uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  753,30,163,18, &cu->bevresol, 0.0, 10.0, 0, 0, "");
2176
2177                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "BevOb:",         753,10,163,18, &cu->bevobj, "");
2178                 uiDefButF(block, NUM, B_MAKEDISP, "Width:",             753,90,163,18, &cu->width, 0.0, 2.0, 1, 0, "");
2179                 uiDefButF(block, NUM, B_MAKEDISP, "Ext1:",              753,70,163,18, &cu->ext1, 0.0, 5.0, 10, 0, "");
2180                 uiDefButF(block, NUM, B_MAKEDISP, "Ext2:",              753,50,163,18, &cu->ext2, 0.0, 2.0, 1, 0, "");
2181                 uiBlockSetCol(block, BUTBLUE);
2182                 if(ob->type==OB_FONT) {
2183                         uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",        833,130,79,18, &cu->flag, 0, 0, 0, 0, "");
2184                         uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 753,130,76,18, &cu->flag, 0, 0, 0, 0, "");
2185                 }
2186                 else {
2187                         uiDefButS(block, TOG|BIT|0, B_CU3D, "3D",                       867,130,47,18, &cu->flag, 0, 0, 0, 0, "");
2188                         uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",        810,130,55,18, &cu->flag, 0, 0, 0, 0, "");
2189                         uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 753,130,53,18, &cu->flag, 0, 0, 0, 0, "");
2190                 }
2191                 uiBlockSetCol(block, BUTGREY);
2192         }
2193
2194         uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",               1090, 80, 164, 19, &editbutsize, 0.001, 1.0, 10, 0, "");
2195
2196         uiDrawBlock(block);
2197 }
2198
2199
2200 /* *************************** CAMERA ******************************** */
2201
2202
2203 void camerabuts(void)
2204 {
2205         Camera *cam;
2206         Object *ob;
2207         uiBlock *block;
2208         float grid=0.0;
2209         char str[64];
2210         
2211         if(G.vd) grid= G.vd->grid; 
2212         if(grid<1.0) grid= 1.0;
2213         
2214         ob= OBACT;
2215         if(ob==0) return;
2216
2217         sprintf(str, "editbuttonswin %d", curarea->win);
2218         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2219         
2220         cam= ob->data;
2221         uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:", 470,178,160,20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
2222         uiDefButF(block, NUM,REDRAWVIEW3D, "ClipSta:", 470,147,160,20, &cam->clipsta, 0.001*grid, 100.0*grid, 10, 0, "Specify the startvalue of the the field of view");
2223         uiDefButF(block, NUM,REDRAWVIEW3D, "ClipEnd:", 470,125,160,20, &cam->clipend, 1.0, 5000.0*grid, 100, 0, "Specify the endvalue of the the field of view");
2224         uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
2225
2226         uiBlockSetCol(block, BUTGREEN);
2227         uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
2228
2229         uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
2230         uiDefButS(block, TOG|BIT|1,REDRAWVIEW3D, "Show Mist", 533,49,97,20, &cam->flag, 0, 0, 0, 0, "Draw a line that indicates the mist area");
2231         
2232         if(G.special1 & G_HOLO) {
2233                 uiBlockSetCol(block, BUTGREY);
2234                 if(cam->netend==0.0) cam->netend= EFRA;
2235                 uiDefButF(block, NUM, REDRAWVIEW3D, "Anim len",         670,80,100,20, &cam->netend, 1.0, 2500.0, 0, 0, "");
2236                 uiDefButF(block, NUM, REDRAWVIEW3D, "Path len:",                670,160,100,20, &cam->hololen, 0.1, 25.0, 10, 0, "");
2237                 uiDefButF(block, NUM, REDRAWVIEW3D, "Shear fac:",               670,140,100,20, &cam->hololen1, 0.1, 5.0, 10, 0, "");
2238                 uiBlockSetCol(block, BUTGREEN);
2239                 uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Holo 1",     670,120,100,20, &cam->flag, 0.0, 0.0, 0, 0, "");
2240                 uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Holo 2",     670,100,100,20, &cam->flag, 0.0, 0.0, 0, 0, "");
2241                 
2242         }
2243         uiDrawBlock(block);
2244 }
2245
2246 /* *************************** FACE/PAINT *************************** */
2247
2248 void do_fpaintbuts(unsigned short event)
2249 {
2250         Mesh *me;
2251         Object *ob;
2252         extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
2253         
2254         ob= OBACT;
2255         if(ob==0) return;
2256
2257         switch(event) { 
2258                 
2259         case B_VPGAMMA:
2260                 vpaint_dogamma();
2261                 break;
2262         case B_COPY_TF_MODE:
2263         case B_COPY_TF_UV:
2264         case B_COPY_TF_COL:
2265         case B_COPY_TF_TEX:
2266                 me= get_mesh(ob);
2267                 if(me && me->tface) {
2268 /*                      extern TFace *lasttface; */
2269                         TFace *tface= me->tface;
2270                         int a= me->totface;
2271                         
2272                         set_lasttface();
2273                         if(lasttface) {
2274                         
2275                                 while(a--) {
2276                                         if(tface!=lasttface && (tface->flag & TF_SELECT)) {
2277                                                 if(event==B_COPY_TF_MODE) {
2278                                                         tface->mode= lasttface->mode;
2279                                                         tface->transp= lasttface->transp;
2280                                                 }
2281                                                 else if(event==B_COPY_TF_UV) {
2282                                                         memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
2283                                                         tface->tpage= lasttface->tpage;
2284                                                         tface->tile= lasttface->tile;
2285                                                         
2286                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2287                                                         else tface->mode &= ~TF_TILES;
2288                                                         
2289                                                 }
2290                                                 else if(event==B_COPY_TF_TEX) {
2291                                                         tface->tpage= lasttface->tpage;
2292                                                         tface->tile= lasttface->tile;
2293
2294                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2295                                                         else tface->mode &= ~TF_TILES;
2296                                                 }
2297                                                 else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
2298                                         }
2299                                         tface++;
2300                                 }
2301                         }
2302                         do_shared_vertexcol(me);
2303                         allqueue(REDRAWVIEW3D, 0);
2304                         allqueue(REDRAWIMAGE, 0);
2305                 }
2306                 break;
2307         case B_SET_VCOL:
2308                 clear_vpaint_selectedfaces();
2309                 break;
2310         case B_REDR_3D_IMA:
2311                 allqueue(REDRAWVIEW3D, 0);
2312                 allqueue(REDRAWIMAGE, 0);
2313                 break;
2314         case B_ASSIGNMESH:
2315                 
2316                 test_object_materials(ob->data);
2317                 allqueue(REDRAWVIEW3D, 0);
2318                 allqueue(REDRAWBUTSGAME, 0);
2319                 break;
2320                 
2321         case B_TFACE_HALO:
2322                 set_lasttface();
2323                 if(lasttface) {
2324                         lasttface->mode &= ~TF_BILLBOARD2;
2325                         allqueue(REDRAWBUTSGAME, 0);
2326                 }
2327                 break;
2328
2329         case B_TFACE_BILLB:
2330                 set_lasttface();
2331                 if(lasttface) {
2332                         lasttface->mode &= ~TF_BILLBOARD;
2333                         allqueue(REDRAWBUTSGAME, 0);
2334                 }
2335                 break;
2336         }       
2337 }
2338
2339 void fpaintbuts(void)
2340 {
2341 /*      extern VPaint Gvp; already in the top of the file */
2342         Object *ob;
2343         uiBlock *block;
2344         char str[32];
2345         
2346         ob= OBACT;
2347         if(ob==0) return;
2348
2349         sprintf(str, "buttonswin %d", curarea->win);
2350         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2351
2352         /* VPAINT BUTTONS */
2353         uiBlockSetCol(block, BUTGREY);
2354
2355         if (G.f & G_VERTEXPAINT) {
2356                 uiDefBut(block, LABEL, 0, "Vertex Paint",       1037,180,194,18, 0, 0, 0, 0, 0, "");
2357         } else if (G.f & G_TEXTUREPAINT) {
2358                 uiDefBut(block, LABEL, 0, "Texture Paint",      1037,180,194,18, 0, 0, 0, 0, 0, "");
2359         } 
2360
2361         uiDefButF(block, NUMSLI, 0, "R ",                       979,160,194,19, &Gvp.r, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of red used for painting");
2362         uiDefButF(block, NUMSLI, 0, "G ",                       979,140,194,19, &Gvp.g, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of green used for painting");
2363         uiDefButF(block, NUMSLI, 0, "B ",                       979,120,194,19, &Gvp.b, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of blue used for painting");
2364         uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2365         uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2366
2367         uiDefButF(block, COL, B_VPCOLSLI, "",           1176,100,28,80, &(Gvp.r), 0, 0, 0, 0, "");
2368
2369         uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
2370         uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
2371         uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
2372         uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
2373         uiDefButS(block, ROW, B_DIFF, "Filter",         1212, 80,63,19, &Gvp.mode, 1.0, 4.0, 0, 0, "Mix the colours with an alpha factor");
2374
2375         uiBlockSetCol(block, BUTGREEN);
2376         uiDefButS(block, TOG|BIT|1, 0, "Area",          980,50,80,19, &Gvp.flag, 0, 0, 0, 0, "Set the area the brush covers");
2377         uiDefButS(block, TOG|BIT|2, 0, "Soft",          1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
2378         uiDefButS(block, TOG|BIT|3, 0, "Normals",       1174,50,102,19, &Gvp.flag, 0, 0, 0, 0, "Use vertex normal for painting");
2379
2380         uiBlockSetCol(block, BUTSALMON);
2381         uiDefBut(block, BUT, B_VPGAMMA, "Set",  980,30,80,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
2382         uiBlockSetCol(block, BUTGREY);
2383         uiDefButF(block, NUM, B_DIFF, "Mul:",           1061,30,112,19, &Gvp.mul, 0.1, 50.0, 10, 0, "Set the number to multiply vertex colours with");
2384         uiDefButF(block, NUM, B_DIFF, "Gamma:",         1174,30,102,19, &Gvp.gamma, 0.1, 5.0, 10, 0, "Change the clarity of the vertex colours");
2385         
2386         uiDefBut(block, LABEL, 0, "Face Select",        600,180,194,18, 0, 0, 0, 0, 0, "");
2387         if(G.f & G_FACESELECT) {
2388                 extern TFace *lasttface;
2389                 
2390                 set_lasttface();
2391                 if(lasttface) {
2392                         
2393                         uiBlockSetCol(block, BUTGREEN);
2394                         uiDefButS(block, TOG|BIT|2, B_REDR_3D_IMA, "Tex",       600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
2395                         uiDefButS(block, TOG|BIT|7, B_REDR_3D_IMA, "Tiles",     660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
2396                         uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Light",      720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
2397                         uiDefButS(block, TOG|BIT|10, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
2398                         uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
2399
2400                         uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "Shared",     600,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Blend vertex colours across face when vertices are shared");
2401                         uiDefButS(block, TOG|BIT|9, REDRAWVIEW3D, "Twoside",    660,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
2402                         uiDefButS(block, TOG|BIT|11, REDRAWVIEW3D, "ObColor",720,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
2403
2404                         uiDefButS(block, TOG|BIT|8, B_TFACE_HALO, "Halo",       600,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
2405                         uiDefButS(block, TOG|BIT|12, B_TFACE_BILLB, "Billboard",660,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
2406                         uiDefButS(block, TOG|BIT|13, REDRAWVIEW3D, "Shadow", 720,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
2407                         uiDefButS(block, TOG|BIT|14, REDRAWVIEW3D, "Text", 780,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
2408
2409                         uiBlockSetCol(block, BUTPURPLE);
2410                         uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,100,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
2411                         uiDefButC(block, ROW, REDRAWVIEW3D, "Add",              660,100,60,19, &lasttface->transp, 2.0, 1.0, 0, 0, "Render face transparent and add colour of face");
2412                         uiDefButC(block, ROW, REDRAWVIEW3D, "Alpha",            720,100,60,19, &lasttface->transp, 2.0, 2.0, 0, 0, "Render polygon transparent, depending on alpha channel of the texture");
2413                         /* uiDefButC(block, ROW, REDRAWVIEW3D, "Sub",   780,100,60,19, &lasttface->transp, 2.0, 3.0, 0, 0); ,""*/
2414
2415                 }
2416         }
2417         uiBlockSetCol(block, BUTSALMON);
2418         if(G.f & G_FACESELECT) {
2419                 uiDefBut(block, BUT, B_SET_VCOL, "Set VertCol", 859,37,103,28, 0, 0, 0, 0, 0, "Set Vertex colour of selection to current (Shift+K)");
2420
2421         }
2422         uiDefBut(block, BUT, B_COPY_TF_MODE, "Copy DrawMode", 650,7,117,28, 0, 0, 0, 0, 0, "Copy the drawmode");
2423         uiDefBut(block, BUT, B_COPY_TF_UV, "Copy UV+tex",               771,7,85,28, 0, 0, 0, 0, 0, "Copy UV information and textures");
2424         uiDefBut(block, BUT, B_COPY_TF_COL, "Copy VertCol",     859,7,103,28, 0, 0, 0, 0, 0, "Copy vertex colours");
2425
2426         uiDrawBlock(block);
2427 }
2428
2429 /* *************************** RADIO ******************************** */
2430
2431 void do_radiobuts(short event)
2432 {
2433         Radio *rad;
2434         int phase;
2435         
2436         phase= rad_phase();
2437         rad= G.scene->radio;
2438         
2439         switch(event) {
2440         case B_RAD_ADD:
2441                 add_radio();
2442                 allqueue(REDRAWBUTSRADIO, 0);
2443                 allqueue(REDRAWVIEW3D, 0);
2444                 break;
2445         case B_RAD_DELETE:
2446                 delete_radio();
2447                 allqueue(REDRAWBUTSRADIO, 0);
2448                 allqueue(REDRAWVIEW3D, 0);
2449                 break;
2450         case B_RAD_FREE:
2451                 freeAllRad();
2452                 allqueue(REDRAWBUTSRADIO, 0);
2453                 allqueue(REDRAWVIEW3D, 0);
2454                 break;
2455         case B_RAD_COLLECT:
2456                 rad_collect_meshes();
2457                 allqueue(REDRAWBUTSRADIO, 0);
2458                 allqueue(REDRAWVIEW3D, 0);
2459                 break;
2460         case B_RAD_INIT:
2461                 if(phase==RAD_PHASE_PATCHES) {
2462                         rad_limit_subdivide();
2463                         allqueue(REDRAWBUTSRADIO, 0);
2464                         allqueue(REDRAWVIEW3D, 0);
2465                 }
2466                 break;
2467         case B_RAD_SHOOTP:
2468                 if(phase==RAD_PHASE_PATCHES) {
2469                         waitcursor(1);
2470                         rad_subdivshootpatch();
2471                         allqueue(REDRAWBUTSRADIO, 0);
2472                         allqueue(REDRAWVIEW3D, 0);
2473                         waitcursor(0);
2474                 }
2475                 break;
2476         case B_RAD_SHOOTE:
2477                 if(phase==RAD_PHASE_PATCHES) {
2478                         waitcursor(1);
2479                         rad_subdivshootelem();
2480                         allqueue(REDRAWBUTSRADIO, 0);
2481                         allqueue(REDRAWVIEW3D, 0);
2482                         waitcursor(0);
2483                 }
2484                 break;
2485         case B_RAD_GO:
2486                 if(phase==RAD_PHASE_PATCHES) {
2487                         waitcursor(1);
2488                         rad_go();
2489                         waitcursor(0);
2490                         allqueue(REDRAWBUTSRADIO, 0);
2491                         allqueue(REDRAWVIEW3D, 0);
2492                 }
2493                 break;
2494         case B_RAD_LIMITS:
2495                 rad_setlimits();
2496                 allqueue(REDRAWVIEW3D, 0);
2497                 allqueue(REDRAWBUTSRADIO, 0);
2498                 break;
2499         case B_RAD_FAC:
2500                 set_radglobal();
2501                 if(phase & RAD_PHASE_FACES) make_face_tab();
2502                 else make_node_display();
2503                 allqueue(REDRAWVIEW3D, 0);
2504                 break;
2505         case B_RAD_NODELIM:
2506                 if(phase & RAD_PHASE_FACES) {
2507                         set_radglobal();
2508                         removeEqualNodes(rad->nodelim);
2509                         make_face_tab();
2510                         allqueue(REDRAWVIEW3D, 0);
2511                         allqueue(REDRAWBUTSRADIO, 0);
2512                 }
2513                 break;
2514         case B_RAD_NODEFILT:
2515                 if(phase & RAD_PHASE_FACES) {
2516                         set_radglobal();
2517                         filterNodes();
2518                         make_face_tab();
2519                         allqueue(REDRAWVIEW3D, 0);
2520                 }
2521                 break;
2522         case B_RAD_FACEFILT:
2523                 if(phase & RAD_PHASE_FACES) {
2524                         filterFaces();
2525                         allqueue(REDRAWVIEW3D, 0);
2526                 }
2527                 break;
2528         case B_RAD_DRAW:
2529                 set_radglobal();
2530                 allqueue(REDRAWVIEW3D, 0);
2531                 break;
2532         case B_RAD_ADDMESH:
2533                 if(phase & RAD_PHASE_FACES) rad_addmesh();
2534                 allqueue(REDRAWVIEW3D, 0);
2535                 break;
2536         case B_RAD_REPLACE:
2537                 if(phase & RAD_PHASE_FACES) rad_replacemesh();
2538                 allqueue(REDRAWVIEW3D, 0);
2539                 break;
2540         }
2541
2542 }
2543
2544
2545 void radiobuts(void)
2546 {
2547         Radio *rad;
2548         uiBlock *block;
2549         int flag;
2550         char str[128];
2551
2552         rad= G.scene->radio;
2553         if(rad==0) {
2554                 add_radio();
2555                 rad= G.scene->radio;
2556         }
2557         
2558         sprintf(str, "buttonswin %d", curarea->win);
2559         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2560
2561         flag= rad_phase();
2562
2563         if(flag & RAD_PHASE_PATCHES) {
2564                 uiBlockSetCol(block, BUTSALMON);
2565                 uiDefBut(block,  BUT, B_RAD_INIT, "Limit Subdivide",    10, 70, 190, 40, NULL, 0, 0, 0, 0, "Subdivide patches");
2566         }
2567         if(flag & RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTPURPLE);
2568         else uiBlockSetCol(block, BUTSALMON);
2569         uiDefBut(block,  BUT, B_RAD_COLLECT, "Collect Meshes",  10, 30, 190, 40, NULL, 0, 0, 0, 0, "Convert selected and visible meshes to patches");
2570         uiDrawBlock(block);
2571
2572         if(flag==0) {
2573         
2574                 sprintf(str, "buttonswin1 %d", curarea->win);
2575                 block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2576                 uiAutoBlock(block, 210, 30, 230, 150, UI_BLOCK_ROWS);
2577                 uiBlockSetCol(block, BUTGREY);
2578                 uiDefButS(block,  NUM, B_RAD_LIMITS, "Hemires:",        0, 0, 10, 10, &rad->hemires, 100.0, 1000.0, 100, 0, "Set the size of a hemicube");
2579                 uiDefButS(block,  NUM, 0, "Max Iterations:",            1, 0, 10, 10, &rad->maxiter, 0.0, 10000.0, 0, 0, "Maximum number of radiosity rounds");
2580                 uiDefButF(block,  NUM, B_RAD_FAC, "Mult:",                      2, 0, 50, 10, &rad->radfac, 0.001, 250.0, 100, 0, "Mulitply the energy values");
2581                 uiDefButF(block,  NUM, B_RAD_FAC, "Gamma:",                     2, 0, 50, 10, &rad->gamma, 0.2, 10.0, 10, 0, "Change the contrast of the energy values");
2582                 uiDefButF(block,  NUM, 0, "Convergence:",                       3, 0, 10, 10, &rad->convergence, 0.0, 1.0, 10, 0, "Set the lower threshold of unshot energy");
2583                 uiDrawBlock(block);
2584         }
2585         else {
2586         
2587         
2588                 sprintf(str, "buttonswin1 %d", curarea->win);
2589                 block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2590                 uiAutoBlock(block, 210, 30, 230, 150, UI_BLOCK_ROWS);
2591                 
2592                 uiBlockSetCol(block, BUTGREEN);
2593                 uiDefButS(block,  ROW, B_RAD_DRAW, "Wire",                      0, 0, 10, 10, &rad->drawtype, 0.0, 0.0, 0, 0, "Enable wireframe drawmode");
2594                 uiDefButS(block,  ROW, B_RAD_DRAW, "Solid",                     0, 0, 10, 10, &rad->drawtype, 0.0, 1.0, 0, 0, "Enable solid drawmode");
2595                 uiDefButS(block,  ROW, B_RAD_DRAW, "Gour",                      0, 0, 10, 10, &rad->drawtype, 0.0, 2.0, 0, 0, "Enable Gourad drawmode");
2596                 uiBlockSetCol(block, BUTGREY);
2597                 uiDefButS(block,  TOG|BIT|0, B_RAD_DRAW, "ShowLim",  1, 0, 10, 10, &rad->flag, 0, 0, 0, 0, "Visualize patch and element limits");
2598                 uiDefButS(block,  TOG|BIT|1, B_RAD_DRAW, "Z",           1, 0, 3, 10, &rad->flag, 0, 0, 0, 0, "Draw limits different");
2599                 uiBlockSetCol(block, BUTGREY);
2600                 uiDefButS(block,  NUM, B_RAD_LIMITS, "ElMax:",          2, 0, 10, 10, &rad->elma, 1.0, 500.0, 0, 0, "Set maximum size of an element");
2601                 uiDefButS(block,  NUM, B_RAD_LIMITS, "ElMin:",          2, 0, 10, 10, &rad->elmi, 1.0, 100.0, 0, 0, "Set minimum size of an element");
2602                 uiDefButS(block,  NUM, B_RAD_LIMITS, "PaMax:",          3, 0, 10, 10, &rad->pama, 10.0, 1000.0, 0, 0, "Set maximum size of a patch");
2603                 uiDefButS(block,  NUM, B_RAD_LIMITS, "PaMin:",          3, 0, 10, 10, &rad->pami, 10.0, 1000.0, 0, 0, "Set minimum size of a patch");
2604                 uiDrawBlock(block);
2605                 
2606                 sprintf(str, "buttonswin2 %d", curarea->win);
2607                 block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2608                 uiAutoBlock(block, 450, 30, 180, 150, UI_BLOCK_ROWS);
2609                 
2610                 if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
2611                 else uiBlockSetCol(block, BUTGREY);
2612                 uiDefBut(block,  BUT, B_RAD_SHOOTE, "Subdiv Shoot Element", 0, 0, 12, 10, NULL, 0, 0, 0, 0, "");
2613                 uiDefBut(block,  BUT, B_RAD_SHOOTP, "Subdiv Shoot Patch",       1, 0, 12, 10, NULL, 0, 0, 0, 0, "Detect high energy changes");
2614                 uiBlockSetCol(block, BUTGREY);
2615                 uiDefButS(block,  NUM, 0, "Max Subdiv Shoot:",                  2, 0, 10, 10, &rad->maxsublamp, 1.0, 250.0, 0, 0, "Set the maximum number of shoot patches that are evaluated");
2616                 uiDefButI(block,  NUM, 0, "MaxEl:",                                             3, 0, 10, 10, &rad->maxnode, 1.0, 250000.0, 0, 0, "Set the maximum allowed number of elements");
2617                 uiDefButS(block,  NUM, B_RAD_LIMITS, "Hemires:",                4, 0, 10, 10, &rad->hemires, 100.0, 1000.0, 100, 0, "Set the size of a hemicube");
2618                 uiDrawBlock(block);
2619                 
2620                 sprintf(str, "buttonswin3 %d", curarea->win);
2621                 block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2622                 uiAutoBlock(block, 640, 30, 200, 150, UI_BLOCK_ROWS);
2623                 
2624                 uiBlockSetCol(block, BUTGREY);
2625                 uiDefButS(block,  NUM, 0, "Max Iterations:",    0, 0, 10, 10, &rad->maxiter, 0.0, 10000.0, 0, 0, "Maximum number of radiosity rounds");
2626                 uiDefButF(block,  NUM, 0, "Convergence:",               1, 0, 10, 10, &rad->convergence, 0.0, 1.0, 10, 0, "Set the lower threshold of unshot energy");
2627                 uiDefButS(block,  NUM, 0, "SubSh P:",                   2, 0, 10, 10, &rad->subshootp, 0.0, 10.0, 0, 0, "Set the number of times the environment is tested to detect pathes");
2628                 uiDefButS(block,  NUM, 0, "SubSh E:",                   2, 0, 10, 10, &rad->subshoote, 0.0, 10.0, 0, 0, "Set the number of times the environment is tested to detect elements");
2629                 if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
2630                 uiDefBut(block,  BUT, B_RAD_GO, "GO",                           3, 0, 10, 15, NULL, 0, 0, 0, 0, "Start the radiosity simulation");
2631                 uiDrawBlock(block);
2632                 
2633                 sprintf(str, "buttonswin4 %d", curarea->win);
2634                 block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2635                 uiAutoBlock(block, 850, 30, 200, 150, UI_BLOCK_ROWS);
2636         
2637                 uiBlockSetCol(block, BUTGREY);
2638                 uiDefButF(block,  NUM, B_RAD_FAC, "Mult:",                      0, 0, 50, 17, &rad->radfac, 0.001, 250.0, 100, 0, "Mulitply the energy values");
2639                 uiDefButF(block,  NUM, B_RAD_FAC, "Gamma:",                     0, 0, 50, 17, &rad->gamma, 0.2, 10.0, 10, 0, "Change the contrast of the energy values");
2640                 if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
2641                 else uiBlockSetCol(block, BUTGREY);
2642                 uiDefBut(block,  BUT, B_RAD_FACEFILT, "FaceFilter",             1, 0, 10, 10, NULL, 0, 0, 0, 0, "Force an extra smoothing");
2643                 if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
2644                 else uiBlockSetCol(block, BUTGREY);
2645                 uiDefBut(block,  BUT, B_RAD_NODELIM, "RemoveDoubles",   2, 0, 30, 10, NULL, 0.0, 50.0, 0, 0, "Join elements which differ less than 'Lim'");
2646                 uiBlockSetCol(block, BUTGREY);
2647                 uiDefButS(block,  NUM, 0, "Lim:",                                       2, 0, 10, 10, &rad->nodelim, 0.0, 50.0, 0, 0, "Set the range for removing doubles");
2648                 if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
2649                 else uiBlockSetCol(block, BUTGREY);
2650                 uiDefBut(block,  BUT, B_RAD_NODEFILT, "Element Filter", 3, 0, 10, 10, NULL, 0, 0, 0, 0, "Filter elements to remove aliasing artefacts");
2651                 uiDrawBlock(block);
2652         
2653                 sprintf(str, "buttonswin5 %d", curarea->win);
2654                 block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2655                 uiAutoBlock(block, 1060, 30, 190, 150, UI_BLOCK_ROWS);
2656         
2657                 if(flag & RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
2658                 else uiBlockSetCol(block, BUTGREY);
2659                 uiDefBut(block,  BUT, B_RAD_FREE, "Free Radio Data",    0, 0, 10, 10, NULL, 0, 0, 0, 0, "Release all memory used by Radiosity");        
2660                 if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
2661                 else uiBlockSetCol(block, BUTGREY);
2662                 uiDefBut(block,  BUT, B_RAD_REPLACE, "Replace Meshes",  1, 0, 10, 10, NULL, 0, 0, 0, 0, "Convert meshes to Mesh objects with vertex colours, changing input-meshes");
2663                 uiDefBut(block,  BUT, B_RAD_ADDMESH, "Add new Meshes",  2, 0, 10, 10, NULL, 0, 0, 0, 0, "Convert meshes to Mesh objects with vertex colours, unchanging input-meshes");
2664                 uiDrawBlock(block);
2665                 
2666                 rad_status_str(str);
2667                 cpack(0);
2668                 glRasterPos2i(210, 189);
2669                 BMF_DrawString(uiBlockGetCurFont(block), str);
2670         }
2671 }
2672
2673
2674 /* *************************** MBALL ******************************** */
2675
2676 void do_mballbuts(unsigned short event)
2677 {
2678         switch(event) {
2679         case B_RECALCMBALL:
2680                 makeDispList(OBACT);
2681                 allqueue(REDRAWVIEW3D, 0);
2682                 break;
2683         }
2684 }
2685
2686 void mballbuts(void)
2687 {
2688         extern MetaElem *lastelem;
2689         MetaBall *mb;
2690         Object *ob;
2691         uiBlock *block;
2692         char str[64];
2693         
2694         ob= OBACT;
2695         if(ob==0) return;
2696
2697         sprintf(str, "editbuttonswin %d", curarea->win);
2698         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2699         
2700         mb= ob->data;   
2701         if (ob==find_basis_mball(ob)) {
2702                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Wiresize:",    470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "");
2703                 uiDefButF(block, NUMSLI, 0, "Rendersize:",                      470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "");
2704                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "");
2705
2706                 uiBlockSetCol(block, BUTBLUE);
2707                 uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
2708                 uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "");
2709                 uiDefButS(block, ROW, B_DIFF, "Half Res",       471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "");
2710                 uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "");
2711                 uiBlockSetCol(block, BUTGREY);
2712         }
2713         
2714         if(ob==G.obedit && lastelem) {
2715                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "");
2716                 if(lastelem->type!=MB_BALL)
2717                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dx:",          750,158,250,19, &lastelem->expx, 0.0, 20.0, 0, 0, "");
2718                 if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
2719                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dy:",          750,138,250,19, &lastelem->expy, 0.0, 20.0, 0, 0, "");
2720
2721                 if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
2722                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dz:",          750,118,250,19, &lastelem->expz, 0.0, 20.0, 0, 0, "");
2723
2724                 uiBlockSetCol(block, BUTGREEN);
2725                 uiDefButS(block, TOG|BIT|1, B_RECALCMBALL, "Negative",753,16,60,19, &lastelem->flag, 0, 0, 0, 0, "");
2726
2727                 uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "");
2728                 uiDefButS(block, ROW, B_RECALCMBALL, "Tube",                    753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "");
2729                 uiDefButS(block, ROW, B_RECALCMBALL, "Plane",                   814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "");
2730                 uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid",                876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "");
2731                 uiDefButS(block, ROW, B_RECALCMBALL, "Cube",                    938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "");
2732         }
2733         uiDrawBlock(block);
2734 }
2735
2736 /* *************************** SCRIPT ******************************** */
2737
2738 static void extend_scriptlink(ScriptLink *slink)
2739 {
2740         void *stmp, *ftmp;
2741
2742         if (!slink) return;
2743                 
2744         stmp= slink->scripts;           
2745         slink->scripts= MEM_mallocN(sizeof(ID*)*(slink->totscript+1), "scriptlistL");
2746         
2747         ftmp= slink->flag;              
2748         slink->flag= MEM_mallocN(sizeof(short*)*(slink->totscript+1), "scriptlistF");
2749         
2750         if (slink->totscript) {
2751                 memcpy(slink->scripts, stmp, sizeof(ID*)*(slink->totscript));
2752                 MEM_freeN(stmp);
2753
2754                 memcpy(slink->flag, ftmp, sizeof(short)*(slink->totscript));
2755                 MEM_freeN(ftmp);
2756         }
2757
2758         slink->scripts[slink->totscript]= NULL;
2759         slink->flag[slink->totscript]= SCRIPT_FRAMECHANGED;
2760
2761         slink->totscript++;
2762                                 
2763         if(slink->actscript<1) slink->actscript=1;
2764 }
2765
2766 static void delete_scriptlink(ScriptLink *slink)
2767 {
2768         int i;
2769         
2770         if (!slink) return;
2771         
2772         if (slink->totscript>0) {
2773                 for (i=slink->actscript-1; i<slink->totscript-1; i++) {
2774                         slink->flag[i]= slink->flag[i+1];
2775                         slink->scripts[i]= slink->scripts[i+1];
2776                 }
2777                 
2778                 slink->totscript--;
2779         }
2780                 
2781         CLAMP(slink->actscript, 1, slink->totscript);
2782                 
2783         if (slink->totscript==0) {
2784                 if (slink->scripts) MEM_freeN(slink->scripts);
2785                 if (slink->flag) MEM_freeN(slink->flag);
2786
2787                 slink->scripts= NULL;
2788                 slink->flag= NULL;
2789                 slink->totscript= slink->actscript= 0;                  
2790         }
2791 }
2792
2793 void do_scriptbuts(short event)
2794 {
2795         Object *ob=NULL;
2796         ScriptLink *script=NULL;
2797         Material *ma;
2798         
2799         switch (event) {
2800         case B_SSCRIPT_ADD:
2801                 extend_scriptlink(&G.scene->scriptlink);
2802                 break;
2803         case B_SSCRIPT_DEL:
2804                 delete_scriptlink(&G.scene->scriptlink);
2805                 break;
2806                 
2807         case B_SCRIPT_ADD:
2808         case B_SCRIPT_DEL:
2809                 ob= OBACT;
2810
2811                 if (ob && G.buts->scriptblock==ID_OB) {
2812                                 script= &ob->scriptlink;
2813
2814                 } else if (ob && G.buts->scriptblock==ID_MA) {
2815                         ma= give_current_material(ob, ob->actcol);
2816                         if (ma) script= &ma->scriptlink;
2817
2818                 } else if (ob && G.buts->scriptblock==ID_CA) {
2819                         if (ob->type==OB_CAMERA)
2820                                 script= &((Camera *)ob->data)->scriptlink;
2821
2822                 } else if (ob && G.buts->scriptblock==ID_LA) {
2823                         if (ob->type==OB_LAMP)
2824                                 script= &((Lamp *)ob->data)->scriptlink;
2825
2826                 } else if (G.buts->scriptblock==ID_WO) {
2827                         if (G.scene->world) 
2828                                 script= &(G.scene->world->scriptlink);
2829                 }
2830                 
2831                 if (event==B_SCRIPT_ADD) extend_scriptlink(script);
2832                 else delete_scriptlink(script);
2833                 
2834                 break;
2835         default:
2836                 break;
2837         }
2838
2839         allqueue(REDRAWBUTSSCRIPT, 0);
2840 }
2841
2842 void draw_scriptlink(uiBlock *block, ScriptLink *script, int sx, int sy, int scene) 
2843 {
2844         char str[256];
2845
2846         uiBlockSetCol(block, BUTGREY);
2847
2848         if (script->totscript) {
2849                 strcpy(str, "FrameChanged%x 1|");
2850                 strcat(str, "Redraw%x 4|");
2851                 if (scene) {
2852                         strcat(str, "OnLoad%x 2");
2853                 }
2854
2855                 uiDefButS(block, MENU, 1, str, (short)sx, (short)sy, 148, 19, &script->flag[script->actscript-1], 0, 0, 0, 0, "Script links for the Frame changed event");
2856
2857                 uiDefIDPoinBut(block, test_scriptpoin_but, 1, "", (short)(sx+150),(short)sy, 98, 19, &script->scripts[script->actscript-1], "Name of Script to link");
2858         }
2859
2860         sprintf(str,"%d Scr:", script->totscript);
2861         uiDefButS(block, NUM, REDRAWBUTSSCRIPT, str, (short)(sx+250), (short)sy,98,19, &script->actscript, 1, script->totscript, 0, 0, "Total / Active Script link (LeftMouse + Drag to change)");
2862
2863         uiBlockSetCol(block, BUTSALMON);
2864
2865         if (scene) {
2866                 if (script->totscript<32767) 
2867                         uiDefBut(block, BUT, B_SSCRIPT_ADD, "New", (short)(sx+350), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Add a new Script link");
2868                 if (script->totscript) 
2869                         uiDefBut(block, BUT, B_SSCRIPT_DEL, "Del", (short)(sx+390), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
2870         } else {
2871                 if (script->totscript<32767) 
2872                         uiDefBut(block, BUT, B_SCRIPT_ADD, "New", (short)(sx+350), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Add a new Script link");
2873                 if (script->totscript) 
2874                         uiDefBut(block, BUT, B_SCRIPT_DEL, "Del", (short)(sx+390), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
2875         }               
2876 }
2877
2878 void scriptbuts(void)
2879 {
2880         Object *ob=NULL;
2881         ScriptLink *script=NULL;
2882         Material *ma;
2883         uiBlock *block;
2884         char str[64];
2885         
2886         ob= OBACT;
2887
2888         sprintf(str, "buttonswin %d", curarea->win);
2889         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2890
2891         if (ob && G.buts->scriptblock==ID_OB) {
2892                 script= &ob->scriptlink;
2893                 
2894         } else if (ob && G.buts->scriptblock==ID_MA) {
2895                 ma= give_current_material(ob, ob->actcol);
2896                 if (ma) script= &ma->scriptlink;
2897                 
2898         } else if (ob && G.buts->scriptblock==ID_CA) {
2899                 if (ob->type==OB_CAMERA)
2900                         script= &((Camera *)ob->data)->scriptlink;
2901                         
2902         } else if (ob && G.buts->scriptblock==ID_LA) {
2903                 if (ob->type==OB_LAMP)
2904                         script= &((Lamp *)ob->data)->scriptlink;
2905
2906         } else if (G.buts->scriptblock==ID_WO) {
2907                 if (G.scene->world)
2908                         script= &(G.scene->world->scriptlink);
2909         }
2910
2911         if (script) draw_scriptlink(block, script, 25, 180, 0);                 
2912         
2913         /* EVENTS */
2914         draw_buttons_edge(curarea->win, 540);
2915
2916         draw_scriptlink(block, &G.scene->scriptlink, 600, 180, 1);
2917
2918         uiDrawBlock(block);
2919 }
2920
2921 /* *************************** IKA ******************************** */
2922 /* is this number used elsewhere? */
2923 /*  static int ika_del_number; */
2924 void do_ikabuts(unsigned short event)
2925 {
2926         Base *base;
2927         Object *ob;
2928         
2929         ob= OBACT;
2930         
2931         switch(event) {
2932         case B_IKASETREF:
2933                 base= FIRSTBASE;
2934                 while(base) {
2935                         if TESTBASELIB(base) {
2936                                 if(base->object->type==OB_IKA) init_defstate_ika(base->object);
2937                         }
2938                         base= base->next;
2939                 }
2940                 break;  
2941         case B_IKARECALC:
2942                 itterate_ika(ob);
2943                 break;
2944         }
2945 }
2946
2947 void ikabuts(void)
2948 {
2949         Ika *ika;
2950         Object *ob;
2951         Limb *li;
2952         Deform *def;
2953         uiBlock *block;
2954         int nr, cury, nlimbs;
2955         char str[32];
2956         
2957         ob= OBACT;
2958         if(ob==0) return;
2959
2960         sprintf(str, "editbuttonswin %d", curarea->win);
2961         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2962
2963         ika= ob->data;
2964         
2965         uiBlockSetCol(block, BUTSALMON);
2966         uiDefBut(block, BUT, B_IKASETREF,       "Set Reference",470,180,200,20, 0, 0, 0, 0, 0, "");
2967
2968         uiBlockSetCol(block, BUTGREEN);
2969         uiDefButS(block, TOG|BIT|1, B_DIFF, "Lock XY Plane",    470,140,200,20, &ika->flag, 0.0, 1.0, 0, 0, "New IK option: allows both X and Y axes to rotate");
2970         uiBlockSetCol(block, BUTGREY);
2971         uiDefButF(block, NUM, B_DIFF, "XY constraint ",         470,120,200,20, &ika->xyconstraint, 0.0, 1.0, 100, 0, "Constrain in radians");
2972
2973         uiDefButF(block, NUMSLI, B_DIFF, "Mem ",                                470,80,200,20, &ika->mem, 0.0, 1.0, 0, 0, "");
2974         uiDefButS(block, NUM, B_DIFF, "Iter: ",                         470,60,200,20, &ika->iter, 2.0, 16.0, 0, 0, "");
2975
2976
2977         uiBlockSetCol(block, BUTGREY);
2978
2979         uiDefBut(block, LABEL, 0, "Limb Weight",                        680, 200, 150, 19, 0, 0, 0, 0, 0, "");
2980         cury= 180;
2981         li= ika->limbbase.first;
2982
2983         nlimbs= BLI_countlist(&ika->limbbase);
2984
2985         for (nr = 0; nr < nlimbs; nr++) {
2986                 sprintf(str, "Limb %d:", nr);
2987                 uiDefButF(block, NUM, B_DIFF, str, 680, (short)cury, 150, 19, &li->fac, 0.01, 1.0, 10, 0, "");
2988                 cury-= 20;
2989                 li= li->next;
2990         }
2991
2992         
2993         
2994         uiDefBut(block, LABEL, 0, "Deform Max Dist",    955, 200, 140, 19, 0, 0, 0, 0, 0, "");
2995         uiDefBut(block, LABEL, 0, "Deform Weight",      1095, 200, 140, 19, 0, 0, 0, 0, 0, "");
2996         
2997
2998         cury= 180;
2999         def= ika->def;
3000         for (nr = 0; nr < ika->totdef; nr++) {
3001                 def = ika->def+nr;
3002                 if(def->ob) {
3003                         if(def->ob->type!=OB_IKA) sprintf(str, "%s   :", def->ob->id.name+2);
3004                         else sprintf(str, "%s (%d):", def->ob->id.name+2, def->par1);
3005                 }
3006                 
3007                 uiDefBut(block, LABEL, 0, str,                  855, (short)cury, 100, 19, 0, 0.01, 0.0, 0, 0, "");
3008                 uiDefButF(block, NUM, B_DIFF, "",       955, (short)cury, 140, 19, &def->dist, 0.0, 40.0, 100, 0, "Beyond this distance the Limb doesn't influence deformation. '0.0' is global influence.");
3009                 uiDefButF(block, NUM, B_DIFF, "",       1095,(short)cury, 140, 19, &def->fac, 0.01, 10.0, 10, 0, "");
3010
3011                 cury-= 20;
3012         }
3013         uiDrawBlock(block);
3014 }
3015
3016 /* *************************** LATTICE ******************************** */
3017
3018 void do_latticebuts(unsigned short event)
3019 {
3020         Object *ob;
3021         Lattice *lt;
3022         
3023         ob= OBACT;
3024         
3025         switch(event) {
3026         case B_RESIZELAT:
3027                 if(ob) {
3028                         if(ob==G.obedit) resizelattice(editLatt);
3029                         else resizelattice(ob->data);
3030                 }
3031                 allqueue(REDRAWVIEW3D, 0);
3032                 break;
3033         case B_DRAWLAT:
3034                 if(ob==G.obedit) calc_lattverts_ext();
3035                 allqueue(REDRAWVIEW3D, 0);
3036                 break;
3037         case B_LATTCHANGED:
3038                 
3039                 lt= ob->data;
3040                 if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
3041                 
3042                 make_displists_by_parent(ob);
3043
3044                 allqueue(REDRAWVIEW3D, 0);
3045                 
3046                 break;
3047         }
3048 }
3049