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