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