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