Initial revision
[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 _WIN32
43 #include "BLI_winstuff.h"
44 #else
45 #include <unistd.h>
46 #endif
47 #include "MEM_guardedalloc.h"
48
49 #include "BMF_Api.h"
50
51 #include "IMB_imbuf_types.h"
52 #include "IMB_imbuf.h"
53
54 #include "BLI_blenlib.h"
55 #include "BLI_arithb.h"
56 #include "BLI_editVert.h"
57
58 #include "DNA_action_types.h"
59 #include "DNA_armature_types.h"
60 #include "DNA_camera_types.h"
61 #include "DNA_constraint_types.h"
62 #include "DNA_curve_types.h"
63 #include "DNA_effect_types.h"
64 #include "DNA_group_types.h"
65 #include "DNA_ika_types.h"
66 #include "DNA_image_types.h"
67 #include "DNA_key_types.h"
68 #include "DNA_lamp_types.h"
69 #include "DNA_lattice_types.h"
70 #include "DNA_material_types.h"
71 #include "DNA_meta_types.h"
72 #include "DNA_mesh_types.h"
73 #include "DNA_object_types.h"
74 #include "DNA_packedFile_types.h"
75 #include "DNA_radio_types.h"
76 #include "DNA_scene_types.h"
77 #include "DNA_screen_types.h"
78 #include "DNA_sound_types.h"
79 #include "DNA_space_types.h"
80 #include "DNA_texture_types.h"
81 #include "DNA_userdef_types.h"
82 #include "DNA_vfont_types.h"
83 #include "DNA_view3d_types.h"
84 #include "DNA_world_types.h"
85
86 #include "BKE_anim.h"
87 #include "BKE_armature.h"
88 #include "BKE_constraint.h"
89 #include "BKE_curve.h"
90 #include "BKE_displist.h"
91 #include "BKE_effect.h"
92 #include "BKE_font.h"
93 #include "BKE_global.h"
94 #include "BKE_ika.h"
95 #include "BKE_image.h"
96 #include "BKE_ipo.h"
97 #include "BKE_lattice.h"
98 #include "BKE_library.h"
99 #include "BKE_main.h"
100 #include "BKE_material.h"
101 #include "BKE_mball.h"
102 #include "BKE_mesh.h"
103 #include "BKE_object.h"
104 #include "BKE_packedFile.h"
105 #include "BKE_plugin_types.h"
106 #include "BKE_sound.h"
107 #include "BKE_texture.h"
108 #include "BKE_utildefines.h"
109 #include "BKE_writeavi.h"
110
111 /* Everything from source (BIF, BDR, BSE) ------------------------------ */ 
112
113 #include "BDR_drawobject.h"
114 #include "BDR_editcurve.h"
115 #include "BDR_editface.h"
116 #include "BDR_editobject.h"
117 #include "BDR_isect.h"
118 #include "BDR_vpaint.h"
119
120 #include "BSE_drawview.h"
121 #include "BSE_editipo.h"
122 #include "BSE_edit.h"
123 #include "BSE_filesel.h"
124 #include "BSE_headerbuttons.h"
125 #include "BSE_trans_types.h"
126 #include "BSE_view.h"
127 #include "BSE_buttons.h"
128
129 #include "BIF_gl.h"
130 #include "BIF_editarmature.h"   
131 #include "BIF_editconstraint.h" 
132 #include "BIF_editdeform.h"
133 #include "BIF_editfont.h"
134 #include "BIF_editmesh.h"
135 #include "BIF_editsca.h"
136 #include "BIF_editsound.h"
137 #include "BIF_interface.h"
138 #include "BIF_mywindow.h"
139 #include "BIF_renderwin.h"
140 #include "BIF_resources.h"
141 #include "BIF_screen.h"
142 #include "BIF_scrarea.h"
143 #include "BIF_space.h"
144 #include "BIF_toets.h"
145 #include "BIF_toolbox.h"
146 #include "BIF_previewrender.h"
147 #include "BIF_writeimage.h"
148 #include "BIF_writeavicodec.h"
149
150 #include "license_key.h"
151 extern int LICENSE_KEY_VALID;
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=.1, prspeed=0.0, prlen=0.0, doublimit= 0.001;
182 int decim_faces=0;
183
184 #ifdef __NLA
185 float editbutvweight=1;
186 #endif
187 float extr_offs= 1.0, editbutweight=1.0, editbutsize=0.1, cumapsize= 1.0;
188 MTex emptytex;
189 char texstr[15][8]= {"None"  , "Clouds" , "Wood",
190                                          "Marble", "Magic"  , "Blend",
191                                          "Stucci", "Noise"  , "Image",
192                                          "Plugin", "EnvMap" , "",
193                                          ""      , ""       , ""};
194
195
196 /* Local functions ----------------------------------------------------- */
197
198 /* event for buttons (ROW) to indicate the backbuffer isn't OK (ogl) */
199 #define B_DIFF                  1       
200
201 /* *********************** */
202 #define B_VIEWBUTS              1100
203
204 #define B_LOADBGPIC             1001
205 #define B_BLENDBGPIC    1002
206 #define B_BGPICBROWSE   1003
207 #define B_BGPICTEX              1004
208 #define B_BGPICCLEAR    1005
209 #define B_BGPICTEXCLEAR 1006
210
211 /* *********************** */
212 #define B_LAMPBUTS              1200
213
214 #define B_LAMPREDRAW    1101
215 #define B_COLLAMP               1102
216 #define B_TEXCLEARLAMP  1103
217
218 /* *********************** */
219 #define B_MATBUTS               1300
220
221 #define B_MATCOL                1201
222 #define B_SPECCOL               1202
223 #define B_MIRCOL                1203
224 #define B_ACTCOL                1204
225 #define B_MATFROM               1205
226 #define B_MATPRV                1206
227 #define B_MTEXCOL               1207
228 #define B_TEXCLEAR              1208
229 #define B_MATPRV_DRAW   1209
230 #define B_MTEXPASTE             1210
231 #define B_MTEXCOPY              1211
232 #define B_MATLAY                1212
233
234 /* *********************** */
235 #define B_TEXBUTS               1400
236
237 #define B_TEXTYPE               1301
238 #define B_DEFTEXVAR             1302
239 #define B_LOADTEXIMA    1303
240 #define B_NAMEIMA               1304
241 #define B_TEXCHANNEL    1305
242 #define B_TEXREDR_PRV   1306
243 #define B_TEXIMABROWSE  1307
244 #define B_IMAPTEST              1308
245 #define B_RELOADIMA             1309
246 #define B_LOADPLUGIN    1310
247 #define B_NAMEPLUGIN    1311
248 #define B_COLORBAND             1312
249 #define B_ADDCOLORBAND  1313
250 #define B_DELCOLORBAND  1314
251 #define B_CALCCBAND             1315
252 #define B_CALCCBAND2    1316
253 #define B_DOCOLORBAND   1317
254 #define B_REDRAWCBAND   1318
255 #define B_BANDCOL               1319
256 #define B_LOADTEXIMA1   1320
257 #define B_PLUGBUT               1321
258
259 /* plugbut reserves 24 buttons at least! */
260
261 #define B_ENV_MAKE              1350
262 #define B_ENV_FREE              1351
263 #define B_ENV_DELETE    1352
264 #define B_ENV_SAVE              1353
265 #define B_ENV_OB                1354
266
267 #define B_PACKIMA               1355
268
269 /* *********************** */
270 #define B_ANIMBUTS              1500
271
272 #define B_RECALCPATH    1401
273 #define B_MUL_IPO               1402
274 #define B_AUTOTIMEOFS   1403
275 #define B_FRAMEMAP              1404
276 #define B_NEWEFFECT             1405
277 #define B_PREVEFFECT    1406
278 #define B_NEXTEFFECT    1407
279 #define B_CHANGEEFFECT  1408
280 #define B_CALCEFFECT    1409
281 #define B_DELEFFECT             1410
282 #define B_RECALCAL              1411
283 #define B_SETSPEED              1412
284 #define B_PRINTSPEED    1413
285 #define B_PRINTLEN              1414
286 #define B_RELKEY                1415
287
288         /* heeft MAX_EFFECT standen! Volgende pas 1450... */
289 #define B_SELEFFECT     1430    
290
291
292 /* *********************** */
293 #define B_WORLDBUTS             1600
294
295 #define B_TEXCLEARWORLD 1501
296
297 /* *********************** */
298 #define B_RENDERBUTS    1700
299
300 #define B_FS_PIC                1601
301 #define B_FS_BACKBUF    1602
302
303 #define B_FS_FTYPE              1604
304 #define B_DORENDER              1605
305 #define B_DOANIM                1606
306 #define B_PLAYANIM              1607
307 #define B_PR_PAL                1608
308 #define B_PR_FULL               1609
309 #define B_PR_PRV                1610
310 #define B_PR_CDI                1611
311 #define B_PR_PAL169             1612
312 #define B_PR_D2MAC              1613
313 #define B_PR_MPEG               1614
314 #define B_REDRAWDISP    1615
315 #define B_SETBROWSE             1616
316 #define B_CLEARSET              1617
317 #define B_PR_PRESET             1618
318 #define B_PR_PANO               1619
319
320 #define B_IS_FTYPE              1622
321 #define B_IS_BACKBUF    1623
322 #define B_PR_PC                 1624
323
324 #define B_PR_PANO360    1627
325 #define B_PR_HALFFIELDS 1628
326 #define B_NEWRENDERPIPE 1629
327 #define B_R_SCALE       1630
328 #define B_G_SCALE       1631
329 #define B_B_SCALE       1632
330 #define B_USE_R_SCALE   1633
331 #define B_USE_G_SCALE   1634
332 #define B_USE_B_SCALE   1635
333 #define B_EDGECOLSLI    1636
334 #define B_GAMMASLI      1637
335
336 #define B_FILETYPEMENU  1638
337 #define B_SELECTCODEC   1639
338 #define B_RTCHANGED             1640
339
340 #ifdef __NLA
341 /* *********************** */
342 enum {
343         B_ARMATUREBUTS  =       1800,
344         B_POSE                  =       1701
345 };
346 #endif
347
348 /* *********************** */
349 #define B_COMMONEDITBUTS        2049
350
351 #define B_MATWICH               2003
352 #define B_MATNEW                2004
353 #define B_MATDEL                2005
354 #define B_MATASS                2006
355 #define B_MATSEL                2007
356 #define B_MATDESEL              2008
357 #define B_HIDE                  2009
358 #define B_REVEAL                2010
359 #define B_SELSWAP               2011
360 #define B_SETSMOOTH             2012
361 #define B_SETSOLID              2013
362 #define B_AUTOTEX               2014
363 #define B_DOCENTRE              2015
364 #define B_DOCENTRENEW   2016
365 #define B_DOCENTRECURSOR        2017
366
367         /* 32 getallen! */
368 #define B_OBLAY                 2018
369
370 #define B_MESHBUTS              2100
371
372 #define B_FLIPNORM              2050
373 #define B_SPIN                  2051
374 #define B_SPINDUP               2052
375 #define B_EXTR                  2053
376 #define B_SCREW                 2054
377 #define B_EXTREP                2055
378 #define B_SPLIT                 2056
379 #define B_REMDOUB               2057
380 #define B_SUBDIV                2058
381 #define B_FRACSUBDIV    2059
382 #define B_XSORT                 2060
383 #define B_HASH                  2061
384 #define B_DELSTICKY             2062
385 #define B_DELVERTCOL    2063
386 #define B_MAKE_TFACES   2064
387 #define B_TOSPHERE              2065
388 #define B_DEL_TFACES    2066
389 #define B_NEWVGROUP             2067
390 #define B_DELVGROUP             2068
391 #define B_ASSIGNVGROUP  2069
392 #define B_REMOVEVGROUP  2070
393 #define B_SELVGROUP             2071    
394 #define B_DESELVGROUP   2072
395 #define B_DECIM_FACES   2073
396 #define B_DECIM_CANCEL  2074
397 #define B_DECIM_APPLY   2075
398 #define B_AUTOVGROUP    2076
399 #define B_SLOWERDRAW    2077
400 #define B_FASTERDRAW    2078
401 #define B_VERTEXNOISE   2079
402 #define B_VERTEXSMOOTH  2080
403 #define B_INTERSECTMESH 2081
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 game.h */
563         return "Physics %t|Sumo %x0|"
564                 "ODE %x4 |None %x7|";
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= 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_INTERSECTMESH:
1460                 intersect_mesh();
1461                 break;
1462         case B_VERTEXNOISE:
1463                 vertexnoise();
1464                 break;
1465         case B_VERTEXSMOOTH:
1466                 vertexsmooth();
1467                 break;
1468         }
1469         /* LETOP: bovenstaande events alleen in editmode! */
1470 }
1471
1472 static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
1473 {
1474         unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
1475 }
1476
1477 void meshbuts(void)
1478 {
1479         Object *ob;
1480         Mesh *me;
1481         uiBlock *block;
1482         uiBut *but;
1483         float val;
1484         char str[64];
1485 #ifdef __NLA
1486         int by;
1487         float   min;
1488         int     defCount;
1489         bDeformGroup    *defGroup;
1490 #endif
1491
1492         ob= OBACT;
1493         if(ob==0) return;
1494         
1495         sprintf(str, "editbuttonswin %d", curarea->win);
1496         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
1497
1498         me= get_mesh(ob);
1499         
1500         if(me) {
1501                 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");
1502                 uiBlockSetCol(block, BUTGREEN);
1503                 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");
1504                 uiBlockSetCol(block, BUTGREY);
1505                 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");
1506                 uiBlockSetCol(block, BUTGREEN);
1507                 uiDefButS(block, TOG|BIT|7, B_MAKEDISP, "SubSurf",      143,100,130,18, &me->flag, 0, 0, 0, 0, "Catmull-Clark Subdivision Surface");
1508                 uiBlockSetCol(block, BUTGREY);
1509                 uiDefButS(block, NUM, B_MAKEDISP, "Subdiv:",                    143, 80, 100, 18, &me->subdiv, 0, 12, 0, 0, "Level of subdivision for interactive display");
1510                 uiDefButS(block, NUM, B_MAKEDISP, "",                           243, 80, 30, 18, &me->subdivr, 0, 12, 0, 0, "Level of subdivision for rendering");
1511                 uiDefButS(block, TOG|BIT|2, REDRAWVIEW3D, "Double Sided",       1090,184,164,19, &me->flag, 0, 0, 0, 0, "Make faces doublesided");
1512                 
1513                 uiBlockSetCol(block, BUTSALMON);
1514                 
1515                 if(me->msticky) val= 1.0; else val= 0.0;
1516                 uiDefBut(block, LABEL, 0, "Sticky", 137,55,70,20, 0, val, 0, 0, 0, "");
1517                 if(me->msticky==0) {
1518                         uiDefBut(block, BUT, B_MAKESTICKY, "Make",      210,58,63,19, 0, 0, 0, 0, 0, "Make sticky texture coords (projected from view)");
1519                 }
1520                 else uiDefBut(block, BUT, B_DELSTICKY, "Delete", 210,58,63,19, 0, 0, 0, 0, 0, "Delete sticky texture coords");
1521         
1522                 if(me->mcol) val= 1.0; else val= 0.0;
1523                 uiDefBut(block, LABEL, 0, "VertCol", 140,33,70,20, 0, val, 0, 0, 0, "");
1524                 if(me->mcol==0) {
1525                         uiDefBut(block, BUT, B_MAKEVERTCOL, "Make",     209,36,64,19, 0, 0, 0, 0, 0, "Enable vertex colours");
1526                 }
1527                 else uiDefBut(block, BUT, B_DELVERTCOL, "Delete", 209,36,64,19, 0, 0, 0, 0, 0, "");
1528
1529                         if(me->tface) val= 1.0; else val= 0.0;
1530                         uiDefBut(block, LABEL, 0, "TexFace", 142,13,70,20, 0, val, 0, 0, 0, "");
1531                         if(me->tface==0) {
1532                                 uiDefBut(block, BUT, B_MAKE_TFACES, "Make",     209,14,64,20, 0, 0, 0, 0, 0, "Enable texture face");
1533                         }
1534                         else uiDefBut(block, BUT, B_DEL_TFACES, "Delete", 209,14,64,20, 0, 0, 0, 0, 0, "Delete texture face");
1535                 
1536                 uiBlockSetCol(block, BUTGREY);
1537         
1538                 uiDefIDPoinBut(block, test_meshpoin_but, 0, "TexMesh:",         477,185,249,19, &me->texcomesh, "Enter the name of a Meshblock");
1539         }               
1540         
1541
1542         /* EDIT */
1543                 
1544         if(me) {
1545 #ifdef NAN_DECIMATION
1546                 int tottria= decimate_count_tria(ob);
1547                 DispList *dl;
1548
1549                 // wacko, wait for new displist system (ton)
1550                 if( (dl=ob->disp.first) && dl->mesh);
1551                 else decim_faces= tottria;
1552
1553                 uiBlockSetCol(block, BUTPURPLE);
1554                 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");
1555                 uiBlockSetCol(block, BUTSALMON);
1556                 uiDefBut(block, BUT,B_DECIM_CANCEL, "Cancel",   477,135,124,19, 0, 0, 0, 0, 0, "restore Mesh");
1557                 uiDefBut(block, BUT,B_DECIM_APPLY, "Apply",             602,135,124,19, 0, 0, 0, 0, 0, "apply decimation to Mesh");
1558 #endif
1559         
1560                 uiBlockSetCol(block, BUTSALMON);
1561                 uiDefBut(block, BUT,B_EXTR,"Extrude",   477,100,249,24, 0, 0, 0, 0, 0, "Convert selected edges to faces");
1562                 uiDefBut(block, BUT,B_SPINDUP,"Spin Dup",       639,75,87,24, 0, 0, 0, 0, 0, "Use spin with duplication tool");
1563                 uiDefBut(block, BUT,B_SPIN, "Spin",             558,75,78,24, 0, 0, 0, 0, 0, "Use spin tool");
1564                 uiDefBut(block, BUT,B_SCREW,"Screw",            477,75,79,24, 0, 0, 0, 0, 0, "Use screw tool");
1565                 uiDefBut(block, BUT,B_EXTREP, "ExtrudeRepeat",477,15,128,19, 0, 0, 0, 0, 0, "Create a repetitive extrude along a straight line");
1566         
1567                 uiBlockSetCol(block, BUTGREY);
1568                 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");
1569                 uiDefButS(block, NUM, B_DIFF, "Steps:",         558,55,78,19, &step,1.0,180.0, 0, 0, "Specify the total number of spin revolutions");
1570                 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");
1571                 uiDefButS(block, TOG|BIT|0, B_DIFF, "Clockwise",        639,35,86,19, &editbutflag, 0, 0, 0, 0, "Specify the direction for screw and spin");
1572                 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");
1573                 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");
1574         }
1575
1576         by=206;
1577
1578         uiBlockSetCol(block, BUTGREEN);
1579         uiDefButS(block, TOG|BIT|2, 0, "Beauty",        847,by-=20,94,19, &editbutflag, 0, 0, 0, 0, "Split face in halves");
1580         uiBlockSetCol(block, BUTSALMON);
1581
1582         uiDefBut(block, BUT, B_INTERSECTMESH, "Intersect",              847,by-=19,94,18, 0, 0, 0, 0, 0, "Intersect selected faces");
1583         uiDefBut(block, BUT,B_SPLIT,"Split",                    847,by-=19,94,18, 0, 0, 0, 0, 0, "Split msh without removing faces");
1584         uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",     847,by-=19,94,18, 0, 0, 0, 0, 0, "Blow vertices up into spherical shape");
1585         uiDefBut(block, BUT,B_SUBDIV,"Subdivide",       847,by-=19,94,18, 0, 0, 0, 0, 0, "Split face in quarters");
1586         uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd",847,by-=19,94,18, 0, 0, 0, 0, 0, "Split face with random factor");
1587         
1588         uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",                              847,by-=19,94,18, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
1589         uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",                            847,by-=19,94,18, 0, 0, 0, 0, 0, "Flatten angels");
1590         uiDefBut(block, BUT,B_XSORT,"Xsort",                    847,by-=19,94,18, 0, 0, 0, 0, 0, "Sort vertices in the X direction");
1591         uiDefBut(block, BUT,B_HASH,"Hash",                      847,by-=19,94,18, 0, 0, 0, 0, 0, "Randomize vertices sequence");
1592
1593         uiBlockSetCol(block, BUTGREY);
1594         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");
1595
1596         uiBlockSetCol(block, BUTSALMON);
1597         
1598         uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    958,173,101,32, 0, 0, 0, 0, 0, "Remove doubles");
1599
1600         uiDefBut(block, BUT,B_FLIPNORM,"Flip Normals",          961,55,100,19, 0, 0, 0, 0, 0, "Toggle the direction of the face normals");
1601
1602         uiDefBut(block, BUT, B_SLOWERDRAW,"SlowerDraw",                 961,35,100,19, 0, 0, 0, 0, 0, "Draw slow but accurate");
1603         uiDefBut(block, BUT, B_FASTERDRAW,"FasterDraw",                 961,15,100,19, 0, 0, 0, 0, 0, "Draw fast but less accurate");
1604
1605 #ifdef __NLA
1606                 
1607                 /* Draw Vertex grouping buttons if we're in editmode*/
1608         if (ob){
1609                 char *s, *menustr;
1610                 bDeformGroup *dg;
1611                 int index;
1612                 
1613                 by = 210;
1614                 uiBlockSetCol(block, BUTGREY);
1615                 uiDefBut(block, LABEL,0,"Vertex Groups",                        740,by-=19,93,18, 0, 0, 0, 0, 0, "");
1616
1617                 defCount=BLI_countlist(&ob->defbase);
1618
1619                 if (!defCount)
1620                         min=0;
1621                 else
1622                         min=1;
1623                                 
1624 #if 0
1625                 sprintf (str, "%d Group:", defCount);
1626                 uiDefButS(block, NUM, REDRAWBUTSEDIT, str,      740, by-=22,93,18, &ob->actdef, min, defCount, 0, 0, "");
1627 #else
1628                 s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
1629
1630                 for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next){
1631                         int cnt= sprintf (s, "%s%%x%d|", dg->name, index);
1632                         
1633                         if (cnt>0)
1634                                 s+= cnt;
1635                 }
1636                 
1637                 by-=22;
1638                 if (defCount)
1639                         uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr, 740, by,18,18, &ob->actdef, min, defCount, 0, 0, "Active deformation group");
1640                 MEM_freeN (menustr);
1641 #endif
1642                 if (ob->actdef){
1643                         defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
1644                         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)");
1645                         uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
1646                 }
1647                 uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          740, by-=22, 93, 18, &editbutvweight, 0, 1, 10, 0, "Change the bone's deformation strength");
1648
1649         }
1650                 
1651         if (G.obedit && G.obedit==ob){
1652
1653                 uiBlockSetCol(block, BUTSALMON);
1654 /*              uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assign deformation groups"); */
1655                 uiDefBut(block, BUT,B_NEWVGROUP,"New",                          740,by-=22,45,18, 0, 0, 0, 0, 0, "Create a new deformation group");
1656                 uiDefBut(block, BUT,B_DELVGROUP,"Delete",                       788,by,45,18, 0, 0, 0, 0, 0, "Remove the current deformation group");
1657
1658                 uiBlockSetCol(block, BUTSALMON);
1659                 uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",                    740,by-=22,93,18, 0, 0, 0, 0, 0, "Assign selected vertices to the current deformation group");
1660                 uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",                    740,by-=22,93,18, 0, 0, 0, 0, 0, "Remove selected vertices from the current deformation group");
1661
1662                 uiBlockSetCol(block, BUTGREY);
1663                 uiDefBut(block, BUT,B_SELVGROUP,"Select",                       740,by-=22,93,18, 0, 0, 0, 0, 0, "Select vertices belonging to the current deformation group");
1664                 uiDefBut(block, BUT,B_DESELVGROUP,"Deselect",                   740,by-=22,93,18, 0, 0, 0, 0, 0, "Deselect vertices belonging to the current deformation group");
1665
1666 }
1667 #endif
1668
1669         uiBlockSetCol(block, BUTGREY);
1670         uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",               1090, 90, 164, 19, &editbutsize, 0.001, 2.0, 10, 0, "Set the length of the face normals");
1671         uiDefButI(block, TOG|BIT|6, REDRAWVIEW3D, "Draw Normals",       1090,70,164,19, &G.f, 0, 0, 0, 0, "Draw face normals");
1672         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces", 1090,50,164,19, &G.f, 0, 0, 0, 0, "Draw faces");
1673         uiDefButI(block, TOG|BIT|11, 0, "All edges",                            1090,10,164,19, &G.f, 0, 0, 0, 0, "Draw edges normally, without optimisation");
1674
1675         uiDrawBlock(block);
1676 }
1677
1678 /* *************************** FONT ******************************** */
1679
1680 short give_vfontnr(VFont *vfont)
1681 {
1682         VFont *vf;
1683         short nr= 1;
1684
1685         vf= G.main->vfont.first;
1686         while(vf) {
1687                 if(vf==vfont) return nr;
1688                 nr++;
1689                 vf= vf->id.next;
1690         }
1691         return -1;
1692 }
1693
1694 VFont *give_vfontpointer(int nr)        /* nr= button */
1695 {
1696         VFont *vf;
1697         short tel= 1;
1698
1699         vf= G.main->vfont.first;
1700         while(vf) {
1701                 if(tel==nr) return vf;
1702                 tel++;
1703                 vf= vf->id.next;
1704         }
1705         return G.main->vfont.first;
1706 }
1707
1708 VFont *exist_vfont(char *str)
1709 {
1710         VFont *vf;
1711
1712         vf= G.main->vfont.first;
1713         while(vf) {
1714                 if(strcmp(vf->name, str)==0) return vf;
1715                 vf= vf->id.next;
1716         }
1717         return 0;
1718 }
1719
1720 static char *give_vfontbutstr(void)
1721 {
1722         VFont *vf;
1723         int len= 0;
1724         char *str, di[FILE_MAXDIR], fi[FILE_MAXFILE];
1725
1726         vf= G.main->vfont.first;
1727         while(vf) {
1728                 strcpy(di, vf->name);
1729                 BLI_splitdirstring(di, fi);
1730                 len+= strlen(fi)+4;
1731                 vf= vf->id.next;
1732         }
1733         
1734         str= MEM_callocN(len+21, "vfontbutstr");
1735         strcpy(str, "FONTS %t");
1736         vf= G.main->vfont.first;
1737         while(vf) {
1738                 
1739                 if(vf->id.us==0) strcat(str, "|0 ");
1740                 else strcat(str, "|   ");
1741                 
1742                 strcpy(di, vf->name);
1743                 BLI_splitdirstring(di, fi);
1744                 
1745                 strcat(str, fi);
1746                 vf= vf->id.next;
1747         }
1748         return str;
1749 }
1750
1751 void load_buts_vfont(char *name)
1752 {
1753         VFont *vf;
1754         Curve *cu;
1755         
1756         if(OBACT && OBACT->type==OB_FONT) cu= OBACT->data;
1757         else return;
1758         
1759         vf= exist_vfont(name);
1760         if(vf==0) {
1761                 vf= load_vfont(name);
1762                 if(vf==0) return;
1763         }
1764         else id_us_plus((ID *)vf);
1765         
1766         if(cu->vfont) cu->vfont->id.us--;
1767         cu->vfont= vf;
1768         
1769         text_to_curve(OBACT, 0);
1770         makeDispList(OBACT);
1771         allqueue(REDRAWVIEW3D, 0);
1772         allqueue(REDRAWBUTSEDIT, 0);
1773 }
1774
1775 void do_fontbuts(unsigned short event)
1776 {
1777         Curve *cu;
1778         VFont *vf;
1779         Object *ob;
1780         ScrArea *sa;
1781         char str[80];
1782         
1783         ob= OBACT;
1784         
1785         switch(event) {
1786         case B_MAKEFONT:
1787                 text_to_curve(ob, 0);
1788                 makeDispList(ob);
1789                 allqueue(REDRAWVIEW3D, 0);
1790                 break;
1791         case B_TOUPPER:
1792                 to_upper();
1793                 break;
1794         case B_LOADFONT:
1795                 vf= give_vfontpointer(G.buts->texnr);
1796                 if(vf && vf->id.prev!=vf->id.next) strcpy(str, vf->name);
1797                 else strcpy(str, U.fontdir);
1798                 
1799                 sa= closest_bigger_area();
1800                 areawinset(sa->win);
1801
1802                 activate_fileselect(FILE_SPECIAL, "SELECT FONT", str, load_buts_vfont);
1803
1804                 break;
1805         case B_PACKFONT:
1806                 if (ob) {
1807                         cu= ob->data;
1808                         if(cu && cu->vfont) {
1809                                 if (cu->vfont->packedfile) {
1810                                         if (G.fileflags & G_AUTOPACK) {
1811                                                 if (okee("Disable AutoPack ?")) {
1812                                                         G.fileflags &= ~G_AUTOPACK;
1813                                                 }
1814                                         }
1815                                         
1816                                         if ((G.fileflags & G_AUTOPACK) == 0) {
1817                                                 if (unpackVFont(cu->vfont, PF_ASK) == RET_OK) {
1818                                                         text_to_curve(ob, 0);
1819                                                         makeDispList(ob);
1820                                                         allqueue(REDRAWVIEW3D, 0);
1821                                                 }
1822                                         }
1823                                 } else {
1824                                         cu->vfont->packedfile = newPackedFile(cu->vfont->name);
1825                                 }
1826                         }
1827                 }
1828                 allqueue(REDRAWHEADERS, 0);
1829                 allqueue(REDRAWBUTSEDIT, 0);
1830                 break;
1831
1832         case B_SETFONT:
1833                 if(ob) {
1834                         cu= ob->data;
1835
1836                         vf= give_vfontpointer(G.buts->texnr);
1837                         if(vf) {
1838                                 id_us_plus((ID *)vf);
1839                                 cu->vfont->id.us--;
1840                                 cu->vfont= vf;
1841                                 text_to_curve(ob, 0);
1842                                 makeDispList(ob);
1843                                 allqueue(REDRAWVIEW3D, 0);
1844                                 allqueue(REDRAWBUTSEDIT, 0);
1845                         }
1846                 }       
1847                 break;
1848         case B_TEXTONCURVE:
1849                 if(ob) {
1850                         cu= ob->data;
1851                         if(cu->textoncurve && cu->textoncurve->type!=OB_CURVE) {
1852                                 error("Only Curve Objects");
1853                                 cu->textoncurve= 0;
1854                                 allqueue(REDRAWBUTSEDIT, 0);
1855                         }
1856                         text_to_curve(ob, 0);
1857                         makeDispList(ob);
1858                 }
1859         }
1860 }
1861
1862
1863
1864 void fontbuts(void)
1865 {
1866         Curve *cu;
1867         uiBlock *block;
1868         char *strp, str[64];
1869         
1870         if(OBACT==0) return;
1871
1872         sprintf(str, "editbuttonswin1 %d", curarea->win);
1873         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
1874
1875         cu= OBACT->data;
1876
1877         uiBlockSetCol(block, BUTGREEN);
1878         uiDefButS(block, ROW,B_MAKEFONT, "Left",                484,139,53,18, &cu->spacemode, 0.0,0.0, 0, 0, "");
1879         uiDefButS(block, ROW,B_MAKEFONT, "Middle",      604,139,61,18, &cu->spacemode, 0.0,1.0, 0, 0, "");
1880         uiDefButS(block, ROW,B_MAKEFONT, "Right",               540,139,62,18, &cu->spacemode, 0.0,2.0, 0, 0, "");
1881         uiDefButS(block, ROW,B_MAKEFONT, "Flush",               665,139,61,18, &cu->spacemode, 0.0,3.0, 0, 0, "");
1882
1883         uiBlockSetCol(block, BUTGREY);
1884
1885         uiDefIDPoinBut(block, test_obpoin_but, B_TEXTONCURVE, "TextOnCurve:",   484,115,243,19, &cu->textoncurve, "");
1886
1887         uiDefButF(block, NUM,B_MAKEFONT, "Size:",               482,56,121,19, &cu->fsize, 0.1,10.0, 10, 0, "");
1888         uiDefButF(block, NUM,B_MAKEFONT, "Linedist:",   605,56,121,19, &cu->linedist, 0.0,10.0, 10, 0, "");
1889         uiDefButF(block, NUM,B_MAKEFONT, "Spacing:",    482,34,121,19, &cu->spacing, 0.0,10.0, 10, 0, "");
1890         uiDefButF(block, NUM,B_MAKEFONT, "Y offset:",   605,34,121,19, &cu->yof, -50.0,50.0, 10, 0, "");
1891         uiDefButF(block, NUM,B_MAKEFONT, "Shear:",      482,12,121,19, &cu->shear, -1.0,1.0, 10, 0, "");
1892         uiDefButF(block, NUM,B_MAKEFONT, "X offset:",   605,12,121,19, &cu->xof, -50.0,50.0, 10, 0, "");
1893
1894         uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 752,192,164,19, cu->family, 0.0, 20.0, 0, 0, "");
1895
1896         uiBlockSetCol(block, BUTSALMON);
1897         uiDefBut(block, BUT, B_TOUPPER, "ToUpper",              623,163,103,23, 0, 0, 0, 0, 0, "");
1898         
1899         uiBlockSetCol(block, BUTGREY);
1900
1901         G.buts->texnr= give_vfontnr(cu->vfont);
1902         
1903         strp= give_vfontbutstr();
1904         
1905         uiDefButS(block, MENU, B_SETFONT, strp, 484,191,220,20, &G.buts->texnr, 0, 0, 0, 0, "");
1906         
1907         if (cu->vfont->packedfile) {
1908                 packdummy = 1;
1909         } else {
1910                 packdummy = 0;
1911         }
1912         
1913         uiBlockSetCol(block, BUTYELLOW);
1914         uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE,       706,191,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this Vectorfont");
1915         
1916         MEM_freeN(strp);
1917         
1918         uiBlockSetCol(block, BUTSALMON);
1919         uiDefBut(block, BUT,B_LOADFONT, "Load Font",    484,163,103,23, 0, 0, 0, 0, 0, "");
1920         
1921         uiDrawBlock(block);
1922 }
1923
1924 /* *************************** CURVE ******************************** */
1925
1926
1927 void do_curvebuts(unsigned short event)
1928 {
1929         extern Nurb *lastnu;
1930         Object *ob;
1931         Curve *cu;
1932         Nurb *nu;
1933         
1934         ob= OBACT;
1935         if(ob==0) return;
1936         
1937         switch(event) { 
1938
1939         case B_CONVERTPOLY:
1940         case B_CONVERTBEZ:
1941         case B_CONVERTBSPL:
1942         case B_CONVERTCARD:
1943         case B_CONVERTNURB:
1944                 if(G.obedit) {
1945                         setsplinetype(event-B_CONVERTPOLY);
1946                         makeDispList(G.obedit);
1947                         allqueue(REDRAWVIEW3D, 0);
1948                 }
1949                 break;
1950         case B_UNIFU:
1951         case B_ENDPU:
1952         case B_BEZU:
1953         case B_UNIFV:
1954         case B_ENDPV:
1955         case B_BEZV:
1956                 if(G.obedit) {
1957                         nu= editNurb.first;
1958                         while(nu) {
1959                                 if(isNurbsel(nu)) {
1960                                         if((nu->type & 7)==CU_NURBS) {
1961                                                 if(event<B_UNIFV) {
1962                                                         nu->flagu &= 1;
1963                                                         nu->flagu += ((event-B_UNIFU)<<1);
1964                                                         makeknots(nu, 1, nu->flagu>>1);
1965                                                 }
1966                                                 else if(nu->pntsv>1) {
1967                                                         nu->flagv &= 1;
1968                                                         nu->flagv += ((event-B_UNIFV)<<1);
1969                                                         makeknots(nu, 2, nu->flagv>>1);
1970                                                 }
1971                                         }
1972                                 }
1973                                 nu= nu->next;
1974                         }
1975                         makeDispList(G.obedit);
1976                         allqueue(REDRAWVIEW3D, 0);
1977                 }
1978                 break;
1979         case B_SETWEIGHT:
1980                 if(G.obedit) {
1981                         weightflagNurb(1, editbutweight, 0);
1982                         makeDispList(G.obedit);
1983                         allqueue(REDRAWVIEW3D, 0);
1984                 }
1985                 break;
1986         case B_SETW1:
1987                 editbutweight= 1.0;
1988                 scrarea_queue_winredraw(curarea);
1989                 break;
1990         case B_SETW2:
1991                 editbutweight= sqrt(2.0)/4.0;
1992                 scrarea_queue_winredraw(curarea);
1993                 break;
1994         case B_SETW3:
1995                 editbutweight= 0.25;
1996                 scrarea_queue_winredraw(curarea);
1997                 break;
1998         case B_SETW4:
1999                 editbutweight= sqrt(0.5);
2000                 scrarea_queue_winredraw(curarea);
2001                 break;
2002         case B_SETORDER:
2003                 if(G.obedit) {
2004                         nu= lastnu;
2005                         if(nu && (nu->type & 7)==CU_NURBS ) {
2006                                 if(nu->orderu>nu->pntsu) {
2007                                         nu->orderu= nu->pntsu;
2008                                         scrarea_queue_winredraw(curarea);
2009                                 }
2010                                 makeknots(nu, 1, nu->flagu>>1);
2011                                 if(nu->orderv>nu->pntsv) {
2012                                         nu->orderv= nu->pntsv;
2013                                         scrarea_queue_winredraw(curarea);
2014                                 }
2015                                 makeknots(nu, 2, nu->flagv>>1);
2016                         }
2017                         makeDispList(G.obedit);
2018                         allqueue(REDRAWVIEW3D, 0);
2019                 }
2020                 break;
2021         case B_MAKEDISP:
2022                 if(ob->type==OB_FONT) text_to_curve(ob, 0);
2023                 makeDispList(ob);
2024                 allqueue(REDRAWVIEW3D, 0);
2025                 allqueue(REDRAWINFO, 1);        /* 1, want header->win==0! */
2026                 break;
2027         
2028         case B_SUBDIVCURVE:
2029                 subdivideNurb();
2030                 break;
2031         case B_SPINNURB:
2032                 /* bad bad bad!!! use brackets!!! In case you wondered:
2033                   {==,!=} goes before & goes before || */
2034                 if( (G.obedit==0) || 
2035                     (G.obedit->type!=OB_SURF) || 
2036                         ((G.obedit->lay & G.vd->lay) == 0) ) return;
2037                 spinNurb(0, 0);
2038                 countall();
2039                 makeDispList(G.obedit);
2040                 allqueue(REDRAWVIEW3D, 0);
2041                 break;
2042         case B_CU3D:        /* allow 3D curve */
2043                 if(G.obedit) {
2044                         cu= G.obedit->data;
2045                         nu= editNurb.first;
2046                         while(nu) {
2047                                 nu->type &= ~CU_2D;
2048                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
2049                                 test2DNurb(nu);
2050                                 nu= nu->next;
2051                         }
2052                 }
2053                 if(ob->type==OB_CURVE) {
2054                         cu= ob->data;
2055                         nu= cu->nurb.first;
2056                         while(nu) {
2057                                 nu->type &= ~CU_2D;
2058                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
2059                                 test2DNurb(nu);
2060                                 nu= nu->next;
2061                         }
2062                 }
2063                 break;
2064         case B_SETRESOLU:
2065                 if(ob->type==OB_CURVE) {
2066                         cu= ob->data;
2067                         if(ob==G.obedit) nu= editNurb.first;
2068                         else nu= cu->nurb.first;
2069                         
2070                         while(nu) {
2071                                 nu->resolu= cu->resolu;
2072                                 nu= nu->next;
2073                         }
2074                 }
2075                 else if(ob->type==OB_FONT) text_to_curve(ob, 0);
2076                 
2077                 makeDispList(ob);
2078                 allqueue(REDRAWVIEW3D, 0);
2079
2080                 break;
2081         }
2082 }
2083
2084 void curvebuts(void)
2085 {
2086         Object *ob;
2087         Curve *cu;
2088         Nurb *nu;
2089         extern Nurb *lastnu;
2090         uiBlock *block;
2091         short *sp;
2092         char str[64];
2093         
2094         ob= OBACT;
2095         if(ob==0) return;
2096
2097         sprintf(str, "editbuttonswin %d", curarea->win);
2098         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2099
2100         cu= ob->data;
2101
2102         if(ob->type==OB_CURVE || ob->type==OB_SURF) {
2103                 uiBlockSetCol(block, BUTSALMON);
2104                 uiDefBut(block, LABEL, 0, "Convert",    463,173,72, 18, 0, 0, 0, 0, 0, "");
2105                 uiDefBut(block, BUT,B_CONVERTPOLY,"Poly",               467,152,72, 18, 0, 0, 0, 0, 0, "");
2106                 uiDefBut(block, BUT,B_CONVERTBEZ,"Bezier",      467,132,72, 18, 0, 0, 0, 0, 0, "");
2107                 uiDefBut(block, BUT,B_CONVERTBSPL,"Bspline",    467,112,72, 18, 0, 0, 0, 0, 0, "");
2108                 uiDefBut(block, BUT,B_CONVERTCARD,"Cardinal",   467,92,72, 18, 0, 0, 0, 0, 0, "");
2109                 uiDefBut(block, BUT,B_CONVERTNURB,"Nurb",               467,72,72, 18, 0, 0, 0, 0, 0, "");
2110         
2111                 uiDefBut(block, LABEL, 0, "Make Knots",562,173,102, 18, 0, 0, 0, 0, 0, "");
2112                 uiDefBut(block, BUT,B_UNIFU,"Uniform U",        565,152,102, 18, 0, 0, 0, 0, 0, "");
2113                 uiDefBut(block, BUT,B_ENDPU,"Endpoint U",       565,132,102, 18, 0, 0, 0, 0, 0, "");
2114                 uiDefBut(block, BUT,B_BEZU,"Bezier U",  565,112,102, 18, 0, 0, 0, 0, 0, "");
2115                 uiDefBut(block, BUT,B_UNIFV,"V",                670,152,50, 18, 0, 0, 0, 0, 0, "");
2116                 uiDefBut(block, BUT,B_ENDPV,"V",                670,132,50, 18, 0, 0, 0, 0, 0, "");
2117                 uiDefBut(block, BUT,B_BEZV,"V",         670,112,50, 18, 0, 0, 0, 0, 0, "");
2118         
2119                 uiDefBut(block, BUT,B_SETWEIGHT,"Set Weight",   465,11,95,49, 0, 0, 0, 0, 0, "");
2120                 uiBlockSetCol(block, BUTGREY);
2121                 uiDefButF(block, NUM,0,"Weight:",       564,36,102,22, &editbutweight, 0.01, 10.0, 10, 0, "");
2122                 uiDefBut(block, BUT,B_SETW1,"1.0",              669,36,50,22, 0, 0, 0, 0, 0, "");
2123                 uiDefBut(block, BUT,B_SETW2,"sqrt(2)/4",        564,11,57,20, 0, 0, 0, 0, 0, "");
2124                 uiDefBut(block, BUT,B_SETW3,"0.25",             621,11,43,20, 0, 0, 0, 0, 0, "");
2125                 uiDefBut(block, BUT,B_SETW4,"sqrt(0.5)",        664,11,57,20, 0, 0, 0, 0, 0, "");
2126                 
2127                 if(ob==G.obedit) {
2128                         nu= lastnu;
2129                         if(nu==0) nu= editNurb.first;
2130                         if(nu) sp= &(nu->orderu); 
2131                         else sp= 0;
2132                         uiDefButS(block, NUM, B_SETORDER, "Order U:", 565,91,102, 18, sp, 2.0, 6.0, 0, 0, "");
2133                         if(nu) sp= &(nu->orderv); 
2134                         else sp= 0;
2135                         uiDefButS(block, NUM, B_SETORDER, "V:",  670,91,50, 18, sp, 2.0, 6.0, 0, 0, "");
2136                         if(nu) sp= &(nu->resolu); 
2137                         else sp= 0;
2138                         uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 18, sp, 1.0, 128.0, 0, 0, "");
2139                         if(nu) sp= &(nu->resolv); 
2140                         else sp= 0;
2141                         uiDefButS(block, NUM, B_MAKEDISP, "V:", 670,70,50, 18, sp, 1.0, 128.0, 0, 0, "");
2142                 }
2143
2144                 uiBlockSetCol(block, BUTSALMON);
2145                 uiDefBut(block, BUT, B_SUBDIVCURVE, "Subdivide",        1092,105,165,20, 0, 0, 0, 0, 0, "");
2146         }
2147
2148         if(ob->type==OB_SURF) {
2149                 uiDefBut(block, BUT, B_SPINNURB, "Spin",        808,92,101,36, 0, 0, 0, 0, 0, "");
2150
2151                 uiBlockSetCol(block, BUTGREY);
2152                 uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                                       143,160,130,18, &cu->flag, 0, 0, 0, 0, "");
2153                 uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "No Puno Flip",       143,140,130,18, &cu->flag, 0, 0, 0, 0, "");
2154         }
2155         else {
2156
2157                 uiBlockSetCol(block, BUTGREY);
2158                 uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                       143,160,130,18, &cu->flag, 0, 0, 0, 0, "");
2159                 
2160                 uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 752,163,132,21, &cu->resolu, 1.0, 128.0, 0, 0, "");
2161                 uiBlockSetCol(block, BUTSALMON);
2162                 uiDefBut(block, BUT, B_SETRESOLU, "Set",                                887,163,29,21, 0, 0, 0, 0, 0, "");
2163                 
2164                 uiBlockSetCol(block, BUTGREY);
2165                 uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  753,30,163,18, &cu->bevresol, 0.0, 10.0, 0, 0, "");
2166
2167                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "BevOb:",         753,10,163,18, &cu->bevobj, "");
2168                 uiDefButF(block, NUM, B_MAKEDISP, "Width:",             753,90,163,18, &cu->width, 0.0, 2.0, 1, 0, "");
2169                 uiDefButF(block, NUM, B_MAKEDISP, "Ext1:",              753,70,163,18, &cu->ext1, 0.0, 5.0, 10, 0, "");
2170                 uiDefButF(block, NUM, B_MAKEDISP, "Ext2:",              753,50,163,18, &cu->ext2, 0.0, 2.0, 1, 0, "");
2171                 uiBlockSetCol(block, BUTBLUE);
2172                 if(ob->type==OB_FONT) {
2173                         uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",        833,130,79,18, &cu->flag, 0, 0, 0, 0, "");
2174                         uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 753,130,76,18, &cu->flag, 0, 0, 0, 0, "");
2175                 }
2176                 else {
2177                         uiDefButS(block, TOG|BIT|0, B_CU3D, "3D",                       867,130,47,18, &cu->flag, 0, 0, 0, 0, "");
2178                         uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",        810,130,55,18, &cu->flag, 0, 0, 0, 0, "");
2179                         uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 753,130,53,18, &cu->flag, 0, 0, 0, 0, "");
2180                 }
2181                 uiBlockSetCol(block, BUTGREY);
2182         }
2183
2184         uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",               1090, 80, 164, 19, &editbutsize, 0.001, 1.0, 10, 0, "");
2185
2186         uiDrawBlock(block);
2187 }
2188
2189
2190 /* *************************** CAMERA ******************************** */
2191
2192
2193 void camerabuts(void)
2194 {
2195         Camera *cam;
2196         Object *ob;
2197         uiBlock *block;
2198         float grid=0.0;
2199         char str[64];
2200         
2201         if(G.vd) grid= G.vd->grid; 
2202         if(grid<1.0) grid= 1.0;
2203         
2204         ob= OBACT;
2205         if(ob==0) return;
2206
2207         sprintf(str, "editbuttonswin %d", curarea->win);
2208         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2209         
2210         cam= ob->data;
2211         uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:", 470,178,160,20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
2212         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");
2213         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");
2214         uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
2215
2216         uiBlockSetCol(block, BUTGREEN);
2217         uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
2218
2219         uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
2220         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");
2221         
2222         if(G.special1 & G_HOLO) {
2223                 uiBlockSetCol(block, BUTGREY);
2224                 if(cam->netend==0.0) cam->netend= EFRA;
2225                 uiDefButF(block, NUM, REDRAWVIEW3D, "Anim len",         670,80,100,20, &cam->netend, 1.0, 2500.0, 0, 0, "");
2226                 uiDefButF(block, NUM, REDRAWVIEW3D, "Path len:",                670,160,100,20, &cam->hololen, 0.1, 25.0, 10, 0, "");
2227                 uiDefButF(block, NUM, REDRAWVIEW3D, "Shear fac:",               670,140,100,20, &cam->hololen1, 0.1, 5.0, 10, 0, "");
2228                 uiBlockSetCol(block, BUTGREEN);
2229                 uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Holo 1",     670,120,100,20, &cam->flag, 0.0, 0.0, 0, 0, "");
2230                 uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Holo 2",     670,100,100,20, &cam->flag, 0.0, 0.0, 0, 0, "");
2231                 
2232         }
2233         uiDrawBlock(block);
2234 }
2235
2236 /* *************************** FACE/PAINT *************************** */
2237
2238 void do_fpaintbuts(unsigned short event)
2239 {
2240         Mesh *me;
2241         Object *ob;
2242         extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
2243         
2244         ob= OBACT;
2245         if(ob==0) return;
2246
2247         switch(event) { 
2248                 
2249         case B_VPGAMMA:
2250                 vpaint_dogamma();
2251                 break;
2252         case B_COPY_TF_MODE:
2253         case B_COPY_TF_UV:
2254         case B_COPY_TF_COL:
2255         case B_COPY_TF_TEX:
2256                 me= get_mesh(ob);
2257                 if(me && me->tface) {
2258 /*                      extern TFace *lasttface; */
2259                         TFace *tface= me->tface;
2260                         int a= me->totface;
2261                         
2262                         set_lasttface();
2263                         if(lasttface) {
2264                         
2265                                 while(a--) {
2266                                         if(tface!=lasttface && (tface->flag & TF_SELECT)) {
2267                                                 if(event==B_COPY_TF_MODE) {
2268                                                         tface->mode= lasttface->mode;
2269                                                         tface->transp= lasttface->transp;
2270                                                 }
2271                                                 else if(event==B_COPY_TF_UV) {
2272                                                         memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
2273                                                         tface->tpage= lasttface->tpage;
2274                                                         tface->tile= lasttface->tile;
2275                                                         
2276                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2277                                                         else tface->mode &= ~TF_TILES;
2278                                                         
2279                                                 }
2280                                                 else if(event==B_COPY_TF_TEX) {
2281                                                         tface->tpage= lasttface->tpage;
2282                                                         tface->tile= lasttface->tile;
2283
2284                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2285                                                         else tface->mode &= ~TF_TILES;
2286                                                 }
2287                                                 else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
2288                                         }
2289                                         tface++;
2290                                 }
2291                         }
2292                         do_shared_vertexcol(me);
2293                         allqueue(REDRAWVIEW3D, 0);
2294                         allqueue(REDRAWIMAGE, 0);
2295                 }
2296                 break;
2297         case B_SET_VCOL:
2298                 clear_vpaint_selectedfaces();
2299                 break;
2300         case B_REDR_3D_IMA:
2301                 allqueue(REDRAWVIEW3D, 0);
2302                 allqueue(REDRAWIMAGE, 0);
2303                 break;
2304         case B_ASSIGNMESH:
2305                 
2306                 test_object_materials(ob->data);
2307                 allqueue(REDRAWVIEW3D, 0);
2308                 allqueue(REDRAWBUTSGAME, 0);
2309                 break;
2310                 
2311         case B_TFACE_HALO:
2312                 set_lasttface();
2313                 if(lasttface) {
2314                         lasttface->mode &= ~TF_BILLBOARD2;
2315                         allqueue(REDRAWBUTSGAME, 0);
2316                 }
2317                 break;
2318
2319         case B_TFACE_BILLB:
2320                 set_lasttface();
2321                 if(lasttface) {
2322                         lasttface->mode &= ~TF_BILLBOARD;
2323                         allqueue(REDRAWBUTSGAME, 0);
2324                 }
2325                 break;
2326         }       
2327 }
2328
2329 void fpaintbuts(void)
2330 {
2331 /*      extern VPaint Gvp; already in the top of the file */
2332         Object *ob;
2333         uiBlock *block;
2334         char str[32];
2335         
2336         ob= OBACT;
2337         if(ob==0) return;
2338
2339         sprintf(str, "buttonswin %d", curarea->win);
2340         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2341
2342         /* VPAINT BUTTONS */
2343         uiBlockSetCol(block, BUTGREY);
2344
2345         if (G.f & G_VERTEXPAINT) {
2346                 uiDefBut(block, LABEL, 0, "Vertex Paint",       1037,180,194,18, 0, 0, 0, 0, 0, "");
2347         } else if (G.f & G_TEXTUREPAINT) {
2348                 uiDefBut(block, LABEL, 0, "Texture Paint",      1037,180,194,18, 0, 0, 0, 0, 0, "");
2349         } 
2350
2351         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");
2352         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");
2353         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");
2354         uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2355         uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2356
2357         uiDefButF(block, COL, B_VPCOLSLI, "",           1176,100,28,80, &(Gvp.r), 0, 0, 0, 0, "");
2358
2359         uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
2360         uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
2361         uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
2362         uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
2363         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");
2364
2365         uiBlockSetCol(block, BUTGREEN);
2366         uiDefButS(block, TOG|BIT|1, 0, "Area",          980,50,80,19, &Gvp.flag, 0, 0, 0, 0, "Set the area the brush covers");
2367         uiDefButS(block, TOG|BIT|2, 0, "Soft",          1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
2368         uiDefButS(block, TOG|BIT|3, 0, "Normals",       1174,50,102,19, &Gvp.flag, 0, 0, 0, 0, "Use vertex normal for painting");
2369
2370         uiBlockSetCol(block, BUTSALMON);
2371         uiDefBut(block, BUT, B_VPGAMMA, "Set",  980,30,80,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
2372         uiBlockSetCol(block, BUTGREY);
2373         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");
2374         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");
2375         
2376         uiDefBut(block, LABEL, 0, "Face Select",        600,180,194,18, 0, 0, 0, 0, 0, "");
2377         if(G.f & G_FACESELECT) {
2378                 extern TFace *lasttface;
2379                 
2380                 set_lasttface();
2381                 if(lasttface) {
2382                         
2383                         uiBlockSetCol(block, BUTGREEN);
2384                         uiDefButS(block, TOG|BIT|2, B_REDR_3D_IMA, "Tex",       600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
2385                         uiDefButS(block, TOG|BIT|7, B_REDR_3D_IMA, "Tiles",     660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
2386                         uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Light",      720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
2387                         uiDefButS(block, TOG|BIT|10, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
2388                         uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
2389
2390                         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");
2391                         uiDefButS(block, TOG|BIT|9, REDRAWVIEW3D, "Twoside",    660,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
2392                         uiDefButS(block, TOG|BIT|11, REDRAWVIEW3D, "ObColor",720,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
2393
2394                         uiDefButS(block, TOG|BIT|8, B_TFACE_HALO, "Halo",       600,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
2395                         uiDefButS(block, TOG|BIT|12, B_TFACE_BILLB, "Billboard",660,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
2396                         uiDefButS(block, TOG|BIT|13, REDRAWVIEW3D, "Shadow", 720,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
2397                         uiDefButS(block, TOG|BIT|14, REDRAWVIEW3D, "Text", 780,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
2398
2399                         uiBlockSetCol(block, BUTPURPLE);
2400                         uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,100,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
2401                         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");
2402                         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");
2403                         /* uiDefButC(block, ROW, REDRAWVIEW3D, "Sub",   780,100,60,19, &lasttface->transp, 2.0, 3.0, 0, 0); ,""*/
2404
2405                 }
2406         }
2407         uiBlockSetCol(block, BUTSALMON);
2408         if(G.f & G_FACESELECT) {
2409                 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)");
2410
2411         }
2412         uiDefBut(block, BUT, B_COPY_TF_MODE, "Copy DrawMode", 650,7,117,28, 0, 0, 0, 0, 0, "Copy the drawmode");
2413         uiDefBut(block, BUT, B_COPY_TF_UV, "Copy UV+tex",               771,7,85,28, 0, 0, 0, 0, 0, "Copy UV information and textures");
2414         uiDefBut(block, BUT, B_COPY_TF_COL, "Copy VertCol",     859,7,103,28, 0, 0, 0, 0, 0, "Copy vertex colours");
2415
2416         uiDrawBlock(block);
2417 }
2418
2419 /* *************************** RADIO ******************************** */
2420
2421 void do_radiobuts(short event)
2422 {
2423         Radio *rad;
2424         int phase;
2425         
2426         phase= rad_phase();
2427         rad= G.scene->radio;
2428         
2429         switch(event) {
2430         case B_RAD_ADD:
2431                 add_radio();
2432                 allqueue(REDRAWBUTSRADIO, 0);
2433                 allqueue(REDRAWVIEW3D, 0);
2434                 break;
2435         case B_RAD_DELETE:
2436                 delete_radio();
2437                 allqueue(REDRAWBUTSRADIO, 0);
2438                 allqueue(REDRAWVIEW3D, 0);
2439                 break;
2440         case B_RAD_FREE:
2441                 freeAllRad();
2442                 allqueue(REDRAWBUTSRADIO, 0);
2443                 allqueue(REDRAWVIEW3D, 0);
2444                 break;
2445         case B_RAD_COLLECT:
2446                 rad_collect_meshes();
2447                 allqueue(REDRAWBUTSRADIO, 0);
2448                 allqueue(REDRAWVIEW3D, 0);
2449                 break;
2450         case B_RAD_INIT:
2451                 if(phase==RAD_PHASE_PATCHES) {
2452                         rad_limit_subdivide();
2453                         allqueue(REDRAWBUTSRADIO, 0);
2454                         allqueue(REDRAWVIEW3D, 0);
2455                 }
2456                 break;
2457         case B_RAD_SHOOTP:
2458                 if(phase==RAD_PHASE_PATCHES) {
2459                         waitcursor(1);
2460                         rad_subdivshootpatch();
2461                         allqueue(REDRAWBUTSRADIO, 0);
2462                         allqueue(REDRAWVIEW3D, 0);
2463                         waitcursor(0);
2464                 }
2465                 break;
2466         case B_RAD_SHOOTE:
2467                 if(phase==RAD_PHASE_PATCHES) {
2468                         waitcursor(1);
2469                         rad_subdivshootelem();
2470                         allqueue(REDRAWBUTSRADIO, 0);
2471                         allqueue(REDRAWVIEW3D, 0);
2472                         waitcursor(0);
2473                 }
2474                 break;
2475         case B_RAD_GO:
2476                 if(phase==RAD_PHASE_PATCHES) {
2477                         waitcursor(1);
2478                         rad_go();
2479                         waitcursor(0);
2480                         allqueue(REDRAWBUTSRADIO, 0);
2481                         allqueue(REDRAWVIEW3D, 0);
2482                 }
2483                 break;
2484         case B_RAD_LIMITS:
2485                 rad_setlimits();
2486                 allqueue(REDRAWVIEW3D, 0);
2487                 allqueue(REDRAWBUTSRADIO, 0);
2488                 break;
2489         case B_RAD_FAC:
2490                 set_radglobal();
2491                 if(phase & RAD_PHASE_FACES) make_face_tab();
2492                 else make_node_display();
2493                 allqueue(REDRAWVIEW3D, 0);
2494                 break;
2495         case B_RAD_NODELIM:
2496                 if(phase & RAD_PHASE_FACES) {
2497                         set_radglobal();
2498                         removeEqualNodes(rad->nodelim);
2499                         make_face_tab();
2500                         allqueue(REDRAWVIEW3D, 0);
2501                         allqueue(REDRAWBUTSRADIO, 0);
2502                 }
2503                 break;
2504         case B_RAD_NODEFILT:
2505                 if(phase & RAD_PHASE_FACES) {
2506                         set_radglobal();
2507                         filterNodes();
2508                         make_face_tab();
2509                         allqueue(REDRAWVIEW3D, 0);
2510                 }
2511                 break;
2512         case B_RAD_FACEFILT:
2513                 if(phase & RAD_PHASE_FACES) {
2514                         filterFaces();
2515                         allqueue(REDRAWVIEW3D, 0);
2516                 }
2517                 break;
2518         case B_RAD_DRAW:
2519                 set_radglobal();
2520                 allqueue(REDRAWVIEW3D, 0);
2521                 break;
2522         case B_RAD_ADDMESH:
2523                 if(phase & RAD_PHASE_FACES) rad_addmesh();
2524                 allqueue(REDRAWVIEW3D, 0);
2525                 break;
2526         case B_RAD_REPLACE:
2527                 if(phase & RAD_PHASE_FACES) rad_replacemesh();
2528                 allqueue(REDRAWVIEW3D, 0);
2529                 break;
2530         }
2531
2532 }
2533
2534
2535 void radiobuts(void)
2536 {
2537         Radio *rad;
2538         uiBlock *block;
2539         int flag;
2540         char str[128];
2541
2542         rad= G.scene->radio;
2543         if(rad==0) {
2544                 add_radio();
2545                 rad= G.scene->radio;
2546         }
2547         
2548         flag= rad_phase();
2549
2550         sprintf(str, "buttonswin %d", curarea->win);
2551         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2552         uiAutoBlock(block, 10, 30, 190, 100, UI_BLOCK_ROWS);
2553
2554         if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
2555         else uiBlockSetCol(block, BUTGREY);
2556         uiDefBut(block,  BUT, B_RAD_INIT, "Limit Subdivide",    0, 0, 10, 10, NULL, 0, 0, 0, 0, "Subdivide patches");
2557         if(flag & RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTPURPLE);
2558         else uiBlockSetCol(block, BUTSALMON);
2559         uiDefBut(block,  BUT, B_RAD_COLLECT, "Collect Meshes",  1, 0, 10, 10, NULL, 0, 0, 0, 0, "Convert selected and visible meshes to patches");
2560         uiDrawBlock(block);
2561
2562         sprintf(str, "buttonswin1 %d", curarea->win);
2563         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2564         uiAutoBlock(block, 210, 30, 230, 150, UI_BLOCK_ROWS);
2565         
2566         uiBlockSetCol(block, BUTGREEN);
2567         uiDefButS(block,  ROW, B_RAD_DRAW, "Wire",                      0, 0, 10, 10, &rad->drawtype, 0.0, 0.0, 0, 0, "Enable wireframe drawmode");
2568         uiDefButS(block,  ROW, B_RAD_DRAW, "Solid",                     0, 0, 10, 10, &rad->drawtype, 0.0, 1.0, 0, 0, "Enable solid drawmode");
2569         uiDefButS(block,  ROW, B_RAD_DRAW, "Gour",                      0, 0, 10, 10, &rad->drawtype, 0.0, 2.0, 0, 0, "Enable Gourad drawmode");
2570         uiBlockSetCol(block, BUTGREY);
2571         uiDefButS(block,  TOG|BIT|0, B_RAD_DRAW, "ShowLim",  1, 0, 10, 10, &rad->flag, 0, 0, 0, 0, "Visualize patch and element limits");
2572         uiDefButS(block,  TOG|BIT|1, B_RAD_DRAW, "Z",           1, 0, 3, 10, &rad->flag, 0, 0, 0, 0, "Draw limits different");
2573         uiBlockSetCol(block, BUTGREY);
2574         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");
2575         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");
2576         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");
2577         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");
2578         uiDrawBlock(block);
2579         
2580         sprintf(str, "buttonswin2 %d", curarea->win);
2581         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2582         uiAutoBlock(block, 450, 30, 180, 150, UI_BLOCK_ROWS);
2583         
2584         if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
2585         else uiBlockSetCol(block, BUTGREY);
2586         uiDefBut(block,  BUT, B_RAD_SHOOTE, "Subdiv Shoot Element", 0, 0, 12, 10, NULL, 0, 0, 0, 0, "");
2587         uiDefBut(block,  BUT, B_RAD_SHOOTP, "Subdiv Shoot Patch",       1, 0, 12, 10, NULL, 0, 0, 0, 0, "Detect high energy changes");
2588         uiBlockSetCol(block, BUTGREY);
2589         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");
2590         uiDefButI(block,  NUM, 0, "MaxEl:",                                             3, 0, 10, 10, &rad->maxnode, 1.0, 250000.0, 0, 0, "Set the maximum allowed number of elements");
2591         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");
2592         uiDrawBlock(block);
2593         
2594         sprintf(str, "buttonswin3 %d", curarea->win);
2595         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2596         uiAutoBlock(block, 640, 30, 200, 150, UI_BLOCK_ROWS);
2597         
2598         uiBlockSetCol(block, BUTGREY);
2599         uiDefButS(block,  NUM, 0, "Max Iterations:",    0, 0, 10, 10, &rad->maxiter, 0.0, 10000.0, 0, 0, "Maximum number of radiosity rounds");
2600         uiDefButF(block,  NUM, 0, "Convergence:",               1, 0, 10, 10, &rad->convergence, 0.0, 1.0, 10, 0, "Set the lower threshold of unshot energy");
2601         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");
2602         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");
2603         if(flag == RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
2604         uiDefBut(block,  BUT, B_RAD_GO, "GO",                           3, 0, 10, 15, NULL, 0, 0, 0, 0, "Start the radiosity simulation");
2605         uiDrawBlock(block);
2606         
2607         sprintf(str, "buttonswin4 %d", curarea->win);
2608         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2609         uiAutoBlock(block, 850, 30, 200, 150, UI_BLOCK_ROWS);
2610
2611         uiBlockSetCol(block, BUTGREY);
2612         uiDefButF(block,  NUM, B_RAD_FAC, "Mult:",                      0, 0, 50, 17, &rad->radfac, 0.001, 250.0, 100, 0, "Mulitply the energy values");
2613         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");
2614         if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
2615         else uiBlockSetCol(block, BUTGREY);
2616         uiDefBut(block,  BUT, B_RAD_FACEFILT, "FaceFilter",             1, 0, 10, 10, NULL, 0, 0, 0, 0, "Force an extra smoothing");
2617         if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
2618         else uiBlockSetCol(block, BUTGREY);
2619         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'");
2620         uiBlockSetCol(block, BUTGREY);
2621         uiDefButS(block,  NUM, 0, "Lim:",                                       2, 0, 10, 10, &rad->nodelim, 0.0, 50.0, 0, 0, "Set the range for removing doubles");
2622         if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
2623         else uiBlockSetCol(block, BUTGREY);
2624         uiDefBut(block,  BUT, B_RAD_NODEFILT, "Element Filter", 3, 0, 10, 10, NULL, 0, 0, 0, 0, "Filter elements to remove aliasing artefacts");
2625         uiDrawBlock(block);
2626
2627         sprintf(str, "buttonswin5 %d", curarea->win);
2628         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2629         uiAutoBlock(block, 1060, 30, 190, 150, UI_BLOCK_ROWS);
2630
2631         if(flag & RAD_PHASE_PATCHES) uiBlockSetCol(block, BUTSALMON);
2632         else uiBlockSetCol(block, BUTGREY);
2633         uiDefBut(block,  BUT, B_RAD_FREE, "Free Radio Data",    0, 0, 10, 10, NULL, 0, 0, 0, 0, "Release all memory used by Radiosity");        
2634         if(flag & RAD_PHASE_FACES) uiBlockSetCol(block, BUTSALMON);
2635         else uiBlockSetCol(block, BUTGREY);
2636         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");
2637         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");
2638         uiDrawBlock(block);
2639         
2640         rad_status_str(str);
2641         cpack(0);
2642         glRasterPos2i(210, 189);
2643         BMF_DrawString(uiBlockGetCurFont(block), str);
2644 }
2645
2646
2647 /* *************************** MBALL ******************************** */
2648
2649 void do_mballbuts(unsigned short event)
2650 {
2651         switch(event) {
2652         case B_RECALCMBALL:
2653                 makeDispList(OBACT);
2654                 allqueue(REDRAWVIEW3D, 0);
2655                 break;
2656         }
2657 }
2658
2659 void mballbuts(void)
2660 {
2661         extern MetaElem *lastelem;
2662         MetaBall *mb;
2663         Object *ob;
2664         uiBlock *block;
2665         char str[64];
2666         
2667         ob= OBACT;
2668         if(ob==0) return;
2669
2670         sprintf(str, "editbuttonswin %d", curarea->win);
2671         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2672         
2673         mb= ob->data;   
2674         if (ob==find_basis_mball(ob)) {
2675                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Wiresize:",    470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "");
2676                 uiDefButF(block, NUMSLI, 0, "Rendersize:",                      470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "");
2677                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "");
2678
2679                 uiBlockSetCol(block, BUTBLUE);
2680                 uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
2681                 uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "");
2682                 uiDefButS(block, ROW, B_DIFF, "Half Res",       471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "");
2683                 uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "");
2684                 uiBlockSetCol(block, BUTGREY);
2685         }
2686         
2687         if(ob==G.obedit && lastelem) {
2688                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "");
2689                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Len:",         750,158,250,19, &lastelem->len, 0.0, 20.0, 0, 0, "");
2690
2691                 uiBlockSetCol(block, BUTGREEN);
2692                 uiDefButS(block, TOG|BIT|1, B_RECALCMBALL, "Negative",752,116,60,19, &lastelem->flag, 0, 0, 0, 0, "");
2693
2694                 uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "");
2695                 uiDefButS(block, ROW, B_RECALCMBALL, "TubeX",                   753,62,60,19, &lastelem->type, 1.0, 1.0, 0, 0, "");
2696                 uiDefButS(block, ROW, B_RECALCMBALL, "TubeY",                   814,62,60,19, &lastelem->type, 1.0, 2.0, 0, 0, "");
2697                 uiDefButS(block, ROW, B_RECALCMBALL, "TubeZ",                   876,62,60,19, &lastelem->type, 1.0, 3.0, 0, 0, "");
2698
2699         }
2700         uiDrawBlock(block);
2701 }
2702
2703 /* *************************** SCRIPT ******************************** */
2704
2705 static void extend_scriptlink(ScriptLink *slink)
2706 {
2707         void *stmp, *ftmp;
2708
2709         if (!slink) return;
2710                 
2711         stmp= slink->scripts;           
2712         slink->scripts= MEM_mallocN(sizeof(ID*)*(slink->totscript+1), "scriptlistL");
2713         
2714         ftmp= slink->flag;              
2715         slink->flag= MEM_mallocN(sizeof(short*)*(slink->totscript+1), "scriptlistF");
2716         
2717         if (slink->totscript) {
2718                 memcpy(slink->scripts, stmp, sizeof(ID*)*(slink->totscript));
2719                 MEM_freeN(stmp);
2720
2721                 memcpy(slink->flag, ftmp, sizeof(short)*(slink->totscript));
2722                 MEM_freeN(ftmp);
2723         }
2724
2725         slink->scripts[slink->totscript]= NULL;
2726         slink->flag[slink->totscript]= SCRIPT_FRAMECHANGED;
2727
2728         slink->totscript++;
2729                                 
2730         if(slink->actscript<1) slink->actscript=1;
2731 }
2732
2733 static void delete_scriptlink(ScriptLink *slink)
2734 {
2735         int i;
2736         
2737         if (!slink) return;
2738         
2739         if (slink->totscript>0) {
2740                 for (i=slink->actscript-1; i<slink->totscript-1; i++) {
2741                         slink->flag[i]= slink->flag[i+1];
2742                         slink->scripts[i]= slink->scripts[i+1];
2743                 }
2744                 
2745                 slink->totscript--;
2746         }
2747                 
2748         CLAMP(slink->actscript, 1, slink->totscript);
2749                 
2750         if (slink->totscript==0) {
2751                 if (slink->scripts) MEM_freeN(slink->scripts);
2752                 if (slink->flag) MEM_freeN(slink->flag);
2753
2754                 slink->scripts= NULL;
2755                 slink->flag= NULL;
2756                 slink->totscript= slink->actscript= 0;                  
2757         }
2758 }
2759
2760 void do_scriptbuts(short event)
2761 {
2762         Object *ob=NULL;
2763         ScriptLink *script=NULL;
2764         Material *ma;
2765         
2766         switch (event) {
2767         case B_SSCRIPT_ADD:
2768                 extend_scriptlink(&G.scene->scriptlink);
2769                 break;
2770         case B_SSCRIPT_DEL:
2771                 delete_scriptlink(&G.scene->scriptlink);
2772                 break;
2773                 
2774         case B_SCRIPT_ADD:
2775         case B_SCRIPT_DEL:
2776                 ob= OBACT;
2777
2778                 if (ob && G.buts->scriptblock==ID_OB) {
2779                                 script= &ob->scriptlink;
2780
2781                 } else if (ob && G.buts->scriptblock==ID_MA) {
2782                         ma= give_current_material(ob, ob->actcol);
2783                         if (ma) script= &ma->scriptlink;
2784
2785                 } else if (ob && G.buts->scriptblock==ID_CA) {
2786                         if (ob->type==OB_CAMERA)
2787                                 script= &((Camera *)ob->data)->scriptlink;
2788
2789                 } else if (ob && G.buts->scriptblock==ID_LA) {
2790                         if (ob->type==OB_LAMP)
2791                                 script= &((Lamp *)ob->data)->scriptlink;
2792
2793                 } else if (G.buts->scriptblock==ID_WO) {
2794                         if (G.scene->world) 
2795                                 script= &(G.scene->world->scriptlink);
2796                 }
2797                 
2798                 if (event==B_SCRIPT_ADD) extend_scriptlink(script);
2799                 else delete_scriptlink(script);
2800                 
2801                 break;
2802         default:
2803                 break;
2804         }
2805
2806         allqueue(REDRAWBUTSSCRIPT, 0);
2807 }
2808
2809 void draw_scriptlink(uiBlock *block, ScriptLink *script, int sx, int sy, int scene) 
2810 {
2811         char str[256];
2812
2813         uiBlockSetCol(block, BUTGREY);
2814
2815         if (script->totscript) {
2816                 strcpy(str, "FrameChanged%x 1|");
2817                 strcat(str, "Redraw%x 4|");
2818                 if (scene) {
2819                         strcat(str, "OnLoad%x 2");
2820                 }
2821
2822                 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");
2823
2824                 uiDefIDPoinBut(block, test_scriptpoin_but, 1, "", (short)(sx+150),(short)sy, 98, 19, &script->scripts[script->actscript-1], "Name of Script to link");
2825         }
2826
2827         sprintf(str,"%d Scr:", script->totscript);
2828         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)");
2829
2830         uiBlockSetCol(block, BUTSALMON);
2831
2832         if (scene) {
2833                 if (script->totscript<32767) 
2834                         uiDefBut(block, BUT, B_SSCRIPT_ADD, "New", (short)(sx+350), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Add a new Script link");
2835                 if (script->totscript) 
2836                         uiDefBut(block, BUT, B_SSCRIPT_DEL, "Del", (short)(sx+390), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
2837         } else {
2838                 if (script->totscript<32767) 
2839                         uiDefBut(block, BUT, B_SCRIPT_ADD, "New", (short)(sx+350), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Add a new Script link");
2840                 if (script->totscript) 
2841                         uiDefBut(block, BUT, B_SCRIPT_DEL, "Del", (short)(sx+390), (short)sy, 38, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
2842         }               
2843 }
2844
2845 void scriptbuts(void)
2846 {
2847         Object *ob=NULL;
2848         ScriptLink *script=NULL;
2849         Material *ma;
2850         uiBlock *block;
2851         char str[64];
2852         
2853         ob= OBACT;
2854
2855         sprintf(str, "buttonswin %d", curarea->win);
2856         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2857
2858         if (ob && G.buts->scriptblock==ID_OB) {
2859                 script= &ob->scriptlink;
2860                 
2861         } else if (ob && G.buts->scriptblock==ID_MA) {
2862                 ma= give_current_material(ob, ob->actcol);
2863                 if (ma) script= &ma->scriptlink;
2864                 
2865         } else if (ob && G.buts->scriptblock==ID_CA) {
2866                 if (ob->type==OB_CAMERA)
2867                         script= &((Camera *)ob->data)->scriptlink;
2868                         
2869         } else if (ob && G.buts->scriptblock==ID_LA) {
2870                 if (ob->type==OB_LAMP)
2871                         script= &((Lamp *)ob->data)->scriptlink;
2872
2873         } else if (G.buts->scriptblock==ID_WO) {
2874                 if (G.scene->world)
2875                         script= &(G.scene->world->scriptlink);
2876         }
2877
2878         if (script) draw_scriptlink(block, script, 25, 180, 0);                 
2879         
2880         /* EVENTS */
2881         draw_buttons_edge(curarea->win, 540);
2882
2883         draw_scriptlink(block, &G.scene->scriptlink, 600, 180, 1);
2884
2885         uiDrawBlock(block);
2886 }
2887
2888 /* *************************** IKA ******************************** */
2889 /* is this number used elsewhere? */
2890 /*  static int ika_del_number; */
2891 void do_ikabuts(unsigned short event)
2892 {
2893         Base *base;
2894         Object *ob;
2895         
2896         ob= OBACT;
2897         
2898         switch(event) {
2899         case B_IKASETREF:
2900                 base= FIRSTBASE;
2901                 while(base) {
2902                         if TESTBASELIB(base) {
2903                                 if(base->object->type==OB_IKA) init_defstate_ika(base->object);
2904                         }
2905                         base= base->next;
2906                 }
2907                 break;  
2908         case B_IKARECALC:
2909                 itterate_ika(ob);
2910                 break;
2911         }
2912 }
2913
2914 void ikabuts(void)
2915 {
2916         Ika *ika;
2917         Object *ob;
2918         Limb *li;
2919         Deform *def;
2920         uiBlock *block;
2921         int nr, cury, nlimbs;
2922         char str[32];
2923         
2924         ob= OBACT;
2925         if(ob==0) return;
2926
2927         sprintf(str, "editbuttonswin %d", curarea->win);
2928         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
2929
2930         ika= ob->data;
2931         
2932         uiBlockSetCol(block, BUTSALMON);
2933         uiDefBut(block, BUT, B_IKASETREF,       "Set Reference",470,180,200,20, 0, 0, 0, 0, 0, "");
2934
2935         uiBlockSetCol(block, BUTGREEN);
2936         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");
2937         uiBlockSetCol(block, BUTGREY);
2938         uiDefButF(block, NUM, B_DIFF, "XY constraint ",         470,120,200,20, &ika->xyconstraint, 0.0, 1.0, 100, 0, "Constrain in radians");
2939
2940         uiDefButF(block, NUMSLI, B_DIFF, "Mem ",                                470,80,200,20, &ika->mem, 0.0, 1.0, 0, 0, "");
2941         uiDefButS(block, NUM, B_DIFF, "Iter: ",                         470,60,200,20, &ika->iter, 2.0, 16.0, 0, 0, "");
2942
2943
2944         uiBlockSetCol(block, BUTGREY);
2945
2946         uiDefBut(block, LABEL, 0, "Limb Weight",                        680, 200, 150, 19, 0, 0, 0, 0, 0, "");
2947         cury= 180;
2948         li= ika->limbbase.first;
2949
2950         nlimbs= BLI_countlist(&ika->limbbase);
2951
2952         for (nr = 0; nr < nlimbs; nr++) {
2953                 sprintf(str, "Limb %d:", nr);
2954                 uiDefButF(block, NUM, B_DIFF, str, 680, (short)cury, 150, 19, &li->fac, 0.01, 1.0, 10, 0, "");
2955                 cury-= 20;
2956                 li= li->next;
2957         }
2958
2959         
2960         
2961         uiDefBut(block, LABEL, 0, "Deform Max Dist",    955, 200, 140, 19, 0, 0, 0, 0, 0, "");
2962         uiDefBut(block, LABEL, 0, "Deform Weight",      1095, 200, 140, 19, 0, 0, 0, 0, 0, "");
2963         
2964
2965         cury= 180;
2966         def= ika->def;
2967         for (nr = 0; nr < ika->totdef; nr++) {
2968                 def = ika->def+nr;
2969                 if(def->ob) {
2970                         if(def->ob->type!=OB_IKA) sprintf(str, "%s   :", def->ob->id.name+2);
2971                         else sprintf(str, "%s (%d):", def->ob->id.name+2, def->par1);
2972                 }
2973                 
2974                 uiDefBut(block, LABEL, 0, str,                  855, (short)cury, 100, 19, 0, 0.01, 0.0, 0, 0, "");
2975                 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.");
2976                 uiDefButF(block, NUM, B_DIFF, "",       1095,(short)cury, 140, 19, &def->fac, 0.01, 10.0, 10, 0, "");
2977
2978                 cury-= 20;
2979         }
2980         uiDrawBlock(block);
2981 }
2982
2983 /* *************************** LATTICE ******************************** */
2984
2985 void do_latticebuts(unsigned short event)
2986 {
2987         Object *ob;
2988         Lattice *lt;
2989         
2990         ob= OBACT;
2991         
2992         switch(event) {
2993         case B_RESIZELAT:
2994                 if(ob) {
2995                         if(ob==G.obedit) resizelattice(editLatt);
2996                         else resizelattice(ob->data);
2997                 }
2998                 allqueue(REDRAWVIEW3D, 0);
2999                 break;
3000         case B_DRAWLAT:
3001                 if(ob==G.obedit) calc_lattverts_ext();
3002                 allqueue(REDRAWVIEW3D, 0);
3003                 break;
3004         case B_LATTCHANGED:
3005                 
3006                 lt= ob->data;
3007                 if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
3008                 
3009                 make_displists_by_parent(ob);
3010
3011                 allqueue(REDRAWVIEW3D, 0);
3012                 
3013                 break;
3014         }
3015 }
3016
3017 void latticebuts(void)
3018 {
3019         Lattice *lt;
3020         Object *ob;
3021         uiBlock *block;
3022         char str[64];
3023         
3024         ob= OBACT;
3025         if(ob==0) return;
3026
3027         sprintf(str, "editbuttonswin %d", curarea->win);
3028         block= uiNewBlock(&curarea->uiblocks, str, UI_EMBOSSX, UI_HELV, curarea->win);
3029
3030         if(ob==G.obedit) lt= editLatt;
3031         else lt= ob->data;
3032
3033         uiSetButLock(lt->key!=0, "Not with VertexKeys");
3034         uiSetButLock(ob==G.obedit, "Unable to perform function in EditMode");
3035         uiDefButS(block, NUM, B_RESIZELAT,      "U:",                   470,178,100,19, &lt->pntsu, 1.0, 64.0, 0, 0, "");
3036         uiDefButS(block, NUM, B_RESIZELAT,      "V:",                   470,158,100,19, &lt->pntsv, 1.0, 64.0, 0, 0, "");
3037         uiDefButS(block, NUM, B_RESIZELAT,      "W:",                   470,138,100,19, &lt->pntsw, 1.0, 64.0, 0, 0, "");
3038         uiClearButLock();
3039         
3040         uiBlockSetCol(block, BUTGREEN);
3041         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_LINEAR, 0, 0, "");
3042         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_CARDINAL, 0, 0, "");
3043         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_BSPLINE, 0, 0, "");
3044
3045         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 158, 40, 19, &lt->typev, 2.0, (float)KEY_LINEAR, 0, 0, "");
3046         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 158, 40, 19, &lt->typev, 2.0, (float)KEY_CARDINAL, 0, 0, "");
3047         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 158, 40, 19, &lt->typev, 2.0, (float)KEY_BSPLINE, 0, 0, "");
3048
3049         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 138, 40, 19, &lt->typew, 3.0, (float)KEY_LINEAR, 0, 0, "");
3050         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 138, 40, 19, &lt->typew, 3.0, (float)KEY_CARDINAL, 0, 0, "");
3051         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 138, 40, 19, &lt->typew, 3.0, (float)KEY_BSPLINE, 0, 0, "");
3052         
3053         uiBlockSetCol(block, BUTSALMON);
3054         uiDefBut(block, BUT, B_RESIZELAT,       "Make Regular",         470,101,99,32, 0, 0, 0, 0, 0, "");
3055
3056         uiBlockSetCol(block, BUTGREEN);
3057         uiDefButS(block, TOG|BIT|1, B_LATTCHANGED, "Outside",   571,101,120,31, &lt->flag, 0, 0, 0, 0, "");
3058
3059         uiDrawBlock(block);
3060 }
3061
3062
3063 /* *************************** TEXTURE ******************************** */
3064
3065 Tex *cur_imatex=0;
3066 int prv_win= 0;
3067
3068 void load_tex_image(char *str)  /* aangeroepen vanuit fileselect */
3069 {
3070         Image *ima=0;
3071         Tex *tex;
3072         
3073         tex= cur_imatex;
3074         if(tex->type==TEX_IMAGE || tex->type==TEX_ENVMAP) {
3075
3076                 ima= add_image(str);
3077                 if(ima) {
3078                         if(tex->ima) {
3079                                 tex->ima->id.us--;
3080                         }
3081                         tex->ima= ima;
3082
3083                         free_image_buffers(ima);        /* forceer opnieuw inlezen */
3084                         ima->ok= 1;
3085                 }
3086
3087                 allqueue(REDRAWBUTSTEX, 0);
3088
3089                 BIF_preview_changed(G.buts);
3090         }
3091 }
3092
3093 void load_plugin_tex(char *str) /* aangeroepen vanuit fileselect */
3094 {
3095         Tex *tex;
3096         
3097         tex= cur_imatex;
3098         if(tex->type!=TEX_PLUGIN) return;
3099         
3100         if(tex->plugin) free_plugin_tex(tex->plugin);
3101         
3102         tex->stype= 0;
3103         tex->plugin= add_plugin_tex(str);
3104
3105         allqueue(REDRAWBUTSTEX, 0);
3106         BIF_preview_changed(G.buts);
3107 }
3108
3109 int vergcband(const void *a1, const void *a2)
3110 {
3111         const CBData *x1=a1, *x2=a2;
3112
3113         if( x1->pos > x2->pos ) return 1;
3114         else if( x1->pos < x2->pos) return -1;
3115         return 0;
3116 }
3117
3118
3119
3120 void save_env(char *name)
3121 {
3122         Tex *tex;
3123         char str[FILE_MAXFILE];
3124         
3125         strcpy(str, name);
3126         BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
3127         tex= G.buts->lockpoin;
3128         
3129         if(tex && GS(tex->id.name)==ID_TE) {
3130                 if(tex->env && tex->env->ok && saveover(str)) {
3131                         waitcursor(1);
3132                         BIF_save_envmap(tex->env, str);
3133                         strcpy(G.ima, name);
3134                         waitcursor(0);
3135                 }
3136         }
3137         
3138 }
3139
3140 void drawcolorband(ColorBand *coba, float x1, float y1, float sizex, float sizey)
3141 {
3142         CBData *cbd;
3143         float v3[2], v1[2], v2[2];
3144         int a;
3145         
3146         if(coba==0) return;
3147         
3148         /* outline */
3149         v1[0]= x1; v1[1]= y1;
3150         glLineWidth((GLfloat)(3));
3151         cpack(0x0);
3152         glBegin(GL_LINE_LOOP);
3153                 glVertex2fv(v1);
3154                 v1[0]+= sizex;
3155                 glVertex2fv(v1);
3156                 v1[1]+= sizey;
3157                 glVertex2fv(v1);
3158                 v1[0]-= sizex;
3159                 glVertex2fv(v1);
3160         glEnd();
3161         glLineWidth((GLfloat)(1));
3162
3163
3164         glShadeModel(GL_SMOOTH);
3165         cbd= coba->data;
3166         
3167         v1[0]= v2[0]= x1;
3168         v1[1]= y1;
3169         v2[1]= y1+sizey;
3170         
3171         glBegin(GL_QUAD_STRIP);
3172         
3173         glColor3fv( &cbd->r );
3174         glVertex2fv(v1); glVertex2fv(v2);
3175         
3176         for(a=0; a<coba->tot; a++, cbd++) {
3177                 
3178                 v1[0]=v2[0]= x1+ cbd->pos*sizex;
3179
3180                 glColor3fv( &cbd->r );
3181                 glVertex2fv(v1); glVertex2fv(v2);
3182         }
3183         
3184         v1[0]=v2[0]= x1+ sizex;
3185         glVertex2fv(v1); glVertex2fv(v2);
3186         
3187         glEnd();
3188         glShadeModel(GL_FLAT);
3189