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