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