The "teac" (measurement info) patch from Campbell Barton
[blender.git] / source / blender / src / buttons_editing.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #ifdef WIN32
43 #include "BLI_winstuff.h"
44 #ifndef snprintf
45 #define snprintf _snprintf
46 #endif
47 #endif
48
49 #include "MEM_guardedalloc.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_space_types.h"
52 #include "DNA_scene_types.h"
53
54 #include "DNA_action_types.h"
55 #include "DNA_armature_types.h"
56 #include "DNA_camera_types.h"
57 #include "DNA_constraint_types.h"
58 #include "DNA_curve_types.h"
59 #include "DNA_effect_types.h"
60 #include "DNA_group_types.h"
61 #include "DNA_ika_types.h"
62 #include "DNA_image_types.h"
63 #include "DNA_key_types.h"
64 #include "DNA_lamp_types.h"
65 #include "DNA_lattice_types.h"
66 #include "DNA_material_types.h"
67 #include "DNA_meta_types.h"
68 #include "DNA_mesh_types.h"
69 #include "DNA_meshdata_types.h"
70 #include "DNA_object_types.h"
71 #include "DNA_radio_types.h"
72 #include "DNA_screen_types.h"
73 #include "DNA_texture_types.h"
74 #include "DNA_userdef_types.h"
75 #include "DNA_vfont_types.h"
76 #include "DNA_view3d_types.h"
77 #include "DNA_world_types.h"
78 #include "DNA_packedFile_types.h"
79
80 #include "BKE_global.h"
81 #include "BKE_main.h"
82 #include "BKE_library.h"
83 #include "BKE_packedFile.h"
84
85 #include "BLI_blenlib.h"
86 #include "BLI_arithb.h"
87 #include "BLI_vfontdata.h"
88 #include "BLI_editVert.h"
89
90 #include "BSE_filesel.h"
91
92 #include "BIF_gl.h"
93 #include "BIF_editarmature.h"
94 #include "BIF_editconstraint.h"
95 #include "BIF_editdeform.h"
96 #include "BIF_editfont.h"
97 #include "BIF_editmesh.h"
98 #include "BIF_interface.h"
99 #include "BIF_meshtools.h"
100 #include "BIF_mywindow.h"
101 #include "BIF_renderwin.h"
102 #include "BIF_resources.h"
103 #include "BIF_screen.h"
104 #include "BIF_scrarea.h"
105 #include "BIF_space.h"
106 #include "BIF_toets.h"
107 #include "BIF_toolbox.h"
108 #include "BIF_previewrender.h"
109 #include "BIF_butspace.h"
110
111 #include "mydevice.h"
112 #include "blendef.h"
113
114 #include "BKE_action.h"
115 #include "BKE_anim.h"
116 #include "BKE_armature.h"
117 #include "BKE_constraint.h"
118 #include "BKE_curve.h"
119 #include "BKE_displist.h"
120 #include "BKE_effect.h"
121 #include "BKE_font.h"
122 #include "BKE_ika.h"
123 #include "BKE_image.h"
124 #include "BKE_ipo.h"
125 #include "BKE_lattice.h"
126 #include "BKE_material.h"
127 #include "BKE_mball.h"
128 #include "BKE_mesh.h"
129 #include "BKE_object.h"
130 #include "BKE_texture.h"
131 #include "BKE_utildefines.h"
132
133 #include "BDR_drawobject.h"
134 #include "BDR_editcurve.h"
135 #include "BDR_editface.h"
136 #include "BDR_editobject.h"
137 #include "BDR_vpaint.h"
138 #include "BDR_unwrapper.h"
139
140 #include "BSE_drawview.h"
141 #include "BSE_editipo.h"
142 #include "BSE_edit.h"
143 #include "BSE_filesel.h"
144 #include "BSE_headerbuttons.h"
145 #include "BSE_trans_types.h"
146 #include "BSE_view.h"
147 #include "BSE_buttons.h"
148 #include "BSE_seqaudio.h"
149
150 #include "LOD_DependKludge.h"
151 #include "LOD_decimation.h"
152
153 #include "RE_renderconverter.h"         // make_sticky
154
155 #include "butspace.h" // own module
156
157 static int decim_faces=0;
158 static short degr= 90, step= 9, turn= 1;
159 static float extr_offs= 1.0;
160 static float editbutweight=1.0;
161 short editbutflag= 1;
162 float doublimit= 0.001, editbutvweight=1, editbutsize=0.1;
163 float uv_calc_radius= 1.0, uv_calc_cubesize= 1.0;
164 short uv_calc_mapdir= 1, uv_calc_mapalign= 1, facesel_draw_edges= 0;
165
166 extern ListBase editNurb;
167
168 /* *************************** MESH DECIMATE ******************************** */
169
170 /* should be removed from this c file (ton) */
171
172 static int decimate_count_tria(Object *ob)
173 {
174         int tottria;
175         MFace *mface;
176         Mesh *me;
177         int a;
178
179         me= ob->data;
180
181         /* count number of trias, since decimator doesnt allow quads */
182         tottria= 0;
183         mface= me->mface;
184         for(a=0; a<me->totface; a++, mface++) {
185                 if(mface->v4) tottria++;
186                 if(mface->v3) tottria++;
187         }
188
189         return tottria;
190 }
191
192 static void decimate_faces(void)
193 {
194         Object *ob;
195         Mesh *me;
196         MVert *mvert;
197         MFace *mface;
198         LOD_Decimation_Info lod;
199         float *vb=NULL;
200         float *vnb=NULL;
201         int *tib=NULL;
202         int a, tottria;
203
204         /* we assume the active object being decimated */
205         ob= OBACT;
206         if(ob==NULL || ob->type!=OB_MESH) return;
207         me= ob->data;
208
209         /* add warning for vertex col and tfaces */
210         if(me->tface || me->mcol || me->dvert || me->medge) {
211                 if(okee("This will remove UV coordinates, vertexcolors, deform weights and edge data")==0) return;
212                 if(me->tface) MEM_freeN(me->tface);
213                 if(me->mcol) MEM_freeN(me->mcol);
214                 if(me->dvert) free_dverts(me->dvert, me->totvert);
215                 me->tface= NULL;
216                 me->mcol= NULL;
217                 me->dvert= NULL;
218         }
219
220         /* count number of trias, since decimator doesnt allow quads */
221         tottria= decimate_count_tria(ob);
222
223         if(tottria<3) {
224                 error("You must have more than 3 input faces selected.");
225                 return;
226         }
227         /* allocate and init */
228         lod.vertex_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "vertices");
229         lod.vertex_normal_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "normals");
230         lod.triangle_index_buffer= MEM_mallocN(3*sizeof(int)*tottria, "trias");
231         lod.vertex_num= me->totvert;
232         lod.face_num= tottria;
233
234         /* fill vertex buffer */
235         vb= lod.vertex_buffer;
236         vnb= lod.vertex_normal_buffer;
237         mvert= me->mvert;
238         for(a=0; a<me->totvert; a++, mvert++, vb+=3, vnb+=3) {
239                 VECCOPY(vb, mvert->co);
240                 VECCOPY(vnb, mvert->no);
241                 Normalise(vnb);
242         }
243
244         /* fill index buffer */
245         mface= me->mface;
246         tib= lod.triangle_index_buffer;
247         for(a=0; a<me->totface; a++, mface++) {
248                 if(mface->v4) {
249                         tib[0]= mface->v1;
250                         tib[1]= mface->v3;
251                         tib[2]= mface->v4;
252                         tib+= 3;
253                 }
254                 if(mface->v3) {
255                         tib[0]= mface->v1;
256                         tib[1]= mface->v2;
257                         tib[2]= mface->v3;
258                         tib+= 3;
259                 }
260         }
261
262         if(LOD_LoadMesh(&lod) ) {
263                 if( LOD_PreprocessMesh(&lod) ) {
264                         DispList *dl;
265                         DispListMesh *dlm;
266                         MFace *mfaceint;
267
268                         /* we assume the decim_faces tells how much to reduce */
269
270                         while(lod.face_num > decim_faces) {
271                                 if( LOD_CollapseEdge(&lod)==0) break;
272                         }
273
274                         /* ok, put back the stuff in a displist */
275                         freedisplist(&(ob->disp));
276                         dl= MEM_callocN(sizeof(DispList), "disp");
277                         BLI_addtail(&ob->disp, dl);
278                         dl->type= DL_MESH;
279                         dlm=dl->mesh= MEM_callocN(sizeof(DispListMesh), "dispmesh");
280                         dlm->mvert= MEM_callocN(lod.vertex_num*sizeof(MVert), "mvert");
281                         dlm->mface= MEM_callocN(lod.face_num*sizeof(MFace), "mface");
282                         dlm->totvert= lod.vertex_num;
283                         dlm->totface= lod.face_num;
284
285                         mvert= dlm->mvert;
286                         vb= lod.vertex_buffer;
287                         for(a=0; a<lod.vertex_num; a++, vb+=3, mvert++) {
288                                 VECCOPY(mvert->co, vb);
289                         }
290
291                         mfaceint= dlm->mface;
292                         tib= lod.triangle_index_buffer;
293                         for(a=0; a<lod.face_num; a++, mfaceint++, tib+=3) {
294                                 mfaceint->v1= tib[0];
295                                 mfaceint->v2= tib[1];
296                                 mfaceint->v3= tib[2];
297                         }
298                 }
299                 else error("No memory");
300
301                 LOD_FreeDecimationData(&lod);
302         }
303         else error("No manifold Mesh");
304
305         MEM_freeN(lod.vertex_buffer);
306         MEM_freeN(lod.vertex_normal_buffer);
307         MEM_freeN(lod.triangle_index_buffer);
308
309         allqueue(REDRAWVIEW3D, 0);
310 }
311
312
313
314 static void decimate_cancel(void)
315 {
316         Object *ob;
317
318         ob= OBACT;
319         if(ob) {
320                 freedisplist(&ob->disp);
321                 makeDispList(ob);
322         }
323         allqueue(REDRAWVIEW3D, 0);
324 }
325
326 static void decimate_apply(void)
327 {
328         Object *ob;
329         DispList *dl;
330         DispListMesh *dlm;
331         Mesh *me;
332         MFace *mface;
333         MFace *mfaceint;
334         int a;
335
336         if(G.obedit) return;
337
338         ob= OBACT;
339         if(ob) {
340                 dl= ob->disp.first;
341                 if(dl && dl->mesh) {
342                         dlm= dl->mesh;
343                         me= ob->data;
344
345                         // vertices
346                         if(me->mvert) MEM_freeN(me->mvert);
347                         me->mvert= dlm->mvert;
348                         dlm->mvert= NULL;
349                         me->totvert= dlm->totvert;
350
351                         // edges
352                         if(me->medge) MEM_freeN(me->medge);
353                         me->medge = NULL;
354                         me->totedge = 0;
355
356                         // faces
357                         if(me->mface) MEM_freeN(me->mface);
358                         me->mface= MEM_callocN(dlm->totface*sizeof(MFace), "mface");
359                         me->totface= dlm->totface;
360                         mface= me->mface;
361                         mfaceint= dlm->mface;
362                         for(a=0; a<me->totface; a++, mface++, mfaceint++) {
363                                 mface->v1= mfaceint->v1;
364                                 mface->v2= mfaceint->v2;
365                                 mface->v3= mfaceint->v3;
366                                 test_index_mface(mface, 3);
367                         }
368
369                         freedisplist(&ob->disp);
370
371                         G.obedit= ob;
372                         make_editMesh();
373                         load_editMesh();
374                         free_editMesh(G.editMesh);
375                         G.obedit= NULL;
376                         tex_space_mesh(me);
377
378                         if (mesh_uses_displist(me)) {
379                                 makeDispList(ob);
380                         }
381                         BIF_undo_push("Apply decimation");
382                 }
383                 else error("Not a decimated Mesh");
384         }
385 }
386
387 /* *************** */
388
389 void do_common_editbuts(unsigned short event) // old name, is a mix of object and editing events.... 
390 {
391         EditMesh *em = G.editMesh;
392         EditFace *efa;
393         Base *base;
394         Object *ob;
395         Mesh *me;
396         Nurb *nu;
397         Curve *cu;
398         BezTriple *bezt;
399         BPoint *bp;
400         unsigned int local;
401         int a, bit, index= -1;
402
403         switch(event) {
404                 
405         case B_MATWICH:
406                 if(G.obedit && G.obedit->actcol>0) {
407                         if(G.obedit->type == OB_MESH) {
408                                 efa= em->faces.first;
409                                 while(efa) {
410                                         if(efa->f & SELECT) {
411                                                 if(index== -1) index= efa->mat_nr;
412                                                 else if(index!=efa->mat_nr) {
413                                                         error("Mixed colors");
414                                                         return;
415                                                 }
416                                         }
417                                         efa= efa->next;
418                                 }
419                         }
420                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
421                                 nu= editNurb.first;
422                                 while(nu) {
423                                         if( isNurbsel(nu) ) {
424                                                 if(index== -1) index= nu->mat_nr;
425                                                 else if(index!=nu->mat_nr) {
426                                                         error("Mixed colors");
427                                                         return;
428                                                 }
429                                         }
430                                         nu= nu->next;
431                                 }                               
432                         }
433                         if(index>=0) {
434                                 G.obedit->actcol= index+1;
435                                 scrarea_queue_winredraw(curarea);
436                         }
437                 }
438                 break;
439         case B_MATNEW:
440                 new_material_to_objectdata((G.scene->basact) ? (G.scene->basact->object) : 0);
441                 scrarea_queue_winredraw(curarea);
442                 BIF_undo_push("New material");
443                 allqueue(REDRAWBUTSSHADING, 0);
444                 allqueue(REDRAWVIEW3D_Z, 0);
445                 allqueue(REDRAWOOPS, 0);
446                 break;
447         case B_MATDEL:
448                 delete_material_index();
449                 scrarea_queue_winredraw(curarea);
450                 BIF_undo_push("Delete material index");
451                 allqueue(REDRAWBUTSSHADING, 0);
452                 allqueue(REDRAWVIEW3D_Z, 0);
453                 allqueue(REDRAWOOPS, 0);
454                 break;
455         case B_MATASS:
456                 if(G.obedit && G.obedit->actcol>0) {
457                         if(G.obedit->type == OB_MESH) {
458                                 efa= em->faces.first;
459                                 while(efa) {
460                                         if(efa->f & SELECT)
461                                                 efa->mat_nr= G.obedit->actcol-1;
462                                         efa= efa->next;
463                                 }
464                         }
465                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
466                                 nu= editNurb.first;
467                                 while(nu) {
468                                         if( isNurbsel(nu) )
469                                                 nu->mat_nr= G.obedit->actcol-1;
470                                         nu= nu->next;
471                                 }
472                         }
473                         allqueue(REDRAWVIEW3D_Z, 0);
474                         makeDispList(G.obedit);
475                         BIF_undo_push("Assign material index");
476                 }
477                 break;
478         case B_MATSEL:
479         case B_MATDESEL:
480                 if(G.obedit) {
481                         if(G.obedit->type == OB_MESH) {
482                                 if (event==B_MATSEL) {
483                                         editmesh_select_by_material(G.obedit->actcol-1);
484                                 } else {
485                                         editmesh_deselect_by_material(G.obedit->actcol-1);
486                                 }
487                                 allqueue(REDRAWVIEW3D, 0);
488                         }
489                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
490                                 nu= editNurb.first;
491                                 while(nu) {
492                                         if(nu->mat_nr==G.obedit->actcol-1) {
493                                                 if(nu->bezt) {
494                                                         a= nu->pntsu;
495                                                         bezt= nu->bezt;
496                                                         while(a--) {
497                                                                 if(bezt->hide==0) {
498                                                                         if(event==B_MATSEL) {
499                                                                                 bezt->f1 |= 1;
500                                                                                 bezt->f2 |= 1;
501                                                                                 bezt->f3 |= 1;
502                                                                         }
503                                                                         else {
504                                                                                 bezt->f1 &= ~1;
505                                                                                 bezt->f2 &= ~1;
506                                                                                 bezt->f3 &= ~1;
507                                                                         }
508                                                                 }
509                                                                 bezt++;
510                                                         }
511                                                 }
512                                                 else if(nu->bp) {
513                                                         a= nu->pntsu*nu->pntsv;
514                                                         bp= nu->bp;
515                                                         while(a--) {
516                                                                 if(bp->hide==0) {
517                                                                         if(event==B_MATSEL) bp->f1 |= 1;
518                                                                         else bp->f1 &= ~1;
519                                                                 }
520                                                                 bp++;
521                                                         }
522                                                 }
523                                         }
524                                         nu= nu->next;
525                                 }
526                                 BIF_undo_push("Select material index");
527                                 allqueue(REDRAWVIEW3D, 0);
528                         }
529                 }
530                 break;
531         case B_HIDE:
532                 if(G.obedit) {
533                         if(G.obedit->type == OB_MESH) hide_mesh(0);
534                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) hideNurb(0);
535                 }
536                 break;
537         case B_REVEAL:
538                 if(G.obedit) {
539                         if(G.obedit->type == OB_MESH) reveal_mesh();
540                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) revealNurb();
541                 }
542                 else if(G.f & G_FACESELECT) reveal_tface();
543                 
544                 break;
545         case B_SELSWAP:
546                 if(G.obedit) {
547                         if(G.obedit->type == OB_MESH) selectswap_mesh();
548                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) selectswapNurb();
549                 }
550                 break;
551         case B_AUTOTEX:
552                 ob= OBACT;
553                 if(ob && G.obedit==0) {
554                         if(ob->type==OB_MESH) tex_space_mesh(ob->data);
555                         else if(ob->type==OB_MBALL) ;
556                         else tex_space_curve(ob->data);
557                 }
558                 break;
559         case B_DOCENTRE:
560                 docentre(0);
561                 break;
562         case B_DOCENTRENEW:
563                 docentre_new();
564                 break;
565         case B_DOCENTRECURSOR:
566                 docentre_cursor();
567                 break;
568         case B_SETSMOOTH:
569         case B_SETSOLID:
570                 if(G.obedit) {
571                         if(G.obedit->type == OB_MESH) {
572                                 efa= em->faces.first;
573                                 while(efa) {
574                                         if(efa->f & SELECT) {
575                                                 if(event==B_SETSMOOTH) efa->flag |= ME_SMOOTH;
576                                                 else efa->flag &= ~ME_SMOOTH;
577                                         }
578                                         efa= efa->next;
579                                 }
580                         }
581                         else {
582                                 nu= editNurb.first;
583                                 while(nu) {
584                                         if(isNurbsel(nu)) {
585                                                 if(event==B_SETSMOOTH) nu->flag |= CU_SMOOTH;
586                                                 else nu->flag &= ~CU_SMOOTH;
587                                         }
588                                         nu= nu->next;
589                                 }
590                         }
591                         makeDispList(G.obedit);
592                         allqueue(REDRAWVIEW3D, 0);
593                 }
594                 else {
595                         base= FIRSTBASE;
596                         while(base) {
597                                 if(TESTBASELIB(base)) {
598                                         if(base->object->type==OB_MESH) {
599                                                 me= base->object->data;
600                                                 mesh_set_smooth_flag(me, (event==B_SETSMOOTH));
601                                                 makeDispList(base->object);
602                                         }
603                                         else if ELEM(base->object->type, OB_SURF, OB_CURVE) {
604                                                 cu= base->object->data;
605                                                 nu= cu->nurb.first;
606                                                 while(nu) {
607                                                         if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
608                                                         else nu->flag &= ~ME_SMOOTH;
609                                                         nu= nu->next;
610                                                 }
611                                                 makeDispList(base->object);
612                                         }
613                                 }
614                                 base= base->next;
615                         }
616                         allqueue(REDRAWVIEW3D, 0);
617                 }
618                 if(event == B_SETSMOOTH) BIF_undo_push("Set Smooth");
619                 else BIF_undo_push("Set Solid");
620
621                 break;
622
623         default:
624                 if(event>=B_OBLAY && event<=B_OBLAY+31) {
625                         local= BASACT->lay & 0xFF000000;
626                         BASACT->lay -= local;
627                         if(BASACT->lay==0 || (G.qual & LR_SHIFTKEY)==0) {
628                                 bit= event-B_OBLAY;
629                                 BASACT->lay= 1<<bit;
630                                 scrarea_queue_winredraw(curarea);
631                         }
632                         BASACT->lay += local;
633                         /* optimal redraw */
634                         if( (OBACT->lay & G.vd->lay) && (BASACT->lay & G.vd->lay) );
635                         else if( (OBACT->lay & G.vd->lay)==0 && (BASACT->lay & G.vd->lay)==0 );
636                         else allqueue(REDRAWVIEW3D, 0);
637                         
638                         OBACT->lay= BASACT->lay;
639                 }
640         }
641
642 }
643
644 /* *************************** MESH  ******************************** */
645
646
647 static void editing_panel_mesh_type(Object *ob, Mesh *me)
648 {
649         uiBlock *block;
650         float val;
651         /* Hope to support more than two subsurf algorithms */
652         char subsurfmenu[]="Subsurf Type%t|Catmull-Clark%x0|Simple Subdiv.%x1";
653
654         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_type", UI_EMBOSS, UI_HELV, curarea->win);
655         if( uiNewPanel(curarea, block, "Mesh", "Editing", 320, 0, 318, 204)==0) return;
656
657         uiBlockBeginAlign(block);
658         uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Auto Smooth",10,180,154,19, &me->flag, 0, 0, 0, 0, "Treats all set-smoothed faces with angles less than Degr: as 'smooth' during render");
659         uiDefButS(block, NUM, B_DIFF, "Degr:",                          10,160,154,19, &me->smoothresh, 1, 80, 0, 0, "Defines maximum angle between face normals that 'Auto Smooth' will operate on");
660
661         uiBlockBeginAlign(block);
662         uiBlockSetCol(block, TH_BUT_SETTING1);
663         uiDefButS(block, TOG|BIT|7, B_MAKEDISP, "SubSurf",      10,134,70,19, &me->flag, 0, 0, 0, 0, "Treats the active object as a Subdivision Surface");
664         uiDefButS(block, MENU, B_MAKEDISP, subsurfmenu,         80,134,84,19, &(me->subsurftype), 0, 0, 0, 0, "Selects type of Subsurf algorithm.");
665         uiBlockSetCol(block, TH_AUTO);
666         uiDefButS(block, NUM, B_MAKEDISP, "Subdiv:",            10, 114,110,19, &me->subdiv, 0, 6, 0, 0, "Defines the level of subdivision to display in real time interactively");
667         uiDefButS(block, NUM, B_DIFF, "",                               120,114, 44, 19, &me->subdivr, 0, 6, 0, 0, "Defines the level of subdivision to apply during rendering");
668         uiDefButS(block, TOG|BIT|8, B_MAKEDISP, "Optimal",      10, 94,154,19, &me->flag, 0, 0, 0, 0, "Only draws optimal wireframe");
669
670         uiBlockBeginAlign(block);
671
672         if(me->medge) val= 1.0; else val= 0.0;
673         uiDefBut(block, LABEL, 0, "Edges",                                      10,70,70,20, 0, val, 0, 0, 0, "");
674         if(me->medge==NULL) {
675                 uiDefBut(block, BUT, B_MAKEEDGES, "Make",               80,70,84,19, 0, 0, 0, 0, 0, "Adds edges data to active Mesh object, enables creases/seams and faster wireframe draw");
676         }
677         else uiDefBut(block, BUT, B_DELEDGES, "Delete",         80,70,84,19, 0, 0, 0, 0, 0, "Deletes edges data from active Mesh object");
678
679         if(me->mcol) val= 1.0; else val= 0.0;
680         uiDefBut(block, LABEL, 0, "VertCol",                            10,50,70,20, 0, val, 0, 0, 0, "");
681         if(me->mcol==NULL) {
682                 uiDefBut(block, BUT, B_MAKEVERTCOL, "Make",             80,50,84,19, 0, 0, 0, 0, 0, "Enables vertex colour painting on active object");
683         }
684         else uiDefBut(block, BUT, B_DELVERTCOL, "Delete",       80,50,84,19, 0, 0, 0, 0, 0, "Deletes vertex colours on active object");
685
686         if(me->tface) val= 1.0; else val= 0.0;
687         uiDefBut(block, LABEL, 0, "TexFace",                            10,30,70,20, 0, val, 0, 0, 0, "");
688         if(me->tface==NULL) {
689                 uiDefBut(block, BUT, B_MAKE_TFACES, "Make",             80,30,84,19, 0, 0, 0, 0, 0, "Enables the active object's faces for UV coordinate mapping");
690         }
691         else uiDefBut(block, BUT, B_DEL_TFACES, "Delete",       80,30,84,19, 0, 0, 0, 0, 0, "Deletes UV coordinates for active object's faces");
692
693         if(me->msticky) val= 1.0; else val= 0.0;
694         uiDefBut(block, LABEL, 0, "Sticky",                             10,10,70,20, 0, val, 0, 0, 0, "");
695         if(me->msticky==NULL) {
696                 uiDefBut(block, BUT, B_MAKESTICKY, "Make",              80,10,84,19, 0, 0, 0, 0, 0, "Creates Sticky coordinates for the active object from the current camera view background picture");
697         }
698         else uiDefBut(block, BUT, B_DELSTICKY, "Delete",        80,10,84,19, 0, 0, 0, 0, 0, "Deletes Sticky texture coordinates");
699
700         uiBlockEndAlign(block);
701
702         /* decimator */
703         if(G.obedit==NULL) {
704                 int tottria= decimate_count_tria(ob);
705                 DispList *dl;
706
707                 // wacko, wait for new displist system (ton)
708                 if( (dl=ob->disp.first) && dl->mesh);
709                 else decim_faces= tottria;
710
711                 uiBlockBeginAlign(block);
712                 uiBlockSetCol(block, TH_BUT_SETTING1);
713                 uiDefButI(block, NUM,B_DECIM_FACES, "Decimator:",       175,180,230,19, &decim_faces, 4.0, tottria, 10, 10, "Defines the number of triangular faces to decimate the active Mesh object to");
714                 uiBlockSetCol(block, TH_AUTO);
715                 uiDefBut(block, BUT,B_DECIM_APPLY, "Apply",             175,160,110,19, 0, 0, 0, 0, 0, "Applies the decimation to the active Mesh object");
716                 uiDefBut(block, BUT,B_DECIM_CANCEL, "Cancel",   285,160,120,19, 0, 0, 0, 0, 0, "Restores the Mesh to its original number of faces");
717                 uiBlockEndAlign(block);
718         }
719
720
721         uiDefIDPoinBut(block, test_meshpoin_but, 0, "TexMesh: ",        175,124,230,19, &me->texcomesh, "Enter the name of a Meshblock");
722
723         if(me->key) {
724                 uiBlockBeginAlign(block);
725                 uiDefButS(block, NUM, B_DIFF, "Slurph:",                                175,95,95,19, &(me->key->slurph), -500.0, 500.0, 0, 0, "");
726                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",                175,75,95,19, &me->key->type, 0, 0, 0, 0, "");
727         }
728
729         uiBlockBeginAlign(block);
730         uiDefBut(block, BUT, B_SLOWERDRAW,"SlowerDraw",                 175,30,95,19, 0, 0, 0, 0, 0, "Displays the active object with all possible edges shown");
731         uiDefBut(block, BUT, B_FASTERDRAW,"FasterDraw",                 175,10,95,19, 0, 0, 0, 0, 0, "Displays the active object faster by omitting some edges when drawing");
732
733         uiBlockBeginAlign(block);
734         uiDefBut(block, BUT,B_DOCENTRE, "Centre",                                       275, 95, 130, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
735         uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New",                        275, 75, 130, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data");
736         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          275, 55, 130, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
737
738         uiBlockBeginAlign(block);
739         uiDefButS(block, TOG|BIT|2, REDRAWVIEW3D, "Double Sided",       275,30,130,19, &me->flag, 0, 0, 0, 0, "Toggles selected faces as doublesided or single-sided");
740         uiDefButS(block, TOG|BIT|1, REDRAWVIEW3D, "No V.Normal Flip",275,10,130,19, &me->flag, 0, 0, 0, 0, "Disables flipping of vertexnormals during render");
741         uiBlockEndAlign(block);
742
743 }
744
745
746
747 /* *************************** FONT ******************************** */
748
749 static short give_vfontnr(VFont *vfont)
750 {
751         VFont *vf;
752         short nr= 1;
753
754         vf= G.main->vfont.first;
755         while(vf) {
756                 if(vf==vfont) return nr;
757                 nr++;
758                 vf= vf->id.next;
759         }
760         return -1;
761 }
762
763 static VFont *give_vfontpointer(int nr) /* nr= button */
764 {
765         VFont *vf;
766         short tel= 1;
767
768         vf= G.main->vfont.first;
769         while(vf) {
770                 if(tel==nr) return vf;
771                 tel++;
772                 vf= vf->id.next;
773         }
774         return G.main->vfont.first;
775 }
776
777 static VFont *exist_vfont(char *str)
778 {
779         VFont *vf;
780
781         vf= G.main->vfont.first;
782         while(vf) {
783                 if(strcmp(vf->name, str)==0) return vf;
784                 vf= vf->id.next;
785         }
786         return 0;
787 }
788
789 static char *give_vfontbutstr(void)
790 {
791         VFont *vf;
792         int len= 0;
793         char *str, di[FILE_MAXDIR], fi[FILE_MAXFILE];
794
795         vf= G.main->vfont.first;
796         while(vf) {
797                 strcpy(di, vf->name);
798                 BLI_splitdirstring(di, fi);
799                 len+= strlen(fi)+4;
800                 vf= vf->id.next;
801         }
802
803         str= MEM_callocN(len+21, "vfontbutstr");
804         strcpy(str, "FONTS %t");
805         vf= G.main->vfont.first;
806         while(vf) {
807
808                 if(vf->id.us==0) strcat(str, "|0 ");
809                 else strcat(str, "|   ");
810
811                 strcpy(di, vf->name);
812                 BLI_splitdirstring(di, fi);
813
814                 strcat(str, fi);
815                 vf= vf->id.next;
816         }
817         return str;
818 }
819
820 static void load_buts_vfont(char *name)
821 {
822         VFont *vf;
823         Curve *cu;
824
825         if(OBACT && OBACT->type==OB_FONT) cu= OBACT->data;
826         else return;
827
828         vf= exist_vfont(name);
829         if(vf==0) {
830                 vf= load_vfont(name);
831                 if(vf==0) return;
832         }
833         else id_us_plus((ID *)vf);
834
835         if(cu->vfont) cu->vfont->id.us--;
836         cu->vfont= vf;
837
838         text_to_curve(OBACT, 0);
839         makeDispList(OBACT);
840         BIF_undo_push("Load vector font");
841         allqueue(REDRAWVIEW3D, 0);
842         allqueue(REDRAWBUTSEDIT, 0);
843 }
844
845 void do_fontbuts(unsigned short event)
846 {
847         Curve *cu;
848         VFont *vf;
849         Object *ob;
850         ScrArea *sa;
851         char str[80];
852
853         ob= OBACT;
854
855         switch(event) {
856         case B_MAKEFONT:
857                 text_to_curve(ob, 0);
858                 makeDispList(ob);
859                 allqueue(REDRAWVIEW3D, 0);
860                 break;
861         case B_TOUPPER:
862                 to_upper();
863                 break;
864         case B_LOADFONT:
865                 vf= give_vfontpointer(G.buts->texnr);
866                 if(vf && vf->id.prev!=vf->id.next) strcpy(str, vf->name);
867                 else strcpy(str, U.fontdir);
868
869                 sa= closest_bigger_area();
870                 areawinset(sa->win);
871
872                 activate_fileselect(FILE_SPECIAL, "SELECT FONT", str, load_buts_vfont);
873
874                 break;
875         case B_PACKFONT:
876                 if (ob) {
877                         cu= ob->data;
878                         if(cu && cu->vfont) {
879                                 if (cu->vfont->packedfile) {
880                                         if (G.fileflags & G_AUTOPACK) {
881                                                 if (okee("Disable AutoPack ?")) {
882                                                         G.fileflags &= ~G_AUTOPACK;
883                                                 }
884                                         }
885
886                                         if ((G.fileflags & G_AUTOPACK) == 0) {
887                                                 if (unpackVFont(cu->vfont, PF_ASK) == RET_OK) {
888                                                         text_to_curve(ob, 0);
889                                                         makeDispList(ob);
890                                                         allqueue(REDRAWVIEW3D, 0);
891                                                 }
892                                         }
893                                 } else {
894                                         cu->vfont->packedfile = newPackedFile(cu->vfont->name);
895                                 }
896                         }
897                 }
898                 allqueue(REDRAWHEADERS, 0);
899                 allqueue(REDRAWBUTSEDIT, 0);
900                 break;
901
902         case B_SETFONT:
903                 if(ob) {
904                         cu= ob->data;
905
906                         vf= give_vfontpointer(G.buts->texnr);
907                         if(vf) {
908                                 id_us_plus((ID *)vf);
909                                 cu->vfont->id.us--;
910                                 cu->vfont= vf;
911                                 text_to_curve(ob, 0);
912                                 makeDispList(ob);
913                                 BIF_undo_push("Set vector font");
914                                 allqueue(REDRAWVIEW3D, 0);
915                                 allqueue(REDRAWBUTSEDIT, 0);
916                         }
917                 }
918                 break;
919         case B_TEXTONCURVE:
920                 if(ob) {
921                         cu= ob->data;
922                         if(cu->textoncurve && cu->textoncurve->type!=OB_CURVE) {
923                                 error("Only Curve Objects");
924                                 cu->textoncurve= 0;
925                                 allqueue(REDRAWBUTSEDIT, 0);
926                         }
927                         text_to_curve(ob, 0);
928                         makeDispList(ob);
929                 }
930         }
931 }
932
933 static void editing_panel_font_type(Object *ob, Curve *cu)
934 {
935         uiBlock *block;
936         char *strp;
937         static int packdummy = 0;
938         VFontData *vfd;
939
940         block= uiNewBlock(&curarea->uiblocks, "editing_panel_font_type", UI_EMBOSS, UI_HELV, curarea->win);
941         if(uiNewPanel(curarea, block, "Font", "Editing", 640, 0, 318, 204)==0) return;
942
943         G.buts->texnr= give_vfontnr(cu->vfont);
944         strp= give_vfontbutstr();
945         vfd= cu->vfont->data;
946
947         uiDefBut(block, BUT,B_LOADFONT, "Load", 480,188,68,20, 0, 0, 0, 0, 0, "Load a new font");
948         uiDefButS(block, MENU, B_SETFONT, strp, 550,188,220,20, &G.buts->texnr, 0, 0, 0, 0, "Change font for object");
949
950         if (cu->vfont->packedfile) {
951                 packdummy = 1;
952         } else {
953                 packdummy = 0;
954         }
955         uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE,       772,188,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this font");
956         uiDefBut(block, LABEL, 0, vfd->name,  480, 165,314,20, 0, 0, 0, 0, 0, "Postscript name of the font");
957
958         MEM_freeN(strp);
959
960         uiBlockBeginAlign(block);
961         uiDefButS(block, ROW,B_MAKEFONT, "Left",                480,135,53,20, &cu->spacemode, 0.0,0.0, 0, 0, "Left align the text from the object centre");
962         uiDefButS(block, ROW,B_MAKEFONT, "Middle",              535,135,55,20, &cu->spacemode, 0.0,1.0, 0, 0, "Middle align the text from the object centre");
963         uiDefButS(block, ROW,B_MAKEFONT, "Right",               592,135,53,20, &cu->spacemode, 0.0,2.0, 0, 0, "Right align the text from the object centre");
964         uiDefButS(block, ROW,B_MAKEFONT, "Flush",               647,135,53,20, &cu->spacemode, 0.0,3.0, 0, 0, "Fill characters to maximum linewidth. (Multiple lines required)");
965         uiDefBut(block, BUT, B_TOUPPER, "ToUpper",              715,135,78,20, 0, 0, 0, 0, 0, "Toggle between upper and lower case in editmode");
966         uiBlockEndAlign(block);
967
968         uiDefIDPoinBut(block, test_obpoin_but, B_TEXTONCURVE, "TextOnCurve:",   480,105,220,19, &cu->textoncurve, "Apply a deforming curve to the text");
969         uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 480,84,220,19, cu->family, 0.0, 20.0, 0, 0, "Blender uses font from selfmade objects");
970
971         uiBlockBeginAlign(block);
972         uiDefButF(block, NUM,B_MAKEFONT, "Size:",               480,56,155,20, &cu->fsize, 0.1,10.0, 10, 0, "Size of the text");
973         uiDefButF(block, NUM,B_MAKEFONT, "Linedist:",   640,56,155,20, &cu->linedist, 0.0,10.0, 10, 0, "Distance between text lines");
974         uiDefButF(block, NUM,B_MAKEFONT, "Spacing:",    480,34,155,20, &cu->spacing, 0.0,10.0, 10, 0, "Spacing of individual characters");
975         uiDefButF(block, NUM,B_MAKEFONT, "X offset:",   640,34,155,20, &cu->xof, -50.0,50.0, 10, 0, "Horizontal position from object centre");
976         uiDefButF(block, NUM,B_MAKEFONT, "Shear:",              480,12,155,20, &cu->shear, -1.0,1.0, 10, 0, "Italic angle of the characters");
977         uiDefButF(block, NUM,B_MAKEFONT, "Y offset:",   640,12,155,20, &cu->yof, -50.0,50.0, 10, 0, "Vertical position from object centre");
978         uiBlockEndAlign(block);
979 }
980
981
982 /* *************************** CURVE ******************************** */
983
984
985 void do_curvebuts(unsigned short event)
986 {
987         extern Nurb *lastnu;
988         extern ListBase editNurb;  /* from editcurve */
989         Base *base;
990         Object *ob;
991         Curve *cu;
992         Nurb *nu;
993
994         ob= OBACT;
995         if(ob==0) return;
996
997         switch(event) {
998
999         case B_CONVERTPOLY:
1000         case B_CONVERTBEZ:
1001         case B_CONVERTBSPL:
1002         case B_CONVERTCARD:
1003         case B_CONVERTNURB:
1004                 if(G.obedit) {
1005                         setsplinetype(event-B_CONVERTPOLY);
1006                         makeDispList(G.obedit);
1007                         allqueue(REDRAWVIEW3D, 0);
1008                 }
1009                 break;
1010         case B_UNIFU:
1011         case B_ENDPU:
1012         case B_BEZU:
1013         case B_UNIFV:
1014         case B_ENDPV:
1015         case B_BEZV:
1016                 if(G.obedit) {
1017                         nu= editNurb.first;
1018                         while(nu) {
1019                                 if(isNurbsel(nu)) {
1020                                         if((nu->type & 7)==CU_NURBS) {
1021                                                 if(event<B_UNIFV) {
1022                                                         nu->flagu &= 1;
1023                                                         nu->flagu += ((event-B_UNIFU)<<1);
1024                                                         makeknots(nu, 1, nu->flagu>>1);
1025                                                 }
1026                                                 else if(nu->pntsv>1) {
1027                                                         nu->flagv &= 1;
1028                                                         nu->flagv += ((event-B_UNIFV)<<1);
1029                                                         makeknots(nu, 2, nu->flagv>>1);
1030                                                 }
1031                                         }
1032                                 }
1033                                 nu= nu->next;
1034                         }
1035                         makeDispList(G.obedit);
1036                         allqueue(REDRAWVIEW3D, 0);
1037                 }
1038                 break;
1039         case B_SETWEIGHT:
1040                 if(G.obedit) {
1041                         weightflagNurb(1, editbutweight, 0);
1042                         makeDispList(G.obedit);
1043                         allqueue(REDRAWVIEW3D, 0);
1044                 }
1045                 break;
1046         case B_SETW1:
1047                 editbutweight= 1.0;
1048                 scrarea_queue_winredraw(curarea);
1049                 break;
1050         case B_SETW2:
1051                 editbutweight= sqrt(2.0)/4.0;
1052                 scrarea_queue_winredraw(curarea);
1053                 break;
1054         case B_SETW3:
1055                 editbutweight= 0.25;
1056                 scrarea_queue_winredraw(curarea);
1057                 break;
1058         case B_SETW4:
1059                 editbutweight= sqrt(0.5);
1060                 scrarea_queue_winredraw(curarea);
1061                 break;
1062         case B_SETORDER:
1063                 if(G.obedit) {
1064                         nu= lastnu;
1065                         if(nu && (nu->type & 7)==CU_NURBS ) {
1066                                 if(nu->orderu>nu->pntsu) {
1067                                         nu->orderu= nu->pntsu;
1068                                         scrarea_queue_winredraw(curarea);
1069                                 }
1070                                 makeknots(nu, 1, nu->flagu>>1);
1071                                 if(nu->orderv>nu->pntsv) {
1072                                         nu->orderv= nu->pntsv;
1073                                         scrarea_queue_winredraw(curarea);
1074                                 }
1075                                 makeknots(nu, 2, nu->flagv>>1);
1076                         }
1077                         makeDispList(G.obedit);
1078                         allqueue(REDRAWVIEW3D, 0);
1079                 }
1080                 break;
1081         case B_MAKEDISP:
1082                 if(ob->type==OB_FONT) text_to_curve(ob, 0);
1083                 makeDispList(ob);
1084                 if(ob!=G.obedit) { // subsurf with linked dupli will crash
1085                         /* we need signal to send to other users of same data to recalc... */
1086                         base= FIRSTBASE;
1087                         while(base) {
1088                                 if(base->lay & G.vd->lay) {
1089                                         if(base->object->data==ob->data && base->object!=ob)
1090                                                 makeDispList(base->object);
1091                                 }
1092                                 base= base->next;
1093                         }
1094                 }
1095                 allqueue(REDRAWVIEW3D, 0);
1096                 allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
1097                 break;
1098
1099         case B_SUBDIVCURVE:
1100                 subdivideNurb();
1101                 break;
1102         case B_SPINNURB:
1103                 /* bad bad bad!!! use brackets!!! In case you wondered:
1104                   {==,!=} goes before & goes before || */
1105                 if( (G.obedit==0) ||
1106                     (G.obedit->type!=OB_SURF) ||
1107                         ((G.obedit->lay & G.vd->lay) == 0) ) return;
1108                 spinNurb(0, 0);
1109                 countall();
1110                 makeDispList(G.obedit);
1111                 allqueue(REDRAWVIEW3D, 0);
1112                 break;
1113         case B_CU3D:        /* allow 3D curve */
1114                 if(G.obedit) {
1115                         cu= G.obedit->data;
1116                         nu= editNurb.first;
1117                         while(nu) {
1118                                 nu->type &= ~CU_2D;
1119                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
1120                                 test2DNurb(nu);
1121                                 nu= nu->next;
1122                         }
1123                 }
1124                 if(ob->type==OB_CURVE) {
1125                         cu= ob->data;
1126                         nu= cu->nurb.first;
1127                         while(nu) {
1128                                 nu->type &= ~CU_2D;
1129                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
1130                                 test2DNurb(nu);
1131                                 nu= nu->next;
1132                         }
1133                 }
1134                 makeDispList(G.obedit);
1135                 allqueue(REDRAWVIEW3D, 0);
1136                 break;
1137         case B_SETRESOLU:
1138                 if(ob->type==OB_CURVE) {
1139                         cu= ob->data;
1140                         if(ob==G.obedit) nu= editNurb.first;
1141                         else nu= cu->nurb.first;
1142
1143                         while(nu) {
1144                                 nu->resolu= cu->resolu;
1145                                 nu= nu->next;
1146                         }
1147                 }
1148                 else if(ob->type==OB_FONT) text_to_curve(ob, 0);
1149
1150                 makeDispList(ob);
1151                 allqueue(REDRAWVIEW3D, 0);
1152
1153                 break;
1154         }
1155 }
1156
1157 static void editing_panel_curve_tools(Object *ob, Curve *cu)
1158 {
1159         Nurb *nu;
1160         extern ListBase editNurb;  /* from editcurve */
1161         extern Nurb *lastnu;
1162         uiBlock *block;
1163         short *sp;
1164
1165         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools", UI_EMBOSS, UI_HELV, curarea->win);
1166         if(uiNewPanel(curarea, block, "Curve Tools", "Editing", 640, 0, 318, 204)==0) return;
1167
1168         uiDefBut(block, LABEL, 0, "Make Knots",562,173,102, 18, 0, 0, 0, 0, 0, "");
1169
1170         if(ob->type==OB_CURVE) {
1171                 uiDefBut(block, LABEL, 0, "Convert",    463,173,72, 18, 0, 0, 0, 0, 0, "");
1172                 uiBlockBeginAlign(block);
1173                 uiDefBut(block, BUT,B_CONVERTPOLY,"Poly",               467,152,72, 18, 0, 0, 0, 0, 0, "Converts selected into regular Polygon vertices");
1174                 uiDefBut(block, BUT,B_CONVERTBEZ,"Bezier",              467,132,72, 18, 0, 0, 0, 0, 0, "Converts selected to Bezier triples");
1175                 uiDefBut(block, BUT,B_CONVERTNURB,"Nurb",               467,112,72, 18, 0, 0, 0, 0, 0, "Converts selected to Nurbs Points");
1176         }
1177         uiBlockBeginAlign(block);
1178         uiDefBut(block, BUT,B_UNIFU,"Uniform U",        565,152,102, 18, 0, 0, 0, 0, 0, "Nurbs only; interpolated result doesn't go to end points in U");
1179         uiDefBut(block, BUT,B_UNIFV,"V",                        670,152,50, 18, 0, 0, 0, 0, 0, "Nurbs only; interpolated result doesn't go to end points in V");
1180         uiDefBut(block, BUT,B_ENDPU,"Endpoint U",       565,132,102, 18, 0, 0, 0, 0, 0, "Nurbs only; interpolated result is forced to end points in U");
1181         uiDefBut(block, BUT,B_ENDPV,"V",                        670,132,50, 18, 0, 0, 0, 0, 0, "Nurbs only; interpolated result is forced to end points in V");
1182         uiDefBut(block, BUT,B_BEZU,"Bezier U",          565,112,102, 18, 0, 0, 0, 0, 0, "Nurbs only; make knots array mimic a Bezier in U");
1183         uiDefBut(block, BUT,B_BEZV,"V",                         670,112,50, 18, 0, 0, 0, 0, 0, "Nurbs only; make knots array mimic a Bezier in V");
1184         uiBlockEndAlign(block);
1185
1186         uiDefBut(block, BUT,B_SETWEIGHT,"Set Weight",   465,11,95,49, 0, 0, 0, 0, 0, "Nurbs only; set weight for select points");
1187
1188         uiBlockBeginAlign(block);
1189         uiDefButF(block, NUM,0,"Weight:",               565,36,102,22, &editbutweight, 0.01, 100.0, 10, 0, "The weight you can assign");
1190         uiDefBut(block, BUT,B_SETW1,"1.0",              670,36,50,22, 0, 0, 0, 0, 0, "");
1191         uiDefBut(block, BUT,B_SETW2,"sqrt(2)/4",565,11,55,20, 0, 0, 0, 0, 0, "");
1192         uiDefBut(block, BUT,B_SETW3,"0.25",             620,11,45,20, 0, 0, 0, 0, 0, "");
1193         uiDefBut(block, BUT,B_SETW4,"sqrt(0.5)",665,11,55,20, 0, 0, 0, 0, 0, "");
1194         uiBlockEndAlign(block);
1195
1196         if(ob==G.obedit) {
1197                 nu= lastnu;
1198                 if(nu==NULL) nu= editNurb.first;
1199                 if(nu) {
1200                         uiBlockBeginAlign(block);
1201                         sp= &(nu->orderu);
1202                         uiDefButS(block, NUM, B_SETORDER, "Order U:", 565,90,102, 19, sp, 2.0, 6.0, 0, 0, "Nurbs only; the amount of control points involved");
1203                         sp= &(nu->orderv);
1204                         uiDefButS(block, NUM, B_SETORDER, "V:",         670,90,50, 19, sp, 2.0, 6.0, 0, 0, "Nurbs only; the amount of control points involved");
1205                         sp= &(nu->resolu);
1206                         uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 19, sp, 1.0, 128.0, 0, 0, "The amount of new points interpolated per control vertex pair");
1207                         sp= &(nu->resolv);
1208                         uiDefButS(block, NUM, B_MAKEDISP, "V:",         670,70,50, 19, sp, 1.0, 128.0, 0, 0, "The amount of new points interpolated per control vertex pair");
1209                 }
1210         }
1211
1212
1213 }
1214
1215 static void editing_panel_curve_tools1(Object *ob, Curve *cu)
1216 {
1217         uiBlock *block;
1218
1219         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools1", UI_EMBOSS, UI_HELV, curarea->win);
1220         if(uiNewPanel(curarea, block, "Curve Tools1", "Editing", 960, 0, 318, 204)==0) return;
1221
1222         uiDefBut(block, BUT, B_SUBDIVCURVE, "Subdivide", 400,180,150,20, 0, 0, 0, 0, 0, "Subdivide selected");
1223         if(ob->type==OB_SURF) {
1224                 uiDefBut(block, BUT, B_SPINNURB, "Spin",         400,160,150,20, 0, 0, 0, 0, 0, "Spin selected 360 degrees");
1225         }
1226         uiBlockBeginAlign(block);
1227         uiDefBut(block, BUT,B_HIDE,             "Hide",                 400,120,150,18, 0, 0, 0, 0, 0, "Hides selected faces");
1228         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               400,100,150,18, 0, 0, 0, 0, 0, "Reveals selected faces");
1229         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  400,80,150,18, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
1230         uiBlockEndAlign(block);
1231
1232         uiDefButF(block, NUM,   REDRAWVIEW3D, "NSize:", 400, 40, 150, 19, &editbutsize, 0.001, 1.0, 10, 0, "Normal size for drawing");
1233 }
1234
1235 /* for curve, surf and font! */
1236 static void editing_panel_curve_type(Object *ob, Curve *cu)
1237 {
1238         uiBlock *block;
1239
1240         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_type", UI_EMBOSS, UI_HELV, curarea->win);
1241         if(uiNewPanel(curarea, block, "Curve and Surface", "Editing", 320, 0, 318, 204)==0) return;
1242
1243         uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                                       600,160,150,19, &cu->flag, 0, 0, 0, 0, "Forces to use UV coordinates for texture mapping 'orco'");
1244         if(ob->type==OB_SURF)
1245                 uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "No Puno Flip",       600,140,150,19, &cu->flag, 0, 0, 0, 0, "Don't flip vertex normals while render");
1246
1247         uiBlockBeginAlign(block);
1248         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");
1249         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");
1250         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          600, 75, 150, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
1251         uiBlockEndAlign(block);
1252
1253         if(ob->type==OB_SURF) {
1254                 if(cu->key) {
1255                         /* uiDefButS(block, NUM, B_DIFF, "Slurph:",                     600,25,140,19, &(cu->key->slurph), -500.0, 500.0,0,0); ,""*/
1256                         uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        600,45,140,19, &cu->key->type, 0, 0, 0, 0, "");
1257                 }
1258         }
1259
1260         if(ob->type!=OB_SURF) {
1261         
1262                 if(ob->type==OB_CURVE) {
1263                         extern float prlen;             // buttons_object.c, should be moved....
1264                         char str[32];
1265                         uiBlockBeginAlign(block);
1266                         uiDefButS(block, NUM, B_RECALCPATH, "PathLen:",                 600,50,150,19, &cu->pathlen, 1.0, 9000.0, 0, 0, "If no speed Ipo was set, the amount of frames of the path");
1267                         uiDefButS(block, TOG|BIT|3, B_RECALCPATH, "CurvePath",  600,30,75,19 , &cu->flag, 0, 0, 0, 0, "Enables curve to become translation path");
1268                         uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "CurveFollow",675,30,75,19, &cu->flag, 0, 0, 0, 0, "Makes curve path children to rotate along path");
1269                         uiDefButS(block, TOG|BIT|7, B_CURVECHECK, "CurveStretch", 600,10,150,19, &cu->flag, 0, 0, 0, 0, "Option for curve-deform: makes deformed child to stretch along entire path");
1270
1271                         uiBlockEndAlign(block);
1272                         sprintf(str, "%.4f", prlen);
1273                         uiDefBut(block, BUT, B_PRINTLEN,                "PrintLen",     600,-10,75,19, 0, 0, 0, 0, 0, "");
1274                         uiDefBut(block, LABEL, 0, str,                                          675,-10,75,19, 0, 1.0, 0, 0, 0, "");
1275                 }
1276
1277                 uiBlockBeginAlign(block);
1278                 uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 760,160,120,19, &cu->resolu, 1.0, 128.0, 0, 0, "Default resolution");
1279                 uiDefBut(block, BUT, B_SETRESOLU, "Set",                880,160,30,19, 0, 0, 0, 0, 0, "Set resolution for interpolation");
1280
1281                 uiBlockBeginAlign(block);
1282                 uiDefButF(block, NUM, B_MAKEDISP, "Width:",             760,90,150,19, &cu->width, 0.0, 2.0, 1, 0, "Make interpolated result thinner or fatter");
1283                 uiDefButF(block, NUM, B_MAKEDISP, "Ext1:",              760,70,150,19, &cu->ext1, 0.0, 5.0, 10, 0, "Extrude depth");
1284                 uiDefButF(block, NUM, B_MAKEDISP, "Ext2:",              760,50,150,19, &cu->ext2, 0.0, 2.0, 1, 0, "Extrude beveling depth");
1285                 uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  760,30,150,19, &cu->bevresol, 0.0, 10.0, 0, 0, "Amount of bevels");
1286                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "BevOb:",         760,10,150,19, &cu->bevobj, "Curve object name that defines the bevel shape");
1287                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "TaperOb:",               760,-10,150,19, &cu->taperobj, "Curve object name that defines the taper (width)");
1288
1289                 uiBlockBeginAlign(block);
1290                 uiBlockSetCol(block, TH_BUT_SETTING1);
1291                 uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 760,130,50,19, &cu->flag, 0, 0, 0, 0, "Draw filled back for curves");
1292                 uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",810,130,50,19, &cu->flag, 0, 0, 0, 0, "Draw filled front for curves");
1293                 uiDefButS(block, TOG|BIT|0, B_CU3D, "3D",               860,130,50,19, &cu->flag, 0, 0, 0, 0, "Allow Curve Object to be 3d, it doesn't fill then");
1294
1295
1296         }
1297
1298 }
1299
1300
1301 /* *************************** CAMERA ******************************** */
1302
1303
1304 static void editing_panel_camera_type(Object *ob, Camera *cam)
1305 {
1306         uiBlock *block;
1307         float grid=0.0;
1308
1309         if(G.vd) grid= G.vd->grid;
1310         if(grid<1.0) grid= 1.0;
1311
1312         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_type", UI_EMBOSS, UI_HELV, curarea->win);
1313         if(uiNewPanel(curarea, block, "Camera", "Editing", 320, 0, 318, 204)==0) return;
1314
1315         uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:", 470,178,160,20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
1316
1317         uiBlockBeginAlign(block);
1318         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");
1319         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");
1320         uiBlockEndAlign(block);
1321
1322         uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
1323
1324         uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
1325         uiBlockBeginAlign(block);
1326         uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
1327         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");
1328         uiBlockEndAlign(block);
1329 }
1330
1331 /* yafray: extra camera panel to set Depth-of-Field parameters */
1332 static void editing_panel_camera_yafraydof(Object *ob, Camera *cam)
1333 {
1334         uiBlock *block;
1335         char *mst1, *mst2;
1336
1337         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_yafraydof", UI_EMBOSS, UI_HELV, curarea->win);
1338         uiNewPanelTabbed("Camera", "Editing");
1339         if(uiNewPanel(curarea, block, "Yafray DoF", "Editing", 320, 0, 318, 204)==0) return;
1340
1341         uiDefButF(block, NUM, REDRAWVIEW3D, "DoFDist:", 10, 147, 180, 20, &cam->YF_dofdist, 0.0, 5000.0, 50, 0, "Sets distance to point of focus (use camera 'ShowLimits' to make visible in 3Dview)");
1342         uiDefButF(block, NUM, B_DIFF, "Aperture:", 10, 125, 180, 20, &cam->YF_aperture, 0.0, 2.0, 1, 0, "Sets lens aperture, the larger, the more blur (use small values, 0 is no DoF)");
1343
1344         uiDefButS(block, TOG|BIT|2, B_DIFF, "Random sampling", 10, 90, 180, 20, &cam->flag, 0, 0, 0, 0, "Use noisy random Lens sampling instead of QMC");
1345
1346         uiDefBut(block, LABEL, 0, "Bokeh", 10, 60, 180, 19, 0, 0.0, 0.0, 0, 0, "");
1347         mst1 = "Bokeh Type%t|Disk1%x0|Disk2%x1|Triangle%x2|Square%x3|Pentagon%x4|Hexagon%x5|Ring%x6";
1348         uiDefButS(block, MENU, B_REDR, mst1, 10, 40, 89, 20, &cam->YF_bkhtype, 0.0, 0.0, 0, 0, "Sets Bokeh type");
1349         
1350         if ((cam->YF_bkhtype!=0) && (cam->YF_bkhtype!=6)) {
1351                 mst2 = "Bokeh Bias%t|Uniform%x0|Center%x1|Edge%x2";
1352                 uiDefButS(block, MENU, B_REDR, mst2, 100, 40, 90, 20, &cam->YF_bkhbias, 0.0, 0.0, 0, 0, "Sets Bokeh bias");
1353                 if (cam->YF_bkhtype>1)
1354                         uiDefButF(block, NUM, B_DIFF, "Rotation:", 10, 15, 180, 20, &cam->YF_bkhrot, 0.0, 360.0, 100, 0, "Shape rotation amount in degrees");
1355         }
1356
1357 }
1358
1359
1360 /* *************************** MBALL ******************************** */
1361
1362 void do_mballbuts(unsigned short event)
1363 {
1364         switch(event) {
1365         case B_RECALCMBALL:
1366                 makeDispList(OBACT);
1367                 allqueue(REDRAWVIEW3D, 0);
1368                 break;
1369         }
1370 }
1371
1372 static void editing_panel_mball_type(Object *ob, MetaBall *mb)
1373 {
1374         uiBlock *block;
1375
1376         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_type", UI_EMBOSS, UI_HELV, curarea->win);
1377         if(uiNewPanel(curarea, block, "MetaBall", "Editing", 320, 0, 318, 204)==0) return;
1378
1379         ob= find_basis_mball(ob);
1380         mb= ob->data;
1381
1382         uiBlockBeginAlign(block);
1383         uiDefButF(block, NUM, B_RECALCMBALL, "Wiresize:",       470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "Polygonization resolution in 3d window");
1384         uiDefButF(block, NUM, 0, "Rendersize:",                 470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "Polygonization resolution in rendering");
1385         uiDefButF(block, NUM, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "Defines influence of meta elements");
1386
1387         uiBlockBeginAlign(block);
1388         uiBlockSetCol(block, TH_BUT_SETTING1);
1389         uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
1390         uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "While editing, always updates");
1391         uiDefButS(block, ROW, B_DIFF, "Half Res",       471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "While editing, updates in half resolution");
1392         uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "While editing, updates without polygonization");
1393         uiDefButS(block, ROW, B_DIFF, "Never",          471, 25, 120, 19, &mb->flag, 0.0, 3.0, 0, 0, "While editing, doesn't update");
1394
1395 }
1396
1397 static void editing_panel_mball_tools(Object *ob, MetaBall *mb)
1398 {
1399         extern MetaElem *lastelem;
1400         uiBlock *block;
1401
1402         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_tools", UI_EMBOSS, UI_HELV, curarea->win);
1403         if( uiNewPanel(curarea, block, "MetaBall tools", "Editing", 640, 0, 318, 204)==0) return;
1404
1405         if(ob==G.obedit && lastelem) {
1406                 uiBlockBeginAlign(block);
1407                 uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "Stiffness for active meta");
1408                 if(lastelem->type!=MB_BALL)
1409                 uiDefButF(block, NUM, B_RECALCMBALL, "dx:",             750,158,250,19, &lastelem->expx, 0.0, 20.0, 0, 0, "X size for active meta");
1410                 if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
1411                 uiDefButF(block, NUM, B_RECALCMBALL, "dy:",             750,138,250,19, &lastelem->expy, 0.0, 20.0, 0, 0, "Y size for active meta");
1412
1413                 if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
1414                 uiDefButF(block, NUM, B_RECALCMBALL, "dz:",             750,118,250,19, &lastelem->expz, 0.0, 20.0, 0, 0, "Z size for active meta");
1415                 uiBlockEndAlign(block);
1416
1417                 uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "Draw active meta as Ball");
1418                 uiBlockBeginAlign(block);
1419                 uiDefButS(block, ROW, B_RECALCMBALL, "Tube",                    753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "Draw active meta as Ball");
1420                 uiDefButS(block, ROW, B_RECALCMBALL, "Plane",                   814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "Draw active meta as Plane");
1421                 uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid",                876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "Draw active meta as Ellipsoid");
1422                 uiDefButS(block, ROW, B_RECALCMBALL, "Cube",                    938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "Draw active meta as Cube");
1423                 uiBlockEndAlign(block);
1424
1425                 uiDefButS(block, TOG|BIT|1, B_RECALCMBALL, "Negative",753,16,250,19, &lastelem->flag, 0, 0, 0, 0, "Make active meta creating holes");
1426
1427         }
1428
1429 }
1430
1431
1432 /* *************************** LATTICE ******************************** */
1433
1434 void do_latticebuts(unsigned short event)
1435 {
1436         Object *ob;
1437         Lattice *lt;
1438
1439         ob= OBACT;
1440         if(ob->type!=OB_LATTICE) return;
1441
1442         switch(event) {
1443         case B_RESIZELAT:
1444                 if(ob) {
1445                         if(ob==G.obedit) resizelattice(editLatt);
1446                         else resizelattice(ob->data);
1447                 }
1448                 allqueue(REDRAWVIEW3D, 0);
1449                 break;
1450         case B_DRAWLAT:
1451                 if(ob==G.obedit) calc_lattverts_ext();
1452                 allqueue(REDRAWVIEW3D, 0);
1453                 break;
1454         case B_LATTCHANGED:
1455
1456                 lt= ob->data;
1457                 if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
1458
1459                 make_displists_by_parent(ob);
1460
1461                 allqueue(REDRAWVIEW3D, 0);
1462
1463                 break;
1464         }
1465 }
1466
1467 static void editing_panel_lattice_type(Object *ob, Lattice *lt)
1468 {
1469         uiBlock *block;
1470
1471         block= uiNewBlock(&curarea->uiblocks, "editing_panel_lattice_type", UI_EMBOSS, UI_HELV, curarea->win);
1472         if(uiNewPanel(curarea, block, "Latice", "Editing", 320, 0, 318, 204)==0) return;
1473
1474
1475         uiSetButLock(lt->key!=0, "Not with VertexKeys");
1476         uiSetButLock(ob==G.obedit, "Unable to perform function in EditMode");
1477
1478         uiBlockBeginAlign(block);
1479
1480         uiDefButS(block, NUM, B_RESIZELAT,      "U:",                           469, 178,100,19, &lt->pntsu, 1.0, 64.0, 0, 0, "Points in U direction");
1481         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1482         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1483         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1484
1485         uiDefButS(block, NUM, B_RESIZELAT,      "V:",                           469, 156,100,19, &lt->pntsv, 1.0, 64.0, 0, 0, "Points in V direction");
1486         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 156, 40, 19, &lt->typev, 2.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1487         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 156, 40, 19, &lt->typev, 2.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1488         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 156, 40, 19, &lt->typev, 2.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1489
1490         uiDefButS(block, NUM, B_RESIZELAT,      "W:",                           469, 134,100,19, &lt->pntsw, 1.0, 64.0, 0, 0, "Points in W direction");
1491         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 134, 40, 19, &lt->typew, 3.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1492         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 134, 40, 19, &lt->typew, 3.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1493         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 134, 40, 19, &lt->typew, 3.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1494
1495         uiBlockEndAlign(block);
1496
1497         uiDefBut(block, BUT, B_RESIZELAT,       "Make Regular",         469,98,102,31, 0, 0, 0, 0, 0, "Make Lattice regular");
1498
1499         uiClearButLock();
1500         uiDefButS(block, TOG|BIT|1, B_LATTCHANGED, "Outside",   571,98,122,31, &lt->flag, 0, 0, 0, 0, "Only draw, and take into account, the outer vertices");
1501
1502         if(lt->key) {
1503                 uiDefButS(block, NUM, B_DIFF, "Slurph:",                        469,60,120,19, &(lt->key->slurph), -500.0, 500.0, 0, 0, "Set time value to denote 'slurph' (sequential delay) vertices with key framing");
1504                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        469,40,120,19, &lt->key->type, 0, 0, 0, 0, "Use relative keys (instead of absolute)");
1505         }
1506
1507 }
1508
1509 /* *************************** ARMATURE ******************************** */
1510
1511
1512
1513 static int editbone_to_parnr (EditBone *bone)
1514 {
1515         EditBone *ebone;
1516         int     index;
1517
1518         for (ebone=G.edbo.first, index=0; ebone; ebone=ebone->next, index++){
1519                 if (ebone==bone)
1520                         return index;
1521         }
1522
1523         return -1;
1524 }
1525
1526 static void parnr_to_editbone(EditBone *bone)
1527 {
1528         if (bone->parNr == -1){
1529                 bone->parent = NULL;
1530                 bone->flag &= ~BONE_IK_TOPARENT;
1531         }
1532         else{
1533                 bone->parent = BLI_findlink(&G.edbo, bone->parNr);
1534                 attach_bone_to_parent(bone);
1535         }
1536 }
1537
1538 static void parnr_to_editbone_cb(void *bonev, void *arg2_unused)
1539 {
1540         EditBone *curBone= bonev;
1541         parnr_to_editbone(curBone);
1542 }
1543
1544 static void build_bonestring (char *string, EditBone *bone)
1545 {
1546         EditBone *curBone;
1547         EditBone *pBone;
1548         int             skip=0;
1549         int             index, numbones, i;
1550         char (*qsort_ptr)[32] = NULL;
1551
1552         sprintf (string, "Parent%%t| %%x%d", -1);       /* That space is there
1553                                                                                                  * for a reason
1554                                                                                                  */
1555
1556         numbones = BLI_countlist(&G.edbo);
1557
1558         /*
1559          * This will hold the bone names temporarily so we can sort them
1560          */
1561         if (numbones > 0)
1562                 qsort_ptr = MEM_callocN (numbones * sizeof (qsort_ptr[0]),
1563                                                                  "qsort_ptr");
1564
1565         numbones = 0;
1566         for (curBone = G.edbo.first, index=0; curBone;
1567                  curBone=curBone->next, index++){
1568                 /* Make sure this is a valid child */
1569                 if (curBone != bone){
1570                         skip=0;
1571                         for (pBone=curBone->parent; pBone; pBone=pBone->parent){
1572                                 if (pBone==bone){
1573                                         skip=1;
1574                                         break;
1575                                 }
1576                         }
1577
1578                         if (skip)
1579                                 continue;
1580
1581                         sprintf (qsort_ptr[numbones], "|%s%%x%d", curBone->name, index);
1582                         numbones++;
1583                 }
1584         }
1585         qsort (qsort_ptr, numbones, sizeof (qsort_ptr[0]),
1586                    ( int (*)(const void *, const void *) ) strcmp);
1587
1588         for (i=0; i < numbones; ++i) {
1589                 sprintf (string, "%s%s", string, qsort_ptr[i]);
1590         }
1591
1592         if (qsort_ptr)
1593                 MEM_freeN(qsort_ptr);
1594 }
1595
1596 static void constraint_ebone_name_fix(ListBase *conlist, EditBone *eBone)
1597 {
1598
1599         bConstraint *curcon;
1600         char *subtarget;
1601
1602         for (curcon = conlist->first; curcon; curcon=curcon->next){
1603                 subtarget = get_con_subtarget_name(curcon, G.obedit);
1604                 if (subtarget)
1605                         if (!strcmp(subtarget,eBone->oldname) )
1606                                 strcpy(subtarget, eBone->name);
1607         }
1608 }
1609
1610 // called in outliner too...
1611 void validate_editbonebutton(EditBone *eBone)
1612 {
1613         EditBone        *prev;
1614         bAction         *act=NULL;
1615         bActionChannel *chan;
1616         Base *base;
1617         bPose        *pose;
1618         bPoseChannel *pchan;
1619
1620         /* Separate the bone from the G.edbo */
1621         prev=eBone->prev;
1622         BLI_remlink (&G.edbo, eBone);
1623
1624         /*      Validate the name */
1625         unique_editbone_name (eBone->name);
1626
1627         /* Re-insert the bone */
1628         if (prev)
1629                 BLI_insertlink(&G.edbo, prev, eBone);
1630         else
1631                 BLI_addhead (&G.edbo, eBone);
1632
1633         /* Rename *action* channel if necessary */
1634         if (G.obedit)
1635                 act = G.obedit->action;
1636
1637         if (act && !act->id.lib){
1638                 /*      Find the appropriate channel
1639                  */
1640                 for (chan = act->chanbase.first; chan; chan=chan->next){
1641                         if (!strcmp (chan->name, eBone->oldname)){
1642                                 strcpy (chan->name, eBone->name);
1643                         }
1644                 }
1645                 allqueue(REDRAWACTION, 0);
1646         }
1647
1648         /* Rename the *pose* channel, if it exists (thus making sure
1649          * that the constraints are still valid)
1650          */
1651         pose = G.obedit->pose;
1652         if (pose) {
1653                 pchan = get_pose_channel(pose, eBone->oldname);
1654                 if (pchan) {
1655                         strcpy (pchan->name, eBone->name);
1656                 }
1657         }
1658
1659         /* Update the parenting info of any users */
1660         /*      Yes, I know this is the worst thing you have ever seen. */
1661
1662         for (base = G.scene->base.first; base; base=base->next){
1663                 Object *ob = base->object;
1664                 ListBase *conlist;
1665
1666                 /* See if an object is parented to this armature */
1667                 if (ob->parent && ob->partype==PARBONE &&
1668                         (ob->parent->type==OB_ARMATURE) &&
1669                         (ob->parent->data == G.obedit->data)){
1670                         if (!strcmp(ob->parsubstr, eBone->oldname))
1671                                 strcpy(ob->parsubstr, eBone->name);
1672                 }
1673
1674                 /* Update any constraints to use the new bone name */
1675                 conlist = &ob->constraints;
1676                 constraint_ebone_name_fix(conlist, eBone);
1677
1678                 switch (ob->type){
1679                         case OB_ARMATURE:
1680                                 if (ob->pose){
1681                                         for (pchan = ob->pose->chanbase.first; pchan;
1682                                                  pchan=pchan->next){
1683                                                 conlist = &pchan->constraints;
1684                                                 constraint_ebone_name_fix(conlist, eBone);
1685                                         }
1686                                 }
1687                                 break;
1688                         default:
1689                                 break;
1690         }
1691
1692         }
1693
1694         exit_editmode(0);       /* To ensure new names make it to the edit armature */
1695
1696 }
1697
1698 static void validate_editbonebutton_cb(void *bonev, void *arg2_unused)
1699 {
1700         EditBone *curBone= bonev;
1701         validate_editbonebutton(curBone);
1702 }
1703
1704 /* called from outliner now, can be used for buttons in posemode too */
1705 /* current Armature should be active Object */
1706 /* after this function, the Bones in Armature are re-allocced! */
1707 void rename_bone_ext(char *oldname, char *newname)
1708 {
1709         EditBone *ebone;
1710         int temp_editmode= 0;
1711
1712         /* since the naming functions work only on editArmature, we have to... */
1713         if(G.obedit!=OBACT) exit_editmode(2);
1714         if(G.obedit==NULL) {
1715                 G.obedit= OBACT;
1716                 make_editArmature();
1717                 temp_editmode= 1;
1718         }
1719         
1720         /* now find the eBone with oldname */
1721         for(ebone= G.edbo.first; ebone; ebone= ebone->next)
1722                 if(strcmp(ebone->name, oldname)==0) break;
1723
1724         if(ebone) {
1725                 strcpy(ebone->oldname, oldname);
1726                 strcpy(ebone->name, newname);
1727                 validate_editbonebutton(ebone); // does exit_editmode... tsk, so armature bones pointers are invalid now
1728         }
1729         if(temp_editmode) exit_editmode(2);
1730         
1731 }
1732
1733
1734 static void armature_rest_pos_func(void *notused1, void *notused2) 
1735 {
1736         clear_object_constraint_status(OBACT);
1737         make_displists_by_armature(OBACT);
1738 }
1739
1740 static void editing_panel_armature_type(Object *ob, bArmature *arm)
1741 {
1742         uiBlock         *block;
1743         uiBut       *but;
1744         int                     bx=148, by=100;
1745
1746         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_type", UI_EMBOSS, UI_HELV, curarea->win);
1747         if(uiNewPanel(curarea, block, "Armature", "Editing", 320, 0, 318, 204)==0) return;
1748
1749         but = uiDefButI(block, TOG|BIT|ARM_RESTPOSBIT,REDRAWVIEW3D,
1750                                         "Rest Pos", bx,by,97,20, &arm->flag, 0, 0, 0, 0,
1751                                         "Disable all animation for this object");
1752         uiButSetFunc(but, armature_rest_pos_func, NULL, NULL);
1753
1754         uiBlockBeginAlign(block);
1755         uiDefButI(block, TOG|BIT|ARM_DRAWAXESBIT,REDRAWVIEW3D, "Draw Axes", bx,by-46,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
1756         uiDefButI(block, TOG|BIT|ARM_DRAWNAMESBIT,REDRAWVIEW3D, "Draw Names", bx,by-69,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
1757         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");
1758         uiDefButI(block, TOG|BIT|ARM_DELAYBIT,REDRAWVIEW3D,
1759                           "Delay Deform", bx,by-115,97,20, &arm->flag, 0, 0, 0, 0,
1760                           "Don't deform children when manipulating bones in pose mode");
1761 }
1762
1763 static void editing_panel_armature_bones(Object *ob, bArmature *arm)
1764 {
1765         uiBlock         *block;
1766         uiBut           *but;
1767         EditBone        *curBone;
1768         char            *boneString=NULL;
1769         int                     bx=148, by=180;
1770         int                     index;
1771
1772         /* Draw the bone name block */
1773
1774         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_bones", UI_EMBOSS, UI_HELV, curarea->win);
1775         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
1776
1777         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1778         /* so first we make it default height */
1779         uiNewPanelHeight(block, 204);
1780
1781
1782         uiDefBut(block, LABEL, 0, "Selected Bones", bx,by,158,18, 0, 0, 0, 0, 0, "Only show in Armature Editmode");
1783         by-=20;
1784         for (curBone=G.edbo.first, index=0; curBone; curBone=curBone->next, index++){
1785                 if (curBone->flag & (BONE_SELECTED)) {
1786
1787                         /* Hide in posemode flag */
1788                         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");
1789
1790                         /*      Bone naming button */
1791                         strcpy (curBone->oldname, curBone->name);
1792                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:", bx-10,by,117,18, &curBone->name, 0, 24, 0, 0, "Change the bone name");
1793                         uiButSetFunc(but, validate_editbonebutton_cb, curBone, NULL);
1794
1795                         uiDefBut(block, LABEL, 0, "child of", bx+107,by,73,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1796
1797                         boneString = malloc((BLI_countlist(&G.edbo) * 64)+64);
1798                         build_bonestring (boneString, curBone);
1799
1800                         curBone->parNr = editbone_to_parnr(curBone->parent);
1801                         but = uiDefButI(block, MENU,REDRAWVIEW3D, boneString, bx+180,by,120,18, &curBone->parNr, 0.0, 0.0, 0.0, 0.0, "Parent");
1802                         uiButSetFunc(but, parnr_to_editbone_cb, curBone, NULL);
1803
1804                         free(boneString);
1805
1806                         /* IK to parent flag */
1807                         if (curBone->parent){
1808                                 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");
1809                                 uiButSetFunc(but, attach_bone_to_parent_cb, curBone, NULL);
1810                         }
1811
1812                         /* Dist and weight buttons */
1813                         uiBlockBeginAlign(block);
1814                         but=uiDefButS(block, MENU, REDRAWVIEW3D,
1815                                                         "Skinnable %x0|" "Unskinnable %x1|" "Head %x2|"
1816                                                         "Neck %x3|" "Back %x4|" "Shoulder %x5|" "Arm %x6|"
1817                                                         "Hand %x7|" "Finger %x8|" "Thumb %x9|" "Pelvis %x10|"
1818                                                         "Leg %x11|" "Foot %x12|" "Toe %x13|" "Tentacle %x14",
1819                                                         bx-10,by-19,117,18, &curBone->boneclass, 0.0, 0.0, 0.0, 0.0,
1820                                                         "Classification of armature element");
1821
1822                         /* Dist and weight buttons */
1823                         uiDefButF(block, NUM,REDRAWVIEW3D, "Dist:", bx+110, by-19,
1824                                                 105, 18, &curBone->dist, 0.0, 1000.0, 10.0, 0.0,
1825                                                 "Bone deformation distance");
1826                         uiDefButF(block, NUM,REDRAWVIEW3D, "Weight:", bx+223, by-19,
1827                                                 110, 18, &curBone->weight, 0.0F, 1000.0F,
1828                                                 10.0F, 0.0F, "Bone deformation weight");
1829
1830                         uiBlockEndAlign(block);
1831                         by-=42;
1832                 }
1833         }
1834
1835         if(by<0) {
1836                 uiNewPanelHeight(block, 204 - by);
1837         }
1838
1839 }
1840
1841
1842 /* *************************** MESH ******************************** */
1843
1844 void do_meshbuts(unsigned short event)
1845 {
1846         Object *ob;
1847         Mesh *me;
1848         float fac;
1849         short randfac;
1850
1851         ob= OBACT;
1852         if(ob && ob->type==OB_MESH) {
1853
1854                 me= get_mesh(ob);
1855                 if(me==0) return;
1856
1857                 switch(event) {
1858                 case B_AUTOVGROUP:
1859                         if (!get_armature(ob->parent)){
1860                                 error ("Mesh must be the child of an armature");
1861                                 break;
1862                         }
1863                                 /* Verify that there are vertex groups for bones in armature */
1864                                 /* Remove selected vertices from all defgroups */
1865                                 /* Perform assignment for selected vertices */
1866
1867                         allqueue (REDRAWVIEW3D, 1);
1868                         break;
1869                 case B_NEWVGROUP:
1870                         add_defgroup (G.obedit);
1871                         scrarea_queue_winredraw(curarea);
1872                         break;
1873                 case B_DELVGROUP:
1874                         del_defgroup (G.obedit);
1875                         allqueue (REDRAWVIEW3D, 1);
1876                         BIF_undo_push("Delete vertex group");
1877                         break;
1878                 case B_ASSIGNVGROUP:
1879                         assign_verts_defgroup ();
1880                         allqueue (REDRAWVIEW3D, 1);
1881                         BIF_undo_push("Assign to vertex group");
1882                         break;
1883                 case B_REMOVEVGROUP:
1884                         remove_verts_defgroup (0);
1885                         allqueue (REDRAWVIEW3D, 1);
1886                         BIF_undo_push("Remove from vertex group");
1887                         break;
1888                 case B_SELVGROUP:
1889                         sel_verts_defgroup(1);
1890                         allqueue (REDRAWVIEW3D, 1);
1891                         break;
1892                 case B_DESELVGROUP:
1893                         sel_verts_defgroup(0);
1894                         allqueue (REDRAWVIEW3D, 1);
1895                         break;
1896                 case B_DELSTICKY:
1897
1898                         if(me->msticky) MEM_freeN(me->msticky);
1899                         me->msticky= NULL;
1900                         allqueue(REDRAWBUTSEDIT, 0);
1901                         break;
1902                 case B_MAKESTICKY:
1903                         RE_make_sticky();
1904                         allqueue(REDRAWBUTSEDIT, 0);
1905                         break;
1906                 
1907                 case B_MAKEEDGES:
1908                         /* in editmode we only have to set edge pointer */
1909                         if(ob==G.obedit) {
1910                                 me->medge= MEM_callocN(sizeof(MEdge), "fake mesh edge");
1911                                 me->totedge= 1;
1912                         }
1913                         else make_edges(me);
1914                         allqueue(REDRAWBUTSEDIT, 0);
1915                         break;
1916                 case B_DELEDGES:
1917                         if(me->medge) MEM_freeN(me->medge);
1918                         me->medge= NULL;
1919                         me->totedge= 0;
1920                         makeDispList(ob);
1921                         allqueue(REDRAWBUTSEDIT, 0);
1922                         allqueue(REDRAWVIEW3D, 0);
1923                         break;
1924                         
1925                 case B_MAKEVERTCOL:
1926                         make_vertexcol();
1927                         break;
1928                 case B_DELVERTCOL:
1929                         if(me->mcol) MEM_freeN(me->mcol);
1930                         me->mcol= NULL;
1931                         G.f &= ~G_VERTEXPAINT;
1932                         freedisplist(&(ob->disp));
1933                         allqueue(REDRAWBUTSEDIT, 0);
1934                         allqueue(REDRAWVIEW3D, 0);
1935                         break;
1936
1937                 case B_MAKE_TFACES:
1938                         make_tfaces(me);
1939                         allqueue(REDRAWBUTSEDIT, 0);
1940                         break;
1941
1942                 case B_DEL_TFACES:
1943                         if(me->tface) MEM_freeN(me->tface);
1944                         me->tface= 0;
1945                         G.f &= ~G_FACESELECT;
1946                         allqueue(REDRAWBUTSEDIT, 0);
1947                         allqueue(REDRAWVIEW3D, 0);
1948                         allqueue(REDRAWIMAGE, 0);
1949                         break;
1950
1951                 case B_FLIPNORM:
1952                         if(G.obedit) {
1953                                 flip_editnormals();
1954                         }
1955                         else flipnorm_mesh( get_mesh(ob) );
1956
1957                         allqueue(REDRAWVIEW3D, 0);
1958                         break;
1959
1960                 case B_DECIM_FACES:
1961                         decimate_faces();
1962                         break;
1963                 case B_DECIM_CANCEL:
1964                         decimate_cancel();
1965                         break;
1966                 case B_DECIM_APPLY:
1967                         decimate_apply();
1968                         break;
1969
1970                 case B_SLOWERDRAW:
1971                         slowerdraw();
1972                         break;
1973                 case B_FASTERDRAW:
1974                         fasterdraw();
1975                         break;
1976                 }
1977         }
1978
1979         if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return;
1980
1981         switch(event) {
1982         case B_SPIN:
1983                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 0);
1984                 break;
1985         case B_SPINDUP:
1986                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 1);
1987                 break;
1988         case B_EXTR:
1989                 G.f |= G_DISABLE_OK;
1990                 if( select_area(SPACE_VIEW3D)) extrude_mesh();
1991                 G.f -= G_DISABLE_OK;
1992                 break;
1993         case B_SCREW:
1994                 if( select_area(SPACE_VIEW3D)) screw_mesh(step, turn);
1995                 break;
1996         case B_EXTREP:
1997                 if( select_area(SPACE_VIEW3D)) extrude_repeat_mesh(step, extr_offs);
1998                 break;
1999         case B_SPLIT:
2000                 G.f |= G_DISABLE_OK;
2001                 split_mesh();
2002                 G.f -= G_DISABLE_OK;
2003                 break;
2004         case B_REMDOUB:
2005                 notice("Removed: %d", removedoublesflag(1, doublimit));
2006                 allqueue(REDRAWVIEW3D, 0);
2007                 BIF_undo_push("Rem Doubles");
2008                 break;
2009         case B_SUBDIV:
2010                 waitcursor(1);
2011                 subdivideflag(1, 0.0, editbutflag & B_BEAUTY);
2012                 countall();
2013                 waitcursor(0);
2014                 allqueue(REDRAWVIEW3D, 0);
2015                 BIF_undo_push("Subdivide");
2016                 break;
2017         case B_FRACSUBDIV:
2018                 randfac= 10;
2019                 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
2020                 waitcursor(1);
2021                 fac= -( (float)randfac )/100;
2022                 subdivideflag(1, fac, editbutflag & B_BEAUTY);
2023                 countall();
2024                 waitcursor(0);
2025                 allqueue(REDRAWVIEW3D, 0);
2026                 BIF_undo_push("Fractal Subdivide");
2027                 break;
2028         case B_XSORT:
2029                 if( select_area(SPACE_VIEW3D)) xsortvert_flag(1);
2030                 break;
2031         case B_HASH:
2032                 hashvert_flag(1);
2033                 break;
2034         case B_TOSPHERE:
2035                 vertices_to_sphere();
2036                 break;
2037         case B_VERTEXNOISE:
2038                 vertexnoise();
2039                 break;
2040         case B_VERTEXSMOOTH:
2041                 vertexsmooth();
2042                 break;
2043         case B_DRAWEDGES:
2044                 G.f &= ~G_DRAWCREASES;
2045                 allqueue(REDRAWBUTSEDIT, 0);
2046                 allqueue(REDRAWVIEW3D, 0);
2047                 break;
2048         case B_DRAWCREASES:
2049                 G.f &= ~G_DRAWEDGES;
2050                 allqueue(REDRAWBUTSEDIT, 0);
2051                 allqueue(REDRAWVIEW3D, 0);
2052                 break;
2053         }
2054         /* WATCH IT: previous events only in editmode! */
2055 }
2056
2057 static void editing_panel_mesh_tools(Object *ob, Mesh *me)
2058 {
2059         uiBlock *block;
2060
2061         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools", UI_EMBOSS, UI_HELV, curarea->win);
2062         if(uiNewPanel(curarea, block, "Mesh Tools", "Editing", 640, 0, 318, 204)==0) return;
2063
2064         uiBlockBeginAlign(block);
2065         uiDefButS(block, TOG|BIT|2, 0, "Beauty",                10,195,80,19, &editbutflag, 0, 0, 0, 0, "Causes 'Subdivide' to split faces in halves instead of quarters");
2066         uiDefBut(block, BUT,B_SUBDIV,"Subdivide",               90,195,80,19, 0, 0, 0, 0, 0, "Splits selected faces into halves or quarters");
2067         uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd", 170,195,85,19, 0, 0, 0, 0, 0, "Subdivides selected faces with a random factor");
2068
2069         uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",              10,175,80,19, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
2070         uiDefBut(block, BUT,B_HASH,"Hash",                              90,175,80,19, 0, 0, 0, 0, 0, "Randomizes selected vertice sequence data");
2071         uiDefBut(block, BUT,B_XSORT,"Xsort",                    170,175,85,19, 0, 0, 0, 0, 0, "Sorts selected vertice data in the X direction");
2072
2073         uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",             10,155,80,19, 0, 0, 0, 0, 0, "Moves selected vertices outwards into a spherical shape");
2074         uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",    90,155,80,19, 0, 0, 0, 0, 0, "Flattens angles of selected faces");
2075         uiDefBut(block, BUT,B_SPLIT,"Split",                    170,155,85,19, 0, 0, 0, 0, 0, "Splits selected verts to separate sub-mesh.");
2076
2077         uiDefBut(block, BUT,B_FLIPNORM,"Flip Normals",  10,135,80,19, 0, 0, 0, 0, 0, "Toggles the direction of the selected face's normals");
2078         uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    90,135,80,19, 0, 0, 0, 0, 0, "Removes duplicates from selected vertices");
2079         uiDefButF(block, NUM, B_DIFF, "Limit:",                 170,135,85,19, &doublimit, 0.0001, 1.0, 10, 0, "Specifies the max distance 'Rem Doubles' will consider vertices as 'doubled'");
2080         uiBlockEndAlign(block);
2081
2082         uiDefBut(block, BUT,B_EXTR,"Extrude",                   10,105,245,24, 0, 0, 0, 0, 0, "Converts selected edges to faces and selects the new vertices");
2083
2084         uiBlockBeginAlign(block);
2085         uiDefBut(block, BUT,B_SCREW,"Screw",                    10,75,80,24, 0, 0, 0, 0, 0, "Activates the screw tool");  // Bish - This could use some more definition
2086         uiDefBut(block, BUT,B_SPIN, "Spin",                             90,75,80,24, 0, 0, 0, 0, 0, "Extrudes the selected vertices in a circle around the cursor in the indicated viewport");
2087         uiDefBut(block, BUT,B_SPINDUP,"Spin Dup",               170,75,85,24, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a circle around the cursor in the indicated viewport");
2088
2089         uiDefButS(block, NUM, B_DIFF, "Degr:",                  10,55,80,19, &degr,10.0,360.0, 0, 0, "Specifies the number of degrees 'Spin' revolves");
2090         uiDefButS(block, NUM, B_DIFF, "Steps:",                 90,55,80,19, &step,1.0,180.0, 0, 0, "Specifies the total number of 'Spin' slices");
2091         uiDefButS(block, NUM, B_DIFF, "Turns:",                 170,55,85,19, &turn,1.0,360.0, 0, 0, "Specifies the number of revolutions the screw turns");
2092         uiDefButS(block, TOG|BIT|1, B_DIFF, "Keep Original",10,35,160,19, &editbutflag, 0, 0, 0, 0, "Keeps a copy of the original vertices and faces after executing tools");
2093         uiDefButS(block, TOG|BIT|0, B_DIFF, "Clockwise",        170,35,85,19, &editbutflag, 0, 0, 0, 0, "Specifies the direction for 'Screw' and 'Spin'");
2094
2095         uiBlockBeginAlign(block);
2096         uiDefBut(block, BUT,B_EXTREP, "Extrude Dup",    10,10,120,19, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a straight line away from the current viewport");
2097         uiDefButF(block, NUM, B_DIFF, "Offset:",                130,10,125,19, &extr_offs, 0.01, 100.0, 100, 0, "Sets the distance between each copy for 'Extrude Dup'");
2098         uiBlockEndAlign(block);
2099 }
2100
2101 static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
2102 {
2103         unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
2104 }
2105
2106
2107
2108 static void editing_panel_mesh_tools1(Object *ob, Mesh *me)
2109 {
2110         uiBlock *block;
2111
2112
2113         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools1", UI_EMBOSS, UI_HELV, curarea->win);
2114         if(uiNewPanel(curarea, block, "Mesh Tools 1", "Editing", 960, 0, 318, 204)==0) return;
2115
2116         uiBlockBeginAlign(block);
2117         uiDefBut(block, BUT,B_DOCENTRE, "Centre",       955, 200, 160, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
2118         uiDefBut(block, BUT,B_HIDE,             "Hide",         1115, 200,  160, 19, 0, 0, 0, 0, 0, "Hides selected faces");
2119         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  955, 180, 160, 19, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
2120         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               1115, 180,  160, 19, 0, 0, 0, 0, 0, "Reveals selected faces");
2121         uiBlockEndAlign(block);
2122
2123         uiBlockBeginAlign(block);
2124         uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",       955, 131, 150, 19, &editbutsize, 0.001, 2.0, 10, 0, "Sets the length to use when displaying face normals");
2125         uiDefButI(block, TOG|BIT|6, REDRAWVIEW3D, "Draw Normals",       955,110,150,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
2126         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces",         955,88,150,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
2127         uiDefButI(block, TOG|BIT|18, REDRAWVIEW3D, "Draw Edges",        955,66,150,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
2128         uiDefButI(block, TOG|BIT|19, REDRAWVIEW3D, "Draw Creases",      955,44,150,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
2129         uiDefButI(block, TOG|BIT|20, REDRAWVIEW3D, "Draw Seams",        955,22,150,19, &G.f, 0, 0, 0, 0, "Displays UV unwrapping seams");
2130         uiDefButI(block, TOG|BIT|11, 0, "All Edges",                    955, 0,150,19, &G.f, 0, 0, 0, 0, "Displays all edges in object mode without optimization");
2131         uiBlockEndAlign(block);
2132         
2133         /* Measurement drawing options */
2134         uiBlockBeginAlign(block);
2135         uiDefButI(block, TOG|BIT|22, REDRAWVIEW3D, "Edge Length",       1125,131,150,19, &G.f, 0, 0, 0, 0, "Displays selected edge lengths");
2136         uiDefButI(block, TOG|BIT|24, REDRAWVIEW3D, "Edge Angles",       1125,88,150,19,  &G.f, 0, 0, 0, 0, "Displays the angles in the selected edges in degrees");
2137         uiDefButI(block, TOG|BIT|23, REDRAWVIEW3D, "Face Area",         1125,110,150,19, &G.f, 0, 0, 0, 0, "Displays the area of selected faces");
2138         uiBlockEndAlign(block);
2139
2140 }
2141
2142 static void editing_panel_links(Object *ob)
2143 {
2144         uiBlock *block;
2145         ID *id, *idfrom;
2146         int *poin, xco=143;
2147         float min;
2148         Material *ma;
2149         char str[64];
2150         uiBut *but;
2151
2152         block= uiNewBlock(&curarea->uiblocks, "editing_panel_links", UI_EMBOSS, UI_HELV, curarea->win);
2153         if(uiNewPanel(curarea, block, "Link and Materials", "Editing", 0, 0, 318, 204)==0) return;
2154
2155         buttons_active_id(&id, &idfrom);
2156
2157         if(id) {
2158                 int alone= 0;
2159                 int local= 0;
2160                 int browse= B_EDITBROWSE;
2161
2162                 if(ob->type==OB_MESH) {
2163                         browse= B_MESHBROWSE;
2164                         alone= B_MESHALONE;
2165                         local= B_MESHLOCAL;
2166                         uiSetButLock(G.obedit!=0, "Unable to perform function in EditMode");
2167                 }
2168                 else if(ob->type==OB_MBALL) {
2169                         alone= B_MBALLALONE;
2170                         local= B_MBALLLOCAL;
2171                 }
2172                 else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
2173                         alone= B_CURVEALONE;
2174                         local= B_CURVELOCAL;
2175                 }
2176                 else if(ob->type==OB_CAMERA) {
2177                         alone= B_CAMERAALONE;
2178                         local= B_CAMERALOCAL;
2179                 }
2180                 else if(ob->type==OB_LAMP) {
2181                         alone= B_LAMPALONE;
2182                         local= B_LAMPLOCAL;
2183                 }
2184                 else if (ob->type==OB_ARMATURE){
2185                         alone = B_ARMALONE;
2186                         local = B_ARMLOCAL;
2187                 }
2188                 else if(ob->type==OB_LATTICE) {
2189                         alone= B_LATTALONE;
2190                         local= B_LATTLOCAL;
2191                 }
2192                 uiBlockSetCol(block, TH_BUT_SETTING2);
2193                 xco= std_libbuttons(block, 143, 180, 0, NULL, browse, id, idfrom, &(G.buts->menunr), alone, local, 0, 0, B_KEEPDATA);
2194                 uiBlockSetCol(block, TH_AUTO);
2195         }
2196         if(ob) {
2197                 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.");
2198                 uiButSetFunc(but, test_idbutton_cb, ob->id.name, NULL);
2199         }
2200
2201
2202
2203         /* to be sure */
2204         if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL);
2205         else return;
2206
2207
2208         if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag );
2209         else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag );
2210         else poin= &( ((Curve *)ob->data)->texflag );
2211         uiDefButI(block, TOG|BIT|0, B_AUTOTEX, "AutoTexSpace",  143,15,140,19, poin, 0, 0, 0, 0, "Adjusts active object's texture space automatically when transforming object");
2212
2213         sprintf(str,"%d Mat:", ob->totcol);
2214         if(ob->totcol) min= 1.0; else min= 0.0;
2215         ma= give_current_material(ob, ob->actcol);
2216
2217         if(ma) uiDefBut(block, LABEL, 0, ma->id.name+2, 318,153, 103, 20, 0, 0, 0, 0, 0, "");
2218
2219         uiBlockBeginAlign(block);
2220         if(ma) uiDefButF(block, COL, B_REDR, "",                        292,123,31,30, &(ma->r), 0, 0, 0, 0, "");
2221         uiDefButC(block, NUM, B_REDR,   str,            324,123,100,30, &ob->actcol, min, (float)(ob->totcol), 0, 0, "Displays total number of material indices and the current index");
2222         uiDefBut(block, BUT,B_MATWICH,  "?",            424,123,30,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces");
2223
2224         uiBlockBeginAlign(block);
2225         uiDefBut(block, BUT,B_MATNEW,   "New",          292,98,80,20, 0, 0, 0, 0, 0, "Adds a new Material index");
2226         uiDefBut(block, BUT,B_MATDEL,   "Delete",       374,98,80,20, 0, 0, 0, 0, 0, "Deletes this Material index");
2227         uiDefBut(block, BUT,B_MATSEL,   "Select",       292,76,80,20, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index");
2228         uiDefBut(block, BUT,B_MATDESEL, "Deselect",     374,76,80,20, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber");
2229         uiDefBut(block, BUT,B_MATASS,   "Assign",       292,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces");
2230
2231         uiBlockBeginAlign(block);
2232         uiDefBut(block, BUT,B_SETSMOOTH,"Set Smooth",   291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces");
2233         uiDefBut(block, BUT,B_SETSOLID, "Set Solid",    373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces");
2234         uiBlockEndAlign(block);
2235
2236         /* vertex group... partially editmode... */
2237         if(ob->type==OB_MESH) {
2238                 uiBut *but;
2239                 int     defCount;
2240                 bDeformGroup    *defGroup;
2241                 char *s, *menustr;
2242                 bDeformGroup *dg;
2243                 int min, index;
2244                 char (*qsort_ptr)[32] = NULL;
2245
2246                 uiDefBut(block, LABEL,0,"Vertex Groups",
2247                                  143,153,130,20, 0, 0, 0, 0, 0, "");
2248
2249                 defCount=BLI_countlist(&ob->defbase);
2250
2251                 if (!defCount) min=0;
2252                 else min=1;
2253
2254                 if (defCount > 0) {
2255                         /*
2256                          * This will hold the group names temporarily
2257                          * so we can sort them
2258                          */
2259                         qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr[0]),
2260                                                                          "qsort_ptr");
2261                         for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
2262                                 snprintf (qsort_ptr[index - 1], sizeof (qsort_ptr[0]),
2263                                                   "%s%%x%d|", dg->name, index);
2264                         }
2265
2266                         qsort (qsort_ptr, defCount, sizeof (qsort_ptr[0]),
2267                                    ( int (*)(const void *, const void *) ) strcmp);
2268                 }
2269
2270                 s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
2271                 for (index = 0; index < defCount; index++) {
2272                         int cnt= sprintf (s, "%s", qsort_ptr[index]);
2273                         if (cnt>0) s+= cnt;
2274                 }
2275
2276                 if (qsort_ptr)
2277                   MEM_freeN (qsort_ptr);
2278
2279                 uiBlockBeginAlign(block);
2280                 if (defCount)
2281                         uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr,
2282                                           143, 132,18,21, &ob->actdef, min, defCount, 0, 0,
2283                                           "Browses available vertex groups");
2284
2285                 MEM_freeN (menustr);
2286
2287                 if (ob->actdef){
2288                         defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
2289                         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.)");
2290                         uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
2291
2292                         uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          143, 111, 140, 21, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
2293                 }
2294                 uiBlockEndAlign(block);
2295
2296                 if (G.obedit && G.obedit==ob){
2297                         uiBlockBeginAlign(block);
2298         /*              uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assigns deformation groups"); */
2299                         uiDefBut(block, BUT,B_NEWVGROUP,"New",                  143,90,70,21, 0, 0, 0, 0, 0, "Creates a new vertex group");
2300                         uiDefBut(block, BUT,B_DELVGROUP,"Delete",               213,90,70,21, 0, 0, 0, 0, 0, "Removes the current vertex group");
2301
2302                         uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",    143,69,70,21, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group");
2303                         uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",    213,69,70,21, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group");
2304
2305                         uiDefBut(block, BUT,B_SELVGROUP,"Select",               143,48,70,21, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group");
2306                         uiDefBut(block, BUT,B_DESELVGROUP,"Desel.",             213,48,70,21, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group");
2307                         uiBlockEndAlign(block);
2308                 }
2309         }
2310
2311
2312 }
2313
2314 /* *************************** FACE/PAINT *************************** */
2315
2316 void do_fpaintbuts(unsigned short event)
2317 {
2318         Mesh *me;
2319         Object *ob;
2320         extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
2321
2322         ob= OBACT;
2323         if(ob==0) return;
2324
2325         switch(event) {
2326
2327         case B_VPGAMMA:
2328                 vpaint_dogamma();
2329                 break;
2330         case B_COPY_TF_MODE:
2331         case B_COPY_TF_UV:
2332         case B_COPY_TF_COL:
2333         case B_COPY_TF_TEX:
2334                 me= get_mesh(ob);
2335                 if(me && me->tface) {
2336 /*                      extern TFace *lasttface; */
2337                         TFace *tface= me->tface;
2338                         int a= me->totface;
2339
2340                         set_lasttface();
2341                         if(lasttface) {
2342
2343                                 while(a--) {
2344                                         if(tface!=lasttface && (tface->flag & TF_SELECT)) {
2345                                                 if(event==B_COPY_TF_MODE) {
2346                                                         tface->mode= lasttface->mode;
2347                                                         tface->transp= lasttface->transp;
2348                                                 }
2349                                                 else if(event==B_COPY_TF_UV) {
2350                                                         memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
2351                                                         tface->tpage= lasttface->tpage;
2352                                                         tface->tile= lasttface->tile;
2353
2354                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2355                                                         else tface->mode &= ~TF_TILES;
2356
2357                                                 }
2358                                                 else if(event==B_COPY_TF_TEX) {
2359                                                         tface->tpage= lasttface->tpage;
2360                                                         tface->tile= lasttface->tile;
2361
2362                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2363                                                         else tface->mode &= ~TF_TILES;
2364                                                 }
2365                                                 else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
2366                                         }
2367                                         tface++;
2368                                 }
2369                         }
2370                         do_shared_vertexcol(me);
2371                         allqueue(REDRAWVIEW3D, 0);
2372                         allqueue(REDRAWIMAGE, 0);
2373                 }
2374                 break;
2375         case B_SET_VCOL:
2376                 clear_vpaint_selectedfaces();
2377                 break;
2378         case B_REDR_3D_IMA:
2379                 allqueue(REDRAWVIEW3D, 0);
2380                 allqueue(REDRAWIMAGE, 0);
2381                 break;
2382         case B_ASSIGNMESH:
2383
2384                 test_object_materials(ob->data);
2385                 allqueue(REDRAWVIEW3D, 0);
2386                 allqueue(REDRAWBUTSEDIT, 0);
2387                 break;
2388
2389         case B_TFACE_HALO:
2390                 set_lasttface();
2391                 if(lasttface) {
2392                         lasttface->mode &= ~TF_BILLBOARD2;
2393                         allqueue(REDRAWBUTSEDIT, 0);
2394                 }
2395                 break;
2396
2397         case B_TFACE_BILLB:
2398                 set_lasttface();
2399                 if(lasttface) {
2400                         lasttface->mode &= ~TF_BILLBOARD;
2401                         allqueue(REDRAWBUTSEDIT, 0);
2402                 }
2403                 break;
2404         }
2405 }
2406
2407
2408 /* -------------------- MODE: vpaint faceselect ------------------- */
2409
2410 static void editing_panel_mesh_paint(void)
2411 {
2412         extern VPaint Gvp;         /* from vpaint */
2413         uiBlock *block;
2414
2415         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_paint", UI_EMBOSS, UI_HELV, curarea->win);
2416         if(uiNewPanel(curarea, block, "Paint", "Editing", 640, 0, 318, 204)==0) return;
2417
2418     uiBlockBeginAlign(block);
2419         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");
2420         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");
2421         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");
2422         uiBlockEndAlign(block);
2423
2424         uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2425         uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2426
2427         uiDefButF(block, COL, B_REDR, "",               1176,99,28,80, &(Gvp.r), 0, 0, 0, B_VPCOLSLI, "");
2428         uiBlockBeginAlign(block);
2429         uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
2430         uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
2431         uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
2432         uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
2433         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");
2434
2435         uiBlockBeginAlign(block);
2436         uiDefButS(block, TOG|BIT|1, 0, "Area",          979,50,81,19, &Gvp.flag, 0, 0, 0, 0, "Vertex paint evaluates the area of the face the brush covers (otherwise vertices only)");
2437         uiDefButS(block, TOG|BIT|2, 0, "Soft",          1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
2438         uiDefButS(block, TOG|BIT|3, 0, "Normals",       1174,50,102,19, &Gvp.flag, 0, 0, 0, 0, "Vertex paint applies the vertex normal before painting");
2439
2440         uiBlockBeginAlign(block);
2441         uiDefBut(block, BUT, B_VPGAMMA, "Set",  979,30,81,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
2442         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");
2443         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");
2444         uiBlockEndAlign(block);
2445
2446         uiDefBut(block, BUT, B_SET_VCOL, "Set VertCol", 979,5,81,20, 0, 0, 0, 0, 0, "Set Vertex colour of selection to current (Shift+K)");
2447
2448 }
2449
2450 static void editing_panel_mesh_texface(void)
2451 {
2452         uiBlock *block;
2453         extern TFace *lasttface;
2454
2455         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_texface", UI_EMBOSS, UI_HELV, curarea->win);
2456         if(uiNewPanel(curarea, block, "Texture face", "Editing", 960, 0, 318, 204)==0) return;
2457
2458         set_lasttface();        // checks for ob type
2459         if(lasttface) {
2460
2461                 uiBlockBeginAlign(block);
2462                 uiDefButS(block, TOG|BIT|2, B_REDR_3D_IMA, "Tex",       600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
2463                 uiDefButS(block, TOG|BIT|7, B_REDR_3D_IMA, "Tiles",     660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
2464                 uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Light",      720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
2465                 uiDefButS(block, TOG|BIT|10, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
2466                 uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
2467
2468                 uiBlockBeginAlign(block);
2469                 uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "Shared",     600,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Blend vertex colours across face when vertices are shared");
2470                 uiDefButS(block, TOG|BIT|9, REDRAWVIEW3D, "Twoside",660,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
2471                 uiDefButS(block, TOG|BIT|11, REDRAWVIEW3D, "ObColor",720,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
2472
2473                 uiBlockBeginAlign(block);
2474                 uiDefButS(block, TOG|BIT|8, B_TFACE_HALO, "Halo",       600,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
2475                 uiDefButS(block, TOG|BIT|12, B_TFACE_BILLB, "Billboard",660,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
2476                 uiDefButS(block, TOG|BIT|13, REDRAWVIEW3D, "Shadow", 720,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
2477                 uiDefButS(block, TOG|BIT|14, REDRAWVIEW3D, "Text", 780,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
2478
2479                 uiBlockBeginAlign(block);
2480                 uiBlockSetCol(block, TH_BUT_SETTING1);
2481                 uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,80,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
2482                 uiDefButC(block, ROW, REDRAWVIEW3D, "Add",              660,80,60,19, &lasttface->transp, 2.0, 1.0, 0, 0, "Render face transparent and add colour of face");
2483                 uiDefButC(block, ROW, REDRAWVIEW3D, "Alpha",    720,80,60,19, &lasttface->transp, 2.0, 2.0, 0, 0, "Render polygon transparent, depending on alpha channel of the texture");
2484
2485                 uiBlockSetCol(block, TH_AUTO);
2486                 uiBlockBeginAlign(block);
2487                 uiDefBut(block, BUT, B_COPY_TF_MODE, "Copy DrawMode", 600,7,117,28, 0, 0, 0, 0, 0, "Copy the drawmode from active face to selected faces");
2488                 uiDefBut(block, BUT, B_COPY_TF_UV, "Copy UV+tex",         721,7,85,28, 0, 0, 0, 0, 0, "Copy UV information and textures from active face to selected faces");
2489                 uiDefBut(block, BUT, B_COPY_TF_COL, "Copy VertCol",       809,7,103,28, 0, 0, 0, 0, 0, "Copy vertex colours from active face to selected faces");
2490         }
2491
2492 }
2493
2494 void do_uvautocalculationbuts(unsigned short event)
2495 {
2496         switch(event) {
2497         case B_UVAUTO_STD1:
2498         case B_UVAUTO_STD2:
2499         case B_UVAUTO_STD4:
2500         case B_UVAUTO_STD8:
2501         case B_UVAUTO_CUBE:
2502                 calculate_uv_map(event);
2503                 break;
2504         case B_UVAUTO_BOUNDS1:
2505         case B_UVAUTO_BOUNDS2:
2506         case B_UVAUTO_BOUNDS4:
2507         case B_UVAUTO_BOUNDS8:
2508         case B_UVAUTO_SPHERE:
2509         case B_UVAUTO_CYLINDER:
2510         case B_UVAUTO_WINDOW:
2511                 if(select_area(SPACE_VIEW3D)) calculate_uv_map(event);
2512                 break;
2513         case B_UVAUTO_LSCM:
2514                 unwrap_lscm();
2515                 break;
2516         }
2517 }
2518
2519 static void editing_panel_mesh_uvautocalculation(void)
2520 {
2521         uiBlock *block;
2522         int butH= 19, butHB= 20, row= 180, butS= 10;
2523
2524         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_uvautocalculation", UI_EMBOSS, UI_HELV, curarea->win);
2525         /* make this a tab of "Texture face" to save screen space*/
2526         uiNewPanelTabbed("Texture face", "Editing");
2527         if(uiNewPanel(curarea, block, "UV Calculation", "Editing", 960, 0, 318, 204)==0)
2528                 return;
2529
2530         uiBlockBeginAlign(block);
2531         uiDefBut(block, BUT, B_UVAUTO_LSCM,"LSCM Unwrap",100,row,200,butH, 0, 0, 0, 0, 0, "Applies conformal UV mapping, preserving local angles");
2532         uiBlockEndAlign(block);
2533         row-= butHB+butS;
2534
2535         uiBlockBeginAlign(block);
2536         uiDefBut(block, BUT, B_UVAUTO_STD1,"Standard",100,row,100,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping");
2537         uiDefBut(block, BUT, B_UVAUTO_STD2,"/2",200,row,33,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/2");
2538         uiDefBut(block, BUT, B_UVAUTO_STD4,"/4",233,row,34,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/4");
2539         uiDefBut(block, BUT, B_UVAUTO_STD8,"/8",267,row,33,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/8");
2540         uiBlockEndAlign(block);
2541         row-= butHB+butS;
2542
2543         uiBlockBeginAlign(block);
2544         uiDefBut(block, BUT, B_UVAUTO_BOUNDS1,"Bounds",100,row,100,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/1");
2545         uiDefBut(block, BUT, B_UVAUTO_BOUNDS2,"/2",200,row,33,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/2");
2546         uiDefBut(block, BUT, B_UVAUTO_BOUNDS4,"/4",233,row,34,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/4");
2547         uiDefBut(block, BUT, B_UVAUTO_BOUNDS8,"/8",267,row,33,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/8");
2548         uiDefBut(block, BUT, B_UVAUTO_WINDOW,"From Window",100,row-butH,200,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping from window");
2549         uiBlockEndAlign(block);
2550         row-= 2*butHB+butS;
2551
2552         uiBlockBeginAlign(block);
2553         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces", 100,row,200,butH, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
2554         uiDefButI(block,TOG|BIT|18,REDRAWVIEW3D,"Draw Edges",100,row-butHB,200,butH,&G.f, 2.0, 0, 0, 0,  "Displays edges of visible faces");
2555         uiDefButI(block,TOG|BIT|21,REDRAWVIEW3D,"Draw Hidden Edges",100,row-2*butHB,200,butH,&G.f, 2.0, 1.0, 0, 0,  "Displays edges of hidden faces");
2556         uiDefButI(block,TOG|BIT|20,REDRAWVIEW3D,"Draw Seams",100,row-3*butHB,200,butH,&G.f, 2.0, 2.0, 0, 0,  "Displays UV unwrapping seams");
2557         uiBlockEndAlign(block);
2558         row-= 4*butHB+butS;
2559
2560         row= 180;
2561
2562         uiBlockBeginAlign(block);
2563         uiDefBut(block, BUT, B_UVAUTO_CUBE,"Cube",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cube UV mapping");
2564         uiDefButF(block, NUM,B_UVAUTO_CUBESIZE ,"Size:",315,row-butHB,200,butH, &uv_calc_cubesize, 0.0001, 100.0, 10, 3, "Defines the cubemap size");
2565         uiBlockEndAlign(block);
2566         row-= 2*butHB+butS;
2567
2568         uiBlockBeginAlign(block);
2569         uiDefBut(block, BUT, B_UVAUTO_SPHERE,"Sphere",315,row,200,butH, 0, 0, 0, 0, 0, "Applies spherical UV mapping");
2570         uiBlockEndAlign(block);
2571         row-= butHB+butS;
2572
2573         uiBlockBeginAlign(block);
2574         uiDefBut(block, BUT, B_UVAUTO_CYLINDER,"Cylinder",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cylindrical UV mapping");
2575         uiDefButF(block, NUM,B_UVAUTO_CYLRADIUS ,"Radius:",315,row-butHB,200,butH, &uv_calc_radius, 0.1, 100.0, 10, 3, "Defines the radius of the UV mapping cylinder");
2576         uiBlockEndAlign(block);
2577         row-= 2*butHB+butS;
2578
2579
2580         uiBlockBeginAlign(block);
2581         uiDefButS(block, ROW,B_UVAUTO_FACE,"View Aligns Face",315,row,200,butH, &uv_calc_mapdir,2.0, 1.0, 0.0,0.0, "View is on equator for cylindrical and spherical UV mapping");
2582         uiDefButS(block, ROW,B_UVAUTO_TOP,"VA Top",315,row-butHB,100,butH, &uv_calc_mapdir,2.0, 0.0, 0.0,0.0, "View is on poles for cylindrical and spherical UV mapping");
2583         uiDefButS(block, ROW,B_UVAUTO_TOP,"Al Obj",415,row-butHB,100,butH, &uv_calc_mapdir,2.0, 2.0, 0.0,0.0, "Align to object for cylindrical and spherical UV mapping");
2584         uiBlockEndAlign(block);
2585         row-= 2*butHB+butS;
2586
2587         uiBlockBeginAlign(block);
2588         uiDefButS(block, ROW,B_UVAUTO_ALIGNX,"Polar ZX",315,row,100,butH, &uv_calc_mapalign,2.0, 0.0, 0.0,0.0, "Polar 0 is X for cylindrical and spherical UV mapping");
2589         uiDefButS(block, ROW,B_UVAUTO_ALIGNY,"Polar ZY",415,row,100,butH, &uv_calc_mapalign,2.0, 1.0, 0.0,0.0, "Polar 0 is Y for cylindrical and spherical UV mapping");
2590         uiBlockEndAlign(block);
2591 }
2592
2593 /* this is a mode context sensitive system */
2594
2595 void editing_panels()
2596 {
2597         Object *ob;
2598         Curve *cu;
2599         MetaBall *mb;
2600         Lattice *lt;
2601         bArmature *arm;
2602         Camera *cam;
2603
2604         ob= OBACT;
2605         if(ob==NULL) return;
2606
2607         switch(ob->type) {
2608         case OB_MESH:
2609                 editing_panel_links(ob); // no editmode!
2610                 editing_panel_mesh_type(ob, ob->data);  // no editmode!
2611                 /* modes */
2612                 if(G.obedit) {
2613                         editing_panel_mesh_tools(ob, ob->data); // no editmode!
2614                         editing_panel_mesh_tools1(ob, ob->data); // no editmode!
2615                 }
2616                 else {
2617                         if(G.f & G_FACESELECT) {
2618                                 editing_panel_mesh_texface();
2619                                 editing_panel_mesh_uvautocalculation();
2620                         }
2621                         if(G.f & (G_VERTEXPAINT | G_TEXTUREPAINT | G_WEIGHTPAINT) ) {
2622                                 editing_panel_mesh_paint();
2623                         }
2624                 }
2625                 break;
2626
2627         case OB_CURVE:
2628         case OB_SURF:
2629                 cu= ob->data;
2630                 editing_panel_links(ob); // no editmode!
2631                 editing_panel_curve_type(ob, cu);
2632                 if(G.obedit) {
2633                         editing_panel_curve_tools(ob, cu);
2634                         editing_panel_curve_tools1(ob, cu);
2635                 }
2636                 break;
2637
2638         case OB_MBALL:
2639                 mb= ob->data;
2640                 editing_panel_links(ob); // no editmode!
2641                 editing_panel_mball_type(ob, mb);
2642                 if(G.obedit) {
2643                         editing_panel_mball_tools(ob, mb);
2644                 }
2645                 break;
2646
2647         case OB_FONT:
2648                 cu= ob->data;
2649                 editing_panel_links(ob); // no editmode!
2650                 editing_panel_curve_type(ob, cu);
2651                 editing_panel_font_type(ob, cu);
2652                 break;
2653
2654         case OB_LATTICE:
2655                 lt= ob->data;
2656                 editing_panel_links(ob); // no editmode!
2657                 editing_panel_lattice_type(ob, lt);
2658                 break;
2659
2660         case OB_LAMP:
2661                 editing_panel_links(ob); // no editmode!
2662                 break;
2663
2664         case OB_EMPTY:
2665                 editing_panel_links(ob); // no editmode!
2666                 break;
2667
2668         case OB_CAMERA:
2669                 cam= ob->data;
2670                 editing_panel_links(ob); // no editmode!
2671                 editing_panel_camera_type(ob, cam);
2672                 /* yafray: extra panel for dof parameters */
2673                 if (G.scene->r.renderer==R_YAFRAY) editing_panel_camera_yafraydof(ob, cam);
2674                 break;
2675
2676         case OB_ARMATURE:
2677                 arm= ob->data;
2678                 editing_panel_links(ob); // no editmode!
2679                 editing_panel_armature_type(ob, arm);
2680                 if(G.obedit) {
2681                         editing_panel_armature_bones(ob, arm);
2682                 }
2683                 break;
2684         }
2685
2686 }