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