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