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