bd61a98829a2d4074d5b370cc251de76d7803e8b
[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         Base *base;
967         Object *ob;
968         Curve *cu;
969         Nurb *nu;
970
971         ob= OBACT;
972         if(ob==0) return;
973
974         switch(event) {
975
976         case B_CONVERTPOLY:
977         case B_CONVERTBEZ:
978         case B_CONVERTBSPL:
979         case B_CONVERTCARD:
980         case B_CONVERTNURB:
981                 if(G.obedit) {
982                         setsplinetype(event-B_CONVERTPOLY);
983                         makeDispList(G.obedit);
984                         allqueue(REDRAWVIEW3D, 0);
985                 }
986                 break;
987         case B_UNIFU:
988         case B_ENDPU:
989         case B_BEZU:
990         case B_UNIFV:
991         case B_ENDPV:
992         case B_BEZV:
993                 if(G.obedit) {
994                         nu= editNurb.first;
995                         while(nu) {
996                                 if(isNurbsel(nu)) {
997                                         if((nu->type & 7)==CU_NURBS) {
998                                                 if(event<B_UNIFV) {
999                                                         nu->flagu &= 1;
1000                                                         nu->flagu += ((event-B_UNIFU)<<1);
1001                                                         makeknots(nu, 1, nu->flagu>>1);
1002                                                 }
1003                                                 else if(nu->pntsv>1) {
1004                                                         nu->flagv &= 1;
1005                                                         nu->flagv += ((event-B_UNIFV)<<1);
1006                                                         makeknots(nu, 2, nu->flagv>>1);
1007                                                 }
1008                                         }
1009                                 }
1010                                 nu= nu->next;
1011                         }
1012                         makeDispList(G.obedit);
1013                         allqueue(REDRAWVIEW3D, 0);
1014                 }
1015                 break;
1016         case B_SETWEIGHT:
1017                 if(G.obedit) {
1018                         weightflagNurb(1, editbutweight, 0);
1019                         makeDispList(G.obedit);
1020                         allqueue(REDRAWVIEW3D, 0);
1021                 }
1022                 break;
1023         case B_SETW1:
1024                 editbutweight= 1.0;
1025                 scrarea_queue_winredraw(curarea);
1026                 break;
1027         case B_SETW2:
1028                 editbutweight= sqrt(2.0)/4.0;
1029                 scrarea_queue_winredraw(curarea);
1030                 break;
1031         case B_SETW3:
1032                 editbutweight= 0.25;
1033                 scrarea_queue_winredraw(curarea);
1034                 break;
1035         case B_SETW4:
1036                 editbutweight= sqrt(0.5);
1037                 scrarea_queue_winredraw(curarea);
1038                 break;
1039         case B_SETORDER:
1040                 if(G.obedit) {
1041                         nu= lastnu;
1042                         if(nu && (nu->type & 7)==CU_NURBS ) {
1043                                 if(nu->orderu>nu->pntsu) {
1044                                         nu->orderu= nu->pntsu;
1045                                         scrarea_queue_winredraw(curarea);
1046                                 }
1047                                 makeknots(nu, 1, nu->flagu>>1);
1048                                 if(nu->orderv>nu->pntsv) {
1049                                         nu->orderv= nu->pntsv;
1050                                         scrarea_queue_winredraw(curarea);
1051                                 }
1052                                 makeknots(nu, 2, nu->flagv>>1);
1053                         }
1054                         makeDispList(G.obedit);
1055                         allqueue(REDRAWVIEW3D, 0);
1056                 }
1057                 break;
1058         case B_MAKEDISP:
1059                 if(ob->type==OB_FONT) text_to_curve(ob, 0);
1060                 makeDispList(ob);
1061                 /* we need signal to send to other users of same data to recalc... */
1062                 base= FIRSTBASE;
1063                 while(base) {
1064                         if(base->lay & G.vd->lay) {
1065                                 if(base->object->data==ob->data && base->object!=ob)
1066                                         makeDispList(base->object);
1067                         }
1068                         base= base->next;
1069                 }
1070                 allqueue(REDRAWVIEW3D, 0);
1071                 allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
1072                 break;
1073
1074         case B_SUBDIVCURVE:
1075                 subdivideNurb();
1076                 break;
1077         case B_SPINNURB:
1078                 /* bad bad bad!!! use brackets!!! In case you wondered:
1079                   {==,!=} goes before & goes before || */
1080                 if( (G.obedit==0) ||
1081                     (G.obedit->type!=OB_SURF) ||
1082                         ((G.obedit->lay & G.vd->lay) == 0) ) return;
1083                 spinNurb(0, 0);
1084                 countall();
1085                 makeDispList(G.obedit);
1086                 allqueue(REDRAWVIEW3D, 0);
1087                 break;
1088         case B_CU3D:        /* allow 3D curve */
1089                 if(G.obedit) {
1090                         cu= G.obedit->data;
1091                         nu= editNurb.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                 if(ob->type==OB_CURVE) {
1100                         cu= ob->data;
1101                         nu= cu->nurb.first;
1102                         while(nu) {
1103                                 nu->type &= ~CU_2D;
1104                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
1105                                 test2DNurb(nu);
1106                                 nu= nu->next;
1107                         }
1108                 }
1109                 makeDispList(G.obedit);
1110                 allqueue(REDRAWVIEW3D, 0);
1111                 break;
1112         case B_SETRESOLU:
1113                 if(ob->type==OB_CURVE) {
1114                         cu= ob->data;
1115                         if(ob==G.obedit) nu= editNurb.first;
1116                         else nu= cu->nurb.first;
1117
1118                         while(nu) {
1119                                 nu->resolu= cu->resolu;
1120                                 nu= nu->next;
1121                         }
1122                 }
1123                 else if(ob->type==OB_FONT) text_to_curve(ob, 0);
1124
1125                 makeDispList(ob);
1126                 allqueue(REDRAWVIEW3D, 0);
1127
1128                 break;
1129         }
1130 }
1131
1132 static void editing_panel_curve_tools(Object *ob, Curve *cu)
1133 {
1134         Nurb *nu;
1135         extern ListBase editNurb;  /* from editcurve */
1136         extern Nurb *lastnu;
1137         uiBlock *block;
1138         short *sp;
1139
1140         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools", UI_EMBOSS, UI_HELV, curarea->win);
1141         if(uiNewPanel(curarea, block, "Curve Tools", "Editing", 640, 0, 318, 204)==0) return;
1142
1143         uiDefBut(block, LABEL, 0, "Make Knots",562,173,102, 18, 0, 0, 0, 0, 0, "");
1144
1145         if(ob->type==OB_CURVE) {
1146                 uiDefBut(block, LABEL, 0, "Convert",    463,173,72, 18, 0, 0, 0, 0, 0, "");
1147                 uiBlockBeginAlign(block);
1148                 uiDefBut(block, BUT,B_CONVERTPOLY,"Poly",               467,152,72, 18, 0, 0, 0, 0, 0, "");
1149                 uiDefBut(block, BUT,B_CONVERTBEZ,"Bezier",      467,132,72, 18, 0, 0, 0, 0, 0, "");
1150                 uiDefBut(block, BUT,B_CONVERTBSPL,"Bspline",    467,112,72, 18, 0, 0, 0, 0, 0, "");
1151                 uiDefBut(block, BUT,B_CONVERTCARD,"Cardinal",   467,92,72, 18, 0, 0, 0, 0, 0, "");
1152                 uiDefBut(block, BUT,B_CONVERTNURB,"Nurb",               467,72,72, 18, 0, 0, 0, 0, 0, "");
1153         }
1154         uiBlockBeginAlign(block);
1155         uiDefBut(block, BUT,B_UNIFU,"Uniform U",        565,152,102, 18, 0, 0, 0, 0, 0, "");
1156         uiDefBut(block, BUT,B_UNIFV,"V",                        670,152,50, 18, 0, 0, 0, 0, 0, "");
1157         uiDefBut(block, BUT,B_ENDPU,"Endpoint U",       565,132,102, 18, 0, 0, 0, 0, 0, "");
1158         uiDefBut(block, BUT,B_ENDPV,"V",                        670,132,50, 18, 0, 0, 0, 0, 0, "");
1159         uiDefBut(block, BUT,B_BEZU,"Bezier U",          565,112,102, 18, 0, 0, 0, 0, 0, "");
1160         uiDefBut(block, BUT,B_BEZV,"V",                         670,112,50, 18, 0, 0, 0, 0, 0, "");
1161         uiBlockEndAlign(block);
1162
1163         uiDefBut(block, BUT,B_SETWEIGHT,"Set Weight",   465,11,95,49, 0, 0, 0, 0, 0, "");
1164
1165         uiBlockBeginAlign(block);
1166         uiDefButF(block, NUM,0,"Weight:",               565,36,102,22, &editbutweight, 0.01, 100.0, 10, 0, "");
1167         uiDefBut(block, BUT,B_SETW1,"1.0",              670,36,50,22, 0, 0, 0, 0, 0, "");
1168         uiDefBut(block, BUT,B_SETW2,"sqrt(2)/4",565,11,55,20, 0, 0, 0, 0, 0, "");
1169         uiDefBut(block, BUT,B_SETW3,"0.25",             620,11,45,20, 0, 0, 0, 0, 0, "");
1170         uiDefBut(block, BUT,B_SETW4,"sqrt(0.5)",665,11,55,20, 0, 0, 0, 0, 0, "");
1171         uiBlockEndAlign(block);
1172
1173         if(ob==G.obedit) {
1174                 nu= lastnu;
1175                 if(nu==NULL) nu= editNurb.first;
1176                 if(nu) {
1177                         uiBlockBeginAlign(block);
1178                         sp= &(nu->orderu);
1179                         uiDefButS(block, NUM, B_SETORDER, "Order U:", 565,90,102, 19, sp, 2.0, 6.0, 0, 0, "");
1180                         sp= &(nu->orderv);
1181                         uiDefButS(block, NUM, B_SETORDER, "V:",         670,90,50, 19, sp, 2.0, 6.0, 0, 0, "");
1182                         sp= &(nu->resolu);
1183                         uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 19, sp, 1.0, 128.0, 0, 0, "");
1184                         sp= &(nu->resolv);
1185                         uiDefButS(block, NUM, B_MAKEDISP, "V:",         670,70,50, 19, sp, 1.0, 128.0, 0, 0, "");
1186                 }
1187         }
1188
1189
1190 }
1191
1192 static void editing_panel_curve_tools1(Object *ob, Curve *cu)
1193 {
1194         uiBlock *block;
1195
1196         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools1", UI_EMBOSS, UI_HELV, curarea->win);
1197         if(uiNewPanel(curarea, block, "Curve Tools1", "Editing", 960, 0, 318, 204)==0) return;
1198
1199         uiDefBut(block, BUT, B_SUBDIVCURVE, "Subdivide", 400,180,150,20, 0, 0, 0, 0, 0, "");
1200         if(ob->type==OB_SURF) {
1201                 uiDefBut(block, BUT, B_SPINNURB, "Spin",         400,160,150,20, 0, 0, 0, 0, 0, "");
1202         }
1203         uiBlockBeginAlign(block);
1204         uiDefBut(block, BUT,B_HIDE,             "Hide",                 400,120,150,18, 0, 0, 0, 0, 0, "Hides selected faces");
1205         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               400,100,150,18, 0, 0, 0, 0, 0, "Reveals selected faces");
1206         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  400,80,150,18, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
1207         uiBlockEndAlign(block);
1208
1209         uiDefButF(block, NUM,   REDRAWVIEW3D, "NSize:", 400, 40, 150, 19, &editbutsize, 0.001, 1.0, 10, 0, "");
1210 }
1211
1212 /* for curve, surf and font! */
1213 static void editing_panel_curve_type(Object *ob, Curve *cu)
1214 {
1215         uiBlock *block;
1216
1217         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_type", UI_EMBOSS, UI_HELV, curarea->win);
1218         if(uiNewPanel(curarea, block, "Curve and Surface", "Editing", 320, 0, 318, 204)==0) return;
1219
1220         uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                                       600,160,150,19, &cu->flag, 0, 0, 0, 0, "");
1221         if(ob->type==OB_SURF)
1222                 uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "No Puno Flip",       600,140,150,19, &cu->flag, 0, 0, 0, 0, "");
1223
1224         uiBlockBeginAlign(block);
1225         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");
1226         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");
1227         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          600, 75, 150, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
1228         uiBlockEndAlign(block);
1229
1230         if(ob->type==OB_SURF) {
1231                 if(cu->key) {
1232                         /* uiDefButS(block, NUM, B_DIFF, "Slurph:",                     600,25,140,19, &(cu->key->slurph), -500.0, 500.0,0,0); ,""*/
1233                         uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        600,45,140,19, &cu->key->type, 0, 0, 0, 0, "");
1234                 }
1235         }
1236
1237         if(ob->type!=OB_SURF) {
1238
1239                 if(ob->type==OB_CURVE) {
1240                         extern float prlen;             // buttons_object.c, should be moved....
1241                         char str[32];
1242                         uiBlockBeginAlign(block);
1243                         uiDefButS(block, NUM, B_RECALCPATH, "PathLen:",                 600,50,150,19, &cu->pathlen, 1.0, 9000.0, 0, 0, "");
1244                         uiDefButS(block, TOG|BIT|3, B_RECALCPATH, "CurvePath",  600,30,75,19 , &cu->flag, 0, 0, 0, 0, "");
1245                         uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "CurveFollow",675,30,75,19, &cu->flag, 0, 0, 0, 0, "");
1246                         sprintf(str, "%.4f", prlen);
1247                         uiDefBut(block, BUT, B_PRINTLEN,                "PrintLen",     600,10,75,19, 0, 0, 0, 0, 0, "");
1248                         uiDefBut(block, LABEL, 0, str,                                          675,10,75,19, 0, 1.0, 0, 0, 0, "");
1249                 }
1250
1251                 uiBlockBeginAlign(block);
1252                 uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 760,160,120,19, &cu->resolu, 1.0, 128.0, 0, 0, "");
1253                 uiDefBut(block, BUT, B_SETRESOLU, "Set",                880,160,30,19, 0, 0, 0, 0, 0, "");
1254
1255                 uiBlockBeginAlign(block);
1256                 uiDefButF(block, NUM, B_MAKEDISP, "Width:",             760,90,150,19, &cu->width, 0.0, 2.0, 1, 0, "");
1257                 uiDefButF(block, NUM, B_MAKEDISP, "Ext1:",              760,70,150,19, &cu->ext1, 0.0, 5.0, 10, 0, "");
1258                 uiDefButF(block, NUM, B_MAKEDISP, "Ext2:",              760,50,150,19, &cu->ext2, 0.0, 2.0, 1, 0, "");
1259                 uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  760,30,150,19, &cu->bevresol, 0.0, 10.0, 0, 0, "");
1260                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "BevOb:",         760,10,150,19, &cu->bevobj, "");
1261
1262                 uiBlockBeginAlign(block);
1263                 uiBlockSetCol(block, TH_BUT_SETTING1);
1264                 uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 760,130,50,19, &cu->flag, 0, 0, 0, 0, "");
1265                 uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",810,130,50,19, &cu->flag, 0, 0, 0, 0, "");
1266                 uiDefButS(block, TOG|BIT|0, B_CU3D, "3D",               860,130,50,19, &cu->flag, 0, 0, 0, 0, "");
1267
1268
1269         }
1270
1271 }
1272
1273
1274 /* *************************** CAMERA ******************************** */
1275
1276
1277 static void editing_panel_camera_type(Object *ob, Camera *cam)
1278 {
1279         uiBlock *block;
1280         float grid=0.0;
1281
1282         if(G.vd) grid= G.vd->grid;
1283         if(grid<1.0) grid= 1.0;
1284
1285         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_type", UI_EMBOSS, UI_HELV, curarea->win);
1286         if(uiNewPanel(curarea, block, "Camera", "Editing", 320, 0, 318, 204)==0) return;
1287
1288         uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:", 470,178,160,20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
1289
1290         uiBlockBeginAlign(block);
1291         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");
1292         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");
1293         uiBlockEndAlign(block);
1294
1295         uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
1296
1297         uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
1298         uiBlockBeginAlign(block);
1299         uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
1300         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");
1301         uiBlockEndAlign(block);
1302 }
1303
1304 /* *************************** MBALL ******************************** */
1305
1306 void do_mballbuts(unsigned short event)
1307 {
1308         switch(event) {
1309         case B_RECALCMBALL:
1310                 makeDispList(OBACT);
1311                 allqueue(REDRAWVIEW3D, 0);
1312                 break;
1313         }
1314 }
1315
1316 static void editing_panel_mball_type(Object *ob, MetaBall *mb)
1317 {
1318         uiBlock *block;
1319
1320         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_type", UI_EMBOSS, UI_HELV, curarea->win);
1321         if(uiNewPanel(curarea, block, "MetaBall", "Editing", 320, 0, 318, 204)==0) return;
1322
1323         ob= find_basis_mball(ob);
1324         mb= ob->data;
1325
1326         uiBlockBeginAlign(block);
1327         uiDefButF(block, NUMSLI, B_RECALCMBALL, "Wiresize:",    470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "");
1328         uiDefButF(block, NUMSLI, 0, "Rendersize:",                      470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "");
1329         uiDefButF(block, NUMSLI, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "");
1330
1331         uiBlockBeginAlign(block);
1332         uiBlockSetCol(block, TH_BUT_SETTING1);
1333         uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
1334         uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "");
1335         uiDefButS(block, ROW, B_DIFF, "Half Res",       471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "");
1336         uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "");
1337         uiDefButS(block, ROW, B_DIFF, "Never",          471, 25, 120, 19, &mb->flag, 0.0, 3.0, 0, 0, "");
1338
1339 }
1340
1341 static void editing_panel_mball_tools(Object *ob, MetaBall *mb)
1342 {
1343         extern MetaElem *lastelem;
1344         uiBlock *block;
1345
1346         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_tools", UI_EMBOSS, UI_HELV, curarea->win);
1347         if( uiNewPanel(curarea, block, "MetaBall tools", "Editing", 640, 0, 318, 204)==0) return;
1348
1349         if(ob==G.obedit && lastelem) {
1350                 uiBlockBeginAlign(block);
1351                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "");
1352                 if(lastelem->type!=MB_BALL)
1353                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dx:",          750,158,250,19, &lastelem->expx, 0.0, 20.0, 0, 0, "");
1354                 if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
1355                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dy:",          750,138,250,19, &lastelem->expy, 0.0, 20.0, 0, 0, "");
1356
1357                 if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
1358                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dz:",          750,118,250,19, &lastelem->expz, 0.0, 20.0, 0, 0, "");
1359                 uiBlockEndAlign(block);
1360
1361                 uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "");
1362                 uiBlockBeginAlign(block);
1363                 uiDefButS(block, ROW, B_RECALCMBALL, "Tube",                    753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "");
1364                 uiDefButS(block, ROW, B_RECALCMBALL, "Plane",                   814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "");
1365                 uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid",                876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "");
1366                 uiDefButS(block, ROW, B_RECALCMBALL, "Cube",                    938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "");
1367                 uiBlockEndAlign(block);
1368
1369                 uiDefButS(block, TOG|BIT|1, B_RECALCMBALL, "Negative",753,16,60,19, &lastelem->flag, 0, 0, 0, 0, "");
1370
1371         }
1372
1373 }
1374
1375
1376 /* *************************** LATTICE ******************************** */
1377
1378 void do_latticebuts(unsigned short event)
1379 {
1380         Object *ob;
1381         Lattice *lt;
1382
1383         ob= OBACT;
1384         if(ob->type!=OB_LATTICE) return;
1385
1386         switch(event) {
1387         case B_RESIZELAT:
1388                 if(ob) {
1389                         if(ob==G.obedit) resizelattice(editLatt);
1390                         else resizelattice(ob->data);
1391                 }
1392                 allqueue(REDRAWVIEW3D, 0);
1393                 break;
1394         case B_DRAWLAT:
1395                 if(ob==G.obedit) calc_lattverts_ext();
1396                 allqueue(REDRAWVIEW3D, 0);
1397                 break;
1398         case B_LATTCHANGED:
1399
1400                 lt= ob->data;
1401                 if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
1402
1403                 make_displists_by_parent(ob);
1404
1405                 allqueue(REDRAWVIEW3D, 0);
1406
1407                 break;
1408         }
1409 }
1410
1411 static void editing_panel_lattice_type(Object *ob, Lattice *lt)
1412 {
1413         uiBlock *block;
1414
1415         block= uiNewBlock(&curarea->uiblocks, "editing_panel_lattice_type", UI_EMBOSS, UI_HELV, curarea->win);
1416         if(uiNewPanel(curarea, block, "Latice", "Editing", 320, 0, 318, 204)==0) return;
1417
1418
1419         uiSetButLock(lt->key!=0, "Not with VertexKeys");
1420         uiSetButLock(ob==G.obedit, "Unable to perform function in EditMode");
1421
1422         uiBlockBeginAlign(block);
1423         uiDefButS(block, NUM, B_RESIZELAT,      "U:",                           470, 178,100,19, &lt->pntsu, 1.0, 64.0, 0, 0, "Points in U direction");
1424         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1425         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1426         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1427
1428         uiBlockBeginAlign(block);
1429         uiDefButS(block, NUM, B_RESIZELAT,      "V:",                           470, 158,100,19, &lt->pntsv, 1.0, 64.0, 0, 0, "Points in V direction");
1430         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 158, 40, 19, &lt->typev, 2.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1431         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 158, 40, 19, &lt->typev, 2.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1432         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 158, 40, 19, &lt->typev, 2.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1433
1434         uiBlockBeginAlign(block);
1435         uiDefButS(block, NUM, B_RESIZELAT,      "W:",                           470, 138,100,19, &lt->pntsw, 1.0, 64.0, 0, 0, "Points in W direction");
1436         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 138, 40, 19, &lt->typew, 3.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1437         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 138, 40, 19, &lt->typew, 3.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1438         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 138, 40, 19, &lt->typew, 3.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1439         uiBlockEndAlign(block);
1440
1441         uiDefBut(block, BUT, B_RESIZELAT,       "Make Regular",         470,101,99,32, 0, 0, 0, 0, 0, "Make Lattice regular");
1442
1443         uiClearButLock();
1444         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");
1445
1446         if(lt->key) {
1447                 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");
1448                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        470,40,120,19, &lt->key->type, 0, 0, 0, 0, "Use relative keys (instead of absolute)");
1449         }
1450
1451 }
1452
1453 /* *************************** ARMATURE ******************************** */
1454
1455
1456
1457 static int editbone_to_parnr (EditBone *bone)
1458 {
1459         EditBone *ebone;
1460         int     index;
1461
1462         for (ebone=G.edbo.first, index=0; ebone; ebone=ebone->next, index++){
1463                 if (ebone==bone)
1464                         return index;
1465         }
1466
1467         return -1;
1468 }
1469
1470 static void parnr_to_editbone(EditBone *bone)
1471 {
1472         if (bone->parNr == -1){
1473                 bone->parent = NULL;
1474                 bone->flag &= ~BONE_IK_TOPARENT;
1475         }
1476         else{
1477                 bone->parent = BLI_findlink(&G.edbo, bone->parNr);
1478                 attach_bone_to_parent(bone);
1479         }
1480 }
1481
1482 static void parnr_to_editbone_cb(void *bonev, void *arg2_unused)
1483 {
1484         EditBone *curBone= bonev;
1485         parnr_to_editbone(curBone);
1486 }
1487
1488 static void build_bonestring (char *string, EditBone *bone){
1489         EditBone *curBone;
1490         EditBone *pBone;
1491         int             skip=0;
1492         int             index, numbones, i;
1493         char (*qsort_ptr)[32] = NULL;
1494
1495         sprintf (string, "Parent%%t| %%x%d", -1);       /* That space is there
1496                                                                                                  * for a reason
1497                                                                                                  */
1498
1499         numbones = BLI_countlist(&G.edbo);
1500
1501         /*
1502          * This will hold the bone names temporarily so we can sort them
1503          */
1504         if (numbones > 0)
1505                 qsort_ptr = MEM_callocN (numbones * sizeof (qsort_ptr[0]),
1506                                                                  "qsort_ptr");
1507
1508         numbones = 0;
1509         for (curBone = G.edbo.first, index=0; curBone;
1510                  curBone=curBone->next, index++){
1511                 /* Make sure this is a valid child */
1512                 if (curBone != bone){
1513                         skip=0;
1514                         for (pBone=curBone->parent; pBone; pBone=pBone->parent){
1515                                 if (pBone==bone){
1516                                         skip=1;
1517                                         break;
1518                                 }
1519                         }
1520
1521                         if (skip)
1522                                 continue;
1523
1524                         sprintf (qsort_ptr[numbones], "|%s%%x%d", curBone->name, index);
1525                         numbones++;
1526                 }
1527         }
1528         qsort (qsort_ptr, numbones, sizeof (qsort_ptr[0]),
1529                    ( int (*)(const void *, const void *) ) strcmp);
1530
1531         for (i=0; i < numbones; ++i) {
1532                 sprintf (string, "%s%s", string, qsort_ptr[i]);
1533         }
1534
1535         if (qsort_ptr)
1536                 MEM_freeN(qsort_ptr);
1537 }
1538
1539 static void constraint_ebone_name_fix(ListBase *conlist, EditBone *eBone)
1540 {
1541
1542         bConstraint *curcon;
1543         char *subtarget;
1544
1545         for (curcon = conlist->first; curcon; curcon=curcon->next){
1546                 subtarget = get_con_subtarget_name(curcon, G.obedit);
1547                 if (subtarget)
1548                         if (!strcmp(subtarget,eBone->oldname) )
1549                                 strcpy(subtarget, eBone->name);
1550         }
1551 }
1552
1553 static void validate_editbonebutton(EditBone *eBone){
1554         EditBone        *prev;
1555         bAction         *act=NULL;
1556         bActionChannel *chan;
1557         Base *base;
1558         bPose        *pose;
1559         bPoseChannel *pchan;
1560
1561         /* Separate the bone from the G.edbo */
1562         prev=eBone->prev;
1563         BLI_remlink (&G.edbo, eBone);
1564
1565         /*      Validate the name */
1566         unique_editbone_name (eBone->name);
1567
1568         /* Re-insert the bone */
1569         if (prev)
1570                 BLI_insertlink(&G.edbo, prev, eBone);
1571         else
1572                 BLI_addhead (&G.edbo, eBone);
1573
1574         /* Rename *action* channel if necessary */
1575         if (G.obedit)
1576                 act = G.obedit->action;
1577
1578         if (act && !act->id.lib){
1579                 /*      Find the appropriate channel
1580                  */
1581                 for (chan = act->chanbase.first; chan; chan=chan->next){
1582                         if (!strcmp (chan->name, eBone->oldname)){
1583                                 strcpy (chan->name, eBone->name);
1584                         }
1585                 }
1586                 allqueue(REDRAWACTION, 0);
1587         }
1588
1589         /* Rename the *pose* channel, if it exists (thus making sure
1590          * that the constraints are still valid)
1591          */
1592         pose = G.obedit->pose;
1593         if (pose) {
1594                 pchan = get_pose_channel(pose, eBone->oldname);
1595                 if (pchan) {
1596                         strcpy (pchan->name, eBone->name);
1597                 }
1598         }
1599
1600         /* Update the parenting info of any users */
1601         /*      Yes, I know this is the worst thing you have ever seen. */
1602
1603         for (base = G.scene->base.first; base; base=base->next){
1604                 Object *ob = base->object;
1605                 ListBase *conlist;
1606
1607                 /* See if an object is parented to this armature */
1608                 if (ob->parent && ob->partype==PARBONE &&
1609                         (ob->parent->type==OB_ARMATURE) &&
1610                         (ob->parent->data == G.obedit->data)){
1611                         if (!strcmp(ob->parsubstr, eBone->oldname))
1612                                 strcpy(ob->parsubstr, eBone->name);
1613                 }
1614
1615                 /* Update any constraints to use the new bone name */
1616                 conlist = &ob->constraints;
1617                 constraint_ebone_name_fix(conlist, eBone);
1618
1619                 switch (ob->type){
1620                         case OB_ARMATURE:
1621                                 if (ob->pose){
1622                                         for (pchan = ob->pose->chanbase.first; pchan;
1623                                                  pchan=pchan->next){
1624                                                 conlist = &pchan->constraints;
1625                                                 constraint_ebone_name_fix(conlist, eBone);
1626                                         }
1627                                 }
1628                                 break;
1629                         default:
1630                                 break;
1631         }
1632
1633         }
1634
1635         exit_editmode(0);       /* To ensure new names make it to the edit armature */
1636
1637 }
1638
1639 static void validate_editbonebutton_cb(void *bonev, void *arg2_unused)
1640 {
1641         EditBone *curBone= bonev;
1642         validate_editbonebutton(curBone);
1643 }
1644
1645 static void armature_rest_pos_func(void *notused1, void *notused2) {
1646         clear_object_constraint_status(OBACT);
1647         make_displists_by_armature(OBACT);
1648 }
1649
1650 static void editing_panel_armature_type(Object *ob, bArmature *arm)
1651 {
1652         uiBlock         *block;
1653         uiBut       *but;
1654         int                     bx=148, by=100;
1655
1656         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_type", UI_EMBOSS, UI_HELV, curarea->win);
1657         if(uiNewPanel(curarea, block, "Armature", "Editing", 320, 0, 318, 204)==0) return;
1658
1659         but = uiDefButI(block, TOG|BIT|ARM_RESTPOSBIT,REDRAWVIEW3D,
1660                                         "Rest Pos", bx,by,97,20, &arm->flag, 0, 0, 0, 0,
1661                                         "Disable all animation for this object");
1662         uiButSetFunc(but, armature_rest_pos_func, NULL, NULL);
1663
1664         uiBlockBeginAlign(block);
1665         uiDefButI(block, TOG|BIT|ARM_DRAWAXESBIT,REDRAWVIEW3D, "Draw Axes", bx,by-46,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
1666         uiDefButI(block, TOG|BIT|ARM_DRAWNAMESBIT,REDRAWVIEW3D, "Draw Names", bx,by-69,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
1667         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");
1668         uiDefButI(block, TOG|BIT|ARM_DELAYBIT,REDRAWVIEW3D,
1669                           "Delay Deform", bx,by-115,97,20, &arm->flag, 0, 0, 0, 0,
1670                           "Don't deform children when manipulating bones in pose mode");
1671 }
1672
1673 static void editing_panel_armature_bones(Object *ob, bArmature *arm)
1674 {
1675         uiBlock         *block;
1676         EditBone        *curBone;
1677         uiBut           *but;
1678         char            *boneString=NULL;
1679         int                     bx=148, by=180;
1680         int                     index;
1681
1682         /* Draw the bone name block */
1683
1684         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_bones", UI_EMBOSS, UI_HELV, curarea->win);
1685         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
1686
1687         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1688         /* so first we make it default height */
1689         uiNewPanelHeight(block, 204);
1690
1691
1692         uiDefBut(block, LABEL, 0, "Selected Bones",                                             bx,by,158,18, 0, 0, 0, 0, 0, "");
1693         by-=20;
1694         for (curBone=G.edbo.first, index=0; curBone; curBone=curBone->next, index++){
1695                 if (curBone->flag & (BONE_SELECTED)) {
1696
1697                         /* Hide in posemode flag */
1698                         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");
1699
1700                         /*      Bone naming button */
1701                         strcpy (curBone->oldname, curBone->name);
1702                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:", bx-10,by,117,18, &curBone->name, 0, 24, 0, 0, "Change the bone name");
1703                         uiButSetFunc(but, validate_editbonebutton_cb, curBone, NULL);
1704
1705                         uiDefBut(block, LABEL, 0, "child of", bx+107,by,73,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1706
1707                         boneString = malloc((BLI_countlist(&G.edbo) * 64)+64);
1708                         build_bonestring (boneString, curBone);
1709
1710                         curBone->parNr = editbone_to_parnr(curBone->parent);
1711                         but = uiDefButI(block, MENU,REDRAWVIEW3D, boneString, bx+180,by,120,18, &curBone->parNr, 0.0, 0.0, 0.0, 0.0, "Parent");
1712                         uiButSetFunc(but, parnr_to_editbone_cb, curBone, NULL);
1713
1714                         free(boneString);
1715
1716                         /* IK to parent flag */
1717                         if (curBone->parent){
1718                                 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");
1719                                 uiButSetFunc(but, attach_bone_to_parent_cb, curBone, NULL);
1720                         }
1721
1722                         /* Dist and weight buttons */
1723                         uiBlockBeginAlign(block);
1724                         but=uiDefButS(block, MENU, REDRAWVIEW3D,
1725                                                         "Skinnable %x0|"
1726                                                         "Unskinnable %x1|"
1727                                                         "Head %x2|"
1728                                                         "Neck %x3|"
1729                                                         "Back %x4|"
1730                                                         "Shoulder %x5|"
1731                                                         "Arm %x6|"
1732                                                         "Hand %x7|"
1733                                                         "Finger %x8|"
1734                                                         "Thumb %x9|"
1735                                                         "Pelvis %x10|"
1736                                                         "Leg %x11|"
1737                                                         "Foot %x12|"
1738                                                         "Toe %x13|"
1739                                                         "Tentacle %x14",
1740                                                         bx-10,by-19,117,18,
1741                                                         &curBone->boneclass,
1742                                                         0.0, 0.0, 0.0, 0.0,
1743                                                         "Classification of armature element");
1744
1745                         /* Dist and weight buttons */
1746                         uiDefButF(block, NUM,REDRAWVIEW3D, "Dist:", bx+110, by-19,
1747                                                 105, 18, &curBone->dist, 0.0, 1000.0, 10.0, 0.0,
1748                                                 "Bone deformation distance");
1749                         uiDefButF(block, NUM,REDRAWVIEW3D, "Weight:", bx+223, by-19,
1750                                                 110, 18, &curBone->weight, 0.0F, 1000.0F,
1751                                                 10.0F, 0.0F, "Bone deformation weight");
1752
1753                         uiBlockEndAlign(block);
1754                         by-=42;
1755                 }
1756         }
1757
1758         if(by<0) {
1759                 uiNewPanelHeight(block, 204 - by);
1760         }
1761
1762 }
1763
1764
1765 /* *************************** MESH ******************************** */
1766
1767
1768
1769 void do_meshbuts(unsigned short event)
1770 {
1771         void decimate_faces(void);
1772         void decimate_cancel(void);
1773         void decimate_apply(void);
1774         Object *ob;
1775         Mesh *me;
1776         float fac;
1777         short randfac;
1778
1779         ob= OBACT;
1780         if(ob && ob->type==OB_MESH) {
1781
1782                 me= get_mesh(ob);
1783                 if(me==0) return;
1784
1785                 switch(event) {
1786                 case B_AUTOVGROUP:
1787                         if (!get_armature(ob->parent)){
1788                                 error ("Mesh must be the child of an armature");
1789                                 break;
1790                         }
1791                                 /* Verify that there are vertex groups for bones in armature */
1792                                 /* Remove selected vertices from all defgroups */
1793                                 /* Perform assignment for selected vertices */
1794
1795                         allqueue (REDRAWVIEW3D, 1);
1796                         break;
1797                 case B_NEWVGROUP:
1798                         add_defgroup (G.obedit);
1799                         scrarea_queue_winredraw(curarea);
1800                         break;
1801                 case B_DELVGROUP:
1802                         del_defgroup (G.obedit);
1803                         allqueue (REDRAWVIEW3D, 1);
1804                         break;
1805                 case B_ASSIGNVGROUP:
1806                         undo_push_mesh("Assign to vertex group");
1807                         assign_verts_defgroup ();
1808                         allqueue (REDRAWVIEW3D, 1);
1809                         break;
1810                 case B_REMOVEVGROUP:
1811                         undo_push_mesh("Remove from vertex group");
1812                         remove_verts_defgroup (0);
1813                         allqueue (REDRAWVIEW3D, 1);
1814                         break;
1815                 case B_SELVGROUP:
1816                         sel_verts_defgroup(1);
1817                         allqueue (REDRAWVIEW3D, 1);
1818                         break;
1819                 case B_DESELVGROUP:
1820                         sel_verts_defgroup(0);
1821                         allqueue (REDRAWVIEW3D, 1);
1822                         break;
1823                 case B_DELSTICKY:
1824
1825                         if(me->msticky) MEM_freeN(me->msticky);
1826                         me->msticky= 0;
1827                         allqueue(REDRAWBUTSEDIT, 0);
1828                         break;
1829                 case B_MAKESTICKY:
1830                         make_sticky();
1831                         break;
1832                 case B_MAKEVERTCOL:
1833                         make_vertexcol();
1834                         break;
1835                 case B_DELVERTCOL:
1836                         if(me->mcol) MEM_freeN(me->mcol);
1837                         me->mcol= 0;
1838                         G.f &= ~G_VERTEXPAINT;
1839                         freedisplist(&(ob->disp));
1840                         allqueue(REDRAWBUTSEDIT, 0);
1841                         allqueue(REDRAWVIEW3D, 0);
1842                         break;
1843
1844                 case B_MAKE_TFACES:
1845                         make_tfaces(me);
1846                         allqueue(REDRAWBUTSEDIT, 0);
1847                         break;
1848
1849                 case B_DEL_TFACES:
1850                         if(me->tface) MEM_freeN(me->tface);
1851                         me->tface= 0;
1852                         G.f &= ~G_FACESELECT;
1853                         allqueue(REDRAWBUTSEDIT, 0);
1854                         allqueue(REDRAWVIEW3D, 0);
1855                         allqueue(REDRAWIMAGE, 0);
1856                         break;
1857
1858                 case B_FLIPNORM:
1859                         if(G.obedit) {
1860                                 flip_editnormals();
1861                         }
1862                         else flipnorm_mesh( get_mesh(ob) );
1863
1864                         allqueue(REDRAWVIEW3D, 0);
1865                         break;
1866
1867                 case B_DECIM_FACES:
1868                         decimate_faces();
1869                         break;
1870                 case B_DECIM_CANCEL:
1871                         decimate_cancel();
1872                         break;
1873                 case B_DECIM_APPLY:
1874                         decimate_apply();
1875                         break;
1876
1877                 case B_SLOWERDRAW:
1878                         slowerdraw();
1879                         break;
1880                 case B_FASTERDRAW:
1881                         fasterdraw();
1882                         break;
1883                 }
1884         }
1885
1886         if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return;
1887
1888         switch(event) {
1889         case B_SPIN:
1890                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 0);
1891                 break;
1892         case B_SPINDUP:
1893                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 1);
1894                 break;
1895         case B_EXTR:
1896                 G.f |= G_DISABLE_OK;
1897                 if( select_area(SPACE_VIEW3D)) extrude_mesh();
1898                 G.f -= G_DISABLE_OK;
1899                 break;
1900         case B_SCREW:
1901                 if( select_area(SPACE_VIEW3D)) screw_mesh(step, turn);
1902                 break;
1903         case B_EXTREP:
1904                 if( select_area(SPACE_VIEW3D)) extrude_repeat_mesh(step, extr_offs);
1905                 break;
1906         case B_SPLIT:
1907                 G.f |= G_DISABLE_OK;
1908                 split_mesh();
1909                 G.f -= G_DISABLE_OK;
1910                 break;
1911         case B_REMDOUB:
1912                 undo_push_mesh("Rem Doubles");
1913                 notice("Removed: %d", removedoublesflag(1, doublimit));
1914                 allqueue(REDRAWVIEW3D, 0);
1915                 break;
1916         case B_SUBDIV:
1917                 waitcursor(1);
1918                 undo_push_mesh("Subdivide");
1919                 subdivideflag(1, 0.0, editbutflag & B_BEAUTY);
1920                 countall();
1921                 waitcursor(0);
1922                 allqueue(REDRAWVIEW3D, 0);
1923                 break;
1924         case B_FRACSUBDIV:
1925                 randfac= 10;
1926                 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
1927                 waitcursor(1);
1928                 undo_push_mesh("Fractal Subdivide");
1929                 fac= -( (float)randfac )/100;
1930                 subdivideflag(1, fac, editbutflag & B_BEAUTY);
1931                 countall();
1932                 waitcursor(0);
1933                 allqueue(REDRAWVIEW3D, 0);
1934                 break;
1935         case B_XSORT:
1936                 if( select_area(SPACE_VIEW3D)) xsortvert_flag(1);
1937                 break;
1938         case B_HASH:
1939                 hashvert_flag(1);
1940                 break;
1941         case B_TOSPHERE:
1942                 vertices_to_sphere();
1943                 break;
1944         case B_VERTEXNOISE:
1945                 vertexnoise();
1946                 break;
1947         case B_VERTEXSMOOTH:
1948                 vertexsmooth();
1949                 break;
1950         }
1951         /* WATCH IT: previous events only in editmode! */
1952 }
1953
1954 static void editing_panel_mesh_tools(Object *ob, Mesh *me)
1955 {
1956         uiBlock *block;
1957
1958         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools", UI_EMBOSS, UI_HELV, curarea->win);
1959         if(uiNewPanel(curarea, block, "Mesh Tools", "Editing", 640, 0, 318, 204)==0) return;
1960
1961         uiBlockBeginAlign(block);
1962         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");
1963         uiDefBut(block, BUT,B_SUBDIV,"Subdivide",               90,195,80,19, 0, 0, 0, 0, 0, "Splits selected faces into halves or quarters");
1964         uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd", 170,195,85,19, 0, 0, 0, 0, 0, "Subdivides selected faces with a random factor");
1965
1966         uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",              10,175,80,19, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
1967         uiDefBut(block, BUT,B_HASH,"Hash",                              90,175,80,19, 0, 0, 0, 0, 0, "Randomizes selected vertice sequence data");
1968         uiDefBut(block, BUT,B_XSORT,"Xsort",                    170,175,85,19, 0, 0, 0, 0, 0, "Sorts selected vertice data in the X direction");
1969
1970         uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",             10,155,80,19, 0, 0, 0, 0, 0, "Moves selected vertices outwards into a spherical shape");
1971         uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",    90,155,80,19, 0, 0, 0, 0, 0, "Flattens angles of selected faces");
1972         uiDefBut(block, BUT,B_SPLIT,"Split",                    170,155,85,19, 0, 0, 0, 0, 0, "Splits selected verts to separate sub-mesh.");
1973
1974         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");
1975         uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    90,135,80,19, 0, 0, 0, 0, 0, "Removes duplicates from selected vertices");
1976         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'");
1977         uiBlockEndAlign(block);
1978
1979         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");
1980
1981         uiBlockBeginAlign(block);
1982         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
1983         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");
1984         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");
1985
1986         uiDefButS(block, NUM, B_DIFF, "Degr:",                  10,55,80,19, &degr,10.0,360.0, 0, 0, "Specifies the number of degrees 'Spin' revolves");
1987         uiDefButS(block, NUM, B_DIFF, "Steps:",                 90,55,80,19, &step,1.0,180.0, 0, 0, "Specifies the total number of 'Spin' slices");
1988         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");
1989         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");
1990         uiDefButS(block, TOG|BIT|0, B_DIFF, "Clockwise",        170,35,85,19, &editbutflag, 0, 0, 0, 0, "Specifies the direction for 'Screw' and 'Spin'");
1991
1992         uiBlockBeginAlign(block);
1993         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");
1994         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'");
1995         uiBlockEndAlign(block);
1996 }
1997
1998 static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
1999 {
2000         unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
2001 }
2002
2003
2004
2005 static void editing_panel_mesh_tools1(Object *ob, Mesh *me)
2006 {
2007         uiBlock *block;
2008
2009
2010         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools1", UI_EMBOSS, UI_HELV, curarea->win);
2011         if(uiNewPanel(curarea, block, "Mesh Tools 1", "Editing", 960, 0, 318, 204)==0) return;
2012
2013         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");
2014         uiBlockBeginAlign(block);
2015         uiDefBut(block, BUT,B_HIDE,             "Hide",         1091,155,77,24, 0, 0, 0, 0, 0, "Hides selected faces");
2016         uiDefBut(block, BUT,B_REVEAL,   "Reveal",       1171,155,86,24, 0, 0, 0, 0, 0, "Reveals selected faces");
2017         uiBlockEndAlign(block);
2018
2019         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  1091,124,166,24, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
2020
2021         uiBlockBeginAlign(block);
2022         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");
2023         uiDefButI(block, TOG|BIT|6, REDRAWVIEW3D, "Draw Normals",       1090,70,164,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
2024         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces", 1090,50,164,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
2025         uiDefButI(block, TOG|BIT|18, REDRAWVIEW3D, "Draw Edges", 1090,30,164,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
2026         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");
2027         uiBlockEndAlign(block);
2028
2029 }
2030
2031
2032 static void editing_panel_links(Object *ob)
2033 {
2034         uiBlock *block;
2035         ID *id, *idfrom;
2036         int *poin, xco=143;
2037         float min;
2038         Material *ma;
2039         char str[64];
2040         uiBut *but;
2041
2042         block= uiNewBlock(&curarea->uiblocks, "editing_panel_links", UI_EMBOSS, UI_HELV, curarea->win);
2043         if(uiNewPanel(curarea, block, "Link and Materials", "Editing", 0, 0, 318, 204)==0) return;
2044
2045         buttons_active_id(&id, &idfrom);
2046
2047         if(id) {
2048                 int alone= 0;
2049                 int local= 0;
2050                 int browse= B_EDITBROWSE;
2051
2052                 if(ob->type==OB_MESH) {
2053                         browse= B_MESHBROWSE;
2054                         alone= B_MESHALONE;
2055                         local= B_MESHLOCAL;
2056                         uiSetButLock(G.obedit!=0, "Unable to perform function in EditMode");
2057                 }
2058                 else if(ob->type==OB_MBALL) {
2059                         alone= B_MBALLALONE;
2060                         local= B_MBALLLOCAL;
2061                 }
2062                 else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
2063                         alone= B_CURVEALONE;
2064                         local= B_CURVELOCAL;
2065                 }
2066                 else if(ob->type==OB_CAMERA) {
2067                         alone= B_CAMERAALONE;
2068                         local= B_CAMERALOCAL;
2069                 }
2070                 else if(ob->type==OB_LAMP) {
2071                         alone= B_LAMPALONE;
2072                         local= B_LAMPLOCAL;
2073                 }
2074                 else if (ob->type==OB_ARMATURE){
2075                         alone = B_ARMALONE;
2076                         local = B_ARMLOCAL;
2077                 }
2078                 else if(ob->type==OB_LATTICE) {
2079                         alone= B_LATTALONE;
2080                         local= B_LATTLOCAL;
2081                 }
2082                 uiBlockSetCol(block, TH_BUT_SETTING2);
2083                 xco= std_libbuttons(block, 143, 180, 0, NULL, browse, id, idfrom, &(G.buts->menunr), alone, local, 0, 0, B_KEEPDATA);
2084                 uiBlockSetCol(block, TH_AUTO);
2085         }
2086         if(ob) {
2087                 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.");
2088                 uiButSetFunc(but, test_idbutton_cb, ob->id.name, NULL);
2089         }
2090
2091
2092
2093         /* to be sure */
2094         if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL);
2095         else return;
2096
2097
2098         if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag );
2099         else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag );
2100         else poin= &( ((Curve *)ob->data)->texflag );
2101         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");
2102
2103         sprintf(str,"%d Mat:", ob->totcol);
2104         if(ob->totcol) min= 1.0; else min= 0.0;
2105         ma= give_current_material(ob, ob->actcol);
2106
2107         if(ma) uiDefBut(block, LABEL, 0, ma->id.name+2, 318,153, 103, 20, 0, 0, 0, 0, 0, "");
2108
2109         uiBlockBeginAlign(block);
2110         if(ma) uiDefButF(block, COL, B_REDR, "",                        291,123,24,30, &(ma->r), 0, 0, 0, 0, "");
2111         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");
2112         uiDefBut(block, BUT,B_MATWICH,  "?",            423,123,31,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces");
2113
2114         uiBlockBeginAlign(block);
2115         uiDefBut(block, BUT,B_MATNEW,   "New",          292,98,80,20, 0, 0, 0, 0, 0, "Adds a new Material index");
2116         uiDefBut(block, BUT,B_MATDEL,   "Delete",       374,98,80,20, 0, 0, 0, 0, 0, "Deletes this Material index");
2117         uiDefBut(block, BUT,B_MATSEL,   "Select",       292,76,80,20, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index");
2118         uiDefBut(block, BUT,B_MATDESEL, "Deselect",     374,76,80,20, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber");
2119         uiDefBut(block, BUT,B_MATASS,   "Assign",       292,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces");
2120
2121         uiBlockBeginAlign(block);
2122         uiDefBut(block, BUT,B_SETSMOOTH,"Set Smooth",   291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces");
2123         uiDefBut(block, BUT,B_SETSOLID, "Set Solid",    373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces");
2124         uiBlockEndAlign(block);
2125
2126         /* vertex group... partially editmode... */
2127         if(ob->type==OB_MESH) {
2128                 uiBut *but;
2129                 int     defCount;
2130                 bDeformGroup    *defGroup;
2131                 char *s, *menustr;
2132                 bDeformGroup *dg;
2133                 int min, index;
2134                 char (*qsort_ptr)[32] = NULL;
2135
2136                 uiDefBut(block, LABEL,0,"Vertex Groups",
2137                                  143,153,130,20, 0, 0, 0, 0, 0, "");
2138
2139                 defCount=BLI_countlist(&ob->defbase);
2140
2141                 if (!defCount) min=0;
2142                 else min=1;
2143
2144                 if (defCount > 0) {
2145                         /*
2146                          * This will hold the group names temporarily
2147                          * so we can sort them
2148                          */
2149                         qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr[0]),
2150                                                                          "qsort_ptr");
2151                         for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
2152                                 snprintf (qsort_ptr[index - 1], sizeof (qsort_ptr[0]),
2153                                                   "%s%%x%d|", dg->name, index);
2154                         }
2155
2156                         qsort (qsort_ptr, defCount, sizeof (qsort_ptr[0]),
2157                                    ( int (*)(const void *, const void *) ) strcmp);
2158                 }
2159
2160                 s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
2161                 for (index = 0; index < defCount; index++) {
2162                         int cnt= sprintf (s, "%s", qsort_ptr[index]);
2163                         if (cnt>0) s+= cnt;
2164                 }
2165
2166                 if (qsort_ptr)
2167                   MEM_freeN (qsort_ptr);
2168
2169                 uiBlockBeginAlign(block);
2170                 if (defCount)
2171                         uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr,
2172                                           143, 132,18,21, &ob->actdef, min, defCount, 0, 0,
2173                                           "Browses available vertex groups");
2174
2175                 MEM_freeN (menustr);
2176
2177                 if (ob->actdef){
2178                         defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
2179                         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.)");
2180                         uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
2181
2182                         uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          143, 111, 140, 21, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
2183                 }
2184                 uiBlockEndAlign(block);
2185
2186                 if (G.obedit && G.obedit==ob){
2187                         uiBlockBeginAlign(block);
2188         /*              uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assigns deformation groups"); */
2189                         uiDefBut(block, BUT,B_NEWVGROUP,"New",                  143,90,70,21, 0, 0, 0, 0, 0, "Creates a new vertex group");
2190                         uiDefBut(block, BUT,B_DELVGROUP,"Delete",               213,90,70,21, 0, 0, 0, 0, 0, "Removes the current vertex group");
2191
2192                         uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",    143,69,70,21, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group");
2193                         uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",    213,69,70,21, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group");
2194
2195                         uiDefBut(block, BUT,B_SELVGROUP,"Select",               143,48,70,21, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group");
2196                         uiDefBut(block, BUT,B_DESELVGROUP,"Desel.",             213,48,70,21, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group");
2197                         uiBlockEndAlign(block);
2198                 }
2199         }
2200
2201
2202 }
2203
2204 /* *************************** FACE/PAINT *************************** */
2205
2206 void do_fpaintbuts(unsigned short event)
2207 {
2208         Mesh *me;
2209         Object *ob;
2210         extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
2211
2212         ob= OBACT;
2213         if(ob==0) return;
2214
2215         switch(event) {
2216
2217         case B_VPGAMMA:
2218                 vpaint_dogamma();
2219                 break;
2220         case B_COPY_TF_MODE:
2221         case B_COPY_TF_UV:
2222         case B_COPY_TF_COL:
2223         case B_COPY_TF_TEX:
2224                 me= get_mesh(ob);
2225                 if(me && me->tface) {
2226 /*                      extern TFace *lasttface; */
2227                         TFace *tface= me->tface;
2228                         int a= me->totface;
2229
2230                         set_lasttface();
2231                         if(lasttface) {
2232
2233                                 while(a--) {
2234                                         if(tface!=lasttface && (tface->flag & TF_SELECT)) {
2235                                                 if(event==B_COPY_TF_MODE) {
2236                                                         tface->mode= lasttface->mode;
2237                                                         tface->transp= lasttface->transp;
2238                                                 }
2239                                                 else if(event==B_COPY_TF_UV) {
2240                                                         memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
2241                                                         tface->tpage= lasttface->tpage;
2242                                                         tface->tile= lasttface->tile;
2243
2244                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2245                                                         else tface->mode &= ~TF_TILES;
2246
2247                                                 }
2248                                                 else if(event==B_COPY_TF_TEX) {
2249                                                         tface->tpage= lasttface->tpage;
2250                                                         tface->tile= lasttface->tile;
2251
2252                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2253                                                         else tface->mode &= ~TF_TILES;
2254                                                 }
2255                                                 else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
2256                                         }
2257                                         tface++;
2258                                 }
2259                         }
2260                         do_shared_vertexcol(me);
2261                         allqueue(REDRAWVIEW3D, 0);
2262                         allqueue(REDRAWIMAGE, 0);
2263                 }
2264                 break;
2265         case B_SET_VCOL:
2266                 clear_vpaint_selectedfaces();
2267                 break;
2268         case B_REDR_3D_IMA:
2269                 allqueue(REDRAWVIEW3D, 0);
2270                 allqueue(REDRAWIMAGE, 0);
2271                 break;
2272         case B_ASSIGNMESH:
2273
2274                 test_object_materials(ob->data);
2275                 allqueue(REDRAWVIEW3D, 0);
2276                 allqueue(REDRAWBUTSEDIT, 0);
2277                 break;
2278
2279         case B_TFACE_HALO:
2280                 set_lasttface();
2281                 if(lasttface) {
2282                         lasttface->mode &= ~TF_BILLBOARD2;
2283                         allqueue(REDRAWBUTSEDIT, 0);
2284                 }
2285                 break;
2286
2287         case B_TFACE_BILLB:
2288                 set_lasttface();
2289                 if(lasttface) {
2290                         lasttface->mode &= ~TF_BILLBOARD;
2291                         allqueue(REDRAWBUTSEDIT, 0);
2292                 }
2293                 break;
2294         }
2295 }
2296
2297
2298 /* -------------------- MODE: vpaint faceselect ------------------- */
2299
2300 static void editing_panel_mesh_paint(void)
2301 {
2302         extern VPaint Gvp;         /* from vpaint */
2303         uiBlock *block;
2304
2305         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_paint", UI_EMBOSS, UI_HELV, curarea->win);
2306         if(uiNewPanel(curarea, block, "Paint", "Editing", 640, 0, 318, 204)==0) return;
2307
2308         uiBlockBeginAlign(block);
2309         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");
2310         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");
2311         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");
2312         uiBlockEndAlign(block);
2313
2314         uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2315         uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2316
2317         uiDefButF(block, COL, B_REDR, "",               1176,100,28,80, &(Gvp.r), 0, 0, 0, B_VPCOLSLI, "");
2318         uiBlockBeginAlign(block);
2319         uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
2320         uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
2321         uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
2322         uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
2323         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");
2324
2325         uiBlockBeginAlign(block);
2326         uiDefButS(block, TOG|BIT|1, 0, "Area",          980,50,80,19, &Gvp.flag, 0, 0, 0, 0, "Set the area the brush covers");
2327         uiDefButS(block, TOG|BIT|2, 0, "Soft",          1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
2328         uiDefButS(block, TOG|BIT|3, 0, "Normals",       1174,50,102,19, &Gvp.flag, 0, 0, 0, 0, "Use vertex normal for painting");
2329
2330         uiBlockBeginAlign(block);
2331         uiDefBut(block, BUT, B_VPGAMMA, "Set",  980,30,80,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
2332         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");
2333         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");
2334         uiBlockEndAlign(block);
2335
2336         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)");
2337
2338 }
2339
2340
2341 static void editing_panel_mesh_texface(void)
2342 {
2343         uiBlock *block;
2344         extern TFace *lasttface;
2345
2346         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_texface", UI_EMBOSS, UI_HELV, curarea->win);
2347         if(uiNewPanel(curarea, block, "Texture face", "Editing", 960, 0, 318, 204)==0) return;
2348
2349         set_lasttface();        // checks for ob type
2350         if(lasttface) {
2351
2352                 uiBlockBeginAlign(block);
2353                 uiDefButS(block, TOG|BIT|2, B_REDR_3D_IMA, "Tex",       600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
2354                 uiDefButS(block, TOG|BIT|7, B_REDR_3D_IMA, "Tiles",     660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
2355                 uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Light",      720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
2356                 uiDefButS(block, TOG|BIT|10, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
2357                 uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
2358
2359                 uiBlockBeginAlign(block);
2360                 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");
2361                 uiDefButS(block, TOG|BIT|9, REDRAWVIEW3D, "Twoside",660,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
2362                 uiDefButS(block, TOG|BIT|11, REDRAWVIEW3D, "ObColor",720,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
2363
2364                 uiBlockBeginAlign(block);
2365                 uiDefButS(block, TOG|BIT|8, B_TFACE_HALO, "Halo",       600,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
2366                 uiDefButS(block, TOG|BIT|12, B_TFACE_BILLB, "Billboard",660,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
2367                 uiDefButS(block, TOG|BIT|13, REDRAWVIEW3D, "Shadow", 720,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
2368                 uiDefButS(block, TOG|BIT|14, REDRAWVIEW3D, "Text", 780,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
2369
2370                 uiBlockBeginAlign(block);
2371                 uiBlockSetCol(block, TH_BUT_SETTING1);
2372                 uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,80,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
2373                 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");
2374                 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");
2375
2376                 uiBlockSetCol(block, TH_AUTO);
2377                 uiBlockBeginAlign(block);
2378                 uiDefBut(block, BUT, B_COPY_TF_MODE, "Copy DrawMode", 600,7,117,28, 0, 0, 0, 0, 0, "Copy the drawmode");
2379                 uiDefBut(block, BUT, B_COPY_TF_UV, "Copy UV+tex",         721,7,85,28, 0, 0, 0, 0, 0, "Copy UV information and textures");
2380                 uiDefBut(block, BUT, B_COPY_TF_COL, "Copy VertCol",       809,7,103,28, 0, 0, 0, 0, 0, "Copy vertex colours");
2381         }
2382
2383 }
2384
2385 void do_uvautocalculationbuts(unsigned short event)
2386 {
2387         switch(event) {
2388         case B_UVAUTO_STD1:
2389         case B_UVAUTO_STD2:
2390         case B_UVAUTO_STD4:
2391         case B_UVAUTO_STD8:
2392         case B_UVAUTO_CUBE:
2393                 calculate_uv_map(event);
2394                 break;
2395         case B_UVAUTO_BOUNDS1:
2396         case B_UVAUTO_BOUNDS2:
2397         case B_UVAUTO_BOUNDS4:
2398         case B_UVAUTO_BOUNDS8:
2399         case B_UVAUTO_SPHERE:
2400         case B_UVAUTO_CYLINDER:
2401         case B_UVAUTO_WINDOW:
2402                 if(select_area(SPACE_VIEW3D)) calculate_uv_map(event);
2403                 break;
2404         }
2405 }
2406
2407 static void editing_panel_mesh_uvautocalculation(void)
2408 {
2409         uiBlock *block;
2410         int butH= 19, butHB= 20, row= 180, butS= 10;
2411
2412         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_uvautocalculation", UI_EMBOSS, UI_HELV, curarea->win);
2413         /* make this a tab of "Texture face" to save screen space*/
2414         uiNewPanelTabbed("Texture face", "Editing");
2415         if(uiNewPanel(curarea, block, "UV Calculation", "Editing", 960, 0, 318, 204)==0)
2416                 return;
2417
2418         uiBlockBeginAlign(block);
2419         uiDefBut(block, BUT, B_UVAUTO_STD1,"Standard 1/1",100,row,200,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping");
2420         uiDefBut(block, BUT, B_UVAUTO_STD2,"1/2",100,row-butHB,66,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/2");
2421         uiDefBut(block, BUT, B_UVAUTO_STD4,"1/4",166,row-butHB,67,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/4");
2422         uiDefBut(block, BUT, B_UVAUTO_STD8,"1/8",234,row-butHB,66,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/8");
2423         uiBlockEndAlign(block);
2424         row-= 2*butHB+butS;
2425
2426         uiBlockBeginAlign(block);
2427         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");
2428         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");
2429         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");
2430         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");
2431         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");
2432         uiBlockEndAlign(block);
2433         row-= 3*butHB+butS;
2434
2435         uiBlockBeginAlign(block);
2436         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");
2437         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");
2438         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");
2439         uiBlockEndAlign(block);
2440         row-= 3*butHB+butS;
2441
2442         row= 180;
2443
2444         uiBlockBeginAlign(block);
2445         uiDefBut(block, BUT, B_UVAUTO_CUBE,"Cube",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cube UV mapping");
2446         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");
2447         uiBlockEndAlign(block);
2448         row-= 2*butHB+butS;
2449
2450         uiBlockBeginAlign(block);
2451         uiDefBut(block, BUT, B_UVAUTO_SPHERE,"Sphere",315,row,200,butH, 0, 0, 0, 0, 0, "Applies spherical UV mapping");
2452         uiBlockEndAlign(block);
2453         row-= butHB+butS;
2454
2455         uiBlockBeginAlign(block);
2456         uiDefBut(block, BUT, B_UVAUTO_CYLINDER,"Cylinder",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cylindrical UV mapping");
2457         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");
2458         uiBlockEndAlign(block);
2459         row-= 2*butHB+butS;
2460
2461
2462         uiBlockBeginAlign(block);
2463         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");
2464         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");
2465         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");
2466         uiBlockEndAlign(block);
2467         row-= 2*butHB+butS;
2468
2469         uiBlockBeginAlign(block);
2470         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");
2471         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");
2472         uiBlockEndAlign(block);
2473 }
2474
2475 /* this is a mode context sensitive system */
2476
2477 void editing_panels()
2478 {
2479         Object *ob;
2480         Curve *cu;
2481         MetaBall *mb;
2482         Lattice *lt;
2483         bArmature *arm;
2484         Camera *cam;
2485
2486         ob= OBACT;
2487         if(ob==NULL) return;
2488
2489         switch(ob->type) {
2490         case OB_MESH:
2491                 editing_panel_links(ob); // no editmode!
2492                 editing_panel_mesh_type(ob, ob->data);  // no editmode!
2493                 /* modes */
2494                 if(G.obedit) {
2495                         editing_panel_mesh_tools(ob, ob->data); // no editmode!
2496                         editing_panel_mesh_tools1(ob, ob->data); // no editmode!
2497                 }
2498                 else {
2499                         if(G.f & G_FACESELECT) {
2500                                 editing_panel_mesh_texface();
2501                                 editing_panel_mesh_uvautocalculation();
2502                         }
2503                         if(G.f & (G_VERTEXPAINT | G_TEXTUREPAINT | G_WEIGHTPAINT) ) {
2504                                 editing_panel_mesh_paint();
2505                         }
2506                 }
2507                 break;
2508
2509         case OB_CURVE:
2510         case OB_SURF:
2511                 cu= ob->data;
2512                 editing_panel_links(ob); // no editmode!
2513                 editing_panel_curve_type(ob, cu);
2514                 if(G.obedit) {
2515                         editing_panel_curve_tools(ob, cu);
2516                         editing_panel_curve_tools1(ob, cu);
2517                 }
2518                 break;
2519
2520         case OB_MBALL:
2521                 mb= ob->data;
2522                 editing_panel_links(ob); // no editmode!
2523                 editing_panel_mball_type(ob, mb);
2524                 if(G.obedit) {
2525                         editing_panel_mball_tools(ob, mb);
2526                 }
2527                 break;
2528
2529         case OB_FONT:
2530                 cu= ob->data;
2531                 editing_panel_links(ob); // no editmode!
2532                 editing_panel_curve_type(ob, cu);
2533                 editing_panel_font_type(ob, cu);
2534                 break;
2535
2536         case OB_LATTICE:
2537                 lt= ob->data;
2538                 editing_panel_links(ob); // no editmode!
2539                 editing_panel_lattice_type(ob, lt);
2540                 break;
2541
2542         case OB_LAMP:
2543                 editing_panel_links(ob); // no editmode!
2544                 break;
2545
2546         case OB_EMPTY:
2547                 editing_panel_links(ob); // no editmode!
2548                 break;
2549
2550         case OB_CAMERA:
2551                 cam= ob->data;
2552                 editing_panel_links(ob); // no editmode!
2553                 editing_panel_camera_type(ob, cam);
2554                 break;
2555
2556         case OB_ARMATURE:
2557                 arm= ob->data;
2558                 editing_panel_links(ob); // no editmode!
2559                 editing_panel_armature_type(ob, arm);
2560                 if(G.obedit) {
2561                         editing_panel_armature_bones(ob, arm);
2562                 }
2563                 break;
2564         }
2565
2566 }