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