Little warming-up getting-feet-wet coding project. :)
[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                         
1266                         sprintf(str, "%.4f", prlen);
1267                         uiDefBut(block, BUT, B_PRINTLEN,                "PrintLen",     600,135,75,19, 0, 0, 0, 0, 0, "");
1268                         uiDefBut(block, LABEL, 0, str,                                          675,135,75,19, 0, 1.0, 0, 0, 0, "");
1269                         
1270                         uiBlockBeginAlign(block);
1271                         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");
1272                         uiDefButS(block, TOG|BIT|3, B_RECALCPATH, "CurvePath",  600,30,75,19 , &cu->flag, 0, 0, 0, 0, "Enables curve to become translation path");
1273                         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");
1274                         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");
1275                         uiDefButS(block, TOG|BIT|8, REDRAWVIEW3D, "PathDist Offs", 600,-10,150,19, &cu->flag, 0, 0, 0, 0, "Children will use TimeOffs value as path distance offset");
1276
1277                         uiBlockEndAlign(block);
1278                 }
1279
1280                 uiBlockBeginAlign(block);
1281                 uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 760,160,120,19, &cu->resolu, 1.0, 128.0, 0, 0, "Default resolution");
1282                 uiDefBut(block, BUT, B_SETRESOLU, "Set",                880,160,30,19, 0, 0, 0, 0, 0, "Set resolution for interpolation");
1283
1284                 uiBlockBeginAlign(block);
1285                 uiDefButF(block, NUM, B_MAKEDISP, "Width:",             760,90,150,19, &cu->width, 0.0, 2.0, 1, 0, "Make interpolated result thinner or fatter");
1286                 uiDefButF(block, NUM, B_MAKEDISP, "Ext1:",              760,70,150,19, &cu->ext1, 0.0, 5.0, 10, 0, "Extrude depth");
1287                 uiDefButF(block, NUM, B_MAKEDISP, "Ext2:",              760,50,150,19, &cu->ext2, 0.0, 2.0, 1, 0, "Extrude beveling depth");
1288                 uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  760,30,150,19, &cu->bevresol, 0.0, 10.0, 0, 0, "Amount of bevels");
1289                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "BevOb:",         760,10,150,19, &cu->bevobj, "Curve object name that defines the bevel shape");
1290                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "TaperOb:",               760,-10,150,19, &cu->taperobj, "Curve object name that defines the taper (width)");
1291
1292                 uiBlockBeginAlign(block);
1293                 uiBlockSetCol(block, TH_BUT_SETTING1);
1294                 uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 760,130,50,19, &cu->flag, 0, 0, 0, 0, "Draw filled back for curves");
1295                 uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",810,130,50,19, &cu->flag, 0, 0, 0, 0, "Draw filled front for curves");
1296                 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");
1297
1298
1299         }
1300
1301 }
1302
1303
1304 /* *************************** CAMERA ******************************** */
1305
1306
1307 static void editing_panel_camera_type(Object *ob, Camera *cam)
1308 {
1309         uiBlock *block;
1310         float grid=0.0;
1311
1312         if(G.vd) grid= G.vd->grid;
1313         if(grid<1.0) grid= 1.0;
1314
1315         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_type", UI_EMBOSS, UI_HELV, curarea->win);
1316         if(uiNewPanel(curarea, block, "Camera", "Editing", 320, 0, 318, 204)==0) return;
1317
1318         if(cam->type==CAM_ORTHO)
1319                 uiDefButF(block, NUM,REDRAWVIEW3D, "Scale:", 470,178,160,20, &cam->ortho_scale, 0.01, 1000.0, 50, 0, "Specify the ortho scaling of the used camera");
1320         else
1321                 uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:", 470,178,160,20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
1322
1323         uiBlockBeginAlign(block);
1324         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");
1325         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");
1326         uiBlockEndAlign(block);
1327
1328         uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
1329
1330         uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
1331         uiBlockBeginAlign(block);
1332         uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
1333         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");
1334         uiBlockEndAlign(block);
1335 }
1336
1337 /* yafray: extra camera panel to set Depth-of-Field parameters */
1338 static void editing_panel_camera_yafraydof(Object *ob, Camera *cam)
1339 {
1340         uiBlock *block;
1341         char *mst1, *mst2;
1342
1343         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_yafraydof", UI_EMBOSS, UI_HELV, curarea->win);
1344         uiNewPanelTabbed("Camera", "Editing");
1345         if(uiNewPanel(curarea, block, "Yafray DoF", "Editing", 320, 0, 318, 204)==0) return;
1346
1347         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)");
1348         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)");
1349
1350         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");
1351
1352         uiDefBut(block, LABEL, 0, "Bokeh", 10, 60, 180, 19, 0, 0.0, 0.0, 0, 0, "");
1353         mst1 = "Bokeh Type%t|Disk1%x0|Disk2%x1|Triangle%x2|Square%x3|Pentagon%x4|Hexagon%x5|Ring%x6";
1354         uiDefButS(block, MENU, B_REDR, mst1, 10, 40, 89, 20, &cam->YF_bkhtype, 0.0, 0.0, 0, 0, "Sets Bokeh type");
1355         
1356         if ((cam->YF_bkhtype!=0) && (cam->YF_bkhtype!=6)) {
1357                 mst2 = "Bokeh Bias%t|Uniform%x0|Center%x1|Edge%x2";
1358                 uiDefButS(block, MENU, B_REDR, mst2, 100, 40, 90, 20, &cam->YF_bkhbias, 0.0, 0.0, 0, 0, "Sets Bokeh bias");
1359                 if (cam->YF_bkhtype>1)
1360                         uiDefButF(block, NUM, B_DIFF, "Rotation:", 10, 15, 180, 20, &cam->YF_bkhrot, 0.0, 360.0, 100, 0, "Shape rotation amount in degrees");
1361         }
1362
1363 }
1364
1365
1366 /* *************************** MBALL ******************************** */
1367
1368 void do_mballbuts(unsigned short event)
1369 {
1370         switch(event) {
1371         case B_RECALCMBALL:
1372                 makeDispList(OBACT);
1373                 allqueue(REDRAWVIEW3D, 0);
1374                 break;
1375         }
1376 }
1377
1378 static void editing_panel_mball_type(Object *ob, MetaBall *mb)
1379 {
1380         uiBlock *block;
1381
1382         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_type", UI_EMBOSS, UI_HELV, curarea->win);
1383         if(uiNewPanel(curarea, block, "MetaBall", "Editing", 320, 0, 318, 204)==0) return;
1384
1385         ob= find_basis_mball(ob);
1386         mb= ob->data;
1387
1388         uiBlockBeginAlign(block);
1389         uiDefButF(block, NUM, B_RECALCMBALL, "Wiresize:",       470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "Polygonization resolution in 3d window");
1390         uiDefButF(block, NUM, 0, "Rendersize:",                 470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "Polygonization resolution in rendering");
1391         uiDefButF(block, NUM, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "Defines influence of meta elements");
1392
1393         uiBlockBeginAlign(block);
1394         uiBlockSetCol(block, TH_BUT_SETTING1);
1395         uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
1396         uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "While editing, always updates");
1397         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");
1398         uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "While editing, updates without polygonization");
1399         uiDefButS(block, ROW, B_DIFF, "Never",          471, 25, 120, 19, &mb->flag, 0.0, 3.0, 0, 0, "While editing, doesn't update");
1400
1401 }
1402
1403 static void editing_panel_mball_tools(Object *ob, MetaBall *mb)
1404 {
1405         extern MetaElem *lastelem;
1406         uiBlock *block;
1407
1408         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_tools", UI_EMBOSS, UI_HELV, curarea->win);
1409         if( uiNewPanel(curarea, block, "MetaBall tools", "Editing", 640, 0, 318, 204)==0) return;
1410
1411         if(ob==G.obedit && lastelem) {
1412                 uiBlockBeginAlign(block);
1413                 uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "Stiffness for active meta");
1414                 if(lastelem->type!=MB_BALL)
1415                 uiDefButF(block, NUM, B_RECALCMBALL, "dx:",             750,158,250,19, &lastelem->expx, 0.0, 20.0, 0, 0, "X size for active meta");
1416                 if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
1417                 uiDefButF(block, NUM, B_RECALCMBALL, "dy:",             750,138,250,19, &lastelem->expy, 0.0, 20.0, 0, 0, "Y size for active meta");
1418
1419                 if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
1420                 uiDefButF(block, NUM, B_RECALCMBALL, "dz:",             750,118,250,19, &lastelem->expz, 0.0, 20.0, 0, 0, "Z size for active meta");
1421                 uiBlockEndAlign(block);
1422
1423                 uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "Draw active meta as Ball");
1424                 uiBlockBeginAlign(block);
1425                 uiDefButS(block, ROW, B_RECALCMBALL, "Tube",                    753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "Draw active meta as Ball");
1426                 uiDefButS(block, ROW, B_RECALCMBALL, "Plane",                   814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "Draw active meta as Plane");
1427                 uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid",                876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "Draw active meta as Ellipsoid");
1428                 uiDefButS(block, ROW, B_RECALCMBALL, "Cube",                    938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "Draw active meta as Cube");
1429                 uiBlockEndAlign(block);
1430
1431                 uiDefButS(block, TOG|BIT|1, B_RECALCMBALL, "Negative",753,16,250,19, &lastelem->flag, 0, 0, 0, 0, "Make active meta creating holes");
1432
1433         }
1434
1435 }
1436
1437
1438 /* *************************** LATTICE ******************************** */
1439
1440 void do_latticebuts(unsigned short event)
1441 {
1442         Object *ob;
1443         Lattice *lt;
1444
1445         ob= OBACT;
1446         if(ob->type!=OB_LATTICE) return;
1447
1448         switch(event) {
1449         case B_RESIZELAT:
1450                 if(ob) {
1451                         if(ob==G.obedit) resizelattice(editLatt);
1452                         else resizelattice(ob->data);
1453                 }
1454                 allqueue(REDRAWVIEW3D, 0);
1455                 break;
1456         case B_DRAWLAT:
1457                 if(ob==G.obedit) calc_lattverts_ext();
1458                 allqueue(REDRAWVIEW3D, 0);
1459                 break;
1460         case B_LATTCHANGED:
1461
1462                 lt= ob->data;
1463                 if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
1464
1465                 make_displists_by_parent(ob);
1466
1467                 allqueue(REDRAWVIEW3D, 0);
1468
1469                 break;
1470         }
1471 }
1472
1473 static void editing_panel_lattice_type(Object *ob, Lattice *lt)
1474 {
1475         uiBlock *block;
1476
1477         block= uiNewBlock(&curarea->uiblocks, "editing_panel_lattice_type", UI_EMBOSS, UI_HELV, curarea->win);
1478         if(uiNewPanel(curarea, block, "Lattice", "Editing", 320, 0, 318, 204)==0) return;
1479
1480
1481         uiSetButLock(lt->key!=0, "Not with VertexKeys");
1482         uiSetButLock(ob==G.obedit, "Unable to perform function in EditMode");
1483
1484         uiBlockBeginAlign(block);
1485
1486         uiDefButS(block, NUM, B_RESIZELAT,      "U:",                           469, 178,100,19, &lt->pntsu, 1.0, 64.0, 0, 0, "Points in U direction");
1487         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1488         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1489         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1490
1491         uiDefButS(block, NUM, B_RESIZELAT,      "V:",                           469, 156,100,19, &lt->pntsv, 1.0, 64.0, 0, 0, "Points in V direction");
1492         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 156, 40, 19, &lt->typev, 2.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1493         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 156, 40, 19, &lt->typev, 2.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1494         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 156, 40, 19, &lt->typev, 2.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1495
1496         uiDefButS(block, NUM, B_RESIZELAT,      "W:",                           469, 134,100,19, &lt->pntsw, 1.0, 64.0, 0, 0, "Points in W direction");
1497         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 134, 40, 19, &lt->typew, 3.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1498         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 134, 40, 19, &lt->typew, 3.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1499         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 134, 40, 19, &lt->typew, 3.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1500
1501         uiBlockEndAlign(block);
1502
1503         uiDefBut(block, BUT, B_RESIZELAT,       "Make Regular",         469,98,102,31, 0, 0, 0, 0, 0, "Make Lattice regular");
1504
1505         uiClearButLock();
1506         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");
1507
1508         if(lt->key) {
1509                 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");
1510                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        469,40,120,19, &lt->key->type, 0, 0, 0, 0, "Use relative keys (instead of absolute)");
1511         }
1512
1513 }
1514
1515 /* *************************** ARMATURE ******************************** */
1516
1517
1518
1519 static int editbone_to_parnr (EditBone *bone)
1520 {
1521         EditBone *ebone;
1522         int     index;
1523
1524         for (ebone=G.edbo.first, index=0; ebone; ebone=ebone->next, index++){
1525                 if (ebone==bone)
1526                         return index;
1527         }
1528
1529         return -1;
1530 }
1531
1532 static void parnr_to_editbone(EditBone *bone)
1533 {
1534         if (bone->parNr == -1){
1535                 bone->parent = NULL;
1536                 bone->flag &= ~BONE_IK_TOPARENT;
1537         }
1538         else{
1539                 bone->parent = BLI_findlink(&G.edbo, bone->parNr);
1540                 attach_bone_to_parent(bone);
1541         }
1542 }
1543
1544 static void parnr_to_editbone_cb(void *bonev, void *arg2_unused)
1545 {
1546         EditBone *curBone= bonev;
1547         parnr_to_editbone(curBone);
1548 }
1549
1550 static void build_bonestring (char *string, EditBone *bone)
1551 {
1552         EditBone *curBone;
1553         EditBone *pBone;
1554         int             skip=0;
1555         int             index, numbones, i;
1556         char (*qsort_ptr)[32] = NULL;
1557
1558         sprintf (string, "Parent%%t| %%x%d", -1);       /* That space is there
1559                                                                                                  * for a reason
1560                                                                                                  */
1561
1562         numbones = BLI_countlist(&G.edbo);
1563
1564         /*
1565          * This will hold the bone names temporarily so we can sort them
1566          */
1567         if (numbones > 0)
1568                 qsort_ptr = MEM_callocN (numbones * sizeof (qsort_ptr[0]),
1569                                                                  "qsort_ptr");
1570
1571         numbones = 0;
1572         for (curBone = G.edbo.first, index=0; curBone;
1573                  curBone=curBone->next, index++){
1574                 /* Make sure this is a valid child */
1575                 if (curBone != bone){
1576                         skip=0;
1577                         for (pBone=curBone->parent; pBone; pBone=pBone->parent){
1578                                 if (pBone==bone){
1579                                         skip=1;
1580                                         break;
1581                                 }
1582                         }
1583
1584                         if (skip)
1585                                 continue;
1586
1587                         sprintf (qsort_ptr[numbones], "|%s%%x%d", curBone->name, index);
1588                         numbones++;
1589                 }
1590         }
1591         qsort (qsort_ptr, numbones, sizeof (qsort_ptr[0]),
1592                    ( int (*)(const void *, const void *) ) strcmp);
1593
1594         for (i=0; i < numbones; ++i) {
1595                 sprintf (string, "%s%s", string, qsort_ptr[i]);
1596         }
1597
1598         if (qsort_ptr)
1599                 MEM_freeN(qsort_ptr);
1600 }
1601
1602 static void constraint_ebone_name_fix(ListBase *conlist, EditBone *eBone)
1603 {
1604
1605         bConstraint *curcon;
1606         char *subtarget;
1607
1608         for (curcon = conlist->first; curcon; curcon=curcon->next){
1609                 subtarget = get_con_subtarget_name(curcon, G.obedit);
1610                 if (subtarget)
1611                         if (!strcmp(subtarget,eBone->oldname) )
1612                                 strcpy(subtarget, eBone->name);
1613         }
1614 }
1615
1616 // called in outliner too...
1617 void validate_editbonebutton(EditBone *eBone)
1618 {
1619         EditBone        *prev;
1620         bAction         *act=NULL;
1621         bActionChannel *chan;
1622         Base *base;
1623         bPose        *pose;
1624         bPoseChannel *pchan;
1625
1626         /* Separate the bone from the G.edbo */
1627         prev=eBone->prev;
1628         BLI_remlink (&G.edbo, eBone);
1629
1630         /*      Validate the name */
1631         unique_editbone_name (eBone->name);
1632
1633         /* Re-insert the bone */
1634         if (prev)
1635                 BLI_insertlink(&G.edbo, prev, eBone);
1636         else
1637                 BLI_addhead (&G.edbo, eBone);
1638
1639         /* Rename *action* channel if necessary */
1640         if (G.obedit)
1641                 act = G.obedit->action;
1642
1643         if (act && !act->id.lib){
1644                 /*      Find the appropriate channel
1645                  */
1646                 for (chan = act->chanbase.first; chan; chan=chan->next){
1647                         if (!strcmp (chan->name, eBone->oldname)){
1648                                 strcpy (chan->name, eBone->name);
1649                         }
1650                 }
1651                 allqueue(REDRAWACTION, 0);
1652         }
1653
1654         /* Rename the *pose* channel, if it exists (thus making sure
1655          * that the constraints are still valid)
1656          */
1657         pose = G.obedit->pose;
1658         if (pose) {
1659                 pchan = get_pose_channel(pose, eBone->oldname);
1660                 if (pchan) {
1661                         strcpy (pchan->name, eBone->name);
1662                 }
1663         }
1664
1665         /* Update the parenting info of any users */
1666         /*      Yes, I know this is the worst thing you have ever seen. */
1667
1668         for (base = G.scene->base.first; base; base=base->next){
1669                 Object *ob = base->object;
1670                 ListBase *conlist;
1671
1672                 /* See if an object is parented to this armature */
1673                 if (ob->parent && ob->partype==PARBONE &&
1674                         (ob->parent->type==OB_ARMATURE) &&
1675                         (ob->parent->data == G.obedit->data)){
1676                         if (!strcmp(ob->parsubstr, eBone->oldname))
1677                                 strcpy(ob->parsubstr, eBone->name);
1678                 }
1679
1680                 /* Update any constraints to use the new bone name */
1681                 conlist = &ob->constraints;
1682                 constraint_ebone_name_fix(conlist, eBone);
1683
1684                 switch (ob->type){
1685                         case OB_ARMATURE:
1686                                 if (ob->pose){
1687                                         for (pchan = ob->pose->chanbase.first; pchan;
1688                                                  pchan=pchan->next){
1689                                                 conlist = &pchan->constraints;
1690                                                 constraint_ebone_name_fix(conlist, eBone);
1691                                         }
1692                                 }
1693                                 break;
1694                         default:
1695                                 break;
1696         }
1697
1698         }
1699
1700         exit_editmode(0);       /* To ensure new names make it to the edit armature */
1701
1702 }
1703
1704 static void validate_editbonebutton_cb(void *bonev, void *arg2_unused)
1705 {
1706         EditBone *curBone= bonev;
1707         validate_editbonebutton(curBone);
1708 }
1709
1710 /* called from outliner now, can be used for buttons in posemode too */
1711 /* current Armature should be active Object */
1712 /* after this function, the Bones in Armature are re-allocced! */
1713 void rename_bone_ext(char *oldname, char *newname)
1714 {
1715         EditBone *ebone;
1716         int temp_editmode= 0;
1717
1718         /* since the naming functions work only on editArmature, we have to... */
1719         if(G.obedit!=OBACT) exit_editmode(2);
1720         if(G.obedit==NULL) {
1721                 G.obedit= OBACT;
1722                 make_editArmature();
1723                 temp_editmode= 1;
1724         }
1725         
1726         /* now find the eBone with oldname */
1727         for(ebone= G.edbo.first; ebone; ebone= ebone->next)
1728                 if(strcmp(ebone->name, oldname)==0) break;
1729
1730         if(ebone) {
1731                 strcpy(ebone->oldname, oldname);
1732                 strcpy(ebone->name, newname);
1733                 validate_editbonebutton(ebone); // does exit_editmode... tsk, so armature bones pointers are invalid now
1734         }
1735         if(temp_editmode) exit_editmode(2);
1736         
1737 }
1738
1739
1740 static void armature_rest_pos_func(void *notused1, void *notused2) 
1741 {
1742         clear_object_constraint_status(OBACT);
1743         make_displists_by_armature(OBACT);
1744 }
1745
1746 static void editing_panel_armature_type(Object *ob, bArmature *arm)
1747 {
1748         uiBlock         *block;
1749         uiBut       *but;
1750         int                     bx=148, by=100;
1751
1752         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_type", UI_EMBOSS, UI_HELV, curarea->win);
1753         if(uiNewPanel(curarea, block, "Armature", "Editing", 320, 0, 318, 204)==0) return;
1754
1755         but = uiDefButI(block, TOG|BIT|ARM_RESTPOSBIT,REDRAWVIEW3D,
1756                                         "Rest Pos", bx,by,97,20, &arm->flag, 0, 0, 0, 0,
1757                                         "Disable all animation for this object");
1758         uiButSetFunc(but, armature_rest_pos_func, NULL, NULL);
1759
1760         uiBlockBeginAlign(block);
1761         uiDefButI(block, TOG|BIT|ARM_DRAWAXESBIT,REDRAWVIEW3D, "Draw Axes", bx,by-46,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
1762         uiDefButI(block, TOG|BIT|ARM_DRAWNAMESBIT,REDRAWVIEW3D, "Draw Names", bx,by-69,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
1763         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");
1764         uiDefButI(block, TOG|BIT|ARM_DELAYBIT,REDRAWVIEW3D,
1765                           "Delay Deform", bx,by-115,97,20, &arm->flag, 0, 0, 0, 0,
1766                           "Don't deform children when manipulating bones in pose mode");
1767 }
1768
1769 static void editing_panel_armature_bones(Object *ob, bArmature *arm)
1770 {
1771         uiBlock         *block;
1772         uiBut           *but;
1773         EditBone        *curBone;
1774         char            *boneString=NULL;
1775         int                     bx=148, by=180;
1776         int                     index;
1777
1778         /* Draw the bone name block */
1779
1780         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_bones", UI_EMBOSS, UI_HELV, curarea->win);
1781         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
1782
1783         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1784         /* so first we make it default height */
1785         uiNewPanelHeight(block, 204);
1786
1787
1788         uiDefBut(block, LABEL, 0, "Selected Bones", bx,by,158,18, 0, 0, 0, 0, 0, "Only show in Armature Editmode");
1789         by-=20;
1790         for (curBone=G.edbo.first, index=0; curBone; curBone=curBone->next, index++){
1791                 if (curBone->flag & (BONE_SELECTED)) {
1792
1793                         /* Hide in posemode flag */
1794                         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");
1795
1796                         /*      Bone naming button */
1797                         strcpy (curBone->oldname, curBone->name);
1798                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:", bx-10,by,117,18, &curBone->name, 0, 24, 0, 0, "Change the bone name");
1799                         uiButSetFunc(but, validate_editbonebutton_cb, curBone, NULL);
1800
1801                         uiDefBut(block, LABEL, 0, "child of", bx+107,by,73,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1802
1803                         boneString = malloc((BLI_countlist(&G.edbo) * 64)+64);
1804                         build_bonestring (boneString, curBone);
1805
1806                         curBone->parNr = editbone_to_parnr(curBone->parent);
1807                         but = uiDefButI(block, MENU,REDRAWVIEW3D, boneString, bx+180,by,120,18, &curBone->parNr, 0.0, 0.0, 0.0, 0.0, "Parent");
1808                         uiButSetFunc(but, parnr_to_editbone_cb, curBone, NULL);
1809
1810                         free(boneString);
1811
1812                         /* IK to parent flag */
1813                         if (curBone->parent){
1814                                 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");
1815                                 uiButSetFunc(but, attach_bone_to_parent_cb, curBone, NULL);
1816                         }
1817
1818                         /* Dist and weight buttons */
1819                         uiBlockBeginAlign(block);
1820                         but=uiDefButS(block, MENU, REDRAWVIEW3D,
1821                                                         "Skinnable %x0|" "Unskinnable %x1|" "Head %x2|"
1822                                                         "Neck %x3|" "Back %x4|" "Shoulder %x5|" "Arm %x6|"
1823                                                         "Hand %x7|" "Finger %x8|" "Thumb %x9|" "Pelvis %x10|"
1824                                                         "Leg %x11|" "Foot %x12|" "Toe %x13|" "Tentacle %x14",
1825                                                         bx-10,by-19,117,18, &curBone->boneclass, 0.0, 0.0, 0.0, 0.0,
1826                                                         "Classification of armature element");
1827
1828                         /* Dist and weight buttons */
1829                         uiDefButF(block, NUM,REDRAWVIEW3D, "Dist:", bx+110, by-19,
1830                                                 105, 18, &curBone->dist, 0.0, 1000.0, 10.0, 0.0,
1831                                                 "Bone deformation distance");
1832                         uiDefButF(block, NUM,REDRAWVIEW3D, "Weight:", bx+223, by-19,
1833                                                 110, 18, &curBone->weight, 0.0F, 1000.0F,
1834                                                 10.0F, 0.0F, "Bone deformation weight");
1835
1836                         uiBlockEndAlign(block);
1837                         by-=42;
1838                 }
1839         }
1840
1841         if(by<0) {
1842                 uiNewPanelHeight(block, 204 - by);
1843         }
1844
1845 }
1846
1847
1848 /* *************************** MESH ******************************** */
1849
1850 void do_meshbuts(unsigned short event)
1851 {
1852         Object *ob;
1853         Mesh *me;
1854         float fac;
1855         short randfac;
1856
1857         ob= OBACT;
1858         if(ob && ob->type==OB_MESH) {
1859
1860                 me= get_mesh(ob);
1861                 if(me==0) return;
1862
1863                 switch(event) {
1864                 case B_AUTOVGROUP:
1865                         if (!get_armature(ob->parent)){
1866                                 error ("Mesh must be the child of an armature");
1867                                 break;
1868                         }
1869                                 /* Verify that there are vertex groups for bones in armature */
1870                                 /* Remove selected vertices from all defgroups */
1871                                 /* Perform assignment for selected vertices */
1872
1873                         allqueue (REDRAWVIEW3D, 1);
1874                         break;
1875                 case B_NEWVGROUP:
1876                         add_defgroup (G.obedit);
1877                         scrarea_queue_winredraw(curarea);
1878                         break;
1879                 case B_DELVGROUP:
1880                         del_defgroup (G.obedit);
1881                         allqueue (REDRAWVIEW3D, 1);
1882                         BIF_undo_push("Delete vertex group");
1883                         break;
1884                 case B_ASSIGNVGROUP:
1885                         assign_verts_defgroup ();
1886                         allqueue (REDRAWVIEW3D, 1);
1887                         BIF_undo_push("Assign to vertex group");
1888                         break;
1889                 case B_REMOVEVGROUP:
1890                         remove_verts_defgroup (0);
1891                         allqueue (REDRAWVIEW3D, 1);
1892                         BIF_undo_push("Remove from vertex group");
1893                         break;
1894                 case B_SELVGROUP:
1895                         sel_verts_defgroup(1);
1896                         allqueue (REDRAWVIEW3D, 1);
1897                         break;
1898                 case B_DESELVGROUP:
1899                         sel_verts_defgroup(0);
1900                         allqueue (REDRAWVIEW3D, 1);
1901                         break;
1902                 case B_DELSTICKY:
1903
1904                         if(me->msticky) MEM_freeN(me->msticky);
1905                         me->msticky= NULL;
1906                         allqueue(REDRAWBUTSEDIT, 0);
1907                         break;
1908                 case B_MAKESTICKY:
1909                         RE_make_sticky();
1910                         allqueue(REDRAWBUTSEDIT, 0);
1911                         break;
1912                 
1913                 case B_MAKEEDGES:
1914                         /* in editmode we only have to set edge pointer */
1915                         if(ob==G.obedit) {
1916                                 me->medge= MEM_callocN(sizeof(MEdge), "fake mesh edge");
1917                                 me->totedge= 1;
1918                         }
1919                         else make_edges(me);
1920                         allqueue(REDRAWBUTSEDIT, 0);
1921                         break;
1922                 case B_DELEDGES:
1923                         if(me->medge) MEM_freeN(me->medge);
1924                         me->medge= NULL;
1925                         me->totedge= 0;
1926                         makeDispList(ob);
1927                         allqueue(REDRAWBUTSEDIT, 0);
1928                         allqueue(REDRAWVIEW3D, 0);
1929                         break;
1930                         
1931                 case B_MAKEVERTCOL:
1932                         make_vertexcol();
1933                         break;
1934                 case B_DELVERTCOL:
1935                         if(me->mcol) MEM_freeN(me->mcol);
1936                         me->mcol= NULL;
1937                         G.f &= ~G_VERTEXPAINT;
1938                         freedisplist(&(ob->disp));
1939                         allqueue(REDRAWBUTSEDIT, 0);
1940                         allqueue(REDRAWVIEW3D, 0);
1941                         break;
1942
1943                 case B_MAKE_TFACES:
1944                         make_tfaces(me);
1945                         allqueue(REDRAWBUTSEDIT, 0);
1946                         break;
1947
1948                 case B_DEL_TFACES:
1949                         if(me->tface) MEM_freeN(me->tface);
1950                         me->tface= 0;
1951                         G.f &= ~G_FACESELECT;
1952                         allqueue(REDRAWBUTSEDIT, 0);
1953                         allqueue(REDRAWVIEW3D, 0);
1954                         allqueue(REDRAWIMAGE, 0);
1955                         break;
1956
1957                 case B_FLIPNORM:
1958                         if(G.obedit) {
1959                                 flip_editnormals();
1960                         }
1961                         else flipnorm_mesh( get_mesh(ob) );
1962
1963                         allqueue(REDRAWVIEW3D, 0);
1964                         break;
1965
1966                 case B_DECIM_FACES:
1967                         decimate_faces();
1968                         break;
1969                 case B_DECIM_CANCEL:
1970                         decimate_cancel();
1971                         break;
1972                 case B_DECIM_APPLY:
1973                         decimate_apply();
1974                         break;
1975
1976                 case B_SLOWERDRAW:
1977                         slowerdraw();
1978                         break;
1979                 case B_FASTERDRAW:
1980                         fasterdraw();
1981                         break;
1982                 }
1983         }
1984
1985         if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return;
1986
1987         switch(event) {
1988         case B_SPIN:
1989                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 0);
1990                 break;
1991         case B_SPINDUP:
1992                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 1);
1993                 break;
1994         case B_EXTR:
1995                 G.f |= G_DISABLE_OK;
1996                 if( select_area(SPACE_VIEW3D)) extrude_mesh();
1997                 G.f -= G_DISABLE_OK;
1998                 break;
1999         case B_SCREW:
2000                 if( select_area(SPACE_VIEW3D)) screw_mesh(step, turn);
2001                 break;
2002         case B_EXTREP:
2003                 if( select_area(SPACE_VIEW3D)) extrude_repeat_mesh(step, extr_offs);
2004                 break;
2005         case B_SPLIT:
2006                 G.f |= G_DISABLE_OK;
2007                 split_mesh();
2008                 G.f -= G_DISABLE_OK;
2009                 break;
2010         case B_REMDOUB:
2011                 notice("Removed: %d", removedoublesflag(1, doublimit));
2012                 allqueue(REDRAWVIEW3D, 0);
2013                 BIF_undo_push("Rem Doubles");
2014                 break;
2015         case B_SUBDIV:
2016                 waitcursor(1);
2017                 subdivideflag(1, 0.0, editbutflag & B_BEAUTY);
2018                 countall();
2019                 waitcursor(0);
2020                 allqueue(REDRAWVIEW3D, 0);
2021                 BIF_undo_push("Subdivide");
2022                 break;
2023         case B_FRACSUBDIV:
2024                 randfac= 10;
2025                 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
2026                 waitcursor(1);
2027                 fac= -( (float)randfac )/100;
2028                 subdivideflag(1, fac, editbutflag & B_BEAUTY);
2029                 countall();
2030                 waitcursor(0);
2031                 allqueue(REDRAWVIEW3D, 0);
2032                 BIF_undo_push("Fractal Subdivide");
2033                 break;
2034         case B_XSORT:
2035                 if( select_area(SPACE_VIEW3D)) xsortvert_flag(1);
2036                 break;
2037         case B_HASH:
2038                 hashvert_flag(1);
2039                 break;
2040         case B_TOSPHERE:
2041                 vertices_to_sphere();
2042                 break;
2043         case B_VERTEXNOISE:
2044                 vertexnoise();
2045                 break;
2046         case B_VERTEXSMOOTH:
2047                 vertexsmooth();
2048                 break;
2049         case B_DRAWEDGES:
2050                 G.f &= ~G_DRAWCREASES;
2051                 allqueue(REDRAWBUTSEDIT, 0);
2052                 allqueue(REDRAWVIEW3D, 0);
2053                 break;
2054         case B_DRAWCREASES:
2055                 G.f &= ~G_DRAWEDGES;
2056                 allqueue(REDRAWBUTSEDIT, 0);
2057                 allqueue(REDRAWVIEW3D, 0);
2058                 break;
2059         }
2060         /* WATCH IT: previous events only in editmode! */
2061 }
2062
2063 static void editing_panel_mesh_tools(Object *ob, Mesh *me)
2064 {
2065         uiBlock *block;
2066
2067         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools", UI_EMBOSS, UI_HELV, curarea->win);
2068         if(uiNewPanel(curarea, block, "Mesh Tools", "Editing", 640, 0, 318, 204)==0) return;
2069
2070         uiBlockBeginAlign(block);
2071         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");
2072         uiDefBut(block, BUT,B_SUBDIV,"Subdivide",               90,195,80,19, 0, 0, 0, 0, 0, "Splits selected faces into halves or quarters");
2073         uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd", 170,195,85,19, 0, 0, 0, 0, 0, "Subdivides selected faces with a random factor");
2074
2075         uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",              10,175,80,19, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
2076         uiDefBut(block, BUT,B_HASH,"Hash",                              90,175,80,19, 0, 0, 0, 0, 0, "Randomizes selected vertice sequence data");
2077         uiDefBut(block, BUT,B_XSORT,"Xsort",                    170,175,85,19, 0, 0, 0, 0, 0, "Sorts selected vertice data in the X direction");
2078
2079         uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",             10,155,80,19, 0, 0, 0, 0, 0, "Moves selected vertices outwards into a spherical shape");
2080         uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",    90,155,80,19, 0, 0, 0, 0, 0, "Flattens angles of selected faces");
2081         uiDefBut(block, BUT,B_SPLIT,"Split",                    170,155,85,19, 0, 0, 0, 0, 0, "Splits selected verts to separate sub-mesh.");
2082
2083         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");
2084         uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    90,135,80,19, 0, 0, 0, 0, 0, "Removes duplicates from selected vertices");
2085         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'");
2086         uiBlockEndAlign(block);
2087
2088         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");
2089
2090         uiBlockBeginAlign(block);
2091         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
2092         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");
2093         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");
2094
2095         uiDefButS(block, NUM, B_DIFF, "Degr:",                  10,55,80,19, &degr,10.0,360.0, 0, 0, "Specifies the number of degrees 'Spin' revolves");
2096         uiDefButS(block, NUM, B_DIFF, "Steps:",                 90,55,80,19, &step,1.0,180.0, 0, 0, "Specifies the total number of 'Spin' slices");
2097         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");
2098         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");
2099         uiDefButS(block, TOG|BIT|0, B_DIFF, "Clockwise",        170,35,85,19, &editbutflag, 0, 0, 0, 0, "Specifies the direction for 'Screw' and 'Spin'");
2100
2101         uiBlockBeginAlign(block);
2102         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");
2103         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'");
2104         uiBlockEndAlign(block);
2105 }
2106
2107 static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
2108 {
2109         unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
2110 }
2111
2112
2113
2114 static void editing_panel_mesh_tools1(Object *ob, Mesh *me)
2115 {
2116         uiBlock *block;
2117
2118
2119         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools1", UI_EMBOSS, UI_HELV, curarea->win);
2120         if(uiNewPanel(curarea, block, "Mesh Tools 1", "Editing", 960, 0, 318, 204)==0) return;
2121
2122         uiBlockBeginAlign(block);
2123         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");
2124         uiDefBut(block, BUT,B_HIDE,             "Hide",         1115, 200,  160, 19, 0, 0, 0, 0, 0, "Hides selected faces");
2125         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  955, 180, 160, 19, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
2126         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               1115, 180,  160, 19, 0, 0, 0, 0, 0, "Reveals selected faces");
2127         uiBlockEndAlign(block);
2128
2129         uiBlockBeginAlign(block);
2130         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");
2131         uiDefButI(block, TOG|BIT|6, REDRAWVIEW3D, "Draw Normals",       955,110,150,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
2132         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces",         955,88,150,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
2133         uiDefButI(block, TOG|BIT|18, REDRAWVIEW3D, "Draw Edges",        955,66,150,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
2134         uiDefButI(block, TOG|BIT|19, REDRAWVIEW3D, "Draw Creases",      955,44,150,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
2135         uiDefButI(block, TOG|BIT|20, REDRAWVIEW3D, "Draw Seams",        955,22,150,19, &G.f, 0, 0, 0, 0, "Displays UV unwrapping seams");
2136         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");
2137         uiBlockEndAlign(block);
2138         
2139         /* Measurement drawing options */
2140         uiBlockBeginAlign(block);
2141         uiDefButI(block, TOG|BIT|22, REDRAWVIEW3D, "Edge Length",       1125,131,150,19, &G.f, 0, 0, 0, 0, "Displays selected edge lengths");
2142         uiDefButI(block, TOG|BIT|24, REDRAWVIEW3D, "Edge Angles",       1125,110,150,19,  &G.f, 0, 0, 0, 0, "Displays the angles in the selected edges in degrees");
2143         uiDefButI(block, TOG|BIT|23, REDRAWVIEW3D, "Face Area",         1125,88,150,19, &G.f, 0, 0, 0, 0, "Displays the area of selected faces");
2144         uiBlockEndAlign(block);
2145
2146 }
2147
2148 static void editing_panel_links(Object *ob)
2149 {
2150         uiBlock *block;
2151         ID *id, *idfrom;
2152         int *poin, xco=143;
2153         float min;
2154         Material *ma;
2155         char str[64];
2156         uiBut *but;
2157
2158         block= uiNewBlock(&curarea->uiblocks, "editing_panel_links", UI_EMBOSS, UI_HELV, curarea->win);
2159         if(uiNewPanel(curarea, block, "Link and Materials", "Editing", 0, 0, 318, 204)==0) return;
2160
2161         buttons_active_id(&id, &idfrom);
2162
2163         if(id) {
2164                 int alone= 0;
2165                 int local= 0;
2166                 int browse= B_EDITBROWSE;
2167
2168                 if(ob->type==OB_MESH) {
2169                         browse= B_MESHBROWSE;
2170                         alone= B_MESHALONE;
2171                         local= B_MESHLOCAL;
2172                         uiSetButLock(G.obedit!=0, "Unable to perform function in EditMode");
2173                 }
2174                 else if(ob->type==OB_MBALL) {
2175                         alone= B_MBALLALONE;
2176                         local= B_MBALLLOCAL;
2177                 }
2178                 else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
2179                         alone= B_CURVEALONE;
2180                         local= B_CURVELOCAL;
2181                 }
2182                 else if(ob->type==OB_CAMERA) {
2183                         alone= B_CAMERAALONE;
2184                         local= B_CAMERALOCAL;
2185                 }
2186                 else if(ob->type==OB_LAMP) {
2187                         alone= B_LAMPALONE;
2188                         local= B_LAMPLOCAL;
2189                 }
2190                 else if (ob->type==OB_ARMATURE){
2191                         alone = B_ARMALONE;
2192                         local = B_ARMLOCAL;
2193                 }
2194                 else if(ob->type==OB_LATTICE) {
2195                         alone= B_LATTALONE;
2196                         local= B_LATTLOCAL;
2197                 }
2198                 uiBlockSetCol(block, TH_BUT_SETTING2);
2199                 xco= std_libbuttons(block, 143, 180, 0, NULL, browse, id, idfrom, &(G.buts->menunr), alone, local, 0, 0, B_KEEPDATA);
2200                 uiBlockSetCol(block, TH_AUTO);
2201         }
2202         if(ob) {
2203                 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.");
2204                 uiButSetFunc(but, test_idbutton_cb, ob->id.name, NULL);
2205         }
2206
2207
2208
2209         /* to be sure */
2210         if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL);
2211         else return;
2212
2213
2214         if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag );
2215         else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag );
2216         else poin= &( ((Curve *)ob->data)->texflag );
2217         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");
2218
2219         sprintf(str,"%d Mat:", ob->totcol);
2220         if(ob->totcol) min= 1.0; else min= 0.0;
2221         ma= give_current_material(ob, ob->actcol);
2222
2223         if(ma) uiDefBut(block, LABEL, 0, ma->id.name+2, 318,153, 103, 20, 0, 0, 0, 0, 0, "");
2224
2225         uiBlockBeginAlign(block);
2226         if(ma) uiDefButF(block, COL, B_REDR, "",                        292,123,31,30, &(ma->r), 0, 0, 0, 0, "");
2227         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");
2228         uiDefBut(block, BUT,B_MATWICH,  "?",            424,123,30,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces");
2229
2230         uiBlockBeginAlign(block);
2231         uiDefBut(block, BUT,B_MATNEW,   "New",          292,98,80,20, 0, 0, 0, 0, 0, "Adds a new Material index");
2232         uiDefBut(block, BUT,B_MATDEL,   "Delete",       374,98,80,20, 0, 0, 0, 0, 0, "Deletes this Material index");
2233         uiDefBut(block, BUT,B_MATSEL,   "Select",       292,76,80,20, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index");
2234         uiDefBut(block, BUT,B_MATDESEL, "Deselect",     374,76,80,20, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber");
2235         uiDefBut(block, BUT,B_MATASS,   "Assign",       292,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces");
2236
2237         uiBlockBeginAlign(block);
2238         uiDefBut(block, BUT,B_SETSMOOTH,"Set Smooth",   291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces");
2239         uiDefBut(block, BUT,B_SETSOLID, "Set Solid",    373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces");
2240         uiBlockEndAlign(block);
2241
2242         /* vertex group... partially editmode... */
2243         if(ob->type==OB_MESH) {
2244                 uiBut *but;
2245                 int     defCount;
2246                 bDeformGroup    *defGroup;
2247                 char *s, *menustr;
2248                 bDeformGroup *dg;
2249                 int min, index;
2250                 char (*qsort_ptr)[32] = NULL;
2251
2252                 uiDefBut(block, LABEL,0,"Vertex Groups",
2253                                  143,153,130,20, 0, 0, 0, 0, 0, "");
2254
2255                 defCount=BLI_countlist(&ob->defbase);
2256
2257                 if (!defCount) min=0;
2258                 else min=1;
2259
2260                 if (defCount > 0) {
2261                         /*
2262                          * This will hold the group names temporarily
2263                          * so we can sort them
2264                          */
2265                         qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr[0]),
2266                                                                          "qsort_ptr");
2267                         for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
2268                                 snprintf (qsort_ptr[index - 1], sizeof (qsort_ptr[0]),
2269                                                   "%s%%x%d|", dg->name, index);
2270                         }
2271
2272                         qsort (qsort_ptr, defCount, sizeof (qsort_ptr[0]),
2273                                    ( int (*)(const void *, const void *) ) strcmp);
2274                 }
2275
2276                 s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
2277                 for (index = 0; index < defCount; index++) {
2278                         int cnt= sprintf (s, "%s", qsort_ptr[index]);
2279                         if (cnt>0) s+= cnt;
2280                 }
2281
2282                 if (qsort_ptr)
2283                   MEM_freeN (qsort_ptr);
2284
2285                 uiBlockBeginAlign(block);
2286                 if (defCount)
2287                         uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr,
2288                                           143, 132,18,21, &ob->actdef, min, defCount, 0, 0,
2289                                           "Browses available vertex groups");
2290
2291                 MEM_freeN (menustr);
2292
2293                 if (ob->actdef){
2294                         defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
2295                         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.)");
2296                         uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
2297
2298                         uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          143, 111, 140, 21, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
2299                 }
2300                 uiBlockEndAlign(block);
2301
2302                 if (G.obedit && G.obedit==ob){
2303                         uiBlockBeginAlign(block);
2304         /*              uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assigns deformation groups"); */
2305                         uiDefBut(block, BUT,B_NEWVGROUP,"New",                  143,90,70,21, 0, 0, 0, 0, 0, "Creates a new vertex group");
2306                         uiDefBut(block, BUT,B_DELVGROUP,"Delete",               213,90,70,21, 0, 0, 0, 0, 0, "Removes the current vertex group");
2307
2308                         uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",    143,69,70,21, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group");
2309                         uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",    213,69,70,21, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group");
2310
2311                         uiDefBut(block, BUT,B_SELVGROUP,"Select",               143,48,70,21, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group");
2312                         uiDefBut(block, BUT,B_DESELVGROUP,"Desel.",             213,48,70,21, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group");
2313                         uiBlockEndAlign(block);
2314                 }
2315         }
2316
2317
2318 }
2319
2320 /* *************************** FACE/PAINT *************************** */
2321
2322 void do_fpaintbuts(unsigned short event)
2323 {
2324         Mesh *me;
2325         Object *ob;
2326         extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
2327         extern VPaint Gvp;         /* from vpaint */
2328
2329         ob= OBACT;
2330         if(ob==0) return;
2331
2332         switch(event) {
2333
2334         case B_VPGAMMA:
2335                 vpaint_dogamma();
2336                 break;
2337         case B_COPY_TF_MODE:
2338         case B_COPY_TF_UV:
2339         case B_COPY_TF_COL:
2340         case B_COPY_TF_TEX:
2341                 me= get_mesh(ob);
2342                 if(me && me->tface) {
2343 /*                      extern TFace *lasttface; */
2344                         TFace *tface= me->tface;
2345                         int a= me->totface;
2346
2347                         set_lasttface();
2348                         if(lasttface) {
2349
2350                                 while(a--) {
2351                                         if(tface!=lasttface && (tface->flag & TF_SELECT)) {
2352                                                 if(event==B_COPY_TF_MODE) {
2353                                                         tface->mode= lasttface->mode;
2354                                                         tface->transp= lasttface->transp;
2355                                                 }
2356                                                 else if(event==B_COPY_TF_UV) {
2357                                                         memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
2358                                                         tface->tpage= lasttface->tpage;
2359                                                         tface->tile= lasttface->tile;
2360
2361                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2362                                                         else tface->mode &= ~TF_TILES;
2363
2364                                                 }
2365                                                 else if(event==B_COPY_TF_TEX) {
2366                                                         tface->tpage= lasttface->tpage;
2367                                                         tface->tile= lasttface->tile;
2368
2369                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2370                                                         else tface->mode &= ~TF_TILES;
2371                                                 }
2372                                                 else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
2373                                         }
2374                                         tface++;
2375                                 }
2376                         }
2377                         do_shared_vertexcol(me);
2378                         allqueue(REDRAWVIEW3D, 0);
2379                         allqueue(REDRAWIMAGE, 0);
2380                 }
2381                 break;
2382         case B_SET_VCOL:
2383                 clear_vpaint_selectedfaces();
2384                 break;
2385         case B_REDR_3D_IMA:
2386                 allqueue(REDRAWVIEW3D, 0);
2387                 allqueue(REDRAWIMAGE, 0);
2388                 break;
2389         case B_ASSIGNMESH:
2390
2391                 test_object_materials(ob->data);
2392                 allqueue(REDRAWVIEW3D, 0);
2393                 allqueue(REDRAWBUTSEDIT, 0);
2394                 break;
2395
2396         case B_TFACE_HALO:
2397                 set_lasttface();
2398                 if(lasttface) {
2399                         lasttface->mode &= ~TF_BILLBOARD2;
2400                         allqueue(REDRAWBUTSEDIT, 0);
2401                 }
2402                 break;
2403
2404         case B_TFACE_BILLB:
2405                 set_lasttface();
2406                 if(lasttface) {
2407                         lasttface->mode &= ~TF_BILLBOARD;
2408                         allqueue(REDRAWBUTSEDIT, 0);
2409                 }
2410                 break;
2411         case B_WEIGHT0_0:
2412                 editbutvweight = 0.0f;
2413                 allqueue(REDRAWBUTSEDIT, 0);
2414                 break;
2415
2416         case B_WEIGHT1_4:
2417                 editbutvweight = 0.25f;
2418                 allqueue(REDRAWBUTSEDIT, 0);
2419                 break;
2420         case B_WEIGHT1_2:
2421                 editbutvweight = 0.5f;
2422                 allqueue(REDRAWBUTSEDIT, 0);
2423                 break;
2424         case B_WEIGHT3_4:
2425                 editbutvweight = 0.75f;
2426                 allqueue(REDRAWBUTSEDIT, 0);
2427                 break;
2428         case B_WEIGHT1_0:
2429                 editbutvweight = 1.0f;
2430                 allqueue(REDRAWBUTSEDIT, 0);
2431                 break;
2432                 
2433         case B_OPA0_0:
2434                 Gvp.a = 0.0f;
2435                 allqueue(REDRAWBUTSEDIT, 0);
2436                 break;
2437         case B_OPA1_4:
2438                 Gvp.a = 0.25f;
2439                 allqueue(REDRAWBUTSEDIT, 0);
2440                 break;
2441         case B_OPA1_2:
2442                 Gvp.a = 0.5f;
2443                 allqueue(REDRAWBUTSEDIT, 0);
2444                 break;
2445         case B_OPA3_4:
2446                 Gvp.a = 0.75f;
2447                 allqueue(REDRAWBUTSEDIT, 0);
2448                 break;
2449         case B_OPA1_0:
2450                 Gvp.a = 1.0f;
2451                 allqueue(REDRAWBUTSEDIT, 0);
2452                 break;
2453                 
2454
2455         }
2456 }
2457
2458
2459 /* -------------------- MODE: vpaint  ------------------- */
2460
2461 static void editing_panel_mesh_paint(void)
2462 {
2463         extern VPaint Gvp;         /* from vpaint */
2464         uiBlock *block;
2465         
2466         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_paint", UI_EMBOSS, UI_HELV, curarea->win);
2467         if(uiNewPanel(curarea, block, "Paint", "Editing", 640, 0, 318, 204)==0) return;
2468         
2469         
2470         if(G.f & ( G_WEIGHTPAINT))
2471         {
2472                 Object *ob;
2473             ob= OBACT;
2474         if(ob==NULL) return;
2475
2476                 uiBlockBeginAlign(block);
2477                 uiDefButF(block, NUMSLI, REDRAWVIEW3D, "Weight:",979,160,194,19, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
2478                 uiDefBut(block, BUT, B_WEIGHT0_0 , "0",                 979,140,40,19, 0, 0, 0, 0, 0, "");
2479                 uiDefBut(block, BUT, B_WEIGHT1_4 , "1/4",                       1020,140,40,19, 0, 0, 0, 0, 0, "");
2480                 uiDefBut(block, BUT, B_WEIGHT1_2 , "1/2",                       1060,140,40,19, 0, 0, 0, 0, 0, "");
2481                 uiDefBut(block, BUT, B_WEIGHT3_4 , "3/4",                       1100,140,40,19, 0, 0, 0, 0, 0, "");
2482                 uiDefBut(block, BUT, B_WEIGHT1_0 , "1",                 1140,140,33,19, 0, 0, 0, 0, 0, "");
2483                 
2484                 uiDefButF(block, NUMSLI, 0, "Opacity ",         979,120,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2485                 uiDefBut(block, BUT, B_OPA0_0 , "0",                    979,100,40,19, 0, 0, 0, 0, 0, "");
2486                 uiDefBut(block, BUT, B_OPA1_4 , "1/4",                  1020,100,40,19, 0, 0, 0, 0, 0, "");
2487                 uiDefBut(block, BUT, B_OPA1_2 , "1/2",                  1060,100,40,19, 0, 0, 0, 0, 0, "");
2488                 uiDefBut(block, BUT, B_OPA3_4 , "3/4",                  1100,100,40,19, 0, 0, 0, 0, 0, "");
2489                 uiDefBut(block, BUT, B_OPA1_0 , "1",                    1140,100,33,19, 0, 0, 0, 0, 0, "");
2490                 uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2491                 uiBlockEndAlign(block);
2492                 if(ob){
2493                 uiBlockBeginAlign(block);
2494         uiDefButBitC(block, TOG, OB_DRAWWIRE, REDRAWVIEW3D, "Wire",     979,40,194,19   , &ob->dtx, 0, 0, 0, 0, "Displays the active object's wireframe in shaded drawing modes");
2495                 uiBlockEndAlign(block);
2496                 }
2497         }
2498         else{
2499                 uiBlockBeginAlign(block);
2500                 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");
2501                 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");
2502                 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");
2503                 uiBlockEndAlign(block);
2504                 uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2505                 uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2506                 
2507                 uiDefButF(block, COL, B_REDR, "",               1176,99,28,80, &(Gvp.r), 0, 0, 0, B_VPCOLSLI, "");
2508                 uiBlockBeginAlign(block);
2509                 uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
2510                 uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
2511                 uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
2512                 uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
2513                 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");
2514                 
2515                 uiBlockBeginAlign(block);
2516                 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)");
2517                 uiDefButS(block, TOG|BIT|2, 0, "Soft",          1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
2518                 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");
2519                 
2520                 uiBlockBeginAlign(block);
2521                 uiDefBut(block, BUT, B_VPGAMMA, "Set",  979,30,81,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
2522                 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");
2523                 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");
2524                 uiBlockEndAlign(block);
2525                 
2526                 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)");
2527         }
2528         
2529 }
2530
2531 static void editing_panel_mesh_texface(void)
2532 {
2533         extern VPaint Gvp;         /* from vpaint */
2534         uiBlock *block;
2535         extern TFace *lasttface;
2536
2537         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_texface", UI_EMBOSS, UI_HELV, curarea->win);
2538         if(uiNewPanel(curarea, block, "Texture face", "Editing", 960, 0, 318, 204)==0) return;
2539
2540         set_lasttface();        // checks for ob type
2541         if(lasttface) {
2542
2543                 uiBlockBeginAlign(block);
2544                 uiDefButS(block, TOG|BIT|2, B_REDR_3D_IMA, "Tex",       600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
2545                 uiDefButS(block, TOG|BIT|7, B_REDR_3D_IMA, "Tiles",     660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
2546                 uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Light",      720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
2547                 uiDefButS(block, TOG|BIT|10, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
2548                 uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
2549
2550                 uiBlockBeginAlign(block);
2551                 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");
2552                 uiDefButS(block, TOG|BIT|9, REDRAWVIEW3D, "Twoside",660,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
2553                 uiDefButS(block, TOG|BIT|11, REDRAWVIEW3D, "ObColor",720,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
2554
2555                 uiBlockBeginAlign(block);
2556                 uiDefButS(block, TOG|BIT|8, B_TFACE_HALO, "Halo",       600,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
2557                 uiDefButS(block, TOG|BIT|12, B_TFACE_BILLB, "Billboard",660,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
2558                 uiDefButS(block, TOG|BIT|13, REDRAWVIEW3D, "Shadow", 720,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
2559                 uiDefButS(block, TOG|BIT|14, REDRAWVIEW3D, "Text", 780,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
2560
2561                 uiBlockBeginAlign(block);
2562                 uiBlockSetCol(block, TH_BUT_SETTING1);
2563                 uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,80,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
2564                 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");
2565                 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");
2566
2567                 uiBlockSetCol(block, TH_AUTO);
2568
2569                 uiBlockBeginAlign(block);
2570                 uiDefButF(block, COL, B_VPCOLSLI, "",                   769,40,40,28, &(Gvp.r), 0, 0, 0, 0, "");
2571                 uiDefBut(block, BUT, B_SET_VCOL, "Set VertCol", 809,40,103,28, 0, 0, 0, 0, 0, "Set Vertex colour of selection to current (Shift+K)");
2572
2573                 uiBlockBeginAlign(block);
2574                 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");
2575                 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");
2576                 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");
2577         }
2578 }
2579
2580 void do_uvautocalculationbuts(unsigned short event)
2581 {
2582         switch(event) {
2583         case B_UVAUTO_STD1:
2584         case B_UVAUTO_STD2:
2585         case B_UVAUTO_STD4:
2586         case B_UVAUTO_STD8:
2587         case B_UVAUTO_CUBE:
2588                 calculate_uv_map(event);
2589                 break;
2590         case B_UVAUTO_BOUNDS1:
2591         case B_UVAUTO_BOUNDS2:
2592         case B_UVAUTO_BOUNDS4:
2593         case B_UVAUTO_BOUNDS8:
2594         case B_UVAUTO_SPHERE:
2595         case B_UVAUTO_CYLINDER:
2596         case B_UVAUTO_WINDOW:
2597                 if(select_area(SPACE_VIEW3D)) calculate_uv_map(event);
2598                 break;
2599         case B_UVAUTO_LSCM:
2600                 unwrap_lscm();
2601                 break;
2602         }
2603 }
2604
2605 static void editing_panel_mesh_uvautocalculation(void)
2606 {
2607         uiBlock *block;
2608         int butH= 19, butHB= 20, row= 180, butS= 10;
2609
2610         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_uvautocalculation", UI_EMBOSS, UI_HELV, curarea->win);
2611         /* make this a tab of "Texture face" to save screen space*/
2612         uiNewPanelTabbed("Texture face", "Editing");
2613         if(uiNewPanel(curarea, block, "UV Calculation", "Editing", 960, 0, 318, 204)==0)
2614                 return;
2615
2616         uiBlockBeginAlign(block);
2617         uiDefBut(block, BUT, B_UVAUTO_LSCM,"LSCM Unwrap",100,row,200,butH, 0, 0, 0, 0, 0, "Applies conformal UV mapping, preserving local angles");
2618         uiBlockEndAlign(block);
2619         row-= butHB+butS;
2620
2621         uiBlockBeginAlign(block);
2622         uiDefBut(block, BUT, B_UVAUTO_STD1,"Standard",100,row,100,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping");
2623         uiDefBut(block, BUT, B_UVAUTO_STD2,"/2",200,row,33,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/2");
2624         uiDefBut(block, BUT, B_UVAUTO_STD4,"/4",233,row,34,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/4");
2625         uiDefBut(block, BUT, B_UVAUTO_STD8,"/8",267,row,33,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/8");
2626         uiBlockEndAlign(block);
2627         row-= butHB+butS;
2628
2629         uiBlockBeginAlign(block);
2630         uiDefBut(block, BUT, B_UVAUTO_BOUNDS1,"Bounds",100,row,100,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/1");
2631         uiDefBut(block, BUT, B_UVAUTO_BOUNDS2,"/2",200,row,33,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/2");
2632         uiDefBut(block, BUT, B_UVAUTO_BOUNDS4,"/4",233,row,34,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/4");
2633         uiDefBut(block, BUT, B_UVAUTO_BOUNDS8,"/8",267,row,33,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/8");
2634         uiDefBut(block, BUT, B_UVAUTO_WINDOW,"From Window",100,row-butH,200,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping from window");
2635         uiBlockEndAlign(block);
2636         row-= 2*butHB+butS;
2637
2638         uiBlockBeginAlign(block);
2639         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces", 100,row,200,butH, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
2640         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");
2641         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");
2642         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");
2643         uiBlockEndAlign(block);
2644         row-= 4*butHB+butS;
2645
2646         row= 180;
2647
2648         uiBlockBeginAlign(block);
2649         uiDefBut(block, BUT, B_UVAUTO_CUBE,"Cube",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cube UV mapping");
2650         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");
2651         uiBlockEndAlign(block);
2652         row-= 2*butHB+butS;
2653
2654         uiBlockBeginAlign(block);
2655         uiDefBut(block, BUT, B_UVAUTO_SPHERE,"Sphere",315,row,200,butH, 0, 0, 0, 0, 0, "Applies spherical UV mapping");
2656         uiBlockEndAlign(block);
2657         row-= butHB+butS;
2658
2659         uiBlockBeginAlign(block);
2660         uiDefBut(block, BUT, B_UVAUTO_CYLINDER,"Cylinder",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cylindrical UV mapping");
2661         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");
2662         uiBlockEndAlign(block);
2663         row-= 2*butHB+butS;
2664
2665
2666         uiBlockBeginAlign(block);
2667         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");
2668         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");
2669         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");
2670         uiBlockEndAlign(block);
2671         row-= 2*butHB+butS;
2672
2673         uiBlockBeginAlign(block);
2674         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");
2675         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");
2676         uiBlockEndAlign(block);
2677 }
2678
2679 /* this is a mode context sensitive system */
2680
2681 void editing_panels()
2682 {
2683         Object *ob;
2684         Curve *cu;
2685         MetaBall *mb;
2686         Lattice *lt;
2687         bArmature *arm;
2688         Camera *cam;
2689
2690         ob= OBACT;
2691         if(ob==NULL) return;
2692
2693         switch(ob->type) {
2694         case OB_MESH:
2695                 editing_panel_links(ob); // no editmode!
2696                 editing_panel_mesh_type(ob, ob->data);  // no editmode!
2697                 /* modes */
2698                 if(G.obedit) {
2699                         editing_panel_mesh_tools(ob, ob->data); // no editmode!
2700                         editing_panel_mesh_tools1(ob, ob->data); // no editmode!
2701                 }
2702                 else {
2703                         if(G.f & G_FACESELECT) {
2704                                 editing_panel_mesh_texface();
2705                                 editing_panel_mesh_uvautocalculation();
2706                         }
2707                         if(G.f & (G_VERTEXPAINT | G_TEXTUREPAINT | G_WEIGHTPAINT) ) {
2708                                 editing_panel_mesh_paint();
2709                         }
2710                 }
2711                 break;
2712
2713         case OB_CURVE:
2714         case OB_SURF:
2715                 cu= ob->data;
2716                 editing_panel_links(ob); // no editmode!
2717                 editing_panel_curve_type(ob, cu);
2718                 if(G.obedit) {
2719                         editing_panel_curve_tools(ob, cu);
2720                         editing_panel_curve_tools1(ob, cu);
2721                 }
2722                 break;
2723
2724         case OB_MBALL:
2725                 mb= ob->data;
2726                 editing_panel_links(ob); // no editmode!
2727                 editing_panel_mball_type(ob, mb);
2728                 if(G.obedit) {
2729                         editing_panel_mball_tools(ob, mb);
2730                 }
2731                 break;
2732
2733         case OB_FONT:
2734                 cu= ob->data;
2735                 editing_panel_links(ob); // no editmode!
2736                 editing_panel_curve_type(ob, cu);
2737                 editing_panel_font_type(ob, cu);
2738                 break;
2739
2740         case OB_LATTICE:
2741                 lt= ob->data;
2742                 editing_panel_links(ob); // no editmode!
2743                 editing_panel_lattice_type(ob, lt);
2744                 break;
2745
2746         case OB_LAMP:
2747                 editing_panel_links(ob); // no editmode!
2748                 break;
2749
2750         case OB_EMPTY:
2751                 editing_panel_links(ob); // no editmode!
2752                 break;
2753
2754         case OB_CAMERA:
2755                 cam= ob->data;
2756                 editing_panel_links(ob); // no editmode!
2757                 editing_panel_camera_type(ob, cam);
2758                 /* yafray: extra panel for dof parameters */
2759                 if (G.scene->r.renderer==R_YAFRAY) editing_panel_camera_yafraydof(ob, cam);
2760                 break;
2761
2762         case OB_ARMATURE:
2763                 arm= ob->data;
2764                 editing_panel_links(ob); // no editmode!
2765                 editing_panel_armature_type(ob, arm);
2766                 if(G.obedit) {
2767                         editing_panel_armature_bones(ob, arm);
2768                 }
2769                 break;
2770         }
2771
2772 }