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