- got rid of silly #define ..._BIT, #define ... (1<<..._BIT) stuff
[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         uiDefButBitS(block, TOG, ME_AUTOSMOOTH, 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         uiDefButBitS(block, TOG, ME_OPT_EDGES, 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         uiDefButBitS(block, TOG, ME_TWOSIDED, REDRAWVIEW3D, "Double Sided",     275,30,130,19, &me->flag, 0, 0, 0, 0, "Toggles selected faces as doublesided or single-sided");
501         uiDefButBitS(block, TOG, ME_NOPUNOFLIP, 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         uiDefButBitC(block, TOG, CU_BOLD, B_STYLETOSEL, "B",            752,165,20,20, &(cu->curinfo.flag), 0,0, 0, 0, "");
827         uiDefButBitC(block, TOG, CU_ITALIC, 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         uiDefButBitS(block, TOG, CU_FAST, 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         uiDefButBitS(block, TOG, CU_UV_ORCO, 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                 uiDefButBitS(block, TOG, CU_NOPUNOFLIP, 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                         uiDefButBitS(block, TOG, CU_PATH, B_RECALCPATH, "CurvePath",    600,30,75,19 , &cu->flag, 0, 0, 0, 0, "Enables curve to become translation path");
1146                         uiDefButBitS(block, TOG, CU_FOLLOW, REDRAWVIEW3D, "CurveFollow",675,30,75,19, &cu->flag, 0, 0, 0, 0, "Makes curve path children to rotate along path");
1147                         uiDefButBitS(block, TOG, CU_STRETCH, 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                         uiDefButBitS(block, TOG, CU_OFFS_PATHDIST, 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                 uiDefButBitS(block, TOG, CU_BACK, B_MAKEDISP, "Back",   760,130,50,19, &cu->flag, 0, 0, 0, 0, "Draw filled back for curves");
1168                 uiDefButBitS(block, TOG, CU_FRONT, B_MAKEDISP, "Front",810,130,50,19, &cu->flag, 0, 0, 0, 0, "Draw filled front for curves");
1169                 uiDefButBitS(block, TOG, CU_3D, 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         uiDefButBitS(block, TOG, CAM_SHOWLIMITS, REDRAWVIEW3D, "ShowLimits", 533,59,97,30, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
1206         uiDefButBitS(block, TOG, CAM_SHOWMIST, 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         uiDefButBitS(block, TOG, CAM_YF_NO_QMC, 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                 uiDefButBitS(block, TOG, MB_NEGATIVE, B_RECALCMBALL, "Negative",753,16,125,19, &lastelem->flag, 0, 0, 0, 0, "Make active meta creating holes");
1323                 uiDefButBitS(block, TOG, MB_HIDE, 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         uiDefButBitS(block, TOG, LT_OUTSIDE, 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 = uiDefButBitI(block, TOG, ARM_RESTPOS, 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         uiDefButBitI(block, TOG, ARM_DELAYDEFORM, REDRAWVIEW3D, "Delay Deform", 160, 180,150,20, &arm->flag, 0, 0, 0, 0, "Don't deform children when manipulating bones in pose mode");
1550         uiBlockBeginAlign(block);
1551         uiDefButI(block, ROW, REDRAWVIEW3D, "Octahedron", 10, 140,100,20, &arm->drawtype, 0, ARM_OCTA, 0, 0, "Draw bone as octahedra");
1552         uiDefButI(block, ROW, REDRAWVIEW3D, "Sticks",   110, 140,100,20, &arm->drawtype, 0, ARM_LINE, 0, 0, "Draw bone as simple 2d lines with dots");
1553         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");
1554         
1555         uiBlockBeginAlign(block);
1556         uiDefButBitI(block, TOG, ARM_DRAWAXES, REDRAWVIEW3D, "Draw Axes", 10, 110,100,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
1557         uiDefButBitI(block, TOG, ARM_DRAWNAMES, REDRAWVIEW3D, "Draw Names", 110,110,100,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
1558         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");
1559 }
1560
1561 static void editing_panel_armature_bones(Object *ob, bArmature *arm)
1562 {
1563         uiBlock         *block;
1564         uiBut           *but;
1565         EditBone        *curBone;
1566         char            *boneString=NULL;
1567         int                     bx=148, by=180;
1568         int                     index;
1569
1570         /* Draw the bone name block */
1571
1572         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_bones", UI_EMBOSS, UI_HELV, curarea->win);
1573         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
1574
1575         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1576         /* so first we make it default height */
1577         uiNewPanelHeight(block, 204);
1578
1579
1580         uiDefBut(block, LABEL, 0, "Selected Bones", bx,by,158,18, 0, 0, 0, 0, 0, "Only show in Armature Editmode");
1581         by-=20;
1582         for (curBone=G.edbo.first, index=0; curBone; curBone=curBone->next, index++){
1583                 if (curBone->flag & (BONE_SELECTED)) {
1584
1585                         /*      Bone naming button */
1586                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:", bx-10,by,117,18, &curBone->name, 0, 24, 0, 0, "Change the bone name");
1587                         uiButSetFunc(but, validate_editbonebutton_cb, curBone, NULL);
1588
1589                         uiDefBut(block, LABEL, 0, "child of", bx+107,by,73,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1590
1591                         boneString = MEM_mallocN((BLI_countlist(&G.edbo) * 64)+64, "Bone str");
1592                         build_bonestring (boneString, curBone);
1593
1594                         curBone->parNr = editbone_to_parnr(curBone->parent);
1595                         but = uiDefButI(block, MENU,REDRAWVIEW3D, boneString, bx+180,by,120,18, &curBone->parNr, 0.0, 0.0, 0.0, 0.0, "Parent");
1596                         /* last arg NULL means button will put old string there */
1597                         uiButSetFunc(but, parnr_to_editbone_cb, curBone, NULL);
1598
1599                         MEM_freeN(boneString);
1600
1601                         /* IK to parent flag */
1602                         if (curBone->parent){
1603                                 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");
1604                                 uiButSetFunc(but, attach_bone_to_parent_cb, curBone, NULL);
1605                         }
1606
1607                         /* Segment, dist and weight buttons */
1608                         uiBlockBeginAlign(block);
1609                         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");
1610                         uiDefButF(block, NUM,REDRAWVIEW3D, "Dist:", bx+110, by-19, 105, 18, &curBone->dist, 0.0, 1000.0, 10.0, 0.0, "Bone deformation distance");
1611                         uiDefButF(block, NUM,REDRAWVIEW3D, "Weight:", bx+223, by-19,110, 18, &curBone->weight, 0.0F, 1000.0F, 10.0F, 0.0F, "Bone deformation weight");
1612                         
1613                         /* bone types */
1614                         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");
1615                         uiDefButBitS(block, TOGN, 1,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");
1616                         /* Hide in posemode flag */
1617                         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");
1618                         
1619                         uiBlockEndAlign(block);
1620                         by-=60;
1621                         
1622                         if(by < -200) break;    // for time being... extreme long panels are very slow
1623                 }
1624         }
1625
1626         if(by<0) {
1627                 uiNewPanelHeight(block, 204 - by);
1628         }
1629
1630 }
1631
1632 static void editing_panel_pose_bones(Object *ob, bArmature *arm)
1633 {
1634         uiBlock         *block;
1635         uiBut           *but;
1636         bPoseChannel *pchan;
1637         Bone            *curBone;
1638         int                     bx=148, by=180;
1639         int                     index;
1640         
1641         /* Draw the bone name block */
1642         
1643         block= uiNewBlock(&curarea->uiblocks, "editing_panel_pose_bones", UI_EMBOSS, UI_HELV, curarea->win);
1644         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
1645         
1646         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1647         /* so first we make it default height */
1648         uiNewPanelHeight(block, 204);
1649         
1650         uiDefBut(block, LABEL, 0, "Selected Bones", bx,by,158,18, 0, 0, 0, 0, 0, "Only show in Armature Editmode/Posemode");
1651         by-=20;
1652         for (pchan=ob->pose->chanbase.first, index=0; pchan; pchan=pchan->next, index++){
1653                 curBone= pchan->bone;
1654                 if (curBone->flag & (BONE_SELECTED)) {
1655
1656                         /*      Bone naming button */
1657                         uiBlockBeginAlign(block);
1658                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:", bx-10,by,117,18, &curBone->name, 0, 24, 0, 0, "Change the bone name");
1659                         uiButSetFunc(but, validate_posebonebutton_cb, curBone, NULL);
1660                         
1661                         /* Dist and weight buttons */
1662                         uiDefButF(block, NUM,REDRAWVIEW3D, "Dist:", bx+107, by, 105, 18, &curBone->dist, 0.0, 1000.0, 10.0, 0.0, "Bone deformation distance");
1663                         uiDefButF(block, NUM,REDRAWVIEW3D, "Weight:", bx+220, by,  110, 18, &curBone->weight, 0.0F, 1000.0F, 10.0F, 0.0F, "Bone deformation weight");
1664                         
1665                         
1666                         /* Segment, ease in/out buttons */
1667                         uiBlockBeginAlign(block);
1668                         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");
1669                         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");
1670                         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");
1671                         
1672                         /* bone types */
1673                         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");
1674                         uiButSetFunc(but, armature_recalc_func, ob, NULL);
1675                         uiDefButBitS(block, TOGN, 1,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");
1676                         /* Hide in posemode flag */
1677                         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");
1678                         uiBlockEndAlign(block);
1679                         
1680                         by-=60;
1681                         if(by < -200) break;    // for time being... extreme long panels are very slow
1682                 }
1683         }
1684         
1685         if(by<0) {
1686                 uiNewPanelHeight(block, 204 - by);
1687         }
1688         
1689 }
1690
1691
1692 /* *************************** MESH ******************************** */
1693
1694 void do_meshbuts(unsigned short event)
1695 {
1696         Object *ob;
1697         Mesh *me;
1698         float fac;
1699         short randfac;
1700
1701         ob= OBACT;
1702         if(ob && ob->type==OB_MESH) {
1703
1704                 me= get_mesh(ob);
1705                 if(me==0) return;
1706
1707                 switch(event) {
1708                 case B_AUTOVGROUP:
1709                         if (!get_armature(ob->parent)){
1710                                 error ("Mesh must be the child of an armature");
1711                                 break;
1712                         }
1713                                 /* Verify that there are vertex groups for bones in armature */
1714                                 /* Remove selected vertices from all defgroups */
1715                                 /* Perform assignment for selected vertices */
1716
1717                         allqueue (REDRAWVIEW3D, 1);
1718                         break;
1719                 case B_NEWVGROUP:
1720                         add_defgroup (G.obedit);
1721                         scrarea_queue_winredraw(curarea);
1722                         break;
1723                 case B_DELVGROUP:
1724                         del_defgroup (G.obedit);
1725                         allqueue (REDRAWVIEW3D, 1);
1726                         BIF_undo_push("Delete vertex group");
1727                         break;
1728                 case B_ASSIGNVGROUP:
1729                         assign_verts_defgroup ();
1730                         allqueue (REDRAWVIEW3D, 1);
1731                         BIF_undo_push("Assign to vertex group");
1732                         break;
1733                 case B_REMOVEVGROUP:
1734                         remove_verts_defgroup (0);
1735                         allqueue (REDRAWVIEW3D, 1);
1736                         BIF_undo_push("Remove from vertex group");
1737                         break;
1738                 case B_SELVGROUP:
1739                         sel_verts_defgroup(1);
1740                         allqueue (REDRAWVIEW3D, 1);
1741                         break;
1742                 case B_DESELVGROUP:
1743                         sel_verts_defgroup(0);
1744                         allqueue (REDRAWVIEW3D, 1);
1745                         break;
1746                 case B_DELSTICKY:
1747
1748                         if(me->msticky) MEM_freeN(me->msticky);
1749                         me->msticky= NULL;
1750                         allqueue(REDRAWBUTSEDIT, 0);
1751                         break;
1752                 case B_MAKESTICKY:
1753                         RE_make_sticky();
1754                         allqueue(REDRAWBUTSEDIT, 0);
1755                         break;
1756                 
1757                 case B_MAKEEDGES:
1758                         /* in editmode we only have to set edge pointer */
1759                         if(ob==G.obedit) {
1760                                 me->medge= MEM_callocN(sizeof(MEdge), "fake mesh edge");
1761                                 me->totedge= 1;
1762                         }
1763                         else make_edges(me);
1764                         allqueue(REDRAWBUTSEDIT, 0);
1765                         break;
1766                 case B_DELEDGES:
1767                         if(me->medge) MEM_freeN(me->medge);
1768                         me->medge= NULL;
1769                         me->totedge= 0;
1770                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1771                         allqueue(REDRAWBUTSEDIT, 0);
1772                         allqueue(REDRAWVIEW3D, 0);
1773                         break;
1774                         
1775                 case B_MAKEVERTCOL:
1776                         make_vertexcol();
1777                         break;
1778                 case B_DELVERTCOL:
1779                         if(me->mcol) MEM_freeN(me->mcol);
1780                         me->mcol= NULL;
1781                         G.f &= ~G_VERTEXPAINT;
1782                         freedisplist(&(ob->disp));
1783                         allqueue(REDRAWBUTSEDIT, 0);
1784                         allqueue(REDRAWVIEW3D, 0);
1785                         break;
1786
1787                 case B_MAKE_TFACES:
1788                         make_tfaces(me);
1789                         allqueue(REDRAWBUTSEDIT, 0);
1790                         break;
1791
1792                 case B_DEL_TFACES:
1793                         if(me->tface) MEM_freeN(me->tface);
1794                         me->tface= 0;
1795                         G.f &= ~G_FACESELECT;
1796                         allqueue(REDRAWBUTSEDIT, 0);
1797                         allqueue(REDRAWVIEW3D, 0);
1798                         allqueue(REDRAWIMAGE, 0);
1799                         break;
1800
1801                 case B_FLIPNORM:
1802                         if(G.obedit) {
1803                                 flip_editnormals();
1804                         }
1805                         else {
1806                                 flipnorm_mesh( get_mesh(ob) );
1807                                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1808                         }
1809
1810                         allqueue(REDRAWVIEW3D, 0);
1811                         break;
1812
1813                 case B_SLOWERDRAW:
1814                         slowerdraw();
1815                         break;
1816                 case B_FASTERDRAW:
1817                         fasterdraw();
1818                         break;
1819                 }
1820         }
1821
1822         if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return;
1823
1824         switch(event) {
1825         case B_SPIN:
1826                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 0);
1827                 break;
1828         case B_SPINDUP:
1829                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 1);
1830                 break;
1831         case B_EXTR:
1832                 G.f |= G_DISABLE_OK;
1833                 if( select_area(SPACE_VIEW3D)) extrude_mesh();
1834                 G.f -= G_DISABLE_OK;
1835                 break;
1836         case B_SCREW:
1837                 if( select_area(SPACE_VIEW3D)) screw_mesh(step, turn);
1838                 break;
1839         case B_EXTREP:
1840                 if( select_area(SPACE_VIEW3D)) extrude_repeat_mesh(step, extr_offs);
1841                 break;
1842         case B_SPLIT:
1843                 G.f |= G_DISABLE_OK;
1844                 split_mesh();
1845                 G.f -= G_DISABLE_OK;
1846                 break;
1847         case B_REMDOUB:
1848                 notice("Removed: %d", removedoublesflag(1, doublimit));
1849                 allqueue(REDRAWVIEW3D, 0);
1850                 BIF_undo_push("Rem Doubles");
1851                 break;
1852         case B_SUBDIV:
1853                 waitcursor(1);
1854                 esubdivideflag(1, 0.0, editbutflag & B_BEAUTY,1,0);
1855                 countall();
1856                 waitcursor(0);
1857                 allqueue(REDRAWVIEW3D, 0);
1858                 BIF_undo_push("Subdivide");
1859                 break;
1860         case B_FRACSUBDIV:
1861                 randfac= 10;
1862                 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
1863                 waitcursor(1);
1864                 fac= -( (float)randfac )/100;
1865                 esubdivideflag(1, fac, editbutflag & B_BEAUTY,1,0);
1866                 countall();
1867                 waitcursor(0);
1868                 allqueue(REDRAWVIEW3D, 0);
1869                 BIF_undo_push("Fractal Subdivide");
1870                 break;
1871         case B_XSORT:
1872                 if( select_area(SPACE_VIEW3D)) xsortvert_flag(1);
1873                 break;
1874         case B_HASH:
1875                 hashvert_flag(1);
1876                 break;
1877         case B_TOSPHERE:
1878                 vertices_to_sphere();
1879                 break;
1880         case B_VERTEXNOISE:
1881                 vertexnoise();
1882                 break;
1883         case B_VERTEXSMOOTH:
1884                 vertexsmooth();
1885                 break;
1886         case B_DRAWEDGES:
1887                 G.f &= ~G_DRAWCREASES;
1888                 allqueue(REDRAWBUTSEDIT, 0);
1889                 allqueue(REDRAWVIEW3D, 0);
1890                 break;
1891         case B_DRAWCREASES:
1892                 G.f &= ~G_DRAWEDGES;
1893                 allqueue(REDRAWBUTSEDIT, 0);
1894                 allqueue(REDRAWVIEW3D, 0);
1895                 break;
1896         }
1897         /* WATCH IT: previous events only in editmode! */
1898 }
1899
1900 static void editing_panel_mesh_tools(Object *ob, Mesh *me)
1901 {
1902         uiBlock *block;
1903
1904         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools", UI_EMBOSS, UI_HELV, curarea->win);
1905         if(uiNewPanel(curarea, block, "Mesh Tools", "Editing", 640, 0, 318, 204)==0) return;
1906
1907         uiBlockBeginAlign(block);
1908         uiDefButBitS(block, TOG, B_BEAUTY, 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");
1909         uiDefButBitS(block, TOG, B_BEAUTY_SHORT, 0, "Short",                50,195,40,19, &editbutflag, 0, 0, 0, 0, "Causes 'Subdivide' to split faces in halves instead of quarters using Short Edges");
1910
1911         uiDefBut(block, BUT,B_SUBDIV,"Subdivide",               90,195,80,19, 0, 0, 0, 0, 0, "Splits selected faces into halves or quarters");
1912         uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd", 170,195,85,19, 0, 0, 0, 0, 0, "Subdivides selected faces with a random factor");
1913
1914         uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",              10,175,80,19, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
1915         uiDefBut(block, BUT,B_HASH,"Hash",                              90,175,80,19, 0, 0, 0, 0, 0, "Randomizes selected vertice sequence data");
1916         uiDefBut(block, BUT,B_XSORT,"Xsort",                    170,175,85,19, 0, 0, 0, 0, 0, "Sorts selected vertice data in the X direction");
1917
1918         uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",             10,155,80,19, 0, 0, 0, 0, 0, "Moves selected vertices outwards into a spherical shape");
1919         uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",    90,155,80,19, 0, 0, 0, 0, 0, "Flattens angles of selected faces");
1920         uiDefBut(block, BUT,B_SPLIT,"Split",                    170,155,85,19, 0, 0, 0, 0, 0, "Splits selected verts to separate sub-mesh.");
1921
1922         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");
1923         uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    90,135,80,19, 0, 0, 0, 0, 0, "Removes duplicates from selected vertices");
1924         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'");
1925         uiBlockEndAlign(block);
1926
1927         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");
1928
1929         uiBlockBeginAlign(block);
1930         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
1931         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");
1932         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");
1933
1934         uiDefButS(block, NUM, B_DIFF, "Degr:",                  10,55,80,19, &degr,10.0,360.0, 0, 0, "Specifies the number of degrees 'Spin' revolves");
1935         uiDefButS(block, NUM, B_DIFF, "Steps:",                 90,55,80,19, &step,1.0,180.0, 0, 0, "Specifies the total number of 'Spin' slices");
1936         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");
1937         uiDefButBitS(block, TOG, B_KEEPORIG, 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");
1938         uiDefButBitS(block, TOG, B_CLOCKWISE, B_DIFF, "Clockwise",      170,35,85,19, &editbutflag, 0, 0, 0, 0, "Specifies the direction for 'Screw' and 'Spin'");
1939
1940         uiBlockBeginAlign(block);
1941         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");
1942         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'");
1943         uiBlockEndAlign(block);
1944 }
1945
1946 static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
1947 {
1948         unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
1949 }
1950
1951
1952
1953 static void editing_panel_mesh_tools1(Object *ob, Mesh *me)
1954 {
1955         uiBlock *block;
1956
1957
1958         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools1", UI_EMBOSS, UI_HELV, curarea->win);
1959         if(uiNewPanel(curarea, block, "Mesh Tools 1", "Editing", 960, 0, 318, 204)==0) return;
1960
1961         uiBlockBeginAlign(block);
1962         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");
1963         uiDefBut(block, BUT,B_HIDE,             "Hide",         1115, 200,  160, 19, 0, 0, 0, 0, 0, "Hides selected faces");
1964         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  955, 180, 160, 19, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
1965         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               1115, 180,  160, 19, 0, 0, 0, 0, 0, "Reveals selected faces");
1966         uiBlockEndAlign(block);
1967
1968         uiBlockBeginAlign(block);
1969         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");
1970         uiDefButBitI(block, TOG, G_DRAWNORMALS, REDRAWVIEW3D, "Draw Normals",   955,110,150,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
1971         uiDefButBitI(block, TOG, G_DRAWFACES, REDRAWVIEW3D, "Draw Faces",               955,88,150,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
1972         uiDefButBitI(block, TOG, G_DRAWEDGES, REDRAWVIEW3D, "Draw Edges",       955,66,150,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
1973         uiDefButBitI(block, TOG, G_DRAWCREASES, REDRAWVIEW3D, "Draw Creases",   955,44,150,19, &G.f, 0, 0, 0, 0, "Displays creases created for subsurf weighting");
1974         uiDefButBitI(block, TOG, G_DRAWSEAMS, REDRAWVIEW3D, "Draw Seams",       955,22,150,19, &G.f, 0, 0, 0, 0, "Displays UV unwrapping seams");
1975         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");
1976         uiBlockEndAlign(block);
1977         
1978         /* Measurement drawing options */
1979         uiBlockBeginAlign(block);
1980         uiDefButBitI(block, TOG, G_DRAW_VNORMALS, REDRAWVIEW3D, "Draw VNormals",1125,110,150,19, &G.f, 0, 0, 0, 0, "Displays vertex normals as lines");
1981         uiDefButBitI(block, TOG, G_DRAW_EDGELEN, REDRAWVIEW3D, "Edge Length",   1125,88,150,19, &G.f, 0, 0, 0, 0, "Displays selected edge lengths");
1982         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");
1983         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");
1984         uiBlockEndAlign(block);
1985
1986 }
1987
1988 char *get_vertexgroup_menustr(Object *ob)
1989 {
1990         bDeformGroup *dg;
1991         int defCount, min, index;
1992         char (*qsort_ptr)[32] = NULL;
1993         char *s, *menustr;
1994         
1995         defCount=BLI_countlist(&ob->defbase);
1996         
1997         if (!defCount) min=0;
1998         else min=1;
1999         
2000         if (defCount > 0) {
2001                 /*
2002                  * This will hold the group names temporarily
2003                  * so we can sort them
2004                  */
2005                 qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr[0]),
2006                                                                  "qsort_ptr");
2007                 for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
2008                         snprintf (qsort_ptr[index - 1], sizeof (qsort_ptr[0]),
2009                                           "%s%%x%d|", dg->name, index);
2010                 }
2011                 
2012                 qsort (qsort_ptr, defCount, sizeof (qsort_ptr[0]),
2013                            ( int (*)(const void *, const void *) ) strcmp);
2014         }
2015         
2016         s= menustr = MEM_callocN((32 * defCount)+30, "menustr");        // plus 30 for when defCount==0
2017         if(defCount) {
2018                 for (index = 0; index < defCount; index++) {
2019                         int cnt= sprintf (s, "%s", qsort_ptr[index]);
2020                         if (cnt>0) s+= cnt;
2021                 }
2022         }
2023         else strcpy(menustr, "No Vertex Groups in Object");
2024         
2025         if (qsort_ptr)
2026                 MEM_freeN (qsort_ptr);
2027         
2028         return menustr;
2029 }
2030
2031 static void editing_panel_links(Object *ob)
2032 {
2033         uiBlock *block;
2034         ID *id, *idfrom;
2035         int *poin, xco=143;
2036         float min;
2037         Material *ma;
2038         char str[64];
2039         uiBut *but;
2040
2041         block= uiNewBlock(&curarea->uiblocks, "editing_panel_links", UI_EMBOSS, UI_HELV, curarea->win);
2042         if(uiNewPanel(curarea, block, "Link and Materials", "Editing", 0, 0, 318, 204)==0) return;
2043
2044         buttons_active_id(&id, &idfrom);
2045
2046         if(id) {
2047                 int alone= 0;
2048                 int local= 0;
2049                 int browse= B_EDITBROWSE;
2050
2051                 if(ob->type==OB_MESH) {
2052                         browse= B_MESHBROWSE;
2053                         alone= B_MESHALONE;
2054                         local= B_MESHLOCAL;
2055                         uiSetButLock(G.obedit!=0, "Unable to perform function in EditMode");
2056                 }
2057                 else if(ob->type==OB_MBALL) {
2058                         alone= B_MBALLALONE;
2059                         local= B_MBALLLOCAL;
2060                 }
2061                 else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
2062                         alone= B_CURVEALONE;
2063                         local= B_CURVELOCAL;
2064                 }
2065                 else if(ob->type==OB_CAMERA) {
2066                         alone= B_CAMERAALONE;
2067                         local= B_CAMERALOCAL;
2068                 }
2069                 else if(ob->type==OB_LAMP) {
2070                         alone= B_LAMPALONE;
2071                         local= B_LAMPLOCAL;
2072                 }
2073                 else if (ob->type==OB_ARMATURE){
2074                         alone = B_ARMALONE;
2075                         local = B_ARMLOCAL;
2076                 }
2077                 else if(ob->type==OB_LATTICE) {
2078                         alone= B_LATTALONE;
2079                         local= B_LATTLOCAL;
2080                 }
2081                 uiBlockSetCol(block, TH_BUT_SETTING2);
2082                 xco= std_libbuttons(block, 143, 180, 0, NULL, browse, id, idfrom, &(G.buts->menunr), alone, local, 0, 0, B_KEEPDATA);
2083                 uiBlockSetCol(block, TH_AUTO);
2084         }
2085         if(ob) {
2086                 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.");
2087                 uiButSetFunc(but, test_idbutton_cb, ob->id.name, NULL);
2088         }
2089
2090
2091
2092         /* to be sure */
2093         if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL);
2094         else return;
2095
2096
2097         if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag );
2098         else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag );
2099         else poin= &( ((Curve *)ob->data)->texflag );
2100         uiDefButBitI(block, TOG, AUTOSPACE, B_AUTOTEX, "AutoTexSpace",  143,15,140,19, poin, 0, 0, 0, 0, "Adjusts active object's texture space automatically when transforming object");
2101
2102         sprintf(str,"%d Mat ", ob->totcol);
2103         if(ob->totcol) min= 1.0; else min= 0.0;
2104         ma= give_current_material(ob, ob->actcol);
2105
2106         if(ma) uiDefBut(block, LABEL, 0, ma->id.name+2, 318,153, 103, 20, 0, 0, 0, 0, 0, "");
2107
2108         uiBlockBeginAlign(block);
2109         if(ma) uiDefButF(block, COL, B_REDR, "",                        292,123,31,30, &(ma->r), 0, 0, 0, 0, "");
2110         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");
2111         uiDefBut(block, BUT,B_MATWICH,  "?",            424,123,30,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces");
2112
2113         uiBlockBeginAlign(block);
2114         uiDefBut(block, BUT,B_MATNEW,   "New",          292,98,80,20, 0, 0, 0, 0, 0, "Adds a new Material index");
2115         uiDefBut(block, BUT,B_MATDEL,   "Delete",       374,98,80,20, 0, 0, 0, 0, 0, "Deletes this Material index");
2116         uiDefBut(block, BUT,B_MATSEL,   "Select",       292,76,80,20, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index");
2117         uiDefBut(block, BUT,B_MATDESEL, "Deselect",     374,76,80,20, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber");
2118         uiDefBut(block, BUT,B_MATASS,   "Assign",       292,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces");
2119
2120         uiBlockBeginAlign(block);
2121         uiDefBut(block, BUT,B_SETSMOOTH,"Set Smooth",   291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces");
2122         uiDefBut(block, BUT,B_SETSOLID, "Set Solid",    373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces");
2123         uiBlockEndAlign(block);
2124
2125         /* vertex group... partially editmode... */
2126         if(ob->type==OB_MESH) {
2127                 uiBut *but;
2128                 int     defCount;
2129                 bDeformGroup    *defGroup;
2130         
2131                 uiDefBut(block, LABEL,0,"Vertex Groups",
2132                                  143,153,130,20, 0, 0, 0, 0, 0, "");
2133
2134                 defCount=BLI_countlist(&ob->defbase);
2135
2136                 uiBlockBeginAlign(block);
2137                 if (defCount) {
2138                         char *menustr= get_vertexgroup_menustr(ob);
2139                         
2140                         uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr, 143, 132,18,21, &ob->actdef, 1, defCount, 0, 0, "Browses available vertex groups");
2141                         MEM_freeN (menustr);
2142                 }
2143                 
2144                 if (ob->actdef){
2145                         defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
2146                         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.)");
2147                         uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
2148
2149                         uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          143, 111, 140, 21, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
2150                 }
2151                 uiBlockEndAlign(block);
2152
2153                 if (G.obedit && G.obedit==ob){
2154                         uiBlockBeginAlign(block);
2155         /*              uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assigns deformation groups"); */
2156                         uiDefBut(block, BUT,B_NEWVGROUP,"New",                  143,90,70,21, 0, 0, 0, 0, 0, "Creates a new vertex group");
2157                         uiDefBut(block, BUT,B_DELVGROUP,"Delete",               213,90,70,21, 0, 0, 0, 0, 0, "Removes the current vertex group");
2158
2159                         uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",    143,69,70,21, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group");
2160                         uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",    213,69,70,21, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group");
2161
2162                         uiDefBut(block, BUT,B_SELVGROUP,"Select",               143,48,70,21, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group");
2163                         uiDefBut(block, BUT,B_DESELVGROUP,"Desel.",             213,48,70,21, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group");
2164                         uiBlockEndAlign(block);
2165                 }
2166         }
2167
2168
2169 }
2170
2171 /* *************************** FACE/PAINT *************************** */
2172
2173 void do_fpaintbuts(unsigned short event)
2174 {
2175         Mesh *me;
2176         Object *ob;
2177         extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
2178         extern VPaint Gvp;         /* from vpaint */
2179
2180         ob= OBACT;
2181         if(ob==0) return;
2182
2183         switch(event) {
2184
2185         case B_VPGAMMA:
2186                 vpaint_dogamma();
2187                 break;
2188         case B_COPY_TF_MODE:
2189         case B_COPY_TF_UV:
2190         case B_COPY_TF_COL:
2191         case B_COPY_TF_TEX:
2192                 me= get_mesh(ob);
2193                 if(me && me->tface) {
2194 /*                      extern TFace *lasttface; */
2195                         TFace *tface= me->tface;
2196                         int a= me->totface;
2197
2198                         set_lasttface();
2199                         if(lasttface) {
2200
2201                                 while(a--) {
2202                                         if(tface!=lasttface && (tface->flag & TF_SELECT)) {
2203                                                 if(event==B_COPY_TF_MODE) {
2204                                                         tface->mode= lasttface->mode;
2205                                                         tface->transp= lasttface->transp;
2206                                                 }
2207                                                 else if(event==B_COPY_TF_UV) {
2208                                                         memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
2209                                                         tface->tpage= lasttface->tpage;
2210                                                         tface->tile= lasttface->tile;
2211
2212                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2213                                                         else tface->mode &= ~TF_TILES;
2214
2215                                                 }
2216                                                 else if(event==B_COPY_TF_TEX) {
2217                                                         tface->tpage= lasttface->tpage;
2218                                                         tface->tile= lasttface->tile;
2219
2220                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2221                                                         else tface->mode &= ~TF_TILES;
2222                                                 }
2223                                                 else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
2224                                         }
2225                                         tface++;
2226                                 }
2227                         }
2228                         do_shared_vertexcol(me);
2229                         allqueue(REDRAWVIEW3D, 0);
2230                         allqueue(REDRAWIMAGE, 0);
2231                 }
2232                 break;
2233         case B_SET_VCOL:
2234                 clear_vpaint_selectedfaces();
2235                 break;
2236         case B_REDR_3D_IMA:
2237                 allqueue(REDRAWVIEW3D, 0);
2238                 allqueue(REDRAWIMAGE, 0);
2239                 break;
2240         case B_ASSIGNMESH:
2241
2242                 test_object_materials(ob->data);
2243                 allqueue(REDRAWVIEW3D, 0);
2244                 allqueue(REDRAWBUTSEDIT, 0);
2245                 break;
2246
2247         case B_TFACE_HALO:
2248                 set_lasttface();
2249                 if(lasttface) {
2250                         lasttface->mode &= ~TF_BILLBOARD2;
2251                         allqueue(REDRAWBUTSEDIT, 0);
2252                 }
2253                 break;
2254
2255         case B_TFACE_BILLB:
2256                 set_lasttface();
2257                 if(lasttface) {
2258                         lasttface->mode &= ~TF_BILLBOARD;
2259                         allqueue(REDRAWBUTSEDIT, 0);
2260                 }
2261                 break;
2262         case B_WEIGHT0_0:
2263                 editbutvweight = 0.0f;
2264                 allqueue(REDRAWBUTSEDIT, 0);
2265                 break;
2266
2267         case B_WEIGHT1_4:
2268                 editbutvweight = 0.25f;
2269                 allqueue(REDRAWBUTSEDIT, 0);
2270                 break;
2271         case B_WEIGHT1_2:
2272                 editbutvweight = 0.5f;
2273                 allqueue(REDRAWBUTSEDIT, 0);
2274                 break;
2275         case B_WEIGHT3_4:
2276                 editbutvweight = 0.75f;
2277                 allqueue(REDRAWBUTSEDIT, 0);
2278                 break;
2279         case B_WEIGHT1_0:
2280                 editbutvweight = 1.0f;
2281                 allqueue(REDRAWBUTSEDIT, 0);
2282                 break;
2283                 
2284         case B_OPA0_0:
2285                 Gvp.a = 0.0f;
2286                 allqueue(REDRAWBUTSEDIT, 0);
2287                 break;
2288         case B_OPA1_4:
2289                 Gvp.a = 0.25f;
2290                 allqueue(REDRAWBUTSEDIT, 0);
2291                 break;
2292         case B_OPA1_2:
2293                 Gvp.a = 0.5f;
2294                 allqueue(REDRAWBUTSEDIT, 0);
2295                 break;
2296         case B_OPA3_4:
2297                 Gvp.a = 0.75f;
2298                 allqueue(REDRAWBUTSEDIT, 0);
2299                 break;
2300         case B_OPA1_0:
2301                 Gvp.a = 1.0f;
2302                 allqueue(REDRAWBUTSEDIT, 0);
2303                 break;
2304                 
2305
2306         }
2307 }
2308
2309
2310 /* -------------------- MODE: vpaint  ------------------- */
2311
2312 static void editing_panel_mesh_paint(void)
2313 {
2314         extern VPaint Gvp;         /* from vpaint */
2315         uiBlock *block;
2316         
2317         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_paint", UI_EMBOSS, UI_HELV, curarea->win);
2318         if(uiNewPanel(curarea, block, "Paint", "Editing", 640, 0, 318, 204)==0) return;
2319         
2320         
2321         if(G.f & ( G_WEIGHTPAINT))
2322         {
2323                 Object *ob;
2324             ob= OBACT;
2325         if(ob==NULL) return;
2326
2327                 uiBlockBeginAlign(block);
2328                 uiDefButF(block, NUMSLI, REDRAWVIEW3D, "Weight:",979,160,194,19, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
2329                 uiDefBut(block, BUT, B_WEIGHT0_0 , "0",                 979,140,40,19, 0, 0, 0, 0, 0, "");
2330                 uiDefBut(block, BUT, B_WEIGHT1_4 , "1/4",                       1020,140,40,19, 0, 0, 0, 0, 0, "");
2331                 uiDefBut(block, BUT, B_WEIGHT1_2 , "1/2",                       1060,140,40,19, 0, 0, 0, 0, 0, "");
2332                 uiDefBut(block, BUT, B_WEIGHT3_4 , "3/4",                       1100,140,40,19, 0, 0, 0, 0, 0, "");
2333                 uiDefBut(block, BUT, B_WEIGHT1_0 , "1",                 1140,140,33,19, 0, 0, 0, 0, 0, "");
2334                 
2335                 uiDefButF(block, NUMSLI, 0, "Opacity ",         979,120,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2336                 uiDefBut(block, BUT, B_OPA0_0 , "0",                    979,100,40,19, 0, 0, 0, 0, 0, "");
2337                 uiDefBut(block, BUT, B_OPA1_4 , "1/4",                  1020,100,40,19, 0, 0, 0, 0, 0, "");
2338                 uiDefBut(block, BUT, B_OPA1_2 , "1/2",                  1060,100,40,19, 0, 0, 0, 0, 0, "");
2339                 uiDefBut(block, BUT, B_OPA3_4 , "3/4",                  1100,100,40,19, 0, 0, 0, 0, 0, "");
2340                 uiDefBut(block, BUT, B_OPA1_0 , "1",                    1140,100,33,19, 0, 0, 0, 0, 0, "");
2341                 uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2342                 uiBlockEndAlign(block);
2343                 if(ob){
2344                 uiBlockBeginAlign(block);
2345         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");
2346                 uiBlockEndAlign(block);
2347                 }
2348         }
2349         else{
2350                 uiBlockBeginAlign(block);
2351                 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");
2352                 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");
2353                 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");
2354                 uiBlockEndAlign(block);
2355                 uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2356                 uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2357                 
2358                 uiDefButF(block, COL, B_REDR, "",               1176,99,28,80, &(Gvp.r), 0, 0, 0, B_VPCOLSLI, "");
2359                 uiBlockBeginAlign(block);
2360                 uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
2361                 uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
2362                 uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
2363                 uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
2364                 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");
2365                 
2366                 uiBlockBeginAlign(block);
2367                 uiDefButBitS(block, TOG, VP_AREA, 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)");
2368                 uiDefButBitS(block, TOG, VP_SOFT, 0, "Soft",            1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
2369                 uiDefButBitS(block, TOG, VP_NORMALS, 0, "Normals",      1174,50,102,19, &Gvp.flag, 0, 0, 0, 0, "Vertex paint applies the vertex normal before painting");
2370
2371                 uiBlockBeginAlign(block);
2372                 uiDefBut(block, BUT, B_VPGAMMA, "Set",  979,30,81,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
2373                 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");
2374                 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");
2375                 uiBlockEndAlign(block);
2376                 
2377                 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)");
2378         }
2379         
2380 }
2381
2382 static void editing_panel_mesh_texface(void)
2383 {
2384         extern VPaint Gvp;         /* from vpaint */
2385         uiBlock *block;
2386         extern TFace *lasttface;
2387
2388         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_texface", UI_EMBOSS, UI_HELV, curarea->win);
2389         if(uiNewPanel(curarea, block, "Texture face", "Editing", 960, 0, 318, 204)==0) return;
2390
2391         set_lasttface();        // checks for ob type
2392         if(lasttface) {
2393
2394                 uiBlockBeginAlign(block);
2395                 uiDefButBitS(block, TOG, TF_TEX, B_REDR_3D_IMA, "Tex",  600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
2396                 uiDefButBitS(block, TOG, TF_TILES, B_REDR_3D_IMA, "Tiles",      660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
2397                 uiDefButBitS(block, TOG, TF_LIGHT, REDRAWVIEW3D, "Light",       720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
2398                 uiDefButBitS(block, TOG, TF_INVISIBLE, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
2399                 uiDefButBitS(block, TOG, TF_DYNAMIC, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
2400
2401                 uiBlockBeginAlign(block);
2402                 uiDefButBitS(block, TOG, TF_SHAREDCOL, REDRAWVIEW3D, "Shared",  600,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Blend vertex colours across face when vertices are shared");
2403                 uiDefButBitS(block, TOG, TF_TWOSIDE, REDRAWVIEW3D, "Twoside",660,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
2404                 uiDefButBitS(block, TOG, TF_OBCOL, REDRAWVIEW3D, "ObColor",720,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
2405
2406                 uiBlockBeginAlign(block);
2407                 
2408                 uiDefButBitS(block, TOG, TF_BILLBOARD, B_TFACE_HALO, "Halo",    600,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
2409                 uiDefButBitS(block, TOG, TF_BILLBOARD2, B_TFACE_BILLB, "Billboard",660,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
2410                 uiDefButBitS(block, TOG, TF_SHADOW, REDRAWVIEW3D, "Shadow", 720,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
2411                 uiDefButBitS(block, TOG, TF_BMFONT, REDRAWVIEW3D, "Text", 780,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
2412
2413                 uiBlockBeginAlign(block);
2414                 uiBlockSetCol(block, TH_BUT_SETTING1);
2415                 uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,80,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
2416                 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");
2417                 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");
2418
2419                 uiBlockSetCol(block, TH_AUTO);
2420
2421                 uiBlockBeginAlign(block);
2422                 uiDefButF(block, COL, B_VPCOLSLI, "",                   769,40,40,28, &(Gvp.r), 0, 0, 0, 0, "");
2423                 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)");
2424
2425                 uiBlockBeginAlign(block);
2426                 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");
2427                 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");
2428                 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");
2429         }
2430 }
2431
2432 void do_uvautocalculationbuts(unsigned short event)
2433 {
2434         switch(event) {
2435         case B_UVAUTO_STD1:
2436         case B_UVAUTO_STD2:
2437         case B_UVAUTO_STD4:
2438         case B_UVAUTO_STD8:
2439         case B_UVAUTO_CUBE:
2440                 calculate_uv_map(event);
2441                 break;
2442         case B_UVAUTO_BOUNDS1:
2443         case B_UVAUTO_BOUNDS2:
2444         case B_UVAUTO_BOUNDS4:
2445         case B_UVAUTO_BOUNDS8:
2446         case B_UVAUTO_SPHERE:
2447         case B_UVAUTO_CYLINDER:
2448         case B_UVAUTO_WINDOW:
2449                 if(select_area(SPACE_VIEW3D)) calculate_uv_map(event);
2450                 break;
2451         case B_UVAUTO_LSCM:
2452                 unwrap_lscm();
2453                 break;
2454         }
2455 }
2456
2457 static void editing_panel_mesh_uvautocalculation(void)
2458 {
2459         uiBlock *block;
2460         int butH= 19, butHB= 20, row= 180, butS= 10;
2461
2462         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_uvautocalculation", UI_EMBOSS, UI_HELV, curarea->win);
2463         /* make this a tab of "Texture face" to save screen space*/
2464         uiNewPanelTabbed("Texture face", "Editing");
2465         if(uiNewPanel(curarea, block, "UV Calculation", "Editing", 960, 0, 318, 204)==0)
2466                 return;
2467
2468         uiBlockBeginAlign(block);
2469         uiDefBut(block, BUT, B_UVAUTO_LSCM,"LSCM Unwrap",100,row,200,butH, 0, 0, 0, 0, 0, "Applies conformal UV mapping, preserving local angles");
2470         uiBlockEndAlign(block);
2471         row-= butHB+butS;
2472
2473         uiBlockBeginAlign(block);
2474         uiDefBut(block, BUT, B_UVAUTO_STD1,"Standard",100,row,100,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping");
2475         uiDefBut(block, BUT, B_UVAUTO_STD2,"/2",200,row,33,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/2");
2476         uiDefBut(block, BUT, B_UVAUTO_STD4,"/4",233,row,34,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/4");
2477         uiDefBut(block, BUT, B_UVAUTO_STD8,"/8",267,row,33,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/8");
2478         uiBlockEndAlign(block);
2479         row-= butHB+butS;
2480
2481         uiBlockBeginAlign(block);
2482         uiDefBut(block, BUT, B_UVAUTO_BOUNDS1,"Bounds",100,row,100,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/1");
2483         uiDefBut(block, BUT, B_UVAUTO_BOUNDS2,"/2",200,row,33,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/2");
2484         uiDefBut(block, BUT, B_UVAUTO_BOUNDS4,"/4",233,row,34,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/4");
2485         uiDefBut(block, BUT, B_UVAUTO_BOUNDS8,"/8",267,row,33,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/8");
2486         uiDefBut(block, BUT, B_UVAUTO_WINDOW,"From Window",100,row-butH,200,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping from window");
2487         uiBlockEndAlign(block);
2488         row-= 2*butHB+butS;
2489
2490         uiBlockBeginAlign(block);
2491         uiDefButBitI(block, TOG, G_DRAWFACES, REDRAWVIEW3D, "Draw Faces",       100,row,200,butH, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
2492         uiDefButBitI(block,TOG, G_DRAWEDGES, REDRAWVIEW3D,"Draw Edges",100,row-butHB,200,butH,&G.f, 2.0, 0, 0, 0,  "Displays edges of visible faces");
2493         uiDefButBitI(block,TOG, G_HIDDENEDGES, REDRAWVIEW3D,"Draw Hidden Edges",100,row-2*butHB,200,butH,&G.f, 2.0, 1.0, 0, 0,  "Displays edges of hidden faces");
2494         uiDefButBitI(block,TOG, G_DRAWSEAMS, REDRAWVIEW3D,"Draw Seams",100,row-3*butHB,200,butH,&G.f, 2.0, 2.0, 0, 0,  "Displays UV unwrapping seams");
2495         uiBlockEndAlign(block);
2496         row-= 4*butHB+butS;
2497
2498         row= 180;
2499
2500         uiBlockBeginAlign(block);
2501         uiDefBut(block, BUT, B_UVAUTO_CUBE,"Cube",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cube UV mapping");
2502         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");
2503         uiBlockEndAlign(block);
2504         row-= 2*butHB+butS;
2505
2506         uiBlockBeginAlign(block);
2507         uiDefBut(block, BUT, B_UVAUTO_SPHERE,"Sphere",315,row,200,butH, 0, 0, 0, 0, 0, "Applies spherical UV mapping");
2508         uiBlockEndAlign(block);
2509         row-= butHB+butS;
2510
2511         uiBlockBeginAlign(block);
2512         uiDefBut(block, BUT, B_UVAUTO_CYLINDER,"Cylinder",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cylindrical UV mapping");
2513         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");
2514         uiBlockEndAlign(block);
2515         row-= 2*butHB+butS;
2516
2517
2518         uiBlockBeginAlign(block);
2519         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");
2520         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");
2521         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");
2522         uiBlockEndAlign(block);
2523         row-= 2*butHB+butS;
2524
2525         uiBlockBeginAlign(block);
2526         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");
2527         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");
2528         uiBlockEndAlign(block);
2529 }
2530
2531 /* this is a mode context sensitive system */
2532
2533 void editing_panels()
2534 {
2535         Object *ob;
2536         Curve *cu;
2537         MetaBall *mb;
2538         Lattice *lt;
2539         bArmature *arm;
2540         Camera *cam;
2541
2542         ob= OBACT;
2543         if(ob==NULL) return;
2544         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2545         
2546         switch(ob->type) {
2547         case OB_MESH:
2548                 editing_panel_links(ob); // no editmode!
2549                 editing_panel_mesh_type(ob, ob->data);  // no editmode!
2550                 /* modes */
2551                 if(G.obedit) {
2552                         editing_panel_mesh_tools(ob, ob->data); // no editmode!
2553                         editing_panel_mesh_tools1(ob, ob->data); // no editmode!
2554                 }
2555                 else {
2556                         if(G.f & G_FACESELECT) {
2557                                 editing_panel_mesh_texface();
2558                                 editing_panel_mesh_uvautocalculation();
2559                         }
2560                         if(G.f & (G_VERTEXPAINT | G_TEXTUREPAINT | G_WEIGHTPAINT) ) {
2561                                 editing_panel_mesh_paint();
2562                         }
2563                 }
2564                 break;
2565
2566         case OB_CURVE:
2567         case OB_SURF:
2568                 cu= ob->data;
2569                 editing_panel_links(ob); // no editmode!
2570                 editing_panel_curve_type(ob, cu);
2571                 if(G.obedit) {
2572                         editing_panel_curve_tools(ob, cu);
2573                         editing_panel_curve_tools1(ob, cu);
2574                 }
2575                 break;
2576
2577         case OB_MBALL:
2578                 mb= ob->data;
2579                 editing_panel_links(ob); // no editmode!
2580                 editing_panel_mball_type(ob, mb);
2581                 if(G.obedit) {
2582                         editing_panel_mball_tools(ob, mb);
2583                 }
2584                 break;
2585
2586         case OB_FONT:
2587                 cu= ob->data;
2588                 editing_panel_links(ob); // no editmode!
2589                 editing_panel_curve_type(ob, cu);
2590                 editing_panel_font_type(ob, cu);
2591                 break;
2592
2593         case OB_LATTICE:
2594                 lt= ob->data;
2595                 editing_panel_links(ob); // no editmode!
2596                 editing_panel_lattice_type(ob, lt);
2597                 break;
2598
2599         case OB_LAMP:
2600                 editing_panel_links(ob); // no editmode!
2601                 break;
2602
2603         case OB_EMPTY:
2604                 editing_panel_links(ob); // no editmode!
2605                 break;
2606
2607         case OB_CAMERA:
2608                 cam= ob->data;
2609                 editing_panel_links(ob); // no editmode!
2610                 editing_panel_camera_type(ob, cam);
2611                 /* yafray: extra panel for dof parameters */
2612                 if (G.scene->r.renderer==R_YAFRAY) editing_panel_camera_yafraydof(ob, cam);
2613                 break;
2614
2615         case OB_ARMATURE:
2616                 arm= ob->data;
2617                 editing_panel_links(ob); // no editmode!
2618                 editing_panel_armature_type(ob, arm);
2619                 if(G.obedit) {
2620                         editing_panel_armature_bones(ob, arm);
2621                 }
2622                 else if(ob->flag & OB_POSEMODE) {
2623                         editing_panel_pose_bones(ob, arm);
2624                 }               
2625                 break;
2626         }
2627         uiClearButLock();
2628 }