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