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