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