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