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