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