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