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