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