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