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