83611318cb4987bb7b0aa0e7e63154a72635893d
[blender-staging.git] / source / blender / src / buttons_editing.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  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #ifdef WIN32
43 #include "BLI_winstuff.h"
44 #endif
45
46 #include "MEM_guardedalloc.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_space_types.h"
49 #include "DNA_scene_types.h"
50
51 #include "DNA_action_types.h"
52 #include "DNA_armature_types.h"
53 #include "DNA_camera_types.h"
54 #include "DNA_constraint_types.h"
55 #include "DNA_curve_types.h"
56 #include "DNA_effect_types.h"
57 #include "DNA_group_types.h"
58 #include "DNA_ika_types.h"
59 #include "DNA_image_types.h"
60 #include "DNA_key_types.h"
61 #include "DNA_lamp_types.h"
62 #include "DNA_lattice_types.h"
63 #include "DNA_material_types.h"
64 #include "DNA_meta_types.h"
65 #include "DNA_mesh_types.h"
66 #include "DNA_object_types.h"
67 #include "DNA_radio_types.h"
68 #include "DNA_screen_types.h"
69 #include "DNA_sound_types.h"
70 #include "DNA_texture_types.h"
71 #include "DNA_userdef_types.h"
72 #include "DNA_vfont_types.h"
73 #include "DNA_view3d_types.h"
74 #include "DNA_world_types.h"
75 #include "DNA_packedFile_types.h"
76
77 #include "BKE_global.h"
78 #include "BKE_main.h"
79 #include "BKE_library.h"
80 #include "BKE_packedFile.h"
81
82 #include "BLI_blenlib.h"
83 #include "BLI_arithb.h"
84
85 #include "BSE_filesel.h"
86
87 #include "BIF_gl.h"
88 #include "BIF_editarmature.h"   
89 #include "BIF_editconstraint.h" 
90 #include "BIF_editdeform.h"
91 #include "BIF_editfont.h"
92 #include "BIF_editmesh.h"
93 #include "BIF_editsound.h"
94 #include "BIF_interface.h"
95 #include "BIF_mywindow.h"
96 #include "BIF_renderwin.h"
97 #include "BIF_resources.h"
98 #include "BIF_screen.h"
99 #include "BIF_scrarea.h"
100 #include "BIF_space.h"
101 #include "BIF_toets.h"
102 #include "BIF_toolbox.h"
103 #include "BIF_previewrender.h"
104 #include "BIF_butspace.h"
105
106 #include "mydevice.h"
107 #include "blendef.h"
108
109 #include "BKE_anim.h"
110 #include "BKE_armature.h"
111 #include "BKE_constraint.h"
112 #include "BKE_curve.h"
113 #include "BKE_displist.h"
114 #include "BKE_effect.h"
115 #include "BKE_font.h"
116 #include "BKE_ika.h"
117 #include "BKE_image.h"
118 #include "BKE_ipo.h"
119 #include "BKE_lattice.h"
120 #include "BKE_material.h"
121 #include "BKE_mball.h"
122 #include "BKE_mesh.h"
123 #include "BKE_object.h"
124 #include "BKE_sound.h"
125 #include "BKE_texture.h"
126 #include "BKE_utildefines.h"
127
128 #include "BDR_drawobject.h"
129 #include "BDR_editcurve.h"
130 #include "BDR_editface.h"
131 #include "BDR_editobject.h"
132 #include "BDR_vpaint.h"
133
134 #include "BSE_drawview.h"
135 #include "BSE_editipo.h"
136 #include "BSE_edit.h"
137 #include "BSE_filesel.h"
138 #include "BSE_headerbuttons.h"
139 #include "BSE_trans_types.h"
140 #include "BSE_view.h"
141 #include "BSE_buttons.h"
142 #include "BSE_seqaudio.h"
143
144 #include "LOD_DependKludge.h"
145 #include "LOD_decimation.h"
146
147 #include "butspace.h" // own module
148
149 int decim_faces=0;
150 short degr= 90, step= 9, turn= 1, editbutflag= 1;
151 float doublimit= 0.001;
152 float editbutvweight=1;
153 float extr_offs= 1.0, editbutweight=1.0, editbutsize=0.1, cumapsize= 1.0;
154
155
156
157
158 /* *************************** MESH DECIMATE ******************************** */
159
160 /* should be removed from this c file (ton) */
161
162 static int decimate_count_tria(Object *ob)
163 {
164         int tottria;
165         MFace *mface;
166         Mesh *me;
167         int a;
168         
169         me= ob->data;
170         
171         /* count number of trias, since decimator doesnt allow quads */
172         tottria= 0;
173         mface= me->mface;
174         for(a=0; a<me->totface; a++, mface++) {
175                 if(mface->v4) tottria++;
176                 if(mface->v3) tottria++;                
177         }
178         
179         return tottria;
180 }
181
182 static void decimate_faces(void)
183 {
184         Object *ob;
185         Mesh *me;
186         MVert *mvert;
187         MFace *mface;
188         LOD_Decimation_Info lod; 
189         float *vb=NULL;
190         float *vnb=NULL;
191         int *tib=NULL;
192         int a, tottria;
193         
194         /* we assume the active object being decimated */
195         ob= OBACT;
196         if(ob==NULL || ob->type!=OB_MESH) return;
197         me= ob->data;
198
199         /* add warning for vertex col and tfaces */
200         if(me->tface || me->mcol) {
201                 if(okee("This will remove UV coordinates and vertexcolors")==0) return;
202                 if(me->tface) MEM_freeN(me->tface);
203                 if(me->mcol) MEM_freeN(me->mcol);
204                 me->tface= NULL;
205                 me->mcol= NULL;
206         }
207         
208         /* count number of trias, since decimator doesnt allow quads */
209         tottria= decimate_count_tria(ob);
210
211         if(tottria<3) {
212                 error("You must have more than 3 input faces selected.");
213                 return;
214         }
215         /* allocate and init */
216         lod.vertex_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "vertices");
217         lod.vertex_normal_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "normals");
218         lod.triangle_index_buffer= MEM_mallocN(3*sizeof(int)*tottria, "trias");
219         lod.vertex_num= me->totvert;
220         lod.face_num= tottria;
221         
222         /* fill vertex buffer */
223         vb= lod.vertex_buffer;
224         vnb= lod.vertex_normal_buffer;
225         mvert= me->mvert;
226         for(a=0; a<me->totvert; a++, mvert++, vb+=3, vnb+=3) {
227                 VECCOPY(vb, mvert->co);
228                 VECCOPY(vnb, mvert->no);
229                 Normalise(vnb);
230         }
231         
232         /* fill index buffer */
233         mface= me->mface;
234         tib= lod.triangle_index_buffer;
235         for(a=0; a<me->totface; a++, mface++) {
236                 if(mface->v4) {
237                         tib[0]= mface->v1;
238                         tib[1]= mface->v3;
239                         tib[2]= mface->v4;
240                         tib+= 3;
241                 }
242                 if(mface->v3) {
243                         tib[0]= mface->v1;
244                         tib[1]= mface->v2;
245                         tib[2]= mface->v3;
246                         tib+= 3;
247                 }
248         }
249
250         if(LOD_LoadMesh(&lod) ) {
251                 if( LOD_PreprocessMesh(&lod) ) {
252                         DispList *dl;
253                         DispListMesh *dlm;
254                         MFaceInt *mfaceint;
255                         
256                         /* we assume the decim_faces tells how much to reduce */
257                         
258                         while(lod.face_num > decim_faces) {
259                                 if( LOD_CollapseEdge(&lod)==0) break;
260                         }
261
262                         /* ok, put back the stuff in a displist */
263                         freedisplist(&(ob->disp));
264                         dl= MEM_callocN(sizeof(DispList), "disp");
265                         BLI_addtail(&ob->disp, dl);
266                         dl->type= DL_MESH;
267                         dlm=dl->mesh= MEM_callocN(sizeof(DispListMesh), "dispmesh");
268                         dlm->mvert= MEM_callocN(lod.vertex_num*sizeof(MVert), "mvert");
269                         dlm->mface= MEM_callocN(lod.face_num*sizeof(MFaceInt), "mface");
270                         dlm->totvert= lod.vertex_num;
271                         dlm->totface= lod.face_num;
272                         
273                         mvert= dlm->mvert;
274                         vb= lod.vertex_buffer;
275                         for(a=0; a<lod.vertex_num; a++, vb+=3, mvert++) {
276                                 VECCOPY(mvert->co, vb);
277                         }
278                         
279                         mfaceint= dlm->mface;
280                         tib= lod.triangle_index_buffer;
281                         for(a=0; a<lod.face_num; a++, mfaceint++, tib+=3) {
282                                 mfaceint->v1= tib[0];
283                                 mfaceint->v2= tib[1];
284                                 mfaceint->v3= tib[2];
285                         }
286                 }
287                 else error("No memory");
288
289                 LOD_FreeDecimationData(&lod);
290         }
291         else error("No manifold Mesh");
292         
293         MEM_freeN(lod.vertex_buffer);
294         MEM_freeN(lod.vertex_normal_buffer);
295         MEM_freeN(lod.triangle_index_buffer);
296         
297         allqueue(REDRAWVIEW3D, 0);
298 }
299
300
301
302 static void decimate_cancel(void)
303 {
304         Object *ob;
305         
306         ob= OBACT;
307         if(ob) {
308                 freedisplist(&ob->disp);
309                 makeDispList(ob);
310         }
311         allqueue(REDRAWVIEW3D, 0);
312 }
313
314 static void decimate_apply(void)
315 {
316         Object *ob;
317         DispList *dl;
318         DispListMesh *dlm;
319         Mesh *me;
320         MFace *mface;
321         MFaceInt *mfaceint;
322         int a;
323         
324         if(G.obedit) return;
325         
326         ob= OBACT;
327         if(ob) {
328                 dl= ob->disp.first;
329                 if(dl && dl->mesh) {
330                         dlm= dl->mesh;
331                         me= ob->data;
332                         
333                         // vertices 
334                         if(me->mvert) MEM_freeN(me->mvert);
335                         me->mvert= dlm->mvert;
336                         dlm->mvert= NULL;
337                         me->totvert= dlm->totvert;
338                         
339                         // faces
340                         if(me->mface) MEM_freeN(me->mface);
341                         me->mface= MEM_callocN(dlm->totface*sizeof(MFace), "mface");
342                         me->totface= dlm->totface;
343                         mface= me->mface;
344                         mfaceint= dlm->mface;
345                         for(a=0; a<me->totface; a++, mface++, mfaceint++) {
346                                 mface->v1= mfaceint->v1;
347                                 mface->v2= mfaceint->v2;
348                                 mface->v3= mfaceint->v3;
349                                 test_index_mface(mface, 3);
350                         }
351                         
352                         freedisplist(&ob->disp);
353                         
354                         G.obedit= ob;
355                         make_editMesh();
356                         load_editMesh();
357                         free_editMesh();
358                         G.obedit= NULL;
359                         tex_space_mesh(me);
360                 }
361                 else error("Not a decimated Mesh");
362         }
363 }
364
365 /* *************************** MESH  ******************************** */
366
367
368 static void editing_panel_mesh_type(Object *ob, Mesh *me)
369 {
370         uiBlock *block;
371         float val;
372         
373         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_type", UI_EMBOSSX, UI_HELV, curarea->win);
374         if( uiNewPanel(curarea, block, "Mesh", "Editing", 320, 0, 318, 204)==0) return;
375
376         uiBlockSetCol(block, BUTGREEN);
377         uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Auto Smooth",10,178,130,17, &me->flag, 0, 0, 0, 0, "Treats all faces with angles less than Degr: as 'smooth' during render");
378         uiBlockSetCol(block, BUTGREY);
379         uiDefButS(block, NUM, B_DIFF, "Degr:",                                  10,156,130,17, &me->smoothresh, 1, 80, 0, 0, "Defines maximum angle between face normals that 'Auto Smooth' will operate on");
380         uiBlockSetCol(block, BUTGREEN);
381         uiDefButS(block, TOG|BIT|7, B_MAKEDISP, "SubSurf",              10,124,130,17, &me->flag, 0, 0, 0, 0, "Treats the active object as a Catmull-Clark Subdivision Surface");
382         uiBlockSetCol(block, BUTGREY);
383         uiDefButS(block, NUM, B_MAKEDISP, "Subdiv:",                    10,104,100,18, &me->subdiv, 0, 12, 0, 0, "Defines the level of subdivision to display in real time interactively");
384         uiDefButS(block, NUM, B_MAKEDISP, "",                                   110, 104, 30, 18, &me->subdivr, 0, 12, 0, 0, "Defines the level of subdivision to apply during rendering");
385         
386         uiBlockSetCol(block, BUTSALMON);
387         
388         if(me->msticky) val= 1.0; else val= 0.0;
389         uiDefBut(block, LABEL, 0, "Sticky", 10,57,70,20, 0, val, 0, 0, 0, "");
390         if(me->msticky==0) {
391                 uiDefBut(block, BUT, B_MAKESTICKY, "Make",      80,59,83,19, 0, 0, 0, 0, 0, "Creates Sticky coordinates for the active object from the current camera view background picture");
392         }
393         else uiDefBut(block, BUT, B_DELSTICKY, "Delete", 80,59,83,19, 0, 0, 0, 0, 0, "Deletes Sticky texture coordinates");
394
395         if(me->mcol) val= 1.0; else val= 0.0;
396         uiDefBut(block, LABEL, 0, "VertCol", 10,34,70,20, 0, val, 0, 0, 0, "");
397         if(me->mcol==0) {
398                 uiDefBut(block, BUT, B_MAKEVERTCOL, "Make",     80,36,84,19, 0, 0, 0, 0, 0, "Enables vertex colour painting on active object");
399         }
400         else uiDefBut(block, BUT, B_DELVERTCOL, "Delete", 80,36,84,19, 0, 0, 0, 0, 0, "Deletes vertex colours on active object");
401
402         if(me->tface) val= 1.0; else val= 0.0;
403         uiDefBut(block, LABEL, 0, "TexFace", 10,14,70,20, 0, val, 0, 0, 0, "");
404         if(me->tface==0) {
405                 uiDefBut(block, BUT, B_MAKE_TFACES, "Make",     80,15,84,20, 0, 0, 0, 0, 0, "Enables the active object's faces for UV coordinate mapping");
406         }
407         else uiDefBut(block, BUT, B_DEL_TFACES, "Delete", 80,15,84,20, 0, 0, 0, 0, 0, "Deletes UV coordinates for active object's faces");
408         
409
410         /* decimator */
411         if(G.obedit==NULL) {
412                 int tottria= decimate_count_tria(ob);
413                 DispList *dl;
414         
415                 // wacko, wait for new displist system (ton)
416                 if( (dl=ob->disp.first) && dl->mesh);
417                 else decim_faces= tottria;
418         
419                 uiBlockSetCol(block, BUTPURPLE);
420                 uiDefButI(block, NUMSLI,B_DECIM_FACES, "Decimator: ",   173,176,233,19, &decim_faces, 4.0, tottria, 10, 10, "Defines the number of triangular faces to decimate the active Mesh object to");
421                 uiBlockSetCol(block, BUTSALMON);
422                 uiDefBut(block, BUT,B_DECIM_CANCEL, "Cancel",   290,156,116,18, 0, 0, 0, 0, 0, "Restores the Mesh to its original number of faces");
423                 uiDefBut(block, BUT,B_DECIM_APPLY, "Apply",             173,156,115,18, 0, 0, 0, 0, 0, "Applies the decimation to the active Mesh object");
424         }
425
426         
427         uiBlockSetCol(block, BUTGREY);
428         uiDefIDPoinBut(block, test_meshpoin_but, 0, "TexMesh: ",        174,120,234,19, &me->texcomesh, "Enter the name of a Meshblock");
429
430         if(me->key) {
431                 uiDefButS(block, NUM, B_DIFF, "Slurph:",                                174,75,100,19, &(me->key->slurph), -500.0, 500.0, 0, 0, "");
432                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",                174,55,100,19, &me->key->type, 0, 0, 0, 0, "");
433         }
434
435         uiBlockSetCol(block, BUTSALMON);
436         uiDefBut(block, BUT, B_SLOWERDRAW,"SlowerDraw",                 174,35,100,19, 0, 0, 0, 0, 0, "Displays the active object with all possible edges shown");
437         uiDefBut(block, BUT, B_FASTERDRAW,"FasterDraw",                 175,15,100,19, 0, 0, 0, 0, 0, "Displays the active object faster by omitting some edges when drawing");
438
439
440         uiBlockSetCol(block, BUTSALMON);
441         uiDefBut(block, BUT,B_DOCENTRE, "Centre",                                       275, 95, 133, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
442         uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New",                        275, 75, 133, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data");
443         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          275, 55, 133, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
444
445         uiBlockSetCol(block, BUTGREEN);
446         uiDefButS(block, TOG|BIT|2, REDRAWVIEW3D, "Double Sided",       275,35,133,19, &me->flag, 0, 0, 0, 0, "Toggles selected faces as doublesided or single-sided");
447         uiDefButS(block, TOG|BIT|1, REDRAWVIEW3D, "No V.Normal Flip",275,15,133,19, &me->flag, 0, 0, 0, 0, "Disables flipping of vertexnormals during render");
448
449 }
450
451
452
453 /* *************************** FONT ******************************** */
454
455 static short give_vfontnr(VFont *vfont)
456 {
457         VFont *vf;
458         short nr= 1;
459
460         vf= G.main->vfont.first;
461         while(vf) {
462                 if(vf==vfont) return nr;
463                 nr++;
464                 vf= vf->id.next;
465         }
466         return -1;
467 }
468
469 static VFont *give_vfontpointer(int nr) /* nr= button */
470 {
471         VFont *vf;
472         short tel= 1;
473
474         vf= G.main->vfont.first;
475         while(vf) {
476                 if(tel==nr) return vf;
477                 tel++;
478                 vf= vf->id.next;
479         }
480         return G.main->vfont.first;
481 }
482
483 static VFont *exist_vfont(char *str)
484 {
485         VFont *vf;
486
487         vf= G.main->vfont.first;
488         while(vf) {
489                 if(strcmp(vf->name, str)==0) return vf;
490                 vf= vf->id.next;
491         }
492         return 0;
493 }
494
495 static char *give_vfontbutstr(void)
496 {
497         VFont *vf;
498         int len= 0;
499         char *str, di[FILE_MAXDIR], fi[FILE_MAXFILE];
500
501         vf= G.main->vfont.first;
502         while(vf) {
503                 strcpy(di, vf->name);
504                 BLI_splitdirstring(di, fi);
505                 len+= strlen(fi)+4;
506                 vf= vf->id.next;
507         }
508         
509         str= MEM_callocN(len+21, "vfontbutstr");
510         strcpy(str, "FONTS %t");
511         vf= G.main->vfont.first;
512         while(vf) {
513                 
514                 if(vf->id.us==0) strcat(str, "|0 ");
515                 else strcat(str, "|   ");
516                 
517                 strcpy(di, vf->name);
518                 BLI_splitdirstring(di, fi);
519                 
520                 strcat(str, fi);
521                 vf= vf->id.next;
522         }
523         return str;
524 }
525
526 static void load_buts_vfont(char *name)
527 {
528         VFont *vf;
529         Curve *cu;
530         
531         if(OBACT && OBACT->type==OB_FONT) cu= OBACT->data;
532         else return;
533         
534         vf= exist_vfont(name);
535         if(vf==0) {
536                 vf= load_vfont(name);
537                 if(vf==0) return;
538         }
539         else id_us_plus((ID *)vf);
540         
541         if(cu->vfont) cu->vfont->id.us--;
542         cu->vfont= vf;
543         
544         text_to_curve(OBACT, 0);
545         makeDispList(OBACT);
546         allqueue(REDRAWVIEW3D, 0);
547         allqueue(REDRAWBUTSEDIT, 0);
548 }
549
550 void do_fontbuts(unsigned short event)
551 {
552         Curve *cu;
553         VFont *vf;
554         Object *ob;
555         ScrArea *sa;
556         char str[80];
557         
558         ob= OBACT;
559         
560         switch(event) {
561         case B_MAKEFONT:
562                 text_to_curve(ob, 0);
563                 makeDispList(ob);
564                 allqueue(REDRAWVIEW3D, 0);
565                 break;
566         case B_TOUPPER:
567                 to_upper();
568                 break;
569         case B_LOADFONT:
570                 vf= give_vfontpointer(G.buts->texnr);
571                 if(vf && vf->id.prev!=vf->id.next) strcpy(str, vf->name);
572                 else strcpy(str, U.fontdir);
573                 
574                 sa= closest_bigger_area();
575                 areawinset(sa->win);
576
577                 activate_fileselect(FILE_SPECIAL, "SELECT FONT", str, load_buts_vfont);
578
579                 break;
580         case B_PACKFONT:
581                 if (ob) {
582                         cu= ob->data;
583                         if(cu && cu->vfont) {
584                                 if (cu->vfont->packedfile) {
585                                         if (G.fileflags & G_AUTOPACK) {
586                                                 if (okee("Disable AutoPack ?")) {
587                                                         G.fileflags &= ~G_AUTOPACK;
588                                                 }
589                                         }
590                                         
591                                         if ((G.fileflags & G_AUTOPACK) == 0) {
592                                                 if (unpackVFont(cu->vfont, PF_ASK) == RET_OK) {
593                                                         text_to_curve(ob, 0);
594                                                         makeDispList(ob);
595                                                         allqueue(REDRAWVIEW3D, 0);
596                                                 }
597                                         }
598                                 } else {
599                                         cu->vfont->packedfile = newPackedFile(cu->vfont->name);
600                                 }
601                         }
602                 }
603                 allqueue(REDRAWHEADERS, 0);
604                 allqueue(REDRAWBUTSEDIT, 0);
605                 break;
606
607         case B_SETFONT:
608                 if(ob) {
609                         cu= ob->data;
610
611                         vf= give_vfontpointer(G.buts->texnr);
612                         if(vf) {
613                                 id_us_plus((ID *)vf);
614                                 cu->vfont->id.us--;
615                                 cu->vfont= vf;
616                                 text_to_curve(ob, 0);
617                                 makeDispList(ob);
618                                 allqueue(REDRAWVIEW3D, 0);
619                                 allqueue(REDRAWBUTSEDIT, 0);
620                         }
621                 }       
622                 break;
623         case B_TEXTONCURVE:
624                 if(ob) {
625                         cu= ob->data;
626                         if(cu->textoncurve && cu->textoncurve->type!=OB_CURVE) {
627                                 error("Only Curve Objects");
628                                 cu->textoncurve= 0;
629                                 allqueue(REDRAWBUTSEDIT, 0);
630                         }
631                         text_to_curve(ob, 0);
632                         makeDispList(ob);
633                 }
634         }
635 }
636
637
638
639 static void editing_panel_font_type(Object *ob, Curve *cu)
640 {
641         uiBlock *block;
642         char *strp;
643         static int packdummy = 0;
644
645         block= uiNewBlock(&curarea->uiblocks, "editing_panel_font_type", UI_EMBOSSX, UI_HELV, curarea->win);
646         if(uiNewPanel(curarea, block, "Font", "Editing", 640, 0, 318, 204)==0) return;
647         
648         uiBlockSetCol(block, BUTGREEN);
649         uiDefButS(block, ROW,B_MAKEFONT, "Left",                484,139,53,18, &cu->spacemode, 0.0,0.0, 0, 0, "");
650         uiDefButS(block, ROW,B_MAKEFONT, "Middle",      604,139,61,18, &cu->spacemode, 0.0,1.0, 0, 0, "");
651         uiDefButS(block, ROW,B_MAKEFONT, "Right",               540,139,62,18, &cu->spacemode, 0.0,2.0, 0, 0, "");
652         uiDefButS(block, ROW,B_MAKEFONT, "Flush",               665,139,61,18, &cu->spacemode, 0.0,3.0, 0, 0, "");
653
654         uiBlockSetCol(block, BUTGREY);
655
656         uiDefIDPoinBut(block, test_obpoin_but, B_TEXTONCURVE, "TextOnCurve:",   484,115,243,19, &cu->textoncurve, "");
657         uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 484,85,243,19, cu->family, 0.0, 20.0, 0, 0, "");
658
659         uiDefButF(block, NUM,B_MAKEFONT, "Size:",               482,56,121,19, &cu->fsize, 0.1,10.0, 10, 0, "");
660         uiDefButF(block, NUM,B_MAKEFONT, "Linedist:",   605,56,121,19, &cu->linedist, 0.0,10.0, 10, 0, "");
661         uiDefButF(block, NUM,B_MAKEFONT, "Spacing:",    482,34,121,19, &cu->spacing, 0.0,10.0, 10, 0, "");
662         uiDefButF(block, NUM,B_MAKEFONT, "Y offset:",   605,34,121,19, &cu->yof, -50.0,50.0, 10, 0, "");
663         uiDefButF(block, NUM,B_MAKEFONT, "Shear:",      482,12,121,19, &cu->shear, -1.0,1.0, 10, 0, "");
664         uiDefButF(block, NUM,B_MAKEFONT, "X offset:",   605,12,121,19, &cu->xof, -50.0,50.0, 10, 0, "");
665
666         uiBlockSetCol(block, BUTSALMON);
667         uiDefBut(block, BUT, B_TOUPPER, "ToUpper",              623,163,103,23, 0, 0, 0, 0, 0, "");
668         
669         uiBlockSetCol(block, BUTGREY);
670
671         G.buts->texnr= give_vfontnr(cu->vfont);
672         
673         strp= give_vfontbutstr();
674         
675         uiDefButS(block, MENU, B_SETFONT, strp, 484,191,220,20, &G.buts->texnr, 0, 0, 0, 0, "");
676         
677         if (cu->vfont->packedfile) {
678                 packdummy = 1;
679         } else {
680                 packdummy = 0;
681         }
682         
683         uiBlockSetCol(block, BUTYELLOW);
684         uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE,       706,191,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this Vectorfont");
685         
686         MEM_freeN(strp);
687         
688         uiBlockSetCol(block, BUTSALMON);
689         uiDefBut(block, BUT,B_LOADFONT, "Load Font",    484,163,103,23, 0, 0, 0, 0, 0, "");
690
691 }
692
693 /* *************************** CURVE ******************************** */
694
695
696 void do_curvebuts(unsigned short event)
697 {
698         extern Nurb *lastnu;
699         extern ListBase editNurb;  /* from editcurve */
700         Object *ob;
701         Curve *cu;
702         Nurb *nu;
703         
704         ob= OBACT;
705         if(ob==0) return;
706         
707         switch(event) { 
708
709         case B_CONVERTPOLY:
710         case B_CONVERTBEZ:
711         case B_CONVERTBSPL:
712         case B_CONVERTCARD:
713         case B_CONVERTNURB:
714                 if(G.obedit) {
715                         setsplinetype(event-B_CONVERTPOLY);
716                         makeDispList(G.obedit);
717                         allqueue(REDRAWVIEW3D, 0);
718                 }
719                 break;
720         case B_UNIFU:
721         case B_ENDPU:
722         case B_BEZU:
723         case B_UNIFV:
724         case B_ENDPV:
725         case B_BEZV:
726                 if(G.obedit) {
727                         nu= editNurb.first;
728                         while(nu) {
729                                 if(isNurbsel(nu)) {
730                                         if((nu->type & 7)==CU_NURBS) {
731                                                 if(event<B_UNIFV) {
732                                                         nu->flagu &= 1;
733                                                         nu->flagu += ((event-B_UNIFU)<<1);
734                                                         makeknots(nu, 1, nu->flagu>>1);
735                                                 }
736                                                 else if(nu->pntsv>1) {
737                                                         nu->flagv &= 1;
738                                                         nu->flagv += ((event-B_UNIFV)<<1);
739                                                         makeknots(nu, 2, nu->flagv>>1);
740                                                 }
741                                         }
742                                 }
743                                 nu= nu->next;
744                         }
745                         makeDispList(G.obedit);
746                         allqueue(REDRAWVIEW3D, 0);
747                 }
748                 break;
749         case B_SETWEIGHT:
750                 if(G.obedit) {
751                         weightflagNurb(1, editbutweight, 0);
752                         makeDispList(G.obedit);
753                         allqueue(REDRAWVIEW3D, 0);
754                 }
755                 break;
756         case B_SETW1:
757                 editbutweight= 1.0;
758                 scrarea_queue_winredraw(curarea);
759                 break;
760         case B_SETW2:
761                 editbutweight= sqrt(2.0)/4.0;
762                 scrarea_queue_winredraw(curarea);
763                 break;
764         case B_SETW3:
765                 editbutweight= 0.25;
766                 scrarea_queue_winredraw(curarea);
767                 break;
768         case B_SETW4:
769                 editbutweight= sqrt(0.5);
770                 scrarea_queue_winredraw(curarea);
771                 break;
772         case B_SETORDER:
773                 if(G.obedit) {
774                         nu= lastnu;
775                         if(nu && (nu->type & 7)==CU_NURBS ) {
776                                 if(nu->orderu>nu->pntsu) {
777                                         nu->orderu= nu->pntsu;
778                                         scrarea_queue_winredraw(curarea);
779                                 }
780                                 makeknots(nu, 1, nu->flagu>>1);
781                                 if(nu->orderv>nu->pntsv) {
782                                         nu->orderv= nu->pntsv;
783                                         scrarea_queue_winredraw(curarea);
784                                 }
785                                 makeknots(nu, 2, nu->flagv>>1);
786                         }
787                         makeDispList(G.obedit);
788                         allqueue(REDRAWVIEW3D, 0);
789                 }
790                 break;
791         case B_MAKEDISP:
792                 if(ob->type==OB_FONT) text_to_curve(ob, 0);
793                 makeDispList(ob);
794                 allqueue(REDRAWVIEW3D, 0);
795                 allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
796                 break;
797         
798         case B_SUBDIVCURVE:
799                 subdivideNurb();
800                 break;
801         case B_SPINNURB:
802                 /* bad bad bad!!! use brackets!!! In case you wondered:
803                   {==,!=} goes before & goes before || */
804                 if( (G.obedit==0) || 
805                     (G.obedit->type!=OB_SURF) || 
806                         ((G.obedit->lay & G.vd->lay) == 0) ) return;
807                 spinNurb(0, 0);
808                 countall();
809                 makeDispList(G.obedit);
810                 allqueue(REDRAWVIEW3D, 0);
811                 break;
812         case B_CU3D:        /* allow 3D curve */
813                 if(G.obedit) {
814                         cu= G.obedit->data;
815                         nu= editNurb.first;
816                         while(nu) {
817                                 nu->type &= ~CU_2D;
818                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
819                                 test2DNurb(nu);
820                                 nu= nu->next;
821                         }
822                 }
823                 if(ob->type==OB_CURVE) {
824                         cu= ob->data;
825                         nu= cu->nurb.first;
826                         while(nu) {
827                                 nu->type &= ~CU_2D;
828                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
829                                 test2DNurb(nu);
830                                 nu= nu->next;
831                         }
832                 }
833                 break;
834         case B_SETRESOLU:
835                 if(ob->type==OB_CURVE) {
836                         cu= ob->data;
837                         if(ob==G.obedit) nu= editNurb.first;
838                         else nu= cu->nurb.first;
839                         
840                         while(nu) {
841                                 nu->resolu= cu->resolu;
842                                 nu= nu->next;
843                         }
844                 }
845                 else if(ob->type==OB_FONT) text_to_curve(ob, 0);
846                 
847                 makeDispList(ob);
848                 allqueue(REDRAWVIEW3D, 0);
849
850                 break;
851         }
852 }
853
854 static void editing_panel_curve_tools(Object *ob, Curve *cu)
855 {
856         Nurb *nu;
857         extern ListBase editNurb;  /* from editcurve */
858         extern Nurb *lastnu;
859         uiBlock *block;
860         short *sp;
861         
862         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools", UI_EMBOSSX, UI_HELV, curarea->win);
863         if(uiNewPanel(curarea, block, "Curve Tools", "Editing", 640, 0, 318, 204)==0) return;
864         
865         uiBlockSetCol(block, BUTSALMON);
866         if(ob->type==OB_CURVE) {
867                 uiDefBut(block, LABEL, 0, "Convert",    463,173,72, 18, 0, 0, 0, 0, 0, "");
868                 uiDefBut(block, BUT,B_CONVERTPOLY,"Poly",               467,152,72, 18, 0, 0, 0, 0, 0, "");
869                 uiDefBut(block, BUT,B_CONVERTBEZ,"Bezier",      467,132,72, 18, 0, 0, 0, 0, 0, "");
870                 uiDefBut(block, BUT,B_CONVERTBSPL,"Bspline",    467,112,72, 18, 0, 0, 0, 0, 0, "");
871                 uiDefBut(block, BUT,B_CONVERTCARD,"Cardinal",   467,92,72, 18, 0, 0, 0, 0, 0, "");
872                 uiDefBut(block, BUT,B_CONVERTNURB,"Nurb",               467,72,72, 18, 0, 0, 0, 0, 0, "");
873         }
874         uiDefBut(block, LABEL, 0, "Make Knots",562,173,102, 18, 0, 0, 0, 0, 0, "");
875         uiDefBut(block, BUT,B_UNIFU,"Uniform U",        565,152,102, 18, 0, 0, 0, 0, 0, "");
876         uiDefBut(block, BUT,B_ENDPU,"Endpoint U",       565,132,102, 18, 0, 0, 0, 0, 0, "");
877         uiDefBut(block, BUT,B_BEZU,"Bezier U",  565,112,102, 18, 0, 0, 0, 0, 0, "");
878         uiDefBut(block, BUT,B_UNIFV,"V",                670,152,50, 18, 0, 0, 0, 0, 0, "");
879         uiDefBut(block, BUT,B_ENDPV,"V",                670,132,50, 18, 0, 0, 0, 0, 0, "");
880         uiDefBut(block, BUT,B_BEZV,"V",         670,112,50, 18, 0, 0, 0, 0, 0, "");
881
882         uiDefBut(block, BUT,B_SETWEIGHT,"Set Weight",   465,11,95,49, 0, 0, 0, 0, 0, "");
883         uiBlockSetCol(block, BUTGREY);
884         uiDefButF(block, NUM,0,"Weight:",       564,36,102,22, &editbutweight, 0.01, 10.0, 10, 0, "");
885         uiDefBut(block, BUT,B_SETW1,"1.0",              669,36,50,22, 0, 0, 0, 0, 0, "");
886         uiDefBut(block, BUT,B_SETW2,"sqrt(2)/4",564,11,57,20, 0, 0, 0, 0, 0, "");
887         uiDefBut(block, BUT,B_SETW3,"0.25",             621,11,43,20, 0, 0, 0, 0, 0, "");
888         uiDefBut(block, BUT,B_SETW4,"sqrt(0.5)",664,11,57,20, 0, 0, 0, 0, 0, "");
889         
890         if(ob==G.obedit) {
891                 nu= lastnu;
892                 if(nu==NULL) nu= editNurb.first;
893                 if(nu) {
894                         sp= &(nu->orderu); 
895                         uiDefButS(block, NUM, B_SETORDER, "Order U:", 565,91,102, 18, sp, 2.0, 6.0, 0, 0, "");
896                         sp= &(nu->orderv); 
897                         uiDefButS(block, NUM, B_SETORDER, "V:",  670,91,50, 18, sp, 2.0, 6.0, 0, 0, "");
898                         sp= &(nu->resolu); 
899                         uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 18, sp, 1.0, 128.0, 0, 0, "");
900                         sp= &(nu->resolv); 
901                         uiDefButS(block, NUM, B_MAKEDISP, "V:", 670,70,50, 18, sp, 1.0, 128.0, 0, 0, "");
902                 }
903         }
904         
905
906 }
907
908 static void editing_panel_curve_tools1(Object *ob, Curve *cu)
909 {
910         uiBlock *block;
911         
912         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools1", UI_EMBOSSX, UI_HELV, curarea->win);
913         if(uiNewPanel(curarea, block, "Curve Tools1", "Editing", 960, 0, 318, 204)==0) return;
914         
915         uiBlockSetCol(block, BUTSALMON);
916
917         uiDefBut(block, BUT, B_SUBDIVCURVE, "Subdivide", 400,180,150,20, 0, 0, 0, 0, 0, "");
918         if(ob->type==OB_SURF) {
919                 uiDefBut(block, BUT, B_SPINNURB, "Spin",         400,160,150,20, 0, 0, 0, 0, 0, "");
920         }
921         
922         uiBlockSetCol(block, BUTGREY);
923         uiDefBut(block, BUT,B_HIDE,             "Hide",                 400,120,150,18, 0, 0, 0, 0, 0, "Hides selected faces");
924         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               400,100,150,18, 0, 0, 0, 0, 0, "Reveals selected faces");
925         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  400,80,150,18, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
926
927         uiDefButF(block, NUM,   REDRAWVIEW3D, "NSize:", 400, 40, 150, 19, &editbutsize, 0.001, 1.0, 10, 0, "");
928 }
929
930 /* for curve, surf and font! */
931 static void editing_panel_curve_type(Object *ob, Curve *cu)
932 {
933         uiBlock *block;
934         
935         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_type", UI_EMBOSSX, UI_HELV, curarea->win);
936         if(uiNewPanel(curarea, block, "Curve and Surface", "Editing", 320, 0, 318, 204)==0) return;
937         
938         uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                                       543,160,130,18, &cu->flag, 0, 0, 0, 0, "");
939         if(ob->type==OB_SURF) 
940                 uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "No Puno Flip",       543,140,130,18, &cu->flag, 0, 0, 0, 0, "");
941
942         uiBlockSetCol(block, BUTSALMON);
943         uiDefBut(block, BUT,B_DOCENTRE, "Centre",                                       543, 115, 140, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
944         uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New",                        543, 95, 140, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data");
945         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          543, 75, 140, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
946
947         if(ob->type==OB_SURF) {
948                 if(cu->key) {
949                         uiBlockSetCol(block, BUTGREEN);
950                         /* uiDefButS(block, NUM, B_DIFF, "Slurph:",                     543,25,140,19, &(cu->key->slurph), -500.0, 500.0,0,0); ,""*/
951                         uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        543,45,140,19, &cu->key->type, 0, 0, 0, 0, "");
952                 }
953         }
954
955         if(ob->type!=OB_SURF) {
956                 
957                 if(ob->type==OB_CURVE) {
958                         static float prlen;
959                         char str[32];
960                         uiBlockSetCol(block, BUTGREY);
961                         uiDefButS(block, NUM, B_RECALCPATH, "PathLen:",                 543,50,140,19, &cu->pathlen, 1.0, 9000.0, 0, 0, "");
962                         uiBlockSetCol(block, BUTGREEN);
963                         uiDefButS(block, TOG|BIT|3, B_RECALCPATH, "CurvePath",  543,30,70,19 , &cu->flag, 0, 0, 0, 0, "");
964                         uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "CurveFollow",613,30,70,19, &cu->flag, 0, 0, 0, 0, "");
965                         uiBlockSetCol(block, BUTGREY);
966                         sprintf(str, "%.4f", prlen);
967                         uiDefBut(block, BUT, B_PRINTLEN,                "PrintLen",     543,10,70,19, 0, 0, 0, 0, 0, "");
968                         uiDefBut(block, LABEL, 0, str,                                          613,10,70,19, 0, 1.0, 0, 0, 0, "");
969                 }
970                 uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 752,163,132,21, &cu->resolu, 1.0, 128.0, 0, 0, "");
971                 uiBlockSetCol(block, BUTSALMON);
972                 uiDefBut(block, BUT, B_SETRESOLU, "Set",                                887,163,29,21, 0, 0, 0, 0, 0, "");
973                 
974                 uiBlockSetCol(block, BUTGREY);
975                 uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  753,30,163,18, &cu->bevresol, 0.0, 10.0, 0, 0, "");
976
977                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "BevOb:",         753,10,163,18, &cu->bevobj, "");
978                 uiDefButF(block, NUM, B_MAKEDISP, "Width:",             753,90,163,18, &cu->width, 0.0, 2.0, 1, 0, "");
979                 uiDefButF(block, NUM, B_MAKEDISP, "Ext1:",              753,70,163,18, &cu->ext1, 0.0, 5.0, 10, 0, "");
980                 uiDefButF(block, NUM, B_MAKEDISP, "Ext2:",              753,50,163,18, &cu->ext2, 0.0, 2.0, 1, 0, "");
981                 uiBlockSetCol(block, BUTBLUE);
982
983                 uiDefButS(block, TOG|BIT|0, B_CU3D, "3D",                       867,130,47,18, &cu->flag, 0, 0, 0, 0, "");
984                 uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",        810,130,55,18, &cu->flag, 0, 0, 0, 0, "");
985                 uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 753,130,53,18, &cu->flag, 0, 0, 0, 0, "");
986
987                 
988         }
989
990 }
991
992
993 /* *************************** CAMERA ******************************** */
994
995
996 static void editing_panel_camera_type(Object *ob, Camera *cam)
997 {
998         uiBlock *block;
999         float grid=0.0;
1000         
1001         if(G.vd) grid= G.vd->grid; 
1002         if(grid<1.0) grid= 1.0;
1003         
1004         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_type", UI_EMBOSSX, UI_HELV, curarea->win);
1005         if(uiNewPanel(curarea, block, "Camera", "Editing", 320, 0, 318, 204)==0) return;
1006
1007
1008         uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:", 470,178,160,20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
1009         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");
1010         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");
1011         uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
1012
1013         uiBlockSetCol(block, BUTGREEN);
1014         uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
1015
1016         uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
1017         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");
1018         
1019         if(G.special1 & G_HOLO) {
1020                 uiBlockSetCol(block, BUTGREY);
1021                 if(cam->netend==0.0) cam->netend= EFRA;
1022                 uiDefButF(block, NUM, REDRAWVIEW3D, "Anim len",         670,80,100,20, &cam->netend, 1.0, 2500.0, 0, 0, "");
1023                 uiDefButF(block, NUM, REDRAWVIEW3D, "Path len:",                670,160,100,20, &cam->hololen, 0.1, 25.0, 10, 0, "");
1024                 uiDefButF(block, NUM, REDRAWVIEW3D, "Shear fac:",               670,140,100,20, &cam->hololen1, 0.1, 5.0, 10, 0, "");
1025                 uiBlockSetCol(block, BUTGREEN);
1026                 uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Holo 1",     670,120,100,20, &cam->flag, 0.0, 0.0, 0, 0, "");
1027                 uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Holo 2",     670,100,100,20, &cam->flag, 0.0, 0.0, 0, 0, "");
1028                 
1029         }
1030
1031 }
1032
1033 /* *************************** MBALL ******************************** */
1034
1035 void do_mballbuts(unsigned short event)
1036 {
1037         switch(event) {
1038         case B_RECALCMBALL:
1039                 makeDispList(OBACT);
1040                 allqueue(REDRAWVIEW3D, 0);
1041                 break;
1042         }
1043 }
1044
1045 static void editing_panel_mball_type(Object *ob, MetaBall *mb)
1046 {
1047         uiBlock *block;
1048         
1049         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_type", UI_EMBOSSX, UI_HELV, curarea->win);
1050         if(uiNewPanel(curarea, block, "MetaBall", "Editing", 320, 0, 318, 204)==0) return;
1051         
1052         if (ob==find_basis_mball(ob)) {
1053                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Wiresize:",    470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "");
1054                 uiDefButF(block, NUMSLI, 0, "Rendersize:",                      470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "");
1055                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "");
1056
1057                 uiBlockSetCol(block, BUTBLUE);
1058                 uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
1059                 uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "");
1060                 uiDefButS(block, ROW, B_DIFF, "Half Res",       471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "");
1061                 uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "");
1062                 uiBlockSetCol(block, BUTGREY);
1063         }
1064         
1065 }
1066
1067 static void editing_panel_mball_tools(Object *ob, MetaBall *mb)
1068 {
1069         extern MetaElem *lastelem;
1070         uiBlock *block;
1071         
1072         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_tools", UI_EMBOSSX, UI_HELV, curarea->win);
1073         if( uiNewPanel(curarea, block, "MetaBall tools", "Editing", 640, 0, 318, 204)==0) return;
1074         
1075         if(ob==G.obedit && lastelem) {
1076                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "");
1077                 if(lastelem->type!=MB_BALL)
1078                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dx:",          750,158,250,19, &lastelem->expx, 0.0, 20.0, 0, 0, "");
1079                 if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
1080                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dy:",          750,138,250,19, &lastelem->expy, 0.0, 20.0, 0, 0, "");
1081
1082                 if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
1083                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dz:",          750,118,250,19, &lastelem->expz, 0.0, 20.0, 0, 0, "");
1084
1085                 uiBlockSetCol(block, BUTGREEN);
1086                 uiDefButS(block, TOG|BIT|1, B_RECALCMBALL, "Negative",753,16,60,19, &lastelem->flag, 0, 0, 0, 0, "");
1087
1088                 uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "");
1089                 uiDefButS(block, ROW, B_RECALCMBALL, "Tube",                    753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "");
1090                 uiDefButS(block, ROW, B_RECALCMBALL, "Plane",                   814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "");
1091                 uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid",                876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "");
1092                 uiDefButS(block, ROW, B_RECALCMBALL, "Cube",                    938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "");
1093         }
1094
1095 }
1096
1097
1098 /* *************************** LATTICE ******************************** */
1099
1100 void do_latticebuts(unsigned short event)
1101 {
1102         Object *ob;
1103         Lattice *lt;
1104         
1105         ob= OBACT;
1106         if(ob->type!=OB_LATTICE) return;
1107         
1108         switch(event) {
1109         case B_RESIZELAT:
1110                 if(ob) {
1111                         if(ob==G.obedit) resizelattice(editLatt);
1112                         else resizelattice(ob->data);
1113                 }
1114                 allqueue(REDRAWVIEW3D, 0);
1115                 break;
1116         case B_DRAWLAT:
1117                 if(ob==G.obedit) calc_lattverts_ext();
1118                 allqueue(REDRAWVIEW3D, 0);
1119                 break;
1120         case B_LATTCHANGED:
1121                 
1122                 lt= ob->data;
1123                 if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
1124                 
1125                 make_displists_by_parent(ob);
1126
1127                 allqueue(REDRAWVIEW3D, 0);
1128                 
1129                 break;
1130         }
1131 }
1132
1133 static void editing_panel_lattice_type(Object *ob, Lattice *lt)
1134 {
1135         uiBlock *block;
1136         
1137         block= uiNewBlock(&curarea->uiblocks, "editing_panel_lattice_type", UI_EMBOSSX, UI_HELV, curarea->win);
1138         if(uiNewPanel(curarea, block, "Latice", "Editing", 320, 0, 318, 204)==0) return;
1139         
1140
1141         uiSetButLock(lt->key!=0, "Not with VertexKeys");
1142         uiSetButLock(ob==G.obedit, "Unable to perform function in EditMode");
1143         uiDefButS(block, NUM, B_RESIZELAT,      "U:",                   470,178,100,19, &lt->pntsu, 1.0, 64.0, 0, 0, "");
1144         uiDefButS(block, NUM, B_RESIZELAT,      "V:",                   470,158,100,19, &lt->pntsv, 1.0, 64.0, 0, 0, "");
1145         uiDefButS(block, NUM, B_RESIZELAT,      "W:",                   470,138,100,19, &lt->pntsw, 1.0, 64.0, 0, 0, "");
1146         uiClearButLock();
1147         
1148         uiBlockSetCol(block, BUTGREEN);
1149         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_LINEAR, 0, 0, "");
1150         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_CARDINAL, 0, 0, "");
1151         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_BSPLINE, 0, 0, "");
1152
1153         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 158, 40, 19, &lt->typev, 2.0, (float)KEY_LINEAR, 0, 0, "");
1154         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 158, 40, 19, &lt->typev, 2.0, (float)KEY_CARDINAL, 0, 0, "");
1155         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 158, 40, 19, &lt->typev, 2.0, (float)KEY_BSPLINE, 0, 0, "");
1156
1157         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 138, 40, 19, &lt->typew, 3.0, (float)KEY_LINEAR, 0, 0, "");
1158         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 138, 40, 19, &lt->typew, 3.0, (float)KEY_CARDINAL, 0, 0, "");
1159         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 138, 40, 19, &lt->typew, 3.0, (float)KEY_BSPLINE, 0, 0, "");
1160         
1161         uiBlockSetCol(block, BUTSALMON);
1162         uiDefBut(block, BUT, B_RESIZELAT,       "Make Regular",         470,101,99,32, 0, 0, 0, 0, 0, "");
1163
1164         uiBlockSetCol(block, BUTGREEN);
1165         uiDefButS(block, TOG|BIT|1, B_LATTCHANGED, "Outside",   571,101,120,31, &lt->flag, 0, 0, 0, 0, "");
1166
1167         if(lt->key) {
1168                 uiDefButS(block, NUM, B_DIFF, "Slurph:",                        470,60,120,19, &(lt->key->slurph), -500.0, 500.0, 0, 0, "");
1169                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        470,40,120,19, &lt->key->type, 0, 0, 0, 0, "");
1170         }
1171
1172 }
1173
1174 /* *************************** ARMATURE ******************************** */
1175
1176
1177
1178 static int editbone_to_parnr (EditBone *bone)
1179 {
1180         EditBone *ebone;
1181         int     index;
1182
1183         for (ebone=G.edbo.first, index=0; ebone; ebone=ebone->next, index++){
1184                 if (ebone==bone)
1185                         return index;
1186         }
1187
1188         return -1;
1189 }
1190
1191
1192
1193 static void attach_bone_to_parent(EditBone *bone)
1194 {
1195         EditBone *curbone;
1196
1197         if (bone->flag & BONE_IK_TOPARENT) {
1198
1199         /* See if there are any other bones that refer to the same parent and disconnect them */
1200                 for (curbone = G.edbo.first; curbone; curbone=curbone->next){
1201                         if (curbone!=bone){
1202                                 if (curbone->parent && (curbone->parent == bone->parent) && (curbone->flag & BONE_IK_TOPARENT))
1203                                         curbone->flag &= ~BONE_IK_TOPARENT;
1204                         }
1205                 }
1206
1207         /* Attach this bone to its parent */
1208                 VECCOPY(bone->head, bone->parent->tail);
1209         }
1210
1211 }
1212
1213 static void attach_bone_to_parent_cb(void *bonev, void *arg2_unused)
1214 {
1215         EditBone *curBone= bonev;
1216         attach_bone_to_parent(curBone);
1217 }
1218
1219 static void parnr_to_editbone(EditBone *bone)
1220 {
1221         if (bone->parNr == -1){
1222                 bone->parent = NULL;
1223                 bone->flag &= ~BONE_IK_TOPARENT;
1224         }
1225         else{
1226                 bone->parent = BLI_findlink(&G.edbo, bone->parNr);
1227                 attach_bone_to_parent(bone);
1228         }
1229 }
1230
1231 static void parnr_to_editbone_cb(void *bonev, void *arg2_unused)
1232 {
1233         EditBone *curBone= bonev;
1234         parnr_to_editbone(curBone);
1235 }
1236
1237
1238 static void build_bonestring (char *string, EditBone *bone){
1239         EditBone *curBone;
1240         EditBone *pBone;
1241         int             skip=0;
1242         int             index;
1243
1244         sprintf (string, "Parent%%t| %%x%d", -1);       /* That space is there for a reason */
1245         
1246         for (curBone = G.edbo.first, index=0; curBone; curBone=curBone->next, index++){
1247                 /* Make sure this is a valid child */
1248                 if (curBone != bone){
1249                         skip=0;
1250                         for (pBone=curBone->parent; pBone; pBone=pBone->parent){
1251                                 if (pBone==bone){
1252                                         skip=1;
1253                                         break;
1254                                 }
1255                         }
1256                         
1257                         if (skip)
1258                                 continue;
1259                         
1260                         sprintf (string, "%s|%s%%x%d", string, curBone->name, index);
1261                 }
1262         }
1263 }
1264
1265 static void validate_editbonebutton(EditBone *eBone){
1266         EditBone        *prev;
1267         bAction         *act=NULL;
1268         bActionChannel *chan;
1269         Base *base;
1270
1271         /* Separate the bone from the G.edbo */
1272         prev=eBone->prev;
1273         BLI_remlink (&G.edbo, eBone);
1274
1275         /*      Validate the name */
1276         unique_editbone_name (eBone->name);
1277
1278         /* Re-insert the bone */
1279         if (prev)
1280                 BLI_insertlink(&G.edbo, prev, eBone);
1281         else
1282                 BLI_addhead (&G.edbo, eBone);
1283
1284         /* Rename channel if necessary */
1285         if (G.obedit)
1286                 act = G.obedit->action;
1287
1288         if (act && !act->id.lib){
1289                 //      Find the appropriate channel
1290                 for (chan = act->chanbase.first; chan; chan=chan->next){
1291                         if (!strcmp (chan->name, eBone->oldname)){
1292                                 strcpy (chan->name, eBone->name);
1293                         }
1294                 }
1295                 allqueue(REDRAWACTION, 0);
1296         }
1297
1298         /* Update the parenting info of any users */
1299         /*      Yes, I know this is the worst thing you have ever seen. */
1300
1301         for (base = G.scene->base.first; base; base=base->next){
1302                 Object *ob = base->object;
1303
1304                 /* See if an object is parented to this armature */
1305                 if (ob->parent && ob->partype==PARBONE && (ob->parent->type==OB_ARMATURE) && (ob->parent->data == G.obedit->data)){
1306                         if (!strcmp(ob->parsubstr, eBone->oldname))
1307                                 strcpy(ob->parsubstr, eBone->name);
1308                 }
1309         }
1310
1311         exit_editmode(0);       /* To ensure new names make it to the edit armature */
1312
1313 }
1314
1315 static void validate_editbonebutton_cb(void *bonev, void *arg2_unused)
1316 {
1317         EditBone *curBone= bonev;
1318         validate_editbonebutton(curBone);
1319 }
1320
1321
1322 static void editing_panel_armature_type(Object *ob, bArmature *arm)
1323 {
1324         uiBlock         *block;
1325         int                     bx=148, by=100;
1326
1327         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_type", UI_EMBOSSX, UI_HELV, curarea->win);
1328         if(uiNewPanel(curarea, block, "Armature", "Editing", 320, 0, 318, 204)==0) return;
1329                 
1330         uiBlockSetCol(block, BUTGREEN);
1331         uiDefButI(block, TOG|BIT|ARM_RESTPOSBIT,REDRAWVIEW3D, "Rest Pos", bx,by,97,20, &arm->flag, 0, 0, 0, 0, "Disable all animation for this object");
1332         uiDefButI(block, TOG|BIT|ARM_DRAWAXESBIT,REDRAWVIEW3D, "Draw Axes", bx,by-46,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
1333         uiDefButI(block, TOG|BIT|ARM_DRAWNAMESBIT,REDRAWVIEW3D, "Draw Names", bx,by-69,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
1334         uiDefButI(block, TOG|BIT|ARM_DRAWXRAYBIT,REDRAWVIEW3D, "X-Ray", bx,by-92,97,20, &arm->flag, 0, 0, 0, 0, "Draw armature in front of shaded objects");
1335         
1336         
1337
1338 }
1339
1340 static void editing_panel_armature_bones(Object *ob, bArmature *arm)
1341 {
1342         uiBlock         *block;
1343         EditBone        *curBone;
1344         uiBut           *but;
1345         char            *boneString=NULL;
1346         int                     bx=148, by=180;
1347         int                     index;
1348
1349         /* Draw the bone name block */
1350
1351         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_bones", UI_EMBOSSX, UI_HELV, curarea->win);
1352         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
1353
1354         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1355         /* so first we make it default height */
1356         uiNewPanelHeight(block, 204);
1357
1358
1359         uiDefBut(block, LABEL, 0, "Selected Bones",                                             bx,by,158,18, 0, 0, 0, 0, 0, "");
1360         by-=20;
1361         for (curBone=G.edbo.first, index=0; curBone; curBone=curBone->next, index++){
1362                 if (curBone->flag & (BONE_SELECTED)) {
1363
1364                         /* Hide in posemode flag */
1365                         uiBlockSetCol(block, BUTGREEN);
1366                         uiDefButI(block, TOG|BIT|BONE_HIDDENBIT, REDRAWVIEW3D, "Hide", bx-55,by,45,18, &curBone->flag, 0, 0, 0, 0, "Toggles display of this bone in posemode");
1367                         
1368                         /*      Bone naming button */
1369                         uiBlockSetCol(block, BUTGREY);
1370                         strcpy (curBone->oldname, curBone->name);
1371                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:", bx-10,by,117,18, &curBone->name, 0, 24, 0, 0, "Change the bone name");
1372                         uiButSetFunc(but, validate_editbonebutton_cb, curBone, NULL);
1373                         
1374                         uiDefBut(block, LABEL, 0, "child of", bx+107,by,73,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1375
1376                         boneString = malloc((BLI_countlist(&G.edbo) * 64)+64);
1377                         build_bonestring (boneString, curBone);
1378                         
1379                         curBone->parNr = editbone_to_parnr(curBone->parent);
1380                         but = uiDefButI(block, MENU,REDRAWVIEW3D, boneString, bx+180,by,120,18, &curBone->parNr, 0.0, 0.0, 0.0, 0.0, "Parent");
1381                         uiButSetFunc(but, parnr_to_editbone_cb, curBone, NULL);
1382
1383                         free(boneString);
1384
1385                         /* IK to parent flag */
1386                         if (curBone->parent){
1387                                 uiBlockSetCol(block, BUTGREEN);
1388                                 but=uiDefButI(block, TOG|BIT|BONE_IK_TOPARENTBIT, REDRAWVIEW3D, "IK", bx+300,by,32,18, &curBone->flag, 0.0, 0.0, 0.0, 0.0, "IK link to parent");
1389                                 uiButSetFunc(but, attach_bone_to_parent_cb, curBone, NULL);
1390                         }
1391
1392                         /* Dist and weight buttons */
1393                         uiBlockSetCol(block, BUTGREY);
1394                         but=uiDefButS(block, MENU, REDRAWVIEW3D,
1395                                                         "Skinnable %x0|"
1396                                                         "Unskinnable %x1|"
1397                                                         "Head %x2|"
1398                                                         "Neck %x3|"
1399                                                         "Back %x4|"
1400                                                         "Shoulder %x5|"
1401                                                         "Arm %x6|"
1402                                                         "Hand %x7|"
1403                                                         "Finger %x8|"
1404                                                         "Thumb %x9|"
1405                                                         "Pelvis %x10|"
1406                                                         "Leg %x11|"
1407                                                         "Foot %x12|"
1408                                                         "Toe %x13|"
1409                                                         "Tentacle %x14",
1410                                                         bx-10,by-19,117,18,
1411                                                         &curBone->boneclass,
1412                                                         0.0, 0.0, 0.0, 0.0, 
1413                                                         "Classification of armature element");
1414                         
1415                         /* Dist and weight buttons */
1416                         uiBlockSetCol(block, BUTGREY);
1417                         uiDefButF(block, NUM,REDRAWVIEW3D, "Dist:", bx+110, by-19, 
1418                                                 105, 18, &curBone->dist, 0.0, 1000.0, 10.0, 0.0, 
1419                                                 "Bone deformation distance");
1420                         uiDefButF(block, NUM,REDRAWVIEW3D, "Weight:", bx+223, by-19, 
1421                                                 110, 18, &curBone->weight, 0.0F, 1000.0F, 
1422                                                 10.0F, 0.0F, "Bone deformation weight");
1423                         
1424                         by-=42; 
1425                 }
1426         }
1427         
1428         if(by<0) {
1429                 uiNewPanelHeight(block, 204 - by);
1430         }
1431         
1432 }
1433
1434
1435 /* *************************** MESH ******************************** */
1436
1437
1438
1439 void do_meshbuts(unsigned short event)
1440 {
1441         void decimate_faces(void);
1442         void decimate_cancel(void);
1443         void decimate_apply(void);
1444         Object *ob;
1445         Mesh *me;
1446         float fac;
1447         short randfac;
1448
1449         ob= OBACT;
1450         if(ob && ob->type==OB_MESH) {
1451                 
1452                 me= get_mesh(ob);
1453                 if(me==0) return;
1454                 
1455                 switch(event) {
1456                 case B_AUTOVGROUP:
1457                         if (!get_armature(ob->parent)){
1458                                 error ("Mesh must be the child of an armature");
1459                                 break;
1460                         }
1461                                 /* Verify that there are vertex groups for bones in armature */
1462                                 /* Remove selected vertices from all defgroups */
1463                                 /* Perform assignment for selected vertices */
1464
1465                         allqueue (REDRAWVIEW3D, 1);
1466                         break;
1467                 case B_NEWVGROUP:
1468                         add_defgroup (G.obedit);
1469                         scrarea_queue_winredraw(curarea);
1470                         break;
1471                 case B_DELVGROUP:
1472                         del_defgroup (G.obedit);
1473                         allqueue (REDRAWVIEW3D, 1);
1474                         break;
1475                 case B_ASSIGNVGROUP:
1476                         undo_push_mesh("Assign to vertex group");
1477                         assign_verts_defgroup ();
1478                         allqueue (REDRAWVIEW3D, 1);
1479                         break;
1480                 case B_REMOVEVGROUP:
1481                         undo_push_mesh("Remove from vertex group");
1482                         remove_verts_defgroup (0);
1483                         allqueue (REDRAWVIEW3D, 1);
1484                         break;
1485                 case B_SELVGROUP:
1486                         sel_verts_defgroup(1);
1487                         allqueue (REDRAWVIEW3D, 1);
1488                         break;
1489                 case B_DESELVGROUP:
1490                         sel_verts_defgroup(0);
1491                         allqueue (REDRAWVIEW3D, 1);
1492                         break;
1493                 case B_DELSTICKY:
1494                 
1495                         if(me->msticky) MEM_freeN(me->msticky);
1496                         me->msticky= 0;
1497                         allqueue(REDRAWBUTSEDIT, 0);
1498                         break;
1499                 case B_MAKESTICKY:
1500                         make_sticky();
1501                         break;
1502                 case B_MAKEVERTCOL:
1503                         make_vertexcol();
1504                         break;
1505                 case B_DELVERTCOL:
1506                         if(me->mcol) MEM_freeN(me->mcol);
1507                         me->mcol= 0;
1508                         G.f &= ~G_VERTEXPAINT;
1509                         freedisplist(&(ob->disp));
1510                         allqueue(REDRAWBUTSEDIT, 0);
1511                         allqueue(REDRAWVIEW3D, 0);
1512                         break;
1513
1514                 case B_MAKE_TFACES:
1515                         make_tfaces(me);
1516                         allqueue(REDRAWBUTSEDIT, 0);
1517                         break;
1518
1519                 case B_DEL_TFACES:
1520                         if(me->tface) MEM_freeN(me->tface);
1521                         me->tface= 0;
1522                         G.f &= ~G_FACESELECT;
1523                         allqueue(REDRAWBUTSEDIT, 0);
1524                         allqueue(REDRAWVIEW3D, 0);
1525                         allqueue(REDRAWIMAGE, 0);
1526                         break;
1527                         
1528                 case B_FLIPNORM:
1529                         if(G.obedit) {
1530                                 flip_editnormals();
1531                         }
1532                         else flipnorm_mesh( get_mesh(ob) );
1533                         
1534                         allqueue(REDRAWVIEW3D, 0);
1535                         break;
1536
1537                 case B_DECIM_FACES:
1538                         decimate_faces();
1539                         break;
1540                 case B_DECIM_CANCEL:
1541                         decimate_cancel();
1542                         break;
1543                 case B_DECIM_APPLY:
1544                         decimate_apply();
1545                         break;
1546
1547                 case B_SLOWERDRAW:
1548                         slowerdraw();
1549                         break;
1550                 case B_FASTERDRAW:
1551                         fasterdraw();
1552                         break;
1553                 }
1554         }
1555         
1556         if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return;
1557         
1558         switch(event) {
1559         case B_SPIN:
1560                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 0);
1561                 break;
1562         case B_SPINDUP:
1563                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 1);
1564                 break;
1565         case B_EXTR:
1566                 G.f |= G_DISABLE_OK;
1567                 if( select_area(SPACE_VIEW3D)) extrude_mesh();
1568                 G.f -= G_DISABLE_OK;
1569                 break;
1570         case B_SCREW:
1571                 if( select_area(SPACE_VIEW3D)) screw_mesh(step, turn);
1572                 break;
1573         case B_EXTREP:
1574                 if( select_area(SPACE_VIEW3D)) extrude_repeat_mesh(step, extr_offs);
1575                 break;
1576         case B_SPLIT:
1577                 G.f |= G_DISABLE_OK;
1578                 split_mesh();
1579                 G.f -= G_DISABLE_OK;
1580                 break;
1581         case B_REMDOUB:
1582                 undo_push_mesh("Rem Doubles");
1583                 notice("Removed: %d", removedoublesflag(1, doublimit));
1584                 allqueue(REDRAWVIEW3D, 0);
1585                 break;
1586         case B_SUBDIV:
1587                 waitcursor(1);
1588                 undo_push_mesh("Subdivide");
1589                 subdivideflag(1, 0.0, editbutflag & B_BEAUTY);
1590                 countall();
1591                 waitcursor(0);
1592                 allqueue(REDRAWVIEW3D, 0);
1593                 break;
1594         case B_FRACSUBDIV:
1595                 randfac= 10;
1596                 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
1597                 waitcursor(1);
1598                 undo_push_mesh("Fractal Subdivide");
1599                 fac= -( (float)randfac )/100;
1600                 subdivideflag(1, fac, editbutflag & B_BEAUTY);
1601                 countall();
1602                 waitcursor(0);
1603                 allqueue(REDRAWVIEW3D, 0);
1604                 break;
1605         case B_XSORT:
1606                 if( select_area(SPACE_VIEW3D)) xsortvert_flag(1);
1607                 break;
1608         case B_HASH:
1609                 hashvert_flag(1);
1610                 break;
1611         case B_TOSPHERE:
1612                 vertices_to_sphere();
1613                 break;
1614         case B_VERTEXNOISE:
1615                 vertexnoise();
1616                 break;
1617         case B_VERTEXSMOOTH:
1618                 vertexsmooth();
1619                 break;
1620         }
1621         /* WATCH IT: previous events only in editmode! */
1622 }
1623
1624 static void editing_panel_mesh_tools(Object *ob, Mesh *me)
1625 {
1626         uiBlock *block;
1627
1628         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools", UI_EMBOSSX, UI_HELV, curarea->win);
1629         if(uiNewPanel(curarea, block, "Mesh Tools", "Editing", 640, 0, 318, 204)==0) return;
1630         
1631
1632         uiBlockSetCol(block, BUTGREEN);
1633         uiDefButS(block, TOG|BIT|2, 0, "Beauty",                477,195,80,19, &editbutflag, 0, 0, 0, 0, "Causes 'Subdivide' to split faces in halves instead of quarters");
1634         uiBlockSetCol(block, BUTSALMON);
1635         uiDefBut(block, BUT,B_SPLIT,"Split",                    477,175,80,19, 0, 0, 0, 0, 0, "Separates selected faces from unselected faces");
1636         uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",             477,155,80,19, 0, 0, 0, 0, 0, "Moves selected vertices outwards into a spherical shape");
1637         uiDefBut(block, BUT,B_SUBDIV,"Subdivide",               477,135,80,19, 0, 0, 0, 0, 0, "Splits selected faces into halves or quarters");
1638
1639         uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd", 557,195,80,19, 0, 0, 0, 0, 0, "Subdivides selected faces with a random factor");
1640         uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",              557,175,80,19, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
1641         uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",    557,155,80,19, 0, 0, 0, 0, 0, "Flattens angles of selected faces");
1642         uiDefBut(block, BUT,B_XSORT,"Xsort",                    557,135,80,19, 0, 0, 0, 0, 0, "Sorts selected vertice data in the X direction");
1643
1644         uiDefBut(block, BUT,B_HASH,"Hash",                              637,195,80,19, 0, 0, 0, 0, 0, "Randomizes selected vertice sequence data");
1645         uiBlockSetCol(block, BUTGREY);
1646         uiDefButF(block, NUM, B_DIFF, "Limit:",                 637,175,80,19, &doublimit, 0.0001, 1.0, 10, 0, "Specifies the max distance 'Rem Doubles' will consider vertices as 'doubled'");
1647         uiBlockSetCol(block, BUTSALMON);
1648         uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    637,155,80,19, 0, 0, 0, 0, 0, "Removes duplicates from selected vertices");
1649         uiDefBut(block, BUT,B_FLIPNORM,"Flip Normals",  637,135,80,19, 0, 0, 0, 0, 0, "Toggles the direction of the selected face's normals");
1650
1651
1652         uiBlockSetCol(block, BUTSALMON);
1653         uiDefBut(block, BUT,B_EXTR,"Extrude",                   477,100,249,24, 0, 0, 0, 0, 0, "Converts selected edges to faces and selects the new vertices");
1654         uiDefBut(block, BUT,B_SPINDUP,"Spin Dupe",              639,75,87,24, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a circle around the cursor in the indicated viewport");
1655         uiDefBut(block, BUT,B_SPIN, "Spin",                             558,75,78,24, 0, 0, 0, 0, 0, "Extrudes the selected vertices in a circle around the cursor in the indicated viewport");
1656         uiDefBut(block, BUT,B_SCREW,"Screw",                    477,75,79,24, 0, 0, 0, 0, 0, "Activates the screw tool");  // Bish - This could use some more definition
1657         uiDefBut(block, BUT,B_EXTREP, "Extrude Dupe",   477,15,128,19, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a straight line away from the current viewport");
1658
1659         uiBlockSetCol(block, BUTGREY);
1660         uiDefButS(block, NUM, B_DIFF, "Degr:",          477,55,78,19, &degr,10.0,360.0, 0, 0, "Specifies the number of degrees 'Spin' revolves");
1661         uiDefButS(block, NUM, B_DIFF, "Steps:",         558,55,78,19, &step,1.0,180.0, 0, 0, "Specifies the total number of 'Spin' slices");
1662         uiDefButS(block, NUM, B_DIFF, "Turns:",         639,55,86,19, &turn,1.0,360.0, 0, 0, "Specifies the number of revolutions the screw turns");
1663         uiDefButS(block, TOG|BIT|0, B_DIFF, "Clockwise",        639,35,86,19, &editbutflag, 0, 0, 0, 0, "Specifies the direction for 'Screw' and 'Spin'");
1664         uiDefButS(block, TOG|BIT|1, B_DIFF, "Keep Original",    477,35,156,19, &editbutflag, 0, 0, 0, 0, "Keeps a copy of the original vertices and faces after executing tools");
1665         uiDefButF(block, NUM, B_DIFF, "Offset:",                608,15,117,19, &extr_offs, 0.01, 10.0, 100, 0, "Sets the distance between each copy for 'Extrude Dupe'");
1666
1667
1668 }
1669
1670 static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
1671 {
1672         unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
1673 }
1674
1675
1676
1677 static void editing_panel_mesh_tools1(Object *ob, Mesh *me)
1678 {
1679         uiBlock *block;
1680
1681
1682         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools1", UI_EMBOSSX, UI_HELV, curarea->win);
1683         if(uiNewPanel(curarea, block, "Mesh Tools 1", "Editing", 960, 0, 318, 204)==0) return;
1684
1685         uiBlockSetCol(block, BUTSALMON);
1686         uiDefBut(block, BUT,B_DOCENTRE, "Centre",                               1091, 200, 100, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
1687
1688
1689         uiDefBut(block, BUT,B_HIDE,             "Hide",         1091,152,77,18, 0, 0, 0, 0, 0, "Hides selected faces");
1690         uiDefBut(block, BUT,B_REVEAL,   "Reveal",       1171,152,86,18, 0, 0, 0, 0, 0, "Reveals selected faces");
1691         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  1091,129,166,18, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
1692
1693         uiBlockSetCol(block, BUTGREY);
1694         uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",               1090, 90, 164, 19, &editbutsize, 0.001, 2.0, 10, 0, "Sets the length to use when displaying face normals");
1695         uiDefButI(block, TOG|BIT|6, REDRAWVIEW3D, "Draw Normals",       1090,70,164,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
1696         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces", 1090,50,164,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
1697         uiDefButI(block, TOG|BIT|18, REDRAWVIEW3D, "Draw Edges", 1090,30,164,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
1698         uiDefButI(block, TOG|BIT|11, 0, "All edges",                            1090,10,164,19, &G.f, 0, 0, 0, 0, "Displays all edges in object mode without optimization");
1699
1700
1701         /* Draw Vertex grouping buttons mostly if we're in editmode */
1702         {
1703                 uiBut *but;
1704                 int     defCount;
1705                 bDeformGroup    *defGroup;
1706                 char *s, *menustr;
1707                 bDeformGroup *dg;
1708                 int min, by=210, index;
1709                 
1710                 uiBlockSetCol(block, BUTGREY);
1711                 uiDefBut(block, LABEL,0,"Vertex Groups",        940,by-=19,113,18, 0, 0, 0, 0, 0, "");
1712
1713                 defCount=BLI_countlist(&ob->defbase);
1714
1715                 if (!defCount) min=0;
1716                 else min=1;
1717                 
1718                 s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
1719
1720                 for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
1721                         int cnt= sprintf (s, "%s%%x%d|", dg->name, index);
1722                         
1723                         if (cnt>0) s+= cnt;
1724                 }
1725                 
1726                 by-=22;
1727                 if (defCount) uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr,   940, by,18,18, &ob->actdef, min, defCount, 0, 0, "Browses available vertex groups");
1728
1729                 MEM_freeN (menustr);
1730
1731                 if (ob->actdef){
1732                         defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
1733                         but= uiDefBut(block, TEX,REDRAWBUTSEDIT,"",             958,by,93-18,18, defGroup->name, 0, 32, 0, 0, "Displays current vertex group name. Click to change. (Match bone name for deformation.)");
1734                         uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
1735                 }
1736
1737                 uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          940, by-=22, 93, 18, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
1738
1739                 if (G.obedit && G.obedit==ob){
1740
1741                         uiBlockSetCol(block, BUTSALMON);
1742         /*              uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assigns deformation groups"); */
1743                         uiDefBut(block, BUT,B_NEWVGROUP,"New",                          940,by-=22,45,18, 0, 0, 0, 0, 0, "Creates a new vertex group");
1744                         uiDefBut(block, BUT,B_DELVGROUP,"Delete",                       988,by,45,18, 0, 0, 0, 0, 0, "Removes the current vertex group");
1745         
1746                         uiBlockSetCol(block, BUTSALMON);
1747                         uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",            940,by-=22,93,18, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group");
1748                         uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",            940,by-=22,93,18, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group");
1749         
1750                         uiBlockSetCol(block, BUTGREY);
1751                         uiDefBut(block, BUT,B_SELVGROUP,"Select",                       940,by-=22,93,18, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group");
1752                         uiDefBut(block, BUT,B_DESELVGROUP,"Deselect",           940,by-=22,93,18, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group");
1753                 }
1754         }
1755
1756 }
1757
1758
1759 static void editing_panel_materials(Object *ob)
1760 {
1761         uiBlock *block;
1762         ID *id, *idfrom;
1763         int *poin, xco=143;
1764         float min;
1765         Material *ma;
1766         char str[64];
1767         uiBut *but;
1768         
1769         block= uiNewBlock(&curarea->uiblocks, "editing_panel_materials", UI_EMBOSSX, UI_HELV, curarea->win);
1770         if(uiNewPanel(curarea, block, "Link and Materials", "Editing", 0, 0, 318, 204)==0) return;
1771
1772         buttons_active_id(&id, &idfrom);
1773         
1774         if(id) {
1775                 int alone= 0;
1776                 int local= 0;
1777                 int browse= B_EDITBROWSE;
1778
1779                 if(ob->type==OB_MESH) {
1780                         browse= B_MESHBROWSE;
1781                         alone= B_MESHALONE;
1782                         local= B_MESHLOCAL;
1783                         uiSetButLock(G.obedit!=0, "Unable to perform function in EditMode");
1784                 }
1785                 else if(ob->type==OB_MBALL) {
1786                         alone= B_MBALLALONE;
1787                         local= B_MBALLLOCAL;
1788                 }
1789                 else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
1790                         alone= B_CURVEALONE;
1791                         local= B_CURVELOCAL;
1792                 }
1793                 else if(ob->type==OB_CAMERA) {
1794                         alone= B_CAMERAALONE;
1795                         local= B_CAMERALOCAL;
1796                 }
1797                 else if(ob->type==OB_LAMP) {
1798                         alone= B_LAMPALONE;
1799                         local= B_LAMPLOCAL;
1800                 }
1801                 else if (ob->type==OB_ARMATURE){
1802                         alone = B_ARMALONE;
1803                         local = B_ARMLOCAL;
1804                 }
1805                 else if(ob->type==OB_LATTICE) {
1806                         alone= B_LATTALONE;
1807                         local= B_LATTLOCAL;
1808                 }
1809                 uiBlockSetCol(block, BUTPURPLE);
1810                 xco= std_libbuttons(block, 143, 180, 0, NULL, browse, id, idfrom, &(G.buts->menunr), alone, local, 0, 0, B_KEEPDATA);
1811                         
1812         }
1813         if(ob) {
1814                 uiBlockSetCol(block, BUTGREY);
1815                 but = uiDefBut(block, TEX, B_IDNAME, "OB:",     xco, 180, 454-xco, YIC, ob->id.name+2, 0.0, 19.0, 0, 0, "Displays Active Object name. Click to change.");
1816                 uiButSetFunc(but, test_idbutton_cb, ob->id.name, NULL);
1817         }
1818
1819
1820
1821         /* to be sure */
1822         if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL);
1823         else return;
1824         
1825         
1826         if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag );
1827         else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag );
1828         else poin= &( ((Curve *)ob->data)->texflag );
1829         uiDefButI(block, TOG|BIT|0, B_AUTOTEX, "AutoTexSpace",  143,15,130,19, poin, 0, 0, 0, 0, "Adjusts active object's texture space automatically when transforming object");
1830
1831         sprintf(str,"%d Mat:", ob->totcol);
1832         if(ob->totcol) min= 1.0; else min= 0.0;
1833         ma= give_current_material(ob, ob->actcol);
1834         
1835         if(ma) {
1836                 uiDefButF(block, COL, 0, "",                    291,123,24,30, &(ma->r), 0, 0, 0, 0, "");
1837                 uiDefBut(block, LABEL, 0, ma->id.name+2, 318,146, 103, 30, 0, 0, 0, 0, 0, "");
1838         }
1839         uiDefButC(block, NUM, B_REDR,   str,            318,123,103,30, &ob->actcol, min, (float)(ob->totcol), 0, 0, "Displays total number of material indices and the current index");
1840         uiDefBut(block, BUT,B_MATWICH,  "?",            423,123,31,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces");
1841         
1842         uiBlockSetCol(block, BUTSALMON);
1843         uiDefBut(block, BUT,B_MATNEW,   "New",          292,101,80,21, 0, 0, 0, 0, 0, "Adds a new Material index");
1844         uiDefBut(block, BUT,B_MATDEL,   "Delete",       374,101,80,21, 0, 0, 0, 0, 0, "Deletes this Material index");
1845         uiDefBut(block, BUT,B_MATASS,   "Assign",       291,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces");
1846
1847         uiBlockSetCol(block, BUTGREY);
1848         uiDefBut(block, BUT,B_MATSEL,   "Select",       292,76,79,22, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index");
1849         uiDefBut(block, BUT,B_MATDESEL, "Deselect",     373,76,79,21, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber");
1850
1851         uiDefBut(block, BUT,B_SETSMOOTH,        "Set Smooth",   291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces");
1852         uiDefBut(block, BUT,B_SETSOLID, "Set Solid",    373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces");
1853         
1854 }
1855
1856 /* *************************** FACE/PAINT *************************** */
1857
1858 void do_fpaintbuts(unsigned short event)
1859 {
1860         Mesh *me;
1861         Object *ob;
1862         extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
1863         
1864         ob= OBACT;
1865         if(ob==0) return;
1866
1867         switch(event) { 
1868                 
1869         case B_VPGAMMA:
1870                 vpaint_dogamma();
1871                 break;
1872         case B_COPY_TF_MODE:
1873         case B_COPY_TF_UV:
1874         case B_COPY_TF_COL:
1875         case B_COPY_TF_TEX:
1876                 me= get_mesh(ob);
1877                 if(me && me->tface) {
1878 /*                      extern TFace *lasttface; */
1879                         TFace *tface= me->tface;
1880                         int a= me->totface;
1881                         
1882                         set_lasttface();
1883                         if(lasttface) {
1884                         
1885                                 while(a--) {
1886                                         if(tface!=lasttface && (tface->flag & TF_SELECT)) {
1887                                                 if(event==B_COPY_TF_MODE) {
1888                                                         tface->mode= lasttface->mode;
1889                                                         tface->transp= lasttface->transp;
1890                                                 }
1891                                                 else if(event==B_COPY_TF_UV) {
1892                                                         memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
1893                                                         tface->tpage= lasttface->tpage;
1894                                                         tface->tile= lasttface->tile;
1895                                                         
1896                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
1897                                                         else tface->mode &= ~TF_TILES;
1898                                                         
1899                                                 }
1900                                                 else if(event==B_COPY_TF_TEX) {
1901                                                         tface->tpage= lasttface->tpage;
1902                                                         tface->tile= lasttface->tile;
1903
1904                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
1905                                                         else tface->mode &= ~TF_TILES;
1906                                                 }
1907                                                 else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
1908                                         }
1909                                         tface++;
1910                                 }
1911                         }
1912                         do_shared_vertexcol(me);
1913                         allqueue(REDRAWVIEW3D, 0);
1914                         allqueue(REDRAWIMAGE, 0);
1915                 }
1916                 break;
1917         case B_SET_VCOL:
1918                 clear_vpaint_selectedfaces();
1919                 break;
1920         case B_REDR_3D_IMA:
1921                 allqueue(REDRAWVIEW3D, 0);
1922                 allqueue(REDRAWIMAGE, 0);
1923                 break;
1924         case B_ASSIGNMESH:
1925                 
1926                 test_object_materials(ob->data);
1927                 allqueue(REDRAWVIEW3D, 0);
1928                 allqueue(REDRAWBUTSEDIT, 0);
1929                 break;
1930                 
1931         case B_TFACE_HALO:
1932                 set_lasttface();
1933                 if(lasttface) {
1934                         lasttface->mode &= ~TF_BILLBOARD2;
1935                         allqueue(REDRAWBUTSEDIT, 0);
1936                 }
1937                 break;
1938
1939         case B_TFACE_BILLB:
1940                 set_lasttface();
1941                 if(lasttface) {
1942                         lasttface->mode &= ~TF_BILLBOARD;
1943                         allqueue(REDRAWBUTSEDIT, 0);
1944                 }
1945                 break;
1946         }       
1947 }
1948
1949
1950 /* -------------------- MODE: vpaint faceselect ------------------- */
1951
1952 static void editing_panel_mesh_paint(void)
1953 {
1954         extern VPaint Gvp;         /* from vpaint */
1955         uiBlock *block;
1956
1957         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_paint", UI_EMBOSSX, UI_HELV, curarea->win);
1958         if(uiNewPanel(curarea, block, "Paint", "Editing", 640, 0, 318, 204)==0) return;
1959
1960         uiBlockSetCol(block, BUTGREY);
1961
1962         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");
1963         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");
1964         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");
1965         uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
1966         uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
1967
1968         uiDefButF(block, COL, B_VPCOLSLI, "",           1176,100,28,80, &(Gvp.r), 0, 0, 0, 0, "");
1969
1970         uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
1971         uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
1972         uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
1973         uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
1974         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");
1975
1976         uiBlockSetCol(block, BUTGREEN);
1977         uiDefButS(block, TOG|BIT|1, 0, "Area",          980,50,80,19, &Gvp.flag, 0, 0, 0, 0, "Set the area the brush covers");
1978         uiDefButS(block, TOG|BIT|2, 0, "Soft",          1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
1979         uiDefButS(block, TOG|BIT|3, 0, "Normals",       1174,50,102,19, &Gvp.flag, 0, 0, 0, 0, "Use vertex normal for painting");
1980
1981         uiBlockSetCol(block, BUTSALMON);
1982         uiDefBut(block, BUT, B_VPGAMMA, "Set",  980,30,80,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
1983         uiBlockSetCol(block, BUTGREY);
1984         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");
1985         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");
1986         
1987         uiBlockSetCol(block, BUTSALMON);
1988         uiDefBut(block, BUT, B_SET_VCOL, "Set VertCol", 980,5,103,28, 0, 0, 0, 0, 0, "Set Vertex colour of selection to current (Shift+K)");
1989
1990 }
1991
1992
1993 static void editing_panel_mesh_texface(void)
1994 {
1995         uiBlock *block;
1996         extern TFace *lasttface;
1997         
1998         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_texface", UI_EMBOSSX, UI_HELV, curarea->win);
1999         if(uiNewPanel(curarea, block, "Texture face", "Editing", 640, 0, 318, 204)==0) return;
2000
2001         set_lasttface();        // checks for ob type
2002         if(lasttface) {
2003                 
2004                 uiBlockSetCol(block, BUTGREEN);
2005                 uiDefButS(block, TOG|BIT|2, B_REDR_3D_IMA, "Tex",       600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
2006                 uiDefButS(block, TOG|BIT|7, B_REDR_3D_IMA, "Tiles",     660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
2007                 uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Light",      720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
2008                 uiDefButS(block, TOG|BIT|10, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
2009                 uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
2010
2011                 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");
2012                 uiDefButS(block, TOG|BIT|9, REDRAWVIEW3D, "Twoside",    660,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
2013                 uiDefButS(block, TOG|BIT|11, REDRAWVIEW3D, "ObColor",720,140,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
2014
2015                 uiDefButS(block, TOG|BIT|8, B_TFACE_HALO, "Halo",       600,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
2016                 uiDefButS(block, TOG|BIT|12, B_TFACE_BILLB, "Billboard",660,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
2017                 uiDefButS(block, TOG|BIT|13, REDRAWVIEW3D, "Shadow", 720,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
2018                 uiDefButS(block, TOG|BIT|14, REDRAWVIEW3D, "Text", 780,120,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
2019
2020                 uiBlockSetCol(block, BUTPURPLE);
2021                 uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,100,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
2022                 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");
2023                 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");
2024                 /* uiDefButC(block, ROW, REDRAWVIEW3D, "Sub",   780,100,60,19, &lasttface->transp, 2.0, 3.0, 0, 0); ,""*/
2025
2026                 uiBlockSetCol(block, BUTSALMON);
2027                 uiDefBut(block, BUT, B_COPY_TF_MODE, "Copy DrawMode", 600,7,117,28, 0, 0, 0, 0, 0, "Copy the drawmode");
2028                 uiDefBut(block, BUT, B_COPY_TF_UV, "Copy UV+tex",         721,7,85,28, 0, 0, 0, 0, 0, "Copy UV information and textures");
2029                 uiDefBut(block, BUT, B_COPY_TF_COL, "Copy VertCol",       809,7,103,28, 0, 0, 0, 0, 0, "Copy vertex colours");
2030         }
2031
2032 }
2033
2034
2035 /* this is a mode context sensitive system */
2036
2037 void editing_panels()
2038 {
2039         Object *ob;
2040         Curve *cu;
2041         MetaBall *mb;
2042         Lattice *lt;
2043         bArmature *arm;
2044         Camera *cam;
2045         
2046         ob= OBACT;
2047         if(ob==NULL) return;
2048         
2049         switch(ob->type) {
2050         case OB_MESH:
2051                 editing_panel_materials(ob); // no editmode!
2052                 editing_panel_mesh_type(ob, ob->data);  // no editmode!
2053                 /* modes */
2054                 if(G.obedit) {
2055                         editing_panel_mesh_tools(ob, ob->data); // no editmode!
2056                         editing_panel_mesh_tools1(ob, ob->data); // no editmode!
2057                 }
2058                 else if(G.f & G_FACESELECT) {
2059                         editing_panel_mesh_texface();
2060                 }
2061                 else if(G.f & (G_VERTEXPAINT | G_TEXTUREPAINT) ) {
2062                         editing_panel_mesh_paint();
2063                 }
2064                 break;
2065                 
2066         case OB_CURVE:
2067         case OB_SURF:
2068                 cu= ob->data;
2069                 editing_panel_materials(ob); // no editmode!
2070                 editing_panel_curve_type(ob, cu);
2071                 if(G.obedit) {
2072                         editing_panel_curve_tools(ob, cu);
2073                         editing_panel_curve_tools1(ob, cu);
2074                 }
2075                 break;
2076
2077         case OB_MBALL:
2078                 mb= ob->data;
2079                 editing_panel_materials(ob); // no editmode!
2080                 editing_panel_mball_type(ob, mb);
2081                 if(G.obedit) {
2082                         editing_panel_mball_tools(ob, mb);
2083                 }
2084                 break;
2085
2086         case OB_FONT:
2087                 cu= ob->data;
2088                 editing_panel_materials(ob); // no editmode!
2089                 editing_panel_curve_type(ob, cu);
2090                 editing_panel_font_type(ob, cu);
2091                 break;
2092
2093         case OB_LATTICE:
2094                 lt= ob->data;
2095                 editing_panel_lattice_type(ob, lt);
2096                 break;
2097                 
2098         case OB_CAMERA:
2099                 cam= ob->data;
2100                 editing_panel_camera_type(ob, cam);
2101                 break;
2102                 
2103         case OB_ARMATURE:
2104                 arm= ob->data;
2105                 editing_panel_armature_type(ob, arm);
2106                 if(G.obedit) {
2107                         editing_panel_armature_bones(ob, arm);
2108                 }
2109                 break;
2110         }
2111
2112 }