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