Tuesday merger of bf-blender into orange branch.
[blender-staging.git] / source / blender / src / buttons_editing.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef WIN32
39 #ifndef snprintf
40 #define snprintf _snprintf
41 #endif
42 #endif
43
44 #include "MEM_guardedalloc.h"
45 #include "DNA_screen_types.h"
46 #include "DNA_space_types.h"
47 #include "DNA_scene_types.h"
48
49 #include "DNA_action_types.h"
50 #include "DNA_armature_types.h"
51 #include "DNA_camera_types.h"
52 #include "DNA_color_types.h"
53 #include "DNA_constraint_types.h"
54 #include "DNA_curve_types.h"
55 #include "DNA_effect_types.h"
56 #include "DNA_group_types.h"
57 #include "DNA_key_types.h"
58 #include "DNA_lamp_types.h"
59 #include "DNA_lattice_types.h"
60 #include "DNA_material_types.h"
61 #include "DNA_meta_types.h"
62 #include "DNA_mesh_types.h"
63 #include "DNA_meshdata_types.h"
64 #include "DNA_modifier_types.h"
65 #include "DNA_nla_types.h"
66 #include "DNA_object_types.h"
67 #include "DNA_object_force.h"
68 #include "DNA_radio_types.h"
69 #include "DNA_screen_types.h"
70 #include "DNA_texture_types.h"
71 #include "DNA_userdef_types.h"
72 #include "DNA_vfont_types.h"
73 #include "DNA_view3d_types.h"
74 #include "DNA_world_types.h"
75 #include "DNA_packedFile_types.h"
76
77 #include "BKE_blender.h"
78 #include "BKE_curve.h"
79 #include "BKE_colortools.h"
80 #include "BKE_depsgraph.h"
81 #include "BKE_global.h"
82 #include "BKE_key.h"
83 #include "BKE_library.h"
84 #include "BKE_main.h"
85 #include "BKE_modifier.h"
86 #include "BKE_packedFile.h"
87 #include "BKE_scene.h"
88
89 #include "BLI_blenlib.h"
90 #include "BLI_arithb.h"
91 #include "BLI_vfontdata.h"
92 #include "BLI_editVert.h"
93 #include "BLI_dynstr.h"
94
95 #include "BSE_filesel.h"
96
97 #include "BIF_gl.h"
98 #include "BIF_editarmature.h"
99 #include "BIF_editconstraint.h"
100 #include "BIF_editdeform.h"
101 #include "BIF_editfont.h"
102 #include "BIF_editkey.h"
103 #include "BIF_editmesh.h"
104 #include "BIF_interface.h"
105 #include "BIF_meshtools.h"
106 #include "BIF_mywindow.h"
107 #include "BIF_poseobject.h"
108 #include "BIF_renderwin.h"
109 #include "BIF_resources.h"
110 #include "BIF_screen.h"
111 #include "BIF_scrarea.h"
112 #include "BIF_space.h"
113 #include "BIF_toets.h"
114 #include "BIF_toolbox.h"
115 #include "BIF_previewrender.h"
116 #include "BIF_butspace.h"
117
118 #include "mydevice.h"
119 #include "blendef.h"
120
121 #include "BKE_action.h"
122 #include "BKE_anim.h"
123 #include "BKE_armature.h"
124 #include "BKE_constraint.h"
125 #include "BKE_curve.h"
126 #include "BKE_displist.h"
127 #include "BKE_DerivedMesh.h"
128 #include "BKE_effect.h"
129 #include "BKE_font.h"
130 #include "BKE_image.h"
131 #include "BKE_ipo.h"
132 #include "BKE_lattice.h"
133 #include "BKE_material.h"
134 #include "BKE_mball.h"
135 #include "BKE_mesh.h"
136 #include "BKE_object.h"
137 #include "BKE_texture.h"
138 #include "BKE_utildefines.h"
139
140 #include "BDR_drawobject.h"
141 #include "BDR_editcurve.h"
142 #include "BDR_editface.h"
143 #include "BDR_editobject.h"
144 #include "BDR_vpaint.h"
145 #include "BDR_unwrapper.h"
146
147 #include "BSE_drawview.h"
148 #include "BSE_editipo.h"
149 #include "BSE_edit.h"
150 #include "BSE_filesel.h"
151 #include "BSE_headerbuttons.h"
152 #include "BSE_trans_types.h"
153 #include "BSE_view.h"
154 #include "BSE_seqaudio.h"
155
156 #include "RE_renderconverter.h"         // make_sticky
157
158 #include "butspace.h" // own module
159
160 static float editbutweight=1.0;
161 float editbutvweight=1;
162 float uv_calc_radius= 1.0, uv_calc_cubesize= 1.0;
163 short uv_calc_mapdir= 1, uv_calc_mapalign= 1, facesel_draw_edges= 0;
164
165 extern ListBase editNurb;
166
167 /* *************************** Unicode Character Groups ****************** */
168 unicodect uctabname[125] = {
169         {"All", "All", 0x0000, 0xffff},
170         {"Basic Latin", "Basic Latin", 0x0000, 0x007f},
171         {"Latin 1 Supp", "Latin-1 Supplement", 0x0080, 0x00ff}, 
172
173         {"Latin Ext. A.", "Latin Extended-A", 0x0100, 0x017F},
174         {"Latin Ext. B.", "Latin Extended-B", 0x0180,0x024F}, 
175         {"Latin Ext. Add.", "Latin Extended Additional", 0x1e00, 0x1eff},
176
177         {"IPA Ext", "IPA Extensions", 0x0250, 0x02AF},
178         {"Spacing Mod.", "Spacing Modifier Letters", 0x02b0, 0x02ff},
179
180         {"Comb. Dia.", "Combining Diacritical Marks", 0x0300, 0x036F},
181         {"Greek, Coptic", "Greek and Coptic", 0x0370, 0x03ff},
182         {"Greek Ext.", "Greek Extended", 0x1f00, 0x1fff},
183
184         {"Cyrillic", "Cyrillic", 0x0400, 0x04ff},
185         {"Cyrillic Supp.", "Cyrillic Supplementary", 0x0500, 0x052f},
186
187         {"Armenian", "Armenian", 0x0530, 0x058f},
188         {"Hebrew", "Hebrew", 0x0590, 0x05ff},
189
190         
191         {"Arabic", "Arabic", 0x0600, 0x06ff},
192         {"Syriac", "Syriac", 0x0700, 0x074f},
193
194         {"Thaana", "Thaana", 0x0780, 0x07bf},
195         {"Devanagari", "Devanagari", 0x0900, 0x097f},
196
197         {"Bengali", "Bengali", 0x0980, 0x09ff},
198         {"Gurmukhi", "Gurmukhi", 0x0a00, 0x0a7f},
199
200         {"Gujarati", "Gujarati", 0x0a80, 0x0aff},
201         {"Oriya", "Oriya", 0x0b00, 0x0b7f},
202
203         {"Tamil", "Tamil", 0x0b80, 0x0bff},
204         {"Tegulu", "Tegulu", 0x0c00, 0x0c7f},
205
206         {"Kannada", "Kannada", 0x0c80, 0x0cff},
207         {"Malayalam", "Malayalam", 0x0d00, 0x0d7f},
208
209         {"Sinhala", "Sinhala", 0x0d80, 0x0dff},
210         {"Thai", "Thai", 0x0e00, 0x0e7f},
211
212         {"Lao", "Lao", 0x0e80, 0x0eff},
213         {"Tibetan", "Tibetan", 0x0f00, 0x0fff},
214
215         {"Myanmar", "Myanmar", 0x1000, 0x109f},
216         {"Georgian", "Georgian", 0x10a0, 0x10ff},
217
218         {"Ethiopic", "Ethiopic", 0x1200, 0x137f},
219
220         {"Cherokee", "Cherokee", 0x13a0, 0x13ff},
221         {"Unif. Canadian", "Unified Canadian Aboriginal Syllabics", 0x1400, 0x167f},
222
223         {"Ogham", "Ogham", 0x1680, 0x169f},
224         {"Runic", "Runic", 0x16a0, 0x16ff},
225
226         {"Tagalog", "Tagalog", 0x1700, 0x171f},
227         {"Hanunoo", "Hanunoo", 0x1720, 0x173f},
228
229         {"Buhid", "Buhid", 0x1740, 0x175f},
230         {"Tagbanwa", "Tagbanwa", 0x1760, 0x177f},
231
232         {"Khmer", "Khmer", 0x1780, 0x17ff},
233         {"Khmer Symb", "Khmer Symbols", 0x19e0, 0x19ff},
234
235         {"Mongolian", "Mongolian", 0x1800, 0x18af},
236
237         {"Limbu", "Limbu", 0x1900, 0x194f},
238         {"Tai Le", "Tai Le", 0x1950, 0x197f},
239
240         {"Phon. Ext.", "Phonetic Extensions", 0x1d00, 0x1d7f},
241
242
243         {"Gen. Punct.", "General Punctutation", 0x2000, 0x206f},
244         {"Super, Sub", "Superscripts and Subscripts", 0x2070, 0x209f},
245
246         {"Curr. Symb.", "Currency Symbols", 0x20a0, 0x20cf},
247         {"Comb. Diacrit.", "Combining Diacritical Marks for Symbols", 0x20d0, 0x20ff},
248
249         {"Letter Symb", "Letterlike Symbols", 0x2100, 0x214f},
250         {"Numb. Forms", "Number Forms", 0x2150, 0x218f},
251
252         {"Arrows", "Arrows", 0x2190, 0x21ff},
253         {"Math Oper.", "Mathematical Operators", 0x2200, 0x22ff},
254
255         {"Misc. Tech.", "Miscellaneous Technical", 0x2300, 0x23ff},
256         {"Ctrl. Pict.", "Control Pictures", 0x2400, 0x243f},
257
258         {"OCR", "Optical Character Recognition", 0x2440, 0x245f},
259         {"Enc. Alpha", "Enclosed Alphanumerics", 0x2460, 0x24ff},
260
261         {"Bow Drawing", "Box Drawing", 0x2500, 0x257f},
262         {"BLock Elem.", "Block Elements", 0x2580, 0x259f},
263
264         {"Geom. Shapes", "Geometric Shapes", 0x25a0, 0x25ff},
265         {"Misc. Symb.", "Miscellaneous Symbols", 0x2600, 0x26ff},
266
267         {"Dingbats", "Dingbats", 0x2700, 0x27bf},
268         {"Misc. Math A", "Miscellaneous Mathematical Symbols-A", 0x27c0, 0x27ef},
269
270         {"Supp. Arrows-A", "Supplemental Arrows-A", 0x27f0, 0x27ff},
271         {"Braille Pat.", "Braille Patterns", 0x2800, 0x28ff},
272
273         {"Supp. Arrows-B", "Supplemental Arrows-B", 0x2900, 0x297f},
274         {"Misc. Math B", "Miscellaneous Mathematical Symbols-B", 0x2980, 0x29ff},
275
276         {"Supp. Math Op.", "Supplemental Mathematical Operators", 0x2a00, 0x2aff},
277         {"Misc. Symb.", "Miscellaneous Symbols and Arrows", 0x2b00, 0x2bff},
278
279         {"Kangxi Rad.", "Kangxi Radicals", 0x2f00, 0x2fdf},
280
281         {"Ideographic", "Ideographic Description Characters", 0x2ff0, 0x2fff},
282
283         {"Hiragana", "Hiragana", 0x3040, 0x309f},
284         {"Katakana", "Katakana", 0x30a0, 0x30ff},
285         {"Katakana Ext.", "Katakana Phonetic Extensions", 0x31f0, 0x31ff},
286
287         {"Bopomofo", "Bopomofo", 0x3100, 0x312f},
288         {"Bopomofo Ext.", "Bopomofo Extended", 0x31a0, 0x31bf},
289
290         {"Hangul", "Hangul Jamo", 0x1100, 0x11ff},
291         {"Hangul Comp.", "Hangul Compatibility Jamo", 0x3130, 0x318f},
292         {"Hangul Syll.", "Hangul Syllables", 0xac00, 0xd7af},
293
294         {"Kanbun", "Kanbun", 0x3190, 0x319f},
295
296
297
298         {"Yijing Hex.", "Yijing Hexagram Symbols", 0x4dc0, 0x4dff},
299
300         {"Yi Syllables", "Yi Syllables", 0xa000, 0xa48f},
301         {"Yi Radicals", "Yi Radicals", 0xa490, 0xa4cf},
302
303         {"High Surr.", "High Surrogate Area", 0xd800, 0xdbff},
304
305         {"Low Surr.", "Low Surrogates", 0xdc00, 0xdfff},
306         {"Priv. Use Area", "Private Use Area", 0xe000, 0xf8ff},
307
308         {"CJK Rad. Supp.", "CJK Radicals Supplement", 0x2e80, 0x2eff},
309         {"CJK Ideographs", "CJK Unified Ideographs", 0x4e00, 0x9faf},
310         {"CJK Ideog. Ext. A", "CJK Unified Ideographs Extension A", 0x3400, 0x4dbf},
311         {"CJK Ideog. Ext. B", "CJK Unified Ideographs Extension B", 0x20000, 0x2a6df},
312         {"CJK Symbols.", "CJK Symbols and Punctuation", 0x3000, 0x303f},
313         {"Enclosed CJK", "Enclosed CJK Letters and Months", 0x3200, 0x32ff},
314         {"CJK Comp.", "CJK Compatibility", 0x3300, 0x33ff},
315         {"CJK Comp. Ideog.", "CJK Compatibility Ideographs", 0xf900, 0xfaff},
316         {"CJK Comp. Forms", "CJK Compatibility Forms", 0xfe30, 0xfe4f},
317         {"CJK Comp. Supp.", "CJK Compatibility Ideographs Supplement", 0x2f800, 0x2fa1f},
318
319         {"Alpha. Pres. Forms", "Alphabetic Presentation Forms", 0xfb00, 0xfb4f},
320
321         {"Arabic Pres. A", "Arabic Presentation Forms-A", 0xfb50, 0xfdff},
322         {"Arabic Pres. B", "Arabic Presentation Forms-B", 0xfe70, 0xfeff},
323
324         {"Var. Sel.", "Variation Selectors", 0xfe00, 0xfe0f},
325
326         {"Comb. Half", "Combining Half Marks", 0xfe20, 0xfe2f},
327
328         {"Sml. From Var.", "Small Form Variants", 0xfe50, 0xfe6f},
329
330         {"Half, Full Forms", "Halfwidth and Fullwidth Forms", 0xff00, 0xffef},
331         {"Specials", "Specials", 0xfff0, 0xffff},
332
333         {"Lin. B Syllab.", "Linear B Syllabary", 0x10000, 0x1007f},
334         {"Lin. B Idog.", "Linear B Ideograms", 0x10080, 0x100ff},
335
336         {"Aegean Num.", "Aegean Numbers", 0x10100, 0x1013f},
337         {"Old Italic", "Old Italic", 0x10300, 0x1032f},
338
339         {"Gothic", "Gothic", 0x10330, 0x1034f},
340         {"Ugaritic", "Ugaritic", 0x10380, 0x1039f},
341
342         {"Deseret", "Deseret", 0x10400, 0x1044f},
343         {"Shavian", "Shavian", 0x10450, 0x1047f},
344
345         {"Osmanya", "Osmanya", 0x10480, 0x104af},
346         {"Cypriot Syll", "Cypriot Syllabary", 0x10800, 0x1083f},
347
348         {"Bysantine Mus.", "Bysantine Musical Symbols", 0x1d000, 0x1d0ff},
349         {"Music Symb.", "Musical Symbols", 0x1d100, 0x1d1ff},
350
351         {"Tai Xuan Symb", "Tai Xuan Jing Symbols", 0x1d300, 0x1d35f},
352         {"Math. Alpha Symb.", "Mathematical Alpanumeric Symbols", 0x1d400, 0x1d7ff},
353
354
355         {"Tags", "Tags", 0xe0000, 0xe007f},
356         {"Var. Supp", "Variation Selectors Supplement", 0xe0100, 0xe01ef},
357
358         {"Supp. Priv. A", "Supplementary Private Use Area-A", 0xf0000, 0xffffd},
359         {"Supp. Priv. B", "Supplementary Private Use Area-B", 0x100000, 0x10fffd}
360 };
361
362
363 /* *************************** static functions prototypes ****************** */
364 VFont *exist_vfont(char *str);
365
366 /* *************** */
367
368 void do_common_editbuts(unsigned short event) // old name, is a mix of object and editing events.... 
369 {
370         EditMesh *em = G.editMesh;
371         EditFace *efa;
372         Base *base;
373         Object *ob= OBACT;
374         Nurb *nu;
375         Curve *cu;
376         BezTriple *bezt;
377         BPoint *bp;
378         unsigned int local;
379         int a, bit, index= -1;
380
381         switch(event) {
382                 
383         case B_MATWICH:
384                 if(G.obedit && G.obedit->actcol>0) {
385                         if(G.obedit->type == OB_MESH) {
386                                 efa= em->faces.first;
387                                 while(efa) {
388                                         if(efa->f & SELECT) {
389                                                 if(index== -1) index= efa->mat_nr;
390                                                 else if(index!=efa->mat_nr) {
391                                                         error("Mixed colors");
392                                                         return;
393                                                 }
394                                         }
395                                         efa= efa->next;
396                                 }
397                         }
398                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
399                                 nu= editNurb.first;
400                                 while(nu) {
401                                         if( isNurbsel(nu) ) {
402                                                 if(index== -1) index= nu->mat_nr;
403                                                 else if(index!=nu->mat_nr) {
404                                                         error("Mixed colors");
405                                                         return;
406                                                 }
407                                         }
408                                         nu= nu->next;
409                                 }                               
410                         }
411                         if(index>=0) {
412                                 G.obedit->actcol= index+1;
413                                 scrarea_queue_winredraw(curarea);
414                         }
415                 }
416                 break;
417         case B_MATNEW:
418                 new_material_to_objectdata(ob);
419                 scrarea_queue_winredraw(curarea);
420                 BIF_undo_push("New material");
421                 allqueue(REDRAWBUTSSHADING, 0);
422                 allqueue(REDRAWVIEW3D_Z, 0);
423                 allqueue(REDRAWOOPS, 0);
424                 break;
425         case B_MATDEL:
426                 delete_material_index();
427                 scrarea_queue_winredraw(curarea);
428                 BIF_undo_push("Delete material index");
429                 allqueue(REDRAWBUTSSHADING, 0);
430                 allqueue(REDRAWVIEW3D_Z, 0);
431                 allqueue(REDRAWOOPS, 0);
432                 break;
433         case B_MATASS:
434                 if(G.obedit && G.obedit->actcol>0) {
435                         if(G.obedit->type == OB_MESH) {
436                                 efa= em->faces.first;
437                                 while(efa) {
438                                         if(efa->f & SELECT)
439                                                 efa->mat_nr= G.obedit->actcol-1;
440                                         efa= efa->next;
441                                 }
442                         }
443                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
444                                 nu= editNurb.first;
445                                 while(nu) {
446                                         if( isNurbsel(nu) )
447                                                 nu->mat_nr= nu->charidx= G.obedit->actcol-1;
448                                         nu= nu->next;
449                                 }
450                         }
451                         else if (G.obedit->type == OB_FONT) {
452                         if (mat_to_sel()) {
453                                 allqueue(REDRAWVIEW3D, 0);
454                         }
455                         }
456                         allqueue(REDRAWVIEW3D_Z, 0);
457                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
458                         shade_buttons_change_3d();
459                         BIF_undo_push("Assign material index");
460                 }
461                 break;
462         case B_MATSEL:
463         case B_MATDESEL:
464                 if(G.obedit) {
465                         if(G.obedit->type == OB_MESH) {
466                                 if (event==B_MATSEL) {
467                                         editmesh_select_by_material(G.obedit->actcol-1);
468                                 } else {
469                                         editmesh_deselect_by_material(G.obedit->actcol-1);
470                                 }
471                                 allqueue(REDRAWVIEW3D, 0);
472                         }
473                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
474                                 nu= editNurb.first;
475                                 while(nu) {
476                                         if(nu->mat_nr==G.obedit->actcol-1) {
477                                                 if(nu->bezt) {
478                                                         a= nu->pntsu;
479                                                         bezt= nu->bezt;
480                                                         while(a--) {
481                                                                 if(bezt->hide==0) {
482                                                                         if(event==B_MATSEL) {
483                                                                                 bezt->f1 |= 1;
484                                                                                 bezt->f2 |= 1;
485                                                                                 bezt->f3 |= 1;
486                                                                         }
487                                                                         else {
488                                                                                 bezt->f1 &= ~1;
489                                                                                 bezt->f2 &= ~1;
490                                                                                 bezt->f3 &= ~1;
491                                                                         }
492                                                                 }
493                                                                 bezt++;
494                                                         }
495                                                 }
496                                                 else if(nu->bp) {
497                                                         a= nu->pntsu*nu->pntsv;
498                                                         bp= nu->bp;
499                                                         while(a--) {
500                                                                 if(bp->hide==0) {
501                                                                         if(event==B_MATSEL) bp->f1 |= 1;
502                                                                         else bp->f1 &= ~1;
503                                                                 }
504                                                                 bp++;
505                                                         }
506                                                 }
507                                         }
508                                         nu= nu->next;
509                                 }
510                                 BIF_undo_push("Select material index");
511                                 allqueue(REDRAWVIEW3D, 0);
512                         }
513                 }
514                 countall();
515                 break;
516         case B_HIDE:
517                 if(G.obedit) {
518                         if(G.obedit->type == OB_MESH) hide_mesh(0);
519                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) hideNurb(0);
520                 }
521                 break;
522         case B_REVEAL:
523                 if(G.obedit) {
524                         if(G.obedit->type == OB_MESH) reveal_mesh();
525                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) revealNurb();
526                 }
527                 else if(G.f & G_FACESELECT) reveal_tface();
528                 
529                 break;
530         case B_SELSWAP:
531                 if(G.obedit) {
532                         if(G.obedit->type == OB_MESH) selectswap_mesh();
533                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) selectswapNurb();
534                 }
535                 break;
536         case B_AUTOTEX:
537                 if(ob && G.obedit==0) {
538                         if(ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) tex_space_curve(ob->data);
539                 }
540                 break;
541         case B_DOCENTRE:
542                 docentre(0);
543                 break;
544         case B_DOCENTRENEW:
545                 docentre_new();
546                 break;
547         case B_DOCENTRECURSOR:
548                 docentre_cursor();
549                 break;
550         case B_SETSMOOTH:
551         case B_SETSOLID:
552                 if(G.obedit) {
553                         if(G.obedit->type == OB_MESH) {
554                                 mesh_set_smooth_faces((event==B_SETSMOOTH));
555                         }
556                         else {
557                                 nurb_set_smooth((event==B_SETSMOOTH));
558                         }
559                 }
560                 else if(G.vd) {
561                         base= FIRSTBASE;
562                         while(base) {
563                                 if(TESTBASELIB(base)) {
564                                         if(base->object->type==OB_MESH) {
565                                                 mesh_set_smooth_flag(base->object, (event==B_SETSMOOTH));
566                                         }
567                                         else if ELEM(base->object->type, OB_SURF, OB_CURVE) {
568                                                 cu= base->object->data;
569                                                 nu= cu->nurb.first;
570                                                 while(nu) {
571                                                         if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
572                                                         else nu->flag &= ~ME_SMOOTH;
573                                                         nu= nu->next;
574                                                 }
575                                                 makeDispListCurveTypes(base->object, 0);
576                                         }
577                                 }
578                                 base= base->next;
579                         }
580                         allqueue(REDRAWVIEW3D, 0);
581                         
582                         if(event == B_SETSMOOTH) BIF_undo_push("Set Smooth");
583                         else BIF_undo_push("Set Solid");
584                 }
585                 break;
586         case B_CHANGEDEP:
587                 DAG_scene_sort(G.scene); // makes new dag
588                 if(ob) ob->recalc |= OB_RECALC;
589                 allqueue(REDRAWVIEW3D, 0);
590                 break;
591         
592         case B_ADDKEY:
593                 insert_shapekey(ob);
594                 break;
595         case B_SETKEY:
596                 ob->shapeflag |= OB_SHAPE_TEMPLOCK;
597                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
598                 allqueue(REDRAWVIEW3D, 0);
599                 allqueue(REDRAWIPO, 0);
600                 allqueue(REDRAWBUTSEDIT, 0);
601                 break;
602         case B_LOCKKEY:
603                 ob->shapeflag &= ~OB_SHAPE_TEMPLOCK;
604                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
605                 allqueue(REDRAWVIEW3D, 0);
606                 allqueue(REDRAWIPO, 0);
607                 allqueue(REDRAWBUTSEDIT, 0);
608                 break;
609         case B_NEXTKEY:
610         {
611                 Key *key= ob_get_key(ob);
612                 if(ob->shapenr == BLI_countlist(&key->block))
613                    ob->shapenr= 1;
614                 else ob->shapenr++;
615                 do_common_editbuts(B_SETKEY);
616                 break;
617         }
618         case B_PREVKEY:
619         {
620                 Key *key= ob_get_key(ob);
621                 if(ob->shapenr <= 1)
622                         ob->shapenr= BLI_countlist(&key->block);
623                 else ob->shapenr--;
624                 do_common_editbuts(B_SETKEY);
625                 break;
626         }
627         case B_NAMEKEY:
628                 allspace(REMAKEIPO, 0);
629         allqueue (REDRAWIPO, 0);
630                 break;
631         case B_DELKEY:
632                 delete_key(OBACT);
633                 break;
634                 
635                 
636         default:
637                 if(event>=B_OBLAY && event<=B_OBLAY+31) {
638                         local= BASACT->lay & 0xFF000000;
639                         BASACT->lay -= local;
640                         if(BASACT->lay==0 || (G.qual & LR_SHIFTKEY)==0) {
641                                 bit= event-B_OBLAY;
642                                 BASACT->lay= 1<<bit;
643                                 scrarea_queue_winredraw(curarea);
644                         }
645                         BASACT->lay += local;
646                         /* optimal redraw */
647                         if( (ob->lay & G.vd->lay) && (BASACT->lay & G.vd->lay) );
648                         else if( (ob->lay & G.vd->lay)==0 && (BASACT->lay & G.vd->lay)==0 );
649                         else {
650                                 allqueue(REDRAWVIEW3D, 0);
651                                 DAG_scene_sort(G.scene);
652                         }
653                         ob->lay= BASACT->lay;
654                 }
655         }
656
657 }
658
659 /* *************************** MESH  ******************************** */
660
661 static void editing_panel_mesh_type(Object *ob, Mesh *me)
662 {
663         uiBlock *block;
664         float val;
665
666         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_type", UI_EMBOSS, UI_HELV, curarea->win);
667         if( uiNewPanel(curarea, block, "Mesh", "Editing", 320, 0, 318, 204)==0) return;
668
669         uiBlockBeginAlign(block);
670         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");
671         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");
672
673         uiBlockBeginAlign(block);
674         uiBlockSetCol(block, TH_AUTO);
675
676         if(me->mcol) val= 1.0; else val= 0.0;
677         uiDefBut(block, LABEL, 0, "VertCol",                            10,50,70,20, 0, val, 0, 0, 0, "");
678         if(me->mcol==NULL) {
679                 uiDefBut(block, BUT, B_MAKEVERTCOL, "Make",             80,50,84,19, 0, 0, 0, 0, 0, "Enables vertex colour painting on active Mesh");
680         }
681         else uiDefBut(block, BUT, B_DELVERTCOL, "Delete",       80,50,84,19, 0, 0, 0, 0, 0, "Deletes vertex colours on active Mesh");
682
683         if(me->tface) val= 1.0; else val= 0.0;
684         uiDefBut(block, LABEL, 0, "TexFace",                            10,30,70,20, 0, val, 0, 0, 0, "");
685         if(me->tface==NULL) {
686                 uiDefBut(block, BUT, B_MAKE_TFACES, "Make",             80,30,84,19, 0, 0, 0, 0, 0, "Enables the active Mesh's faces for UV coordinate mapping");
687         }
688         else uiDefBut(block, BUT, B_DEL_TFACES, "Delete",       80,30,84,19, 0, 0, 0, 0, 0, "Deletes UV coordinates for active Mesh's faces");
689
690         if(me->msticky) val= 1.0; else val= 0.0;
691         uiDefBut(block, LABEL, 0, "Sticky",                             10,10,70,20, 0, val, 0, 0, 0, "");
692         if(me->msticky==NULL) {
693                 uiDefBut(block, BUT, B_MAKESTICKY, "Make",              80,10,84,19, 0, 0, 0, 0, 0, "Creates Sticky coordinates for the active Mesh from the current camera view background picture");
694         }
695         else uiDefBut(block, BUT, B_DELSTICKY, "Delete",        80,10,84,19, 0, 0, 0, 0, 0, "Deletes Sticky texture coordinates");
696
697         uiBlockEndAlign(block);
698
699         uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, B_REDR, "TexMesh: ",    175,124,230,19, &me->texcomesh, "Enter the name of a Meshblock");
700         
701         if(me->key) {
702                 uiBlockBeginAlign(block);
703                 uiDefButS(block, NUM, B_DIFF, "Slurph:",                                175,95,95,19, &(me->key->slurph), -500.0, 500.0, 0, 0, "");
704                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",                175,75,95,19, &me->key->type, 0, 0, 0, 0, "");
705         }
706
707         uiBlockBeginAlign(block);
708         uiDefBut(block, BUT, B_SLOWERDRAW,"SlowerDraw",                 175,30,95,19, 0, 0, 0, 0, 0, "Displays the active object with all possible edges shown");
709         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");
710
711         uiBlockBeginAlign(block);
712         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");
713         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");
714         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          275, 55, 130, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
715
716         uiBlockBeginAlign(block);
717         uiDefButBitS(block, TOG, ME_TWOSIDED, REDRAWVIEW3D, "Double Sided",     275,30,130,19, &me->flag, 0, 0, 0, 0, "Render/display the mesh as double or single sided");
718         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");
719         uiBlockEndAlign(block);
720
721 }
722
723 /* *************************** MODIFIERS ******************************** */
724
725 void do_modifier_panels(unsigned short event)
726 {
727         Object *ob = OBACT;
728
729         switch(event) {
730         case B_MODIFIER_REDRAW:
731                 allqueue(REDRAWBUTSEDIT, 0);
732                 allqueue(REDRAWOOPS, 0);
733                 break;
734
735         case B_MODIFIER_RECALC:
736                 ob->softflag |= OB_SB_RESET;
737                 allqueue(REDRAWBUTSEDIT, 0);
738                 allqueue(REDRAWVIEW3D, 0);
739                 allqueue(REDRAWIMAGE, 0);
740                 allqueue(REDRAWOOPS, 0);
741                 countall();
742                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
743                 break;
744         }
745 }
746
747 static void modifiers_add(void *ob_v, int type)
748 {
749         Object *ob = ob_v;
750         ModifierTypeInfo *mti = modifierType_getInfo(type);
751         
752         if (mti->flags&eModifierTypeFlag_RequiresOriginalData) {
753                 ModifierData *md = ob->modifiers.first;
754
755                 while (md && modifierType_getInfo(md->type)->type==eModifierTypeType_OnlyDeform) {
756                         md = md->next;
757                 }
758
759                 BLI_insertlinkbefore(&ob->modifiers, md, modifier_new(type));
760         } else {
761                 BLI_addtail(&ob->modifiers, modifier_new(type));
762         }
763
764         BIF_undo_push("Add modifier");
765 }
766
767 static uiBlock *modifiers_add_menu(void *ob_v)
768 {
769         Object *ob = ob_v;
770         uiBlock *block;
771         int i, yco=0;
772         
773         block= uiNewBlock(&curarea->uiblocks, "modifier_add_menu", UI_EMBOSSP, UI_HELV, curarea->win);
774         uiBlockSetButmFunc(block, modifiers_add, ob);
775
776         for (i=eModifierType_None+1; i<NUM_MODIFIER_TYPES; i++) {
777                 ModifierTypeInfo *mti = modifierType_getInfo(i);
778
779                         /* Only allow adding through appropriate other interfaces */
780                 if (ELEM(i, eModifierType_Softbody, eModifierType_Hook)) continue;
781                         
782                 if (    (mti->flags&eModifierTypeFlag_AcceptsCVs) || 
783                                 (ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) {
784                         uiDefBut(block, BUTM, B_MODIFIER_RECALC, mti->name,             0, yco-=20, 160, 19, NULL, 0, 0, 1, i, "");
785                 }
786         }
787         
788         uiTextBoundsBlock(block, 50);
789         uiBlockSetDirection(block, UI_DOWN);
790
791         return block;
792 }
793
794 static void modifiers_del(void *ob_v, void *md_v)
795 {
796         Object *ob = ob_v;
797         ModifierData *md;
798
799                 /* It seems on rapid delete it is possible to
800                  * get called twice on same modifier, so make
801                  * sure it is in list.
802                  */
803         for (md=ob->modifiers.first; md; md=md->next)
804                 if (md==md_v)
805                         break;
806         
807         if (!md)
808                 return;
809
810         BLI_remlink(&ob->modifiers, md_v);
811
812         modifier_free(md_v);
813
814         BIF_undo_push("Del modifier");
815 }
816
817 static void modifiers_moveUp(void *ob_v, void *md_v)
818 {
819         Object *ob = ob_v;
820         ModifierData *md = md_v;
821
822         if (md->prev) {
823                 ModifierTypeInfo *mti = modifierType_getInfo(md->type);
824
825                 if (mti->type!=eModifierTypeType_OnlyDeform) {
826                         ModifierTypeInfo *nmti = modifierType_getInfo(md->prev->type);
827
828                         if (nmti->flags&eModifierTypeFlag_RequiresOriginalData) {
829                                 error("Cannot move above a modifier requiring original data.");
830                                 return;
831                         }
832                 }
833
834                 BLI_remlink(&ob->modifiers, md);
835                 BLI_insertlink(&ob->modifiers, md->prev->prev, md);
836         }
837
838         BIF_undo_push("Move modifier");
839 }
840
841 static void modifiers_moveDown(void *ob_v, void *md_v)
842 {
843         Object *ob = ob_v;
844         ModifierData *md = md_v;
845
846         if (md->next) {
847                 ModifierTypeInfo *mti = modifierType_getInfo(md->type);
848
849                 if (mti->flags&eModifierTypeFlag_RequiresOriginalData) {
850                         ModifierTypeInfo *nmti = modifierType_getInfo(md->next->type);
851
852                         if (nmti->type!=eModifierTypeType_OnlyDeform) {
853                                 error("Cannot move beyond a non-deforming modifier.");
854                                 return;
855                         }
856                 }
857
858                 BLI_remlink(&ob->modifiers, md);
859                 BLI_insertlink(&ob->modifiers, md->next, md);
860         }
861
862         BIF_undo_push("Move modifier");
863 }
864
865 static void modifier_testLatticeObj(char *name, ID **idpp)
866 {
867         ID *id;
868
869         for (id= G.main->object.first; id; id= id->next) {
870                 if( strcmp(name, id->name+2)==0 ) {
871                         if (((Object *)id)->type != OB_LATTICE) {
872                                 error ("Lattice deform object must be a lattice");
873                                 break;
874                         } 
875                         *idpp= id;
876                         return;
877                 }
878         }
879         *idpp= 0;
880 }
881
882 static void modifier_testCurveObj(char *name, ID **idpp)
883 {
884         ID *id;
885
886         for (id= G.main->object.first; id; id= id->next) {
887                 if( strcmp(name, id->name+2)==0 ) {
888                         if (((Object *)id)->type != OB_CURVE) {
889                                 error ("Curve deform object must be a curve");
890                                 break;
891                         } 
892                         *idpp= id;
893                         return;
894                 }
895         }
896         *idpp= 0;
897 }
898
899 static void modifier_testMeshObj(char *name, ID **idpp)
900 {
901         ID *id;
902
903         for (id= G.main->object.first; id; id= id->next) {
904                 if( strcmp(name, id->name+2)==0 ) {
905                         if (((Object *)id)->type != OB_MESH) {
906                                 error ("Boolean modifier object must be a mesh");
907                                 break;
908                         } 
909                         *idpp= id;
910                         return;
911                 }
912         }
913         *idpp= 0;
914 }
915
916 static void modifier_testArmatureObj(char *name, ID **idpp)
917 {
918         ID *id;
919
920         for (id= G.main->object.first; id; id= id->next) {
921                 if( strcmp(name, id->name+2)==0 ) {
922                         if (((Object *)id)->type != OB_ARMATURE) {
923                                 error ("Armature deform object must be an armature");
924                                 break;
925                         } 
926                         *idpp= id;
927                         return;
928                 }
929         }
930         *idpp= 0;
931 }
932
933 static void modifiers_applyModifier(void *obv, void *mdv)
934 {
935         Object *ob = obv;
936         ModifierData *md = mdv;
937         DerivedMesh *dm;
938         DispListMesh *dlm;
939         Mesh *me = ob->data;
940         int converted = 0;
941
942         if (G.obedit) {
943                 error("Modifiers cannot be applied in editmode");
944                 return;
945         } else if (((ID*) ob->data)->us>1) {
946                 error("Modifiers cannot be applied to multi-user data");
947                 return;
948         }
949
950         if (md!=ob->modifiers.first) {
951                 if (!okee("Modifier is not first"))
952                         return;
953         }
954
955         if (ob->type==OB_MESH) {
956                 dm = mesh_create_derived_for_modifier(ob, md);
957                 if (!dm) {
958                         error("Modifier is disabled or returned error, skipping apply");
959                         return;
960                 }
961
962                 dlm= dm->convertToDispListMesh(dm, 0);
963
964                 if ((!me->tface || dlm->tface) || okee("Applying will delete mesh UVs and vertex colors")) {
965                         if ((!me->mcol || dlm->mcol) || okee("Applying will delete mesh vertex colors")) {
966                                 if (dlm->totvert==me->totvert || okee("Applying will delete mesh sticky, keys, and vertex groups")) {
967                                         displistmesh_to_mesh(dlm, me);
968                                         converted = 1;
969                                 }
970                         }
971                 }
972
973                 if (!converted) {
974                         displistmesh_free(dlm);
975                 }
976                 dm->release(dm);
977         } 
978         else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
979                 ModifierTypeInfo *mti = modifierType_getInfo(md->type);
980                 Curve *cu = ob->data;
981                 int numVerts;
982                 float (*vertexCos)[3];
983
984                 if (!okee("Apply will only change CV points, not tesselated/bevel vertices"))
985                         return;
986
987                 if (!(md->mode&eModifierMode_Realtime) || (mti->isDisabled && mti->isDisabled(md))) {
988                         error("Modifier is disabled, skipping apply");
989                         return;
990                 }
991
992                 vertexCos = curve_getVertexCos(cu, &cu->nurb, &numVerts);
993                 mti->deformVerts(md, ob, NULL, vertexCos, numVerts);
994                 curve_applyVertexCos(cu, &cu->nurb, vertexCos);
995                 MEM_freeN(vertexCos);
996
997                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
998         }
999         else {
1000                 error("Cannot apply modifier for this object type");
1001                 return;
1002         }
1003
1004         if (converted) {
1005                 BLI_remlink(&ob->modifiers, md);
1006                 modifier_free(md);
1007
1008                 BIF_undo_push("Apply modifier");
1009         }
1010 }
1011
1012 static void modifiers_copyModifier(void *ob_v, void *md_v)
1013 {
1014         Object *ob = ob_v;
1015         ModifierData *md = md_v;
1016         ModifierData *nmd = modifier_new(md->type);
1017
1018         modifier_copyData(md, nmd);
1019
1020         BLI_insertlink(&ob->modifiers, md, nmd);
1021
1022         BIF_undo_push("Copy modifier");
1023 }
1024
1025 static void modifiers_setOnCage(void *ob_v, void *md_v)
1026 {
1027         Object *ob = ob_v;
1028         ModifierData *md;
1029         
1030         int i, cageIndex = modifiers_getCageIndex(ob, NULL );
1031
1032         for( i = 0, md=ob->modifiers.first; md; ++i, md=md->next )
1033                 if( md == md_v ) {
1034                         if( i >= cageIndex )
1035                                 md->mode ^= eModifierMode_OnCage;
1036                         break;
1037                 }
1038 }
1039
1040 static void modifiers_clearHookOffset(void *ob_v, void *md_v)
1041 {
1042         Object *ob = ob_v;
1043         ModifierData *md = md_v;
1044         HookModifierData *hmd = (HookModifierData*) md;
1045         
1046         if (hmd->object) {
1047                 Mat4Invert(hmd->object->imat, hmd->object->obmat);
1048                 Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL);
1049                 BIF_undo_push("Clear hook");
1050         }
1051 }
1052
1053 static void modifiers_cursorHookCenter(void *ob_v, void *md_v)
1054 {
1055         Object *ob = ob_v;
1056         ModifierData *md = md_v;
1057         HookModifierData *hmd = (HookModifierData*) md;
1058
1059         if (G.vd) {
1060                 float *curs = give_cursor();
1061                 float bmat[3][3], imat[3][3];
1062
1063                 where_is_object(ob);
1064         
1065                 Mat3CpyMat4(bmat, ob->obmat);
1066                 Mat3Inv(imat, bmat);
1067
1068                 curs= give_cursor();
1069                 hmd->cent[0]= curs[0]-ob->obmat[3][0];
1070                 hmd->cent[1]= curs[1]-ob->obmat[3][1];
1071                 hmd->cent[2]= curs[2]-ob->obmat[3][2];
1072                 Mat3MulVecfl(imat, hmd->cent);
1073
1074                 BIF_undo_push("Hook cursor center");
1075         }
1076 }
1077
1078 static void modifiers_selectHook(void *ob_v, void *md_v)
1079 {
1080         ModifierData *md = md_v;
1081         HookModifierData *hmd = (HookModifierData*) md;
1082
1083         hook_select(hmd);
1084 }
1085
1086 static void modifiers_reassignHook(void *ob_v, void *md_v)
1087 {
1088         ModifierData *md = md_v;
1089         HookModifierData *hmd = (HookModifierData*) md;
1090         float cent[3];
1091         int *indexar, tot, ok;
1092         char name[32];
1093                 
1094         ok= hook_getIndexArray(&tot, &indexar, name, cent);
1095
1096         if (!ok) {
1097                 error("Requires selected vertices or active Vertex Group");
1098         } else {
1099                 if (hmd->indexar) {
1100                         MEM_freeN(hmd->indexar);
1101                 }
1102
1103                 VECCOPY(hmd->cent, cent);
1104                 hmd->indexar = indexar;
1105                 hmd->totindex = tot;
1106         }
1107 }
1108
1109 static void modifiers_convertToReal(void *ob_v, void *md_v)
1110 {
1111         Object *ob = ob_v;
1112         ModifierData *md = md_v;
1113         ModifierData *nmd = modifier_new(md->type);
1114
1115         modifier_copyData(md, nmd);
1116         nmd->mode &= ~eModifierMode_Virtual;
1117
1118         BLI_addhead(&ob->modifiers, nmd);
1119
1120         ob->partype = PAROBJECT;
1121
1122         BIF_undo_push("Modifier convert to real");
1123 }
1124
1125 static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco, int *yco, int index, int cageIndex, int lastCageIndex)
1126 {
1127         ModifierTypeInfo *mti = modifierType_getInfo(md->type);
1128         uiBut *but;
1129         int isVirtual = md->mode&eModifierMode_Virtual;
1130         int x = *xco, y = *yco, color = md->error?TH_REDALERT:TH_BUT_NEUTRAL;
1131         int editing = (G.obedit==ob);
1132     short height=26, width = 295, buttonWidth = width-120-10;
1133         char str[128];
1134
1135         /* rounded header */
1136         uiBlockSetCol(block, color);
1137                 /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
1138         uiDefBut(block, ROUNDBOX, 0, "", x-10, y-4, width, 25, NULL, 7.0, 0.0, 
1139                          (!isVirtual && (md->mode&eModifierMode_Expanded))?3:15, 20, ""); 
1140         uiBlockSetCol(block, TH_AUTO);
1141         
1142         /* open/close icon */
1143         if (!isVirtual) {
1144                 uiBlockSetEmboss(block, UI_EMBOSSN);
1145                 uiDefIconButBitI(block, ICONTOG, eModifierMode_Expanded, B_MODIFIER_REDRAW, VICON_DISCLOSURE_TRI_RIGHT, x-10, y-2, 20, 20, &md->mode, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Modifier");
1146         }
1147
1148         uiBlockSetEmboss(block, UI_EMBOSS);
1149         
1150         if (isVirtual) {
1151                 sprintf(str, "%s parent deform", md->name);
1152                 uiDefBut(block, LABEL, 0, str, x+10, y-1, width-110, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); 
1153
1154                 but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Make Real", x+width-100, y, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Convert virtual modifier to a real modifier");
1155                 uiButSetFunc(but, modifiers_convertToReal, ob, md);
1156         } else {
1157                 uiBlockBeginAlign(block);
1158                 uiDefBut(block, TEX, B_MODIFIER_REDRAW, "", x+10, y-1, buttonWidth-60, 19, md->name, 0.0, sizeof(md->name)-1, 0.0, 0.0, "Modifier name"); 
1159
1160                         /* Softbody not allowed in this situation, enforce! */
1161                 if (md->type!=eModifierType_Softbody || !(ob->pd && ob->pd->deflect)) {
1162                         uiDefIconButBitI(block, TOG, eModifierMode_Render, B_MODIFIER_RECALC, ICON_SCENE, x+10+buttonWidth-60, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering");
1163                         uiDefIconButBitI(block, TOG, eModifierMode_Realtime, B_MODIFIER_RECALC, VICON_VIEW3D, x+10+buttonWidth-40, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display");
1164                         if (mti->flags&eModifierTypeFlag_SupportsEditmode) {
1165                                 uiDefIconButBitI(block, TOG, eModifierMode_Editmode, B_MODIFIER_RECALC, VICON_EDIT, x+10+buttonWidth-20, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during Editmode (only if enabled for display)");
1166                         }
1167                 }
1168                 uiBlockEndAlign(block);
1169
1170                 uiBlockSetEmboss(block, UI_EMBOSSR);
1171
1172                 if (ob->type==OB_MESH && modifier_couldBeCage(md) && index<=lastCageIndex) {
1173                         int icon, color;
1174
1175                         if (index==cageIndex) {
1176                                 color = TH_BUT_SETTING;
1177                                 icon = VICON_EDITMODE_HLT;
1178                         } else if (index<cageIndex) {
1179                                 color = TH_BUT_NEUTRAL;
1180                                 icon = VICON_EDITMODE_DEHLT;
1181                         } else {
1182                                 color = TH_BUT_NEUTRAL;
1183                                 icon = ICON_BLANK1;
1184                         }
1185                         uiBlockSetCol(block, color);
1186                         but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, icon, x+width-105, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Apply modifier to editing cage during Editmode");
1187                         uiButSetFunc(but, modifiers_setOnCage, ob, md);
1188                         uiBlockSetCol(block, TH_AUTO);
1189                 }
1190
1191                 uiBlockSetCol(block, TH_BUT_ACTION);
1192
1193                 but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_UP, x+width-75, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier up in stack");
1194                 uiButSetFunc(but, modifiers_moveUp, ob, md);
1195
1196                 but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_DOWN, x+width-75+20, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier down in stack");
1197                 uiButSetFunc(but, modifiers_moveDown, ob, md);
1198                 
1199                 uiBlockSetEmboss(block, UI_EMBOSSN);
1200
1201                 but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_X, x+width-70+40, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Delete modifier");
1202                 uiButSetFunc(but, modifiers_del, ob, md);
1203                 uiBlockSetCol(block, TH_AUTO);
1204         }
1205
1206         uiBlockSetEmboss(block, UI_EMBOSS);
1207
1208         if (isVirtual || !(md->mode&eModifierMode_Expanded)) {
1209                 y -= 18;
1210         } else {
1211                 int cy = y - 8;
1212                 int lx = x + width - 60 - 15;
1213
1214                 if (md->type==eModifierType_Subsurf) {
1215                         height = 106;
1216                 } else if (md->type==eModifierType_Lattice) {
1217                         height = 46;
1218                 } else if (md->type==eModifierType_Curve) {
1219                         height = 46;
1220                 } else if (md->type==eModifierType_Build) {
1221                         height = 86;
1222                 } else if (md->type==eModifierType_Mirror) {
1223                         height = 46;
1224                 } else if (md->type==eModifierType_Decimate) {
1225                         height = 46;
1226                 } else if (md->type==eModifierType_Wave) {
1227                         height = 200;
1228                 } else if (md->type==eModifierType_Armature) {
1229                         height = 46;
1230                 } else if (md->type==eModifierType_Hook) {
1231                         HookModifierData *hmd = (HookModifierData*) md;
1232                         height = 86;
1233                         if (editing)
1234                                 height += 20;
1235                         if(hmd->indexar==NULL)
1236                                 height += 20;
1237                 } else if (md->type==eModifierType_Softbody) {
1238                         height = 26;
1239                 } else if (md->type==eModifierType_Boolean) {
1240                         height = 46;
1241                 }
1242
1243                                                         /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
1244                 uiDefBut(block, ROUNDBOX, 0, "", x-10, y-height-2, width, height-2, NULL, 5.0, 0.0, 12, 40, ""); 
1245
1246                 y -= 18;
1247
1248                 if (!isVirtual) {
1249                         uiBlockBeginAlign(block);
1250                         but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Apply",  lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Apply the current modifier and remove from the stack");
1251                         uiButSetFunc(but, modifiers_applyModifier, ob, md);
1252                         if (md->type!=eModifierType_Softbody) {
1253                                 but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Copy",   lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Duplicate the current modifier at the same position in the stack");
1254                                 uiButSetFunc(but, modifiers_copyModifier, ob, md);
1255                         }
1256                         uiBlockEndAlign(block);
1257                 }
1258
1259                 lx = x + 10;
1260                 cy = y + 10 - 1;
1261                 uiBlockBeginAlign(block);
1262                 if (md->type==eModifierType_Subsurf) {
1263                         SubsurfModifierData *smd = (SubsurfModifierData*) md;
1264                         char subsurfmenu[]="Subsurf Type%t|Catmull-Clark%x0|Simple Subdiv.%x1";
1265                         uiDefButS(block, MENU, B_MODIFIER_RECALC, subsurfmenu,          lx,(cy-=19),buttonWidth,19, &smd->subdivType, 0, 0, 0, 0, "Selects type of subdivision algorithm.");
1266                         uiDefButS(block, NUM, B_MODIFIER_RECALC, "Levels:",             lx, (cy-=19), buttonWidth,19, &smd->levels, 1, 6, 0, 0, "Number subdivisions to perform");
1267                         uiDefButS(block, NUM, B_MODIFIER_RECALC, "Render Levels:",              lx, (cy-=19), buttonWidth,19, &smd->renderLevels, 1, 6, 0, 0, "Number subdivisions to perform when rendering");
1268
1269                         /* Disabled until non-EM DerivedMesh implementation is complete */
1270
1271                         /*
1272                         uiDefButBitS(block, TOG, eSubsurfModifierFlag_Incremental, B_MODIFIER_RECALC, "Incremental", lx, (cy-=19),90,19,&smd->flags, 0, 0, 0, 0, "Use incremental calculation, even outside of mesh mode");
1273                         uiDefButBitS(block, TOG, eSubsurfModifierFlag_DebugIncr, B_MODIFIER_RECALC, "Debug", lx+90, cy,buttonWidth-90,19,&smd->flags, 0, 0, 0, 0, "Visualize the subsurf incremental calculation, for debugging effect of other modifiers");
1274                         */
1275
1276                         uiDefButBitS(block, TOG, eSubsurfModifierFlag_ControlEdges, B_MODIFIER_RECALC, "Optimal Draw", lx, (cy-=19), buttonWidth,19,&smd->flags, 0, 0, 0, 0, "Skip drawing/rendering of interior subdivided edges");
1277                         uiDefButBitS(block, TOG, eSubsurfModifierFlag_SubsurfUv, B_MODIFIER_RECALC, "Subsurf UV", lx, (cy-=19),buttonWidth,19,&smd->flags, 0, 0, 0, 0, "Use subsurf to subdivide UVs");
1278                 } else if (md->type==eModifierType_Lattice) {
1279                         LatticeModifierData *lmd = (LatticeModifierData*) md;
1280                         uiDefIDPoinBut(block, modifier_testLatticeObj, ID_OB, B_CHANGEDEP, "Ob: ",      lx, (cy-=19), buttonWidth,19, &lmd->object, "Lattice object to deform with");
1281                         but=uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ",                           lx, (cy-=19), buttonWidth,19, &lmd->name, 0.0, 31.0, 0, 0, "Vertex Group name");
1282                         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)lmd->object);
1283                 } else if (md->type==eModifierType_Curve) {
1284                         CurveModifierData *cmd = (CurveModifierData*) md;
1285                         uiDefIDPoinBut(block, modifier_testCurveObj, ID_OB, B_CHANGEDEP, "Ob: ", lx, (cy-=19), buttonWidth,19, &cmd->object, "Curve object to deform with");
1286                         but=uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ",                           lx, (cy-=19), buttonWidth,19, &cmd->name, 0.0, 31.0, 0, 0, "Vertex Group name");
1287                         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)cmd->object);
1288                 } else if (md->type==eModifierType_Build) {
1289                         BuildModifierData *bmd = (BuildModifierData*) md;
1290                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Start:", lx, (cy-=19), buttonWidth,19, &bmd->start, 1.0, MAXFRAMEF, 100, 0, "Specify the start frame of the effect");
1291                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Length:", lx, (cy-=19), buttonWidth,19, &bmd->length, 1.0, MAXFRAMEF, 100, 0, "Specify the total time the build effect requires");
1292                         uiDefButI(block, TOG, B_MODIFIER_RECALC, "Randomize", lx, (cy-=19), buttonWidth,19, &bmd->randomize, 0, 0, 1, 0, "Randomize the faces or edges during build.");
1293                         uiDefButI(block, NUM, B_MODIFIER_RECALC, "Seed:", lx, (cy-=19), buttonWidth,19, &bmd->seed, 1.0, MAXFRAMEF, 100, 0, "Specify the seed for random if used.");
1294                 } else if (md->type==eModifierType_Mirror) {
1295                         MirrorModifierData *mmd = (MirrorModifierData*) md;
1296                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Merge Limit:", lx, (cy-=19), buttonWidth,19, &mmd->tolerance, 0.0, 1.0, 10, 10, "Distance from axis within which mirrored vertices are merged");
1297                         uiDefButS(block, ROW, B_MODIFIER_RECALC, "X",   lx, (cy-=19), 20,19, &mmd->axis, 1, 0, 0, 0, "Specify the axis to mirror about");
1298                         uiDefButS(block, ROW, B_MODIFIER_RECALC, "Y",   lx+20, cy, 20,19, &mmd->axis, 1, 1, 0, 0, "Specify the axis to mirror about");
1299                         uiDefButS(block, ROW, B_MODIFIER_RECALC, "Z",   lx+40, cy, 20,19, &mmd->axis, 1, 2, 0, 0, "Specify the axis to mirror about");
1300                         uiDefButBitS(block, TOG, MOD_MIR_CLIPPING, B_MODIFIER_RECALC, "Do Clipping",    lx+60, cy, buttonWidth-60,19, &mmd->flag, 1, 2, 0, 0, "Prevents during Transform vertices to go through Mirror");
1301                 } else if (md->type==eModifierType_Decimate) {
1302                         DecimateModifierData *dmd = (DecimateModifierData*) md;
1303                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Percent:",    lx,(cy-=19),buttonWidth,19, &dmd->percent, 0.0, 1.0, 10, 0, "Defines the percentage of triangles to reduce to");
1304                         sprintf(str, "Face Count: %d", dmd->faceCount);
1305                         uiDefBut(block, LABEL, 1, str,  lx, (cy-=19), 160,19, NULL, 0.0, 0.0, 0, 0, "Displays the current number of faces in the decimated mesh");
1306                 } else if (md->type==eModifierType_Wave) {
1307                         WaveModifierData *wmd = (WaveModifierData*) md;
1308                         uiDefButBitS(block, TOG, WAV_X, B_MODIFIER_RECALC, "X",         lx,(cy-=19),45,19, &wmd->flag, 0, 0, 0, 0, "Enable X axis motion");
1309                         uiDefButBitS(block, TOG, WAV_Y, B_MODIFIER_RECALC, "Y",         lx+45,cy,45,19, &wmd->flag, 0, 0, 0, 0, "Enable Y axis motion");
1310                         uiDefButBitS(block, TOG, WAV_CYCL, B_MODIFIER_RECALC, "Cycl",   lx+90,cy,buttonWidth-90,19, &wmd->flag, 0, 0, 0, 0, "Enable cyclic wave effect");
1311                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Time sta:",   lx,(cy-=19),buttonWidth,19, &wmd->timeoffs, -1000.0, 1000.0, 100, 0, "Specify startingframe of the wave");
1312                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Lifetime:",   lx,(cy-=19),buttonWidth,19, &wmd->lifetime,  -1000.0, 1000.0, 100, 0, "Specify the lifespan of the wave");
1313                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Damptime:",   lx,(cy-=19),buttonWidth,19, &wmd->damp,  -1000.0, 1000.0, 100, 0, "Specify the dampingtime of the wave");
1314                         cy -= 19;
1315                         uiBlockBeginAlign(block);
1316                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Sta x:",              lx,(cy-=19),113,19, &wmd->startx, -100.0, 100.0, 100, 0, "Starting position for the X axis");
1317                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Sta y:",              lx+115,cy,105,19, &wmd->starty, -100.0, 100.0, 100, 0, "Starting position for the Y axis");
1318                         uiBlockBeginAlign(block);
1319                         uiDefButF(block, NUMSLI, B_MODIFIER_RECALC, "Speed:",   lx,(cy-=19),220,19, &wmd->speed, -2.0, 2.0, 0, 0, "Specify the wave speed");
1320                         uiDefButF(block, NUMSLI, B_MODIFIER_RECALC, "Heigth:",  lx,(cy-=19),220,19, &wmd->height, -2.0, 2.0, 0, 0, "Specify the amplitude of the wave");
1321                         uiDefButF(block, NUMSLI, B_MODIFIER_RECALC, "Width:",   lx,(cy-=19),220,19, &wmd->width, 0.0, 5.0, 0, 0, "Specify the width of the wave");
1322                         uiDefButF(block, NUMSLI, B_MODIFIER_RECALC, "Narrow:",  lx,(cy-=19),220,19, &wmd->narrow, 0.0, 10.0, 0, 0, "Specify how narrow the wave follows");
1323                 } else if (md->type==eModifierType_Armature) {
1324                         ArmatureModifierData *amd = (ArmatureModifierData*) md;
1325                         uiDefIDPoinBut(block, modifier_testArmatureObj, ID_OB, B_CHANGEDEP, "Ob: ", lx, (cy-=19), buttonWidth,19, &amd->object, "Armature object to deform with");
1326                         
1327                         uiDefButBitS(block, TOG, ARM_DEF_VGROUP, B_ARM_RECALCDATA, "Vert.Groups",       lx,cy-=19,buttonWidth/2,20, &amd->deformflag, 0, 0, 0, 0, "Enable VertexGroups defining deform");
1328                         uiDefButBitS(block, TOG, ARM_DEF_ENVELOPE, B_ARM_RECALCDATA, "Envelopes",       lx+buttonWidth/2,cy,buttonWidth/2,20, &amd->deformflag, 0, 0, 0, 0, "Enable Bone Envelopes defining deform");
1329                         
1330                 } else if (md->type==eModifierType_Hook) {
1331                         HookModifierData *hmd = (HookModifierData*) md;
1332                         uiDefButF(block, NUM, B_MODIFIER_RECALC, "Falloff: ",           lx, (cy-=19), buttonWidth,19, &hmd->falloff, 0.0, 100.0, 100, 0, "If not zero, the distance from hook where influence ends");
1333                         uiDefButF(block, NUMSLI, B_MODIFIER_RECALC, "Force: ",          lx, (cy-=19), buttonWidth,19, &hmd->force, 0.0, 1.0, 100, 0, "Set relative force of hook");
1334                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CHANGEDEP, "Ob: ", lx, (cy-=19), buttonWidth,19, &hmd->object, "Parent Object for hook, also recalculates and clears offset"); 
1335                         if(hmd->indexar==NULL) {
1336                                 but=uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ",         lx, (cy-=19), buttonWidth,19, &hmd->name, 0.0, 31.0, 0, 0, "Vertex Group name");
1337                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)hmd->object);
1338                         }
1339                         uiBlockBeginAlign(block);
1340                         but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Reset",          lx, (cy-=19), 80,19,                    NULL, 0.0, 0.0, 0, 0, "Recalculate and clear offset (transform) of hook");
1341                         uiButSetFunc(but, modifiers_clearHookOffset, ob, md);
1342                         but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Recenter",       lx+80, cy, buttonWidth-80,19,   NULL, 0.0, 0.0, 0, 0, "Sets hook center to cursor position");
1343                         uiButSetFunc(but, modifiers_cursorHookCenter, ob, md);
1344
1345                         if (editing) {
1346                                 but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Select",                 lx, (cy-=19), 80,19, NULL, 0.0, 0.0, 0, 0, "Selects effected vertices on mesh");
1347                                 uiButSetFunc(but, modifiers_selectHook, ob, md);
1348                                 but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Reassign",               lx+80, cy, buttonWidth-80,19, NULL, 0.0, 0.0, 0, 0, "Reassigns selected vertices to hook");
1349                                 uiButSetFunc(but, modifiers_reassignHook, ob, md);
1350                         }
1351                 } else if (md->type==eModifierType_Softbody) {
1352                         uiDefBut(block, LABEL, 1, "See Softbody panel.",        lx, (cy-=19), buttonWidth,19, NULL, 0.0, 0.0, 0, 0, "");
1353                 } else if (md->type==eModifierType_Boolean) {
1354                         BooleanModifierData *bmd = (BooleanModifierData*) md;
1355                         uiDefButI(block, MENU, B_MODIFIER_RECALC, "Operation%t|Intersect%x0|Union%x1|Difference%x2",    lx,(cy-=19),buttonWidth,19, &bmd->operation, 0.0, 1.0, 0, 0, "Boolean operation to perform");
1356                         uiDefIDPoinBut(block, modifier_testMeshObj, ID_OB, B_CHANGEDEP, "Ob: ", lx, (cy-=19), buttonWidth,19, &bmd->object, "Mesh object to use for boolean operation");
1357                 }
1358                 uiBlockEndAlign(block);
1359
1360                 y-=height;
1361         }
1362
1363         if (md->error) {
1364                 char str[512];
1365
1366                 y -= 20;
1367
1368                 uiBlockSetCol(block, color);
1369                                         /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
1370                 uiDefBut(block, ROUNDBOX, 0, "", x-10, y, width, 20, NULL, 5.0, 0.0, 15, 40, ""); 
1371                 uiBlockSetCol(block, TH_AUTO);
1372
1373                 sprintf(str, "Modifier Error: %s", md->error);
1374                 uiDefBut(block, LABEL, B_NOP, str, x+15, y+15, width-35, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1375         }
1376
1377         y -= 3+6;
1378
1379         *xco = x;
1380         *yco = y;
1381 }
1382
1383 static void editing_panel_modifiers(Object *ob)
1384 {
1385         ModifierData *md;
1386         uiBlock *block;
1387         char str[64];
1388         int xco, yco, i, lastCageIndex, cageIndex = modifiers_getCageIndex(ob, &lastCageIndex);
1389
1390         block= uiNewBlock(&curarea->uiblocks, "editing_panel_modifiers", UI_EMBOSS, UI_HELV, curarea->win);
1391         if( uiNewPanel(curarea, block, "Modifiers", "Editing", 640, 0, 318, 204)==0) return;
1392
1393         uiNewPanelHeight(block, 204);
1394
1395         uiDefBlockBut(block, modifiers_add_menu, ob, "Add Modifier", 0, 190, 130, 20, "Add a new modifier");
1396
1397         sprintf(str, "To: %s", ob->id.name+2);
1398         uiDefBut(block, LABEL, 1, str,  140, 190, 150, 20, NULL, 0.0, 0.0, 0, 0, "Object whose modifier stack is being edited");
1399
1400         xco = 0;
1401         yco = 160;
1402
1403         md = modifiers_getVirtualModifierList(ob);
1404
1405         for (i=0; md; i++, md=md->next) {
1406                 draw_modifier(block, ob, md, &xco, &yco, i, cageIndex, lastCageIndex);
1407                 if (md->mode&eModifierMode_Virtual) i--;
1408         }
1409         
1410         if(yco < 0) uiNewPanelHeight(block, 204-yco);
1411 }
1412
1413 static char *make_key_menu(Key *key)
1414 {
1415         KeyBlock *kb;
1416         int index= 1;
1417         char *str, item[64];
1418
1419         for (kb = key->block.first; kb; kb=kb->next, index++);
1420         str= MEM_mallocN(index*40, "key string");
1421         str[0]= 0;
1422         
1423         index= 1;
1424         for (kb = key->block.first; kb; kb=kb->next, index++) {
1425                 sprintf (item,  "|%s%%x%d", kb->name, index);
1426                 strcat(str, item);
1427         }
1428         
1429         return str;
1430 }
1431
1432 static void editing_panel_shapes(Object *ob)
1433 {
1434         uiBlock *block;
1435         Key *key= NULL;
1436         KeyBlock *kb;
1437         int icon;
1438         char *strp;
1439         
1440         block= uiNewBlock(&curarea->uiblocks, "editing_panel_shapes", UI_EMBOSS, UI_HELV, curarea->win);
1441         uiNewPanelTabbed("Modifiers", "Editing");
1442         if( uiNewPanel(curarea, block, "Shapes", "Editing", 640, 0, 318, 204)==0) return;
1443         
1444         uiDefBut(block, BUT, B_ADDKEY, "Add Shape Key" ,        10, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, "Add new Shape Key");
1445         
1446         key= ob_get_key(ob);
1447         if(key==NULL) {
1448                 /* label aligns add button */
1449                 uiDefBut(block, LABEL, 0, "",           170, 180,140,20, NULL, 0, 0, 0, 0, "");
1450                 return;
1451         }
1452         
1453         uiDefButS(block, TOG, B_RELKEY, "Relative",             170, 180,140,20, &key->type, 0, 0, 0, 0, "Makes Shape Keys relative");
1454
1455         kb= BLI_findlink(&key->block, ob->shapenr-1);
1456         if(kb==NULL) {
1457                 ob->shapenr= 1;
1458                 kb= key->block.first;
1459         }
1460
1461         uiBlockBeginAlign(block);
1462         if(ob->shapeflag & OB_SHAPE_LOCK) icon= ICON_PIN_HLT; else icon= ICON_PIN_DEHLT;
1463         uiDefIconButBitC(block, TOG, OB_SHAPE_LOCK, B_LOCKKEY, icon, 10,150,25,20, &ob->shapeflag, 0, 0, 0, 0, "Always show the current Shape for this Object");
1464         uiSetButLock(G.obedit==ob, "Unable to perform in EditMode");
1465         uiDefIconBut(block, BUT, B_PREVKEY, ICON_TRIA_LEFT,             35,150,20,20, NULL, 0, 0, 0, 0, "Previous Shape Key");
1466         strp= make_key_menu(key);
1467         uiDefButC(block, MENU, B_SETKEY, strp,                                  55,150,20,20, &ob->shapenr, 0, 0, 0, 0, "Browses existing choices or adds NEW");
1468         MEM_freeN(strp);
1469         uiDefIconBut(block, BUT, B_NEXTKEY, ICON_TRIA_RIGHT,    75,150,20,20, NULL, 0, 0, 0, 0, "Next Shape Key");
1470         uiClearButLock();
1471         uiDefBut(block, TEX, B_NAMEKEY, "",                                             95, 150, 190, 20, kb->name, 0.0, 31.0, 0, 0, "Current Shape Key name");
1472         uiDefIconBut(block, BUT, B_DELKEY, ICON_X,                              285,150,25,20, 0, 0, 0, 0, 0, "Deletes current Shape Key");
1473         uiBlockEndAlign(block);
1474
1475         if(key->type && (ob->shapeflag & OB_SHAPE_LOCK)==0 && ob->shapenr!=1) {
1476                 uiBlockBeginAlign(block);
1477                 make_rvk_slider(block, ob, ob->shapenr-1,                       10, 120, 150, 20, "Key value, when used it inserts an animation curve point");
1478                 uiDefButF(block, NUM, B_REDR, "Min ",                           160,120, 75, 20, &kb->slidermin, -10.0, 10.0, 100, 1, "Minumum for slider");
1479                 uiDefButF(block, NUM, B_REDR, "Max ",                           235,120, 75, 20, &kb->slidermax, -10.0, 10.0, 100, 1, "Maximum for slider");
1480                 uiBlockEndAlign(block);
1481         }
1482         if(key->type && ob->shapenr!=1)
1483                 uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ",     10, 90, 150,19, &kb->vgroup, 0.0, 31.0, 0, 0, "Vertex Weight Group name, to blend with Basis Shape");
1484
1485 }
1486
1487 /* *************************** FONT ******************************** */
1488
1489 static short give_vfontnr(VFont *vfont)
1490 {
1491         VFont *vf;
1492         short nr= 1;
1493
1494         vf= G.main->vfont.first;
1495         while(vf) {
1496                 if(vf==vfont) return nr;
1497                 nr++;
1498                 vf= vf->id.next;
1499         }
1500         return -1;
1501 }
1502
1503 static VFont *give_vfontpointer(int nr) /* nr= button */
1504 {
1505         VFont *vf;
1506         short tel= 1;
1507
1508         vf= G.main->vfont.first;
1509         while(vf) {
1510                 if(tel==nr) return vf;
1511                 tel++;
1512                 vf= vf->id.next;
1513         }
1514         return G.main->vfont.first;
1515 }
1516
1517 VFont *exist_vfont(char *str)
1518 {
1519         VFont *vf;
1520
1521         vf= G.main->vfont.first;
1522         while(vf) {
1523                 if(strcmp(vf->name, str)==0) return vf;
1524                 vf= vf->id.next;
1525         }
1526         return 0;
1527 }
1528
1529 static char *give_vfontbutstr(void)
1530 {
1531         VFont *vf;
1532         int len= 0;
1533         char *str, di[FILE_MAXDIR], fi[FILE_MAXFILE];
1534
1535         vf= G.main->vfont.first;
1536         while(vf) {
1537                 strcpy(di, vf->name);
1538                 BLI_splitdirstring(di, fi);
1539                 len+= strlen(fi)+4;
1540                 vf= vf->id.next;
1541         }
1542
1543         str= MEM_callocN(len+21, "vfontbutstr");
1544         strcpy(str, "FONTS %t");
1545         vf= G.main->vfont.first;
1546         while(vf) {
1547
1548                 if(vf->id.us==0) strcat(str, "|0 ");
1549                 else strcat(str, "|   ");
1550
1551                 strcpy(di, vf->name);
1552                 BLI_splitdirstring(di, fi);
1553
1554                 strcat(str, fi);
1555                 vf= vf->id.next;
1556         }
1557         return str;
1558 }
1559
1560 static void load_buts_vfont(char *name)
1561 {
1562         VFont *vf;
1563         Curve *cu;
1564
1565         if(OBACT && OBACT->type==OB_FONT) cu= OBACT->data;
1566         else return;
1567
1568         vf= exist_vfont(name);
1569         if(vf==0) {
1570                 vf= load_vfont(name);
1571                 if(vf==0) return;
1572         }
1573         else id_us_plus((ID *)vf);
1574         
1575         switch(cu->curinfo.flag & CU_STYLE) {
1576                 case CU_BOLD:
1577                         if(cu->vfontb) cu->vfontb->id.us--;
1578                         cu->vfontb= vf;
1579                         break;
1580                 case CU_ITALIC:
1581                         if(cu->vfonti) cu->vfonti->id.us--;             
1582                         cu->vfonti= vf;
1583                         break;                                          
1584                 case (CU_BOLD|CU_ITALIC):
1585                         if(cu->vfontbi) cu->vfontbi->id.us--;
1586                         cu->vfontbi= vf;
1587                         break;
1588                 default:
1589                         if(cu->vfont) cu->vfont->id.us--;
1590                         cu->vfont= vf;
1591                         break;                                          
1592         }       
1593
1594         DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
1595         BIF_undo_push("Load vector font");
1596         allqueue(REDRAWVIEW3D, 0);
1597         allqueue(REDRAWBUTSEDIT, 0);
1598 }
1599
1600 static void set_unicode_text_fs(char *file)
1601 {
1602         if (file > 0) paste_unicodeText(file); 
1603 }
1604
1605 void do_fontbuts(unsigned short event)
1606 {
1607         Curve *cu;
1608         VFont *vf;
1609         Object *ob;
1610         ScrArea *sa;
1611         char str[80];
1612         int ctevt;
1613         char *ctmenu;
1614         DynStr *ds;
1615         int i, style=0;
1616
1617         ob= OBACT;
1618
1619         switch(event) {
1620         case B_MAKEFONT:
1621                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1622                 allqueue(REDRAWVIEW3D, 0);
1623                 break;
1624
1625         case B_STYLETOSELU:     
1626         case B_STYLETOSELB:
1627         case B_STYLETOSELI:
1628                 switch (event) {
1629                         case B_STYLETOSELU: style = CU_UNDERLINE; break;
1630                         case B_STYLETOSELB: style = CU_BOLD; break;                     
1631                         case B_STYLETOSELI: style = CU_ITALIC; break;
1632                 }
1633                 if (style_to_sel(style, ((Curve*)ob->data)->curinfo.flag & style)) {
1634                         text_to_curve(ob, 0);
1635                         makeDispListCurveTypes(ob, 0);
1636                         allqueue(REDRAWVIEW3D, 0);
1637                 }
1638                 allqueue(REDRAWBUTSEDIT, 0);
1639                 break;          
1640                 
1641         case B_FASTFONT:
1642                 if (G.obedit) {
1643                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1644                         allqueue(REDRAWVIEW3D, 0);
1645                 }
1646                 break;
1647         case B_INSTB:
1648                 cu= ob->data;
1649                 if (cu->totbox < 256) {
1650                         for (i = cu->totbox; i>cu->actbox; i--) cu->tb[i]= cu->tb[i-1];
1651                         cu->tb[cu->actbox]= cu->tb[cu->actbox-1];
1652                         cu->actbox++;
1653                         cu->totbox++;
1654                         allqueue(REDRAWBUTSEDIT, 0);
1655                         allqueue(REDRAWVIEW3D, 0);
1656                         text_to_curve(ob, 0);
1657                         makeDispListCurveTypes(ob, 0);
1658                 }
1659                 else {
1660                         error("Do you really need that many text frames?");
1661                 }
1662                 break;
1663         case B_DELTB:
1664                 cu= ob->data;
1665                 if (cu->totbox > 1) {
1666                         for (i = cu->actbox-1; i < cu->totbox; i++) cu->tb[i]= cu->tb[i+1];
1667                         cu->totbox--;
1668                         cu->actbox--;
1669                         allqueue(REDRAWBUTSEDIT, 0);
1670                         allqueue(REDRAWVIEW3D, 0);
1671                         text_to_curve(ob, 0);
1672                         makeDispListCurveTypes(ob, 0);
1673                 }
1674                 break;
1675         case B_TOUPPER:
1676                 to_upper();
1677                 break;
1678         case B_LOADFONT:
1679                 vf= give_vfontpointer(G.buts->texnr);
1680                 if(vf && vf->id.prev!=vf->id.next) strcpy(str, vf->name);
1681                 else strcpy(str, U.fontdir);
1682
1683                 sa= closest_bigger_area();
1684                 areawinset(sa->win);
1685
1686                 activate_fileselect(FILE_SPECIAL, "SELECT FONT", str, load_buts_vfont);
1687
1688                 break;
1689         case B_PACKFONT:
1690                 if (ob) {
1691                         cu= ob->data;
1692                         if(cu && cu->vfont) {
1693                                 if (cu->vfont->packedfile) {
1694                                         if (G.fileflags & G_AUTOPACK) {
1695                                                 if (okee("Disable AutoPack ?")) {
1696                                                         G.fileflags &= ~G_AUTOPACK;
1697                                                 }
1698                                         }
1699
1700                                         if ((G.fileflags & G_AUTOPACK) == 0) {
1701                                                 if (unpackVFont(cu->vfont, PF_ASK) == RET_OK) {
1702                                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1703                                                         allqueue(REDRAWVIEW3D, 0);
1704                                                 }
1705                                         }
1706                                 } else {
1707                                         cu->vfont->packedfile = newPackedFile(cu->vfont->name);
1708                                 }
1709                         }
1710                 }
1711                 allqueue(REDRAWHEADERS, 0);
1712                 allqueue(REDRAWBUTSEDIT, 0);
1713                 break;
1714
1715         case B_LOAD3DTEXT:
1716                 if (!G.obedit) { error("Only in editmode!"); return; }
1717                 if (G.obedit->type != OB_FONT) return;  
1718                 activate_fileselect(FILE_SPECIAL, "Open Text File", G.sce, load_3dtext_fs);
1719                 break;
1720                 
1721         case B_LOREM:
1722                 if (!G.obedit) { error("Only in editmode!"); return; }
1723                 if (G.obedit->type != OB_FONT) return;  
1724                 add_lorem();
1725                 
1726                 break;          
1727
1728         case B_SETFONT:
1729                 if(ob) {
1730                         cu= ob->data;
1731
1732                         vf= give_vfontpointer(G.buts->texnr);
1733                         if(vf) {
1734                                 id_us_plus((ID *)vf);
1735
1736                                 switch(cu->curinfo.flag & CU_STYLE) {
1737                                         case CU_BOLD:
1738                                                 cu->vfontb->id.us--;
1739                                                 cu->vfontb= vf;
1740                                                 break;
1741                                         case CU_ITALIC:
1742                                                 cu->vfonti->id.us--;
1743                                                 cu->vfonti= vf;
1744                                                 break;                                          
1745                                         case (CU_BOLD|CU_ITALIC):
1746                                                 cu->vfontbi->id.us--;
1747                                                 cu->vfontbi= vf;
1748                                                 break;
1749                                         default:
1750                                                 cu->vfont->id.us--;
1751                                                 cu->vfont= vf;
1752                                                 break;                                          
1753                                 }
1754                                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1755
1756                                 BIF_undo_push("Set vector font");
1757                                 allqueue(REDRAWVIEW3D, 0);
1758                                 allqueue(REDRAWBUTSEDIT, 0);
1759                         }
1760                 }
1761                 break;
1762                 
1763         case B_SETCHAR:
1764                 G.charmin = 0x0000;
1765                 G.charmax = 0xffff;
1766                 if(G.charstart < 0)
1767                         G.charstart = 0;        
1768                 if(G.charstart > (0xffff - 12*6))
1769                         G.charstart = 0xffff - (12*6);
1770                 allqueue(REDRAWBUTSEDIT, 0);
1771                 break;
1772                 
1773         case B_SETUPCHAR:
1774                 G.charstart = G.charstart - (12*6);
1775                 if(G.charstart < 0)
1776                         G.charstart = 0;        
1777                 if(G.charstart < G.charmin)
1778                         G.charstart = G.charmin;
1779                 allqueue(REDRAWBUTSEDIT, 0);
1780                 break;
1781                 
1782         case B_SETCAT:
1783                 // Create new dynamic string
1784                 ds = BLI_dynstr_new();
1785                 
1786                 // Fill the dynamic string with entries
1787                 for(i=0;i<104;i++)
1788                 {
1789                         BLI_dynstr_append(ds, "|");
1790                         BLI_dynstr_append(ds, uctabname[i].name);
1791                 }
1792                 
1793                 // Create the menu string from dyn string
1794                 ctmenu = BLI_dynstr_get_cstring(ds);
1795                 
1796                 // Call the popup menu
1797                 ctevt = pupmenu_col(ctmenu, 40);
1798                 G.charstart = uctabname[ctevt-1].start;
1799                 G.charmin = uctabname[ctevt-1].start;
1800                 G.charmax = uctabname[ctevt-1].end;
1801
1802                 // Free all data
1803                 BLI_dynstr_free(ds);
1804                 MEM_freeN(ctmenu);
1805
1806                 // And refresh
1807                 allqueue(REDRAWVIEW3D, 0);
1808                 allqueue(REDRAWBUTSEDIT, 0);
1809                 
1810                 break;  
1811                 
1812         case B_SETDOWNCHAR:
1813                 G.charstart = G.charstart + (12*6);
1814                 if(G.charstart > (0xffff - 12*6))
1815                         G.charstart = 0xffff - (12*6);
1816                 if(G.charstart > G.charmax - 12*6)
1817                         G.charstart = G.charmax - 12*6;
1818                 allqueue(REDRAWBUTSEDIT, 0);
1819                 break;
1820                 
1821         case B_SETUNITEXT:
1822                 sa= closest_bigger_area();
1823                 areawinset(sa->win);
1824
1825                 if(ob==G.obedit) {
1826                         activate_fileselect(FILE_SPECIAL, "Open Text File", G.sce, set_unicode_text_fs);
1827                 }
1828                 break;          
1829                 
1830         case B_TEXTONCURVE:
1831                 if(ob) {
1832                         cu= ob->data;
1833                         if(cu->textoncurve && cu->textoncurve->type!=OB_CURVE) {
1834                                 error("Only Curve Objects");
1835                                 cu->textoncurve= 0;
1836                                 allqueue(REDRAWBUTSEDIT, 0);
1837                         }
1838                         DAG_scene_sort(G.scene); // makes new dag
1839                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1840                         allqueue(REDRAWVIEW3D, 0);
1841                 }
1842         }
1843 }
1844
1845 static void editing_panel_char_type(Object *ob, Curve *cu)
1846 {
1847         uiBlock *block;
1848
1849         block= uiNewBlock(&curarea->uiblocks, "editing_panel_char_type", UI_EMBOSS, UI_HELV, curarea->win);
1850         uiNewPanelTabbed("Font", "Editing");
1851         if(uiNewPanel(curarea, block, "Char", "Editing", 640, 0, 318, 204)==0) 
1852                 return;
1853
1854         // Set the selected font
1855         G.selfont = cu->vfont;
1856         
1857         uiDefIconBut(block, BUT, B_SETUNITEXT, ICON_TEXT,       0,210,20,20, 0, 0, 0, 0, 0, "Load Unicode Text file");
1858
1859         // Unicode categorization selection button
1860         uiDefBut(block, BUT, B_SETCAT, "Unicode Table", 22,210,226,20, 0, 0, 0, 0, 0, "Select Unicode Table");
1861         uiDefButI(block, NUM, /*B_SETUPCHAR*/ 0, "", 250,210,50,20, &G.charstart, 0, 0xffff, 0, 0, "UT");
1862
1863         // Character selection button
1864         uiDefBut(block, CHARTAB, B_SETCHAR, "", 0, 0, 264, 200, 0, 0, 0, 0, 0, "Select character");
1865
1866         // Buttons to change the max, min
1867         uiDefButI(block, BUT, B_SETUPCHAR, "U", 280, 185, 15, 15, &G.charstart, 0, 0xffff, 0, 0, "Scroll character table up");
1868         uiDefButI(block, BUT, B_SETDOWNCHAR, "D", 280, 0, 15, 15, &G.charstart, 0, 0xffff, 0, 0, "Scroll character table down");
1869 }
1870
1871 static void editing_panel_font_type(Object *ob, Curve *cu)
1872 {
1873         uiBlock *block;
1874         char *strp;
1875         static int packdummy = 0;
1876         char str[32];
1877
1878         block= uiNewBlock(&curarea->uiblocks, "editing_panel_font_type", UI_EMBOSS, UI_HELV, curarea->win);
1879         if(uiNewPanel(curarea, block, "Font", "Editing", 640, 0, 470, 204)==0) return;
1880
1881         switch(cu->curinfo.flag & CU_STYLE) {
1882                 case CU_BOLD:
1883                         G.buts->texnr= give_vfontnr(cu->vfontb);
1884                         break;
1885                 case CU_ITALIC:
1886                         G.buts->texnr= give_vfontnr(cu->vfonti);
1887                         break;                                          
1888                 case (CU_BOLD|CU_ITALIC):
1889                         G.buts->texnr= give_vfontnr(cu->vfontbi);
1890                         break;
1891                 default:
1892                         G.buts->texnr= give_vfontnr(cu->vfont);
1893                         break;                                          
1894         }       
1895
1896         strp= give_vfontbutstr();
1897 //      vfd= cu->vfont->data;
1898
1899         uiDefBut(block, BUT,B_LOADFONT, "Load", 480,188,68,20, 0, 0, 0, 0, 0, "Load a new font");
1900         uiDefButS(block, MENU, B_SETFONT, strp, 550,188,220,20, &G.buts->texnr, 0, 0, 0, 0, "Change font for object");
1901
1902         if (cu->vfont->packedfile) {
1903                 packdummy = 1;
1904         } else {
1905                 packdummy = 0;
1906         }
1907         uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE,       772,188,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this font");
1908
1909         /* This doesn't work anyway */
1910 //      uiDefBut(block, LABEL, 0, vfd->name,  480, 165,314,20, 0, 0, 0, 0, 0, "Postscript name of the font");
1911
1912         uiDefBut(block, BUT, B_LOAD3DTEXT, "Insert Text", 480, 165, 90, 20, 0, 0, 0, 0, 0, "Insert text file at cursor");
1913         uiDefBut(block, BUT, B_LOREM, "Lorem", 575, 165, 70, 20, 0, 0, 0, 0, 0, "Insert a paragraph of Lorem Ipsum at cursor"); 
1914         uiDefButC(block, TOG|BIT|2,B_STYLETOSELU, "U",          727,165,20,20, &(cu->curinfo.flag), 0,0, 0, 0, "");     
1915         uiBlockBeginAlign(block);
1916         uiDefButBitC(block, TOG, CU_BOLD, B_STYLETOSELB, "B",           752,165,20,20, &(cu->curinfo.flag), 0,0, 0, 0, "");
1917         uiDefButBitC(block, TOG, CU_ITALIC, B_STYLETOSELI, "i",         772,165,20,20, &(cu->curinfo.flag), 0, 0, 0, 0, "");    
1918         uiBlockEndAlign(block);
1919
1920         MEM_freeN(strp);
1921
1922         uiBlockBeginAlign(block);
1923         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");
1924         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");
1925         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");
1926         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 by expanding whitespace");
1927         uiDefButS(block, ROW,B_MAKEFONT, "Flush",               668,135,47,20, &cu->spacemode, 0.0,4.0, 0, 0, "Fill every line to maximum textframe width, distributing space among all characters");   
1928         uiDefBut(block, BUT, B_TOUPPER, "ToUpper",              715,135,78,20, 0, 0, 0, 0, 0, "Toggle between upper and lower case in editmode");
1929         uiBlockEndAlign(block);
1930         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");     
1931
1932         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_TEXTONCURVE, "TextOnCurve:",    480,105,220,19, &cu->textoncurve, "Apply a deforming curve to the text");
1933         uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 480,84,220,19, cu->family, 0.0, 20.0, 0, 0, "Blender uses font from selfmade objects");
1934
1935         uiBlockBeginAlign(block);
1936         uiDefButF(block, NUM,B_MAKEFONT, "Size:",               480,56,155,20, &cu->fsize, 0.1,10.0, 10, 0, "Size of the text");
1937         uiDefButF(block, NUM,B_MAKEFONT, "Linedist:",   640,56,155,20, &cu->linedist, 0.0,10.0, 10, 0, "Distance between text lines");
1938         uiDefButF(block, NUM,B_MAKEFONT, "Word spacing:",       795,56,155,20, &cu->wordspace, 0.0,10.0, 10, 0, "Distance factor between words");               
1939         uiDefButF(block, NUM,B_MAKEFONT, "Spacing:",    480,34,155,20, &cu->spacing, 0.0,10.0, 10, 0, "Spacing of individual characters");
1940         uiDefButF(block, NUM,B_MAKEFONT, "X offset:",   640,34,155,20, &cu->xof, -50.0,50.0, 10, 0, "Horizontal position from object centre");
1941         uiDefButF(block, NUM,B_MAKEFONT, "UL position:",        795,34,155,20, &cu->ulpos, -0.2,0.8, 10, 0, "Vertical position of underline");                  
1942         uiDefButF(block, NUM,B_MAKEFONT, "Shear:",              480,12,155,20, &cu->shear, -1.0,1.0, 10, 0, "Italic angle of the characters");
1943         uiDefButF(block, NUM,B_MAKEFONT, "Y offset:",   640,12,155,20, &cu->yof, -50.0,50.0, 10, 0, "Vertical position from object centre");
1944         uiDefButF(block, NUM,B_MAKEFONT, "UL height:",  795,12,155,20, &cu->ulheight, 0.01,0.5, 10, 0, "Thickness of underline");                               
1945         uiBlockEndAlign(block); 
1946         
1947         sprintf(str, "%d TextFrame: ", cu->totbox);
1948         uiBlockBeginAlign(block);
1949         uiDefButI(block, NUM, REDRAWVIEW3D, str, 805, 188, 145, 20, &cu->actbox, 1.0, cu->totbox, 0, 10, "Textbox to show settings for");
1950         uiDefBut(block, BUT,B_INSTB, "Insert", 805, 168, 72, 20, 0, 0, 0, 0, 0, "Insert a new text frame after the current one");
1951         uiDefBut(block, BUT,B_DELTB, "Delete", 877, 168, 73, 20, 0, 0, 0, 0, 0, "Delete current text frame and shift the others up");   
1952         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");
1953         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");     
1954         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");
1955         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");         
1956         uiBlockEndAlign(block);
1957 }
1958
1959
1960 /* *************************** CURVE ******************************** */
1961
1962
1963 void do_curvebuts(unsigned short event)
1964 {
1965         extern Nurb *lastnu;
1966         extern ListBase editNurb;  /* from editcurve */
1967         Object *ob;
1968         Curve *cu;
1969         Nurb *nu;
1970
1971         ob= OBACT;
1972         if(ob==0) return;
1973
1974         switch(event) {
1975
1976         case B_CONVERTPOLY:
1977         case B_CONVERTBEZ:
1978         case B_CONVERTBSPL:
1979         case B_CONVERTCARD:
1980         case B_CONVERTNURB:
1981                 if(G.obedit) {
1982                         setsplinetype(event-B_CONVERTPOLY);
1983                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
1984                         allqueue(REDRAWVIEW3D, 0);
1985                 }
1986                 break;
1987         case B_UNIFU:
1988         case B_ENDPU:
1989         case B_BEZU:
1990         case B_UNIFV:
1991         case B_ENDPV:
1992         case B_BEZV:
1993                 if(G.obedit) {
1994                         nu= editNurb.first;
1995                         while(nu) {
1996                                 if(isNurbsel(nu)) {
1997                                         if((nu->type & 7)==CU_NURBS) {
1998                                                 if(event<B_UNIFV) {
1999                                                         nu->flagu &= 1;
2000                                                         nu->flagu += ((event-B_UNIFU)<<1);
2001                                                         makeknots(nu, 1, nu->flagu>>1);
2002                                                 }
2003                                                 else if(nu->pntsv>1) {
2004                                                         nu->flagv &= 1;
2005                                                         nu->flagv += ((event-B_UNIFV)<<1);
2006                                                         makeknots(nu, 2, nu->flagv>>1);
2007                                                 }
2008                                         }
2009                                 }
2010                                 nu= nu->next;
2011                         }
2012                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2013                         allqueue(REDRAWVIEW3D, 0);
2014                 }
2015                 break;
2016         case B_SETWEIGHT:
2017                 if(G.obedit) {
2018                         weightflagNurb(1, editbutweight, 0);
2019                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2020                         allqueue(REDRAWVIEW3D, 0);
2021                 }
2022                 break;
2023         case B_SETW1:
2024                 editbutweight= 1.0;
2025                 scrarea_queue_winredraw(curarea);
2026                 break;
2027         case B_SETW2:
2028                 editbutweight= sqrt(2.0)/4.0;
2029                 scrarea_queue_winredraw(curarea);
2030                 break;
2031         case B_SETW3:
2032                 editbutweight= 0.25;
2033                 scrarea_queue_winredraw(curarea);
2034                 break;
2035         case B_SETW4:
2036                 editbutweight= sqrt(0.5);
2037                 scrarea_queue_winredraw(curarea);
2038                 break;
2039         case B_SETORDER:
2040                 if(G.obedit) {
2041                         nu= lastnu;
2042                         if(nu && (nu->type & 7)==CU_NURBS ) {
2043                                 if(nu->orderu>nu->pntsu) {
2044                                         nu->orderu= nu->pntsu;
2045                                         scrarea_queue_winredraw(curarea);
2046                                 }
2047                                 makeknots(nu, 1, nu->flagu>>1);
2048                                 if(nu->orderv>nu->pntsv) {
2049                                         nu->orderv= nu->pntsv;
2050                                         scrarea_queue_winredraw(curarea);
2051                                 }
2052                                 makeknots(nu, 2, nu->flagv>>1);
2053                         }
2054                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2055                         allqueue(REDRAWVIEW3D, 0);
2056                 }
2057                 break;
2058         case B_SUBSURFTYPE:
2059                 /* fallthrough */
2060         case B_MAKEDISP:
2061                 if(G.vd) {
2062                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2063                         allqueue(REDRAWVIEW3D, 0);
2064                         allqueue(REDRAWBUTSALL, 0);
2065                         allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
2066                 }
2067                 break;
2068
2069         case B_SUBDIVCURVE:
2070                 subdivideNurb();
2071                 break;
2072         case B_SPINNURB:
2073                 if( (G.obedit==NULL) || (G.obedit->type!=OB_SURF) || (G.vd==NULL) ||
2074                         ((G.obedit->lay & G.vd->lay) == 0) ) return;
2075                 spinNurb(0, 0);
2076                 countall();
2077                 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2078                 allqueue(REDRAWVIEW3D, 0);
2079                 break;
2080         case B_CU3D:        /* allow 3D curve */
2081                 if(G.obedit) {
2082                         cu= G.obedit->data;
2083                         nu= editNurb.first;
2084                         while(nu) {
2085                                 nu->type &= ~CU_2D;
2086                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
2087                                 test2DNurb(nu);
2088                                 nu= nu->next;
2089                         }
2090                 }
2091                 if(ob->type==OB_CURVE) {
2092                         cu= ob->data;
2093                         nu= cu->nurb.first;
2094                         while(nu) {
2095                                 nu->type &= ~CU_2D;
2096                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
2097                                 test2DNurb(nu);
2098                                 nu= nu->next;
2099                         }
2100                 }
2101                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2102                 allqueue(REDRAWVIEW3D, 0);
2103                 break;
2104         case B_SETRESOLU:
2105                 if(ob->type==OB_CURVE) {
2106                         cu= ob->data;
2107                         if(ob==G.obedit) nu= editNurb.first;
2108                         else nu= cu->nurb.first;
2109
2110                         while(nu) {
2111                                 nu->resolu= cu->resolu;
2112                                 nu= nu->next;
2113                         }
2114                 }
2115
2116                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2117                 allqueue(REDRAWVIEW3D, 0);
2118
2119                 break;
2120         }
2121 }
2122
2123 static void editing_panel_curve_tools(Object *ob, Curve *cu)
2124 {
2125         Nurb *nu;
2126         extern ListBase editNurb;  /* from editcurve */
2127         extern Nurb *lastnu;
2128         uiBlock *block;
2129         short *sp;
2130
2131         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools", UI_EMBOSS, UI_HELV, curarea->win);
2132         if(uiNewPanel(curarea, block, "Curve Tools", "Editing", 640, 0, 318, 204)==0) return;
2133
2134         uiDefBut(block, LABEL, 0, "Make Knots",562,173,102, 18, 0, 0, 0, 0, 0, "");
2135
2136         if(ob->type==OB_CURVE) {
2137                 uiDefBut(block, LABEL, 0, "Convert",    463,173,72, 18, 0, 0, 0, 0, 0, "");
2138                 uiBlockBeginAlign(block);
2139                 uiDefBut(block, BUT,B_CONVERTPOLY,"Poly",               467,152,72, 18, 0, 0, 0, 0, 0, "Converts selected into regular Polygon vertices");
2140                 uiDefBut(block, BUT,B_CONVERTBEZ,"Bezier",              467,132,72, 18, 0, 0, 0, 0, 0, "Converts selected to Bezier triples");
2141                 uiDefBut(block, BUT,B_CONVERTNURB,"Nurb",               467,112,72, 18, 0, 0, 0, 0, 0, "Converts selected to Nurbs Points");
2142         }
2143         uiBlockBeginAlign(block);
2144         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");
2145         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");
2146         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");
2147         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");
2148         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");
2149         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");
2150         uiBlockEndAlign(block);
2151
2152         uiDefBut(block, BUT,B_SETWEIGHT,"Set Weight",   465,11,95,49, 0, 0, 0, 0, 0, "Nurbs only; set weight for select points");
2153
2154         uiBlockBeginAlign(block);
2155         uiDefButF(block, NUM,0,"Weight:",               565,36,102,22, &editbutweight, 0.01, 100.0, 10, 0, "The weight you can assign");
2156         uiDefBut(block, BUT,B_SETW1,"1.0",              670,36,50,22, 0, 0, 0, 0, 0, "");
2157         uiDefBut(block, BUT,B_SETW2,"sqrt(2)/4",565,11,55,20, 0, 0, 0, 0, 0, "");
2158         uiDefBut(block, BUT,B_SETW3,"0.25",             620,11,45,20, 0, 0, 0, 0, 0, "");
2159         uiDefBut(block, BUT,B_SETW4,"sqrt(0.5)",665,11,55,20, 0, 0, 0, 0, 0, "");
2160         uiBlockEndAlign(block);
2161
2162         if(ob==G.obedit) {
2163                 nu= lastnu;
2164                 if(nu==NULL) nu= editNurb.first;
2165                 if(nu) {
2166                         uiBlockBeginAlign(block);
2167                         sp= &(nu->orderu);
2168                         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");
2169                         sp= &(nu->orderv);
2170                         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");
2171                         sp= &(nu->resolu);
2172                         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");
2173                         sp= &(nu->resolv);
2174                         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");
2175                 }
2176         }
2177
2178
2179 }
2180
2181 static void editing_panel_curve_tools1(Object *ob, Curve *cu)
2182 {
2183         uiBlock *block;
2184
2185         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools1", UI_EMBOSS, UI_HELV, curarea->win);
2186         if(uiNewPanel(curarea, block, "Curve Tools1", "Editing", 960, 0, 318, 204)==0) return;
2187
2188         uiDefBut(block, BUT, B_SUBDIVCURVE, "Subdivide", 400,180,150,20, 0, 0, 0, 0, 0, "Subdivide selected");
2189         if(ob->type==OB_SURF) {
2190                 uiDefBut(block, BUT, B_SPINNURB, "Spin",         400,160,150,20, 0, 0, 0, 0, 0, "Spin selected 360 degrees");
2191         }
2192         uiBlockBeginAlign(block);
2193         uiDefBut(block, BUT,B_HIDE,             "Hide",                 400,120,150,18, 0, 0, 0, 0, 0, "Hides selected faces");
2194         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               400,100,150,18, 0, 0, 0, 0, 0, "Reveals selected faces");
2195         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  400,80,150,18, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
2196         uiBlockEndAlign(block);
2197
2198         uiDefButF(block, NUM,   REDRAWVIEW3D, "NSize:", 400, 40, 150, 19, &G.scene->editbutsize, 0.001, 1.0, 10, 0, "Normal size for drawing");
2199 }
2200
2201 /* only for bevel or taper */
2202 static void test_obcurpoin_but(char *name, ID **idpp)
2203 {
2204         ID *id;
2205         
2206         for(id= G.main->object.first; id; id= id->next) {
2207                 if( strcmp(name, id->name+2)==0 ) {
2208                         if (((Object *)id)->type != OB_CURVE) {
2209                                 error ("Bevel/Taper Object must be a Curve");
2210                                 break;
2211                         }
2212                         if(id == (ID *)OBACT) {
2213                                 error ("Cannot Bevel/Taper own Object");
2214                                 break;
2215                         }
2216                         
2217                         *idpp= id;
2218                         return;
2219                 }
2220         }
2221         *idpp= NULL;
2222 }
2223
2224
2225
2226 /* for curve, surf and font! */
2227 static void editing_panel_curve_type(Object *ob, Curve *cu)
2228 {
2229         uiBlock *block;
2230
2231         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_type", UI_EMBOSS, UI_HELV, curarea->win);
2232         if(uiNewPanel(curarea, block, "Curve and Surface", "Editing", 320, 0, 318, 204)==0) return;
2233
2234         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'");
2235         if(ob->type==OB_SURF)
2236                 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");
2237
2238         uiBlockBeginAlign(block);
2239         uiDefBut(block, BUT,B_DOCENTRE, "Centre",                                       600, 115, 55, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
2240         uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New",                        655, 115, 95, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data");
2241         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          600, 95, 150, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
2242         uiBlockEndAlign(block);
2243
2244         if(cu->key) {
2245                 /* uiDefButS(block, NUM, B_DIFF, "Slurph:",                     600,25,140,19, &(cu->key->slurph), -500.0, 500.0,0,0); ,""*/
2246                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        600, 72,150,19, &cu->key->type, 0, 0, 0, 0, "");
2247         }
2248
2249
2250         if(ob->type!=OB_SURF) {
2251         
2252                 if(ob->type==OB_CURVE) {
2253                         extern float prlen;             // buttons_object.c, should be moved....
2254                         char str[32];
2255                         
2256                         sprintf(str, "%.4f", prlen);
2257                         uiDefBut(block, BUT, B_PRINTLEN,                "PrintLen",     600,135,75,19, 0, 0, 0, 0, 0, "");
2258                         uiDefBut(block, LABEL, 0, str,                                          675,135,75,19, 0, 1.0, 0, 0, 0, "");
2259                         
2260                         uiBlockBeginAlign(block);
2261                         uiDefButS(block, NUM, B_RECALCPATH, "PathLen:",                 600,50,150,19, &cu->pathlen, 1.0, MAXFRAMEF, 0, 0, "If no speed Ipo was set, the amount of frames of the path");
2262                         uiDefButBitS(block, TOG, CU_PATH, B_RECALCPATH, "CurvePath",    600,30,75,19 , &cu->flag, 0, 0, 0, 0, "Enables curve to become translation path");
2263                         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");
2264                         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");
2265                         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");
2266
2267                         uiBlockEndAlign(block);
2268                 }
2269
2270                 uiBlockBeginAlign(block);
2271                 uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 760,160,120,19, &cu->resolu, 1.0, 1024.0, 0, 0, "Default resolution");
2272                 uiDefBut(block, BUT, B_SETRESOLU, "Set",                880,160,30,19, 0, 0, 0, 0, 0, "Set resolution for interpolation");
2273
2274                 uiBlockBeginAlign(block);
2275                 uiDefButF(block, NUM, B_MAKEDISP, "Width:",             760,90,150,19, &cu->width, 0.0, 2.0, 1, 0, "Make interpolated result thinner or fatter");
2276                 uiDefButF(block, NUM, B_MAKEDISP, "Extrude:",           760,70,150,19, &cu->ext1, 0.0, 5.0, 10, 0, "Curve extrusion size when not using a bevel object");
2277                 uiDefButF(block, NUM, B_MAKEDISP, "Bevel Depth:",               760,50,150,19, &cu->ext2, 0.0, 2.0, 1, 0, "Bevel depth when not using a bevel object");
2278                 uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  760,30,150,19, &cu->bevresol, 0.0, 10.0, 0, 0, "Bevel resolution when depth is non-zero and not using a bevel object");
2279                 uiDefIDPoinBut(block, test_obcurpoin_but, ID_OB, B_CHANGEDEP, "BevOb:",         760,10,150,19, &cu->bevobj, "Curve object name that defines the bevel shape");
2280                 uiDefIDPoinBut(block, test_obcurpoin_but, ID_OB, B_CHANGEDEP, "TaperOb:",               760,-10,150,19, &cu->taperobj, "Curve object name that defines the taper (width)");
2281
2282                 uiBlockBeginAlign(block);
2283                 uiBlockSetCol(block, TH_BUT_SETTING1);
2284                 uiDefButBitS(block, TOG, CU_BACK, B_MAKEDISP, "Back",   760,130,50,19, &cu->flag, 0, 0, 0, 0, "Draw filled back for curves");
2285                 uiDefButBitS(block, TOG, CU_FRONT, B_MAKEDISP, "Front",810,130,50,19, &cu->flag, 0, 0, 0, 0, "Draw filled front for curves");
2286                 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");
2287         }
2288 }
2289
2290
2291 /* *************************** CAMERA ******************************** */
2292
2293
2294 static void editing_panel_camera_type(Object *ob, Camera *cam)
2295 {
2296         uiBlock *block;
2297         float grid=0.0;
2298
2299         if(G.vd) grid= G.vd->grid;
2300         if(grid<1.0) grid= 1.0;
2301
2302         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_type", UI_EMBOSS, UI_HELV, curarea->win);
2303         if(uiNewPanel(curarea, block, "Camera", "Editing", 320, 0, 318, 204)==0) return;
2304
2305 if(cam->type==CAM_ORTHO) {
2306                 uiDefButF(block, NUM,REDRAWVIEW3D, "Scale:",
2307                                   0, 145, 150, 20, &cam->ortho_scale, 0.01, 1000.0, 50, 0, "Specify the ortho scaling of the used camera");
2308         } else {
2309                 uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:",
2310                                   0, 145, 150, 20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
2311         }
2312         
2313         uiDefButS(block, TOG, REDRAWVIEW3D, "Orthographic",
2314                           0, 120, 150, 20, &cam->type, 0, 0, 0, 0, "Render orthogonally");
2315         
2316         uiDefBut(block, LABEL, 0, "Clipping:", 0, 90, 150, 20, 0, 0.0, 0.0, 0, 0, "");
2317         
2318         uiBlockBeginAlign(block);
2319         uiDefButF(block, NUM,REDRAWVIEW3D, "Start:",
2320                           0, 70, 150, 20, &cam->clipsta, 0.001*grid, 100.0*grid, 10, 0, "Specify the startvalue of the the field of view");
2321         uiDefButF(block, NUM,REDRAWVIEW3D, "End:",
2322                           0, 50, 150, 20, &cam->clipend, 1.0, 5000.0*grid, 100, 0, "Specify the endvalue of the the field of view");
2323         uiBlockEndAlign(block);
2324                         
2325         uiDefButF(block, NUM,REDRAWVIEW3D, "Size:",
2326                           0, 25, 150, 20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "The size that the camera is displayed in the 3D View (different to the object's scale)");
2327         
2328         uiDefBut(block, LABEL, 0, "Show:", 160, 155, 150, 20, 0, 0.0, 0.0, 0, 0, "");
2329
2330         uiBlockBeginAlign(block);
2331         uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Limits",
2332                           160, 135, 150, 20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
2333         uiDefButS(block, TOG|BIT|1, REDRAWVIEW3D, "Mist",
2334                           160, 115, 150, 20, &cam->flag, 0, 0, 0, 0, "Draw a line that indicates the mist area");
2335         uiBlockEndAlign(block);
2336         
2337         uiBlockBeginAlign(block);
2338         uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Name",
2339                           160, 90, 150, 20, &cam->flag, 0, 0, 0, 0, "Draw the active camera's name in camera view");
2340                 uiDefButS(block, TOG|BIT|3, REDRAWVIEW3D, "Title Safe",
2341                           160, 70, 150, 20, &cam->flag, 0, 0, 0, 0, "Draw a the title safe zone in camera view");
2342         uiBlockEndAlign(block);
2343         
2344         uiBlockBeginAlign(block);       
2345         uiDefButS(block, TOG|BIT|2, REDRAWVIEW3D, "Passepartout",
2346                           160, 45, 150, 20, &cam->flag, 0, 0, 0, 0, "Draw a darkened passepartout over the off-screen area in camera view");
2347         uiDefButF(block, NUMSLI, REDRAWVIEW3D, "Alpha: ",
2348                         160, 25, 150, 20, &cam->passepartalpha, 0.0, 1.0, 0, 0, "The opacity (darkness) of the passepartout");
2349         uiBlockEndAlign(block);
2350
2351
2352 }
2353
2354 /* yafray: extra camera panel to set Depth-of-Field parameters */
2355 static void editing_panel_camera_yafraydof(Object *ob, Camera *cam)
2356 {
2357         uiBlock *block;
2358         char *mst1, *mst2;
2359
2360         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_yafraydof", UI_EMBOSS, UI_HELV, curarea->win);
2361         uiNewPanelTabbed("Camera", "Editing");
2362         if(uiNewPanel(curarea, block, "Yafray DoF", "Editing", 320, 0, 318, 204)==0) return;
2363
2364         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)");
2365         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)");
2366
2367         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");
2368
2369         uiDefBut(block, LABEL, 0, "Bokeh", 10, 60, 180, 19, 0, 0.0, 0.0, 0, 0, "");
2370         mst1 = "Bokeh Type%t|Disk1%x0|Disk2%x1|Triangle%x2|Square%x3|Pentagon%x4|Hexagon%x5|Ring%x6";
2371         uiDefButS(block, MENU, B_REDR, mst1, 10, 40, 89, 20, &cam->YF_bkhtype, 0.0, 0.0, 0, 0, "Sets Bokeh type");
2372         
2373         if ((cam->YF_bkhtype!=0) && (cam->YF_bkhtype!=6)) {
2374                 mst2 = "Bokeh Bias%t|Uniform%x0|Center%x1|Edge%x2";
2375                 uiDefButS(block, MENU, B_REDR, mst2, 100, 40, 90, 20, &cam->YF_bkhbias, 0.0, 0.0, 0, 0, "Sets Bokeh bias");
2376                 if (cam->YF_bkhtype>1)
2377                         uiDefButF(block, NUM, B_DIFF, "Rotation:", 10, 15, 180, 20, &cam->YF_bkhrot, 0.0, 360.0, 100, 0, "Shape rotation amount in degrees");
2378         }
2379
2380 }
2381
2382 /* **************************** CAMERA *************************** */
2383
2384 void do_cambuts(unsigned short event)
2385 {
2386         Object *ob;
2387         Camera *cam;
2388         
2389         ob= OBACT;
2390         if (ob==0) return;
2391         cam= ob->data;
2392
2393         switch(event) {
2394         case 0:
2395                 ;
2396                 break;
2397         }
2398 }
2399
2400 /* *************************** MBALL ******************************** */
2401
2402 void do_mballbuts(unsigned short event)
2403 {
2404         switch(event) {
2405         case B_RECALCMBALL:
2406                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
2407                 allqueue(REDRAWVIEW3D, 0);
2408                 break;
2409         }
2410 }
2411
2412 static void editing_panel_mball_type(Object *ob, MetaBall *mb)
2413 {
2414         uiBlock *block;
2415
2416         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_type", UI_EMBOSS, UI_HELV, curarea->win);
2417         if(uiNewPanel(curarea, block, "MetaBall", "Editing", 320, 0, 318, 204)==0) return;
2418
2419         ob= find_basis_mball(ob);
2420         mb= ob->data;
2421
2422         uiBlockBeginAlign(block);
2423         uiDefButF(block, NUM, B_RECALCMBALL, "Wiresize:", 470,178,250,19, &mb->wiresize, 0.05, 1.0, 1, 0, "Polygonization resolution in 3d window");
2424         uiDefButF(block, NUM, B_NOP, "Rendersize:", 470,158,250,19, &mb->rendersize, 0.05, 1.0, 1, 0, "Polygonization resolution in rendering");
2425         uiDefButF(block, NUM, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 1, 0, "Defines influence of meta elements");
2426
2427         uiBlockBeginAlign(block);
2428         uiBlockSetCol(block, TH_BUT_SETTING1);
2429         uiDefBut(block, LABEL, 0, "Update:", 471,108,120,19, 0, 0, 0, 0, 0, "");
2430         uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "While editing, always updates");
2431         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");
2432         uiDefButS(block, ROW, B_DIFF, "Fast", 471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "While editing, updates without polygonization");
2433         uiDefButS(block, ROW, B_DIFF, "Never", 471, 25, 120, 19, &mb->flag, 0.0, 3.0, 0, 0, "While editing, doesn't update");
2434
2435 }
2436
2437 static void editing_panel_mball_tools(Object *ob, MetaBall *mb)
2438 {
2439         extern MetaElem *lastelem;
2440         uiBlock *block;
2441
2442         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_tools", UI_EMBOSS, UI_HELV, curarea->win);
2443         if( uiNewPanel(curarea, block, "MetaBall tools", "Editing", 640, 0, 318, 204)==0) return;
2444
2445         if(ob==G.obedit && lastelem) {
2446                 uiBlockBeginAlign(block);
2447                 uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 1, 0, "Stiffness for active meta");
2448                 if(lastelem->type!=MB_BALL)
2449                 uiDefButF(block, NUM, B_RECALCMBALL, "dx:", 750,158,250,19, &lastelem->expx, 0.0, 20.0, 1, 0, "X size for active meta");
2450                 if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
2451                 uiDefButF(block, NUM, B_RECALCMBALL, "dy:", 750,138,250,19, &lastelem->expy, 0.0, 20.0, 1, 0, "Y size for active meta");
2452
2453                 if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
2454                 uiDefButF(block, NUM, B_RECALCMBALL, "dz:", 750,118,250,19, &lastelem->expz, 0.0, 20.0, 1, 0, "Z size for active meta");
2455                 uiBlockEndAlign(block);
2456
2457                 uiDefButS(block, ROW, B_RECALCMBALL, "Ball", 753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "Draw active meta as Ball");
2458                 uiBlockBeginAlign(block);
2459                 uiDefButS(block, ROW, B_RECALCMBALL, "Tube", 753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "Draw active meta as Ball");
2460                 uiDefButS(block, ROW, B_RECALCMBALL, "Plane", 814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "Draw active meta as Plane");
2461                 uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid", 876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "Draw active meta as Ellipsoid");
2462                 uiDefButS(block, ROW, B_RECALCMBALL, "Cube", 938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "Draw active meta as Cube");
2463                 uiBlockEndAlign(block);
2464
2465                 uiBlockBeginAlign(block);
2466                 uiDefButBitS(block, TOG, MB_NEGATIVE, B_RECALCMBALL, "Negative",753,16,125,19, &lastelem->flag, 0, 0, 0, 0, "Make active meta creating holes");
2467                 uiDefButBitS(block, TOG, MB_HIDE, B_RECALCMBALL, "Hide",878,16,125,19, &lastelem->flag, 0, 0, 0, 0, "Make active meta invisible");
2468                 uiBlockEndAlign(block);
2469
2470         }
2471
2472 }
2473
2474
2475 /* *************************** LATTICE ******************************** */
2476
2477 void do_latticebuts(unsigned short event)
2478 {
2479         Object *ob;
2480         Lattice *lt;
2481
2482         ob= OBACT;
2483         if(ob->type!=OB_LATTICE) return;
2484
2485         switch(event) {
2486         case B_REGULARLAT:
2487                 if(ob) {
2488                         lt = ob->data;
2489                         if(ob==G.obedit) resizelattice(editLatt, lt->opntsu, lt->opntsv, lt->opntsw, NULL);
2490                         else resizelattice(ob->data, lt->opntsu, lt->opntsv, lt->opntsw, NULL);
2491                         ob->softflag |= OB_SB_REDO;
2492                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2493                         allqueue(REDRAWVIEW3D, 0);
2494                 }
2495         case B_RESIZELAT:
2496                 if(ob) {
2497                         lt = ob->data;
2498                         resizelattice(ob->data, lt->opntsu, lt->opntsv, lt->opntsw, ob);
2499                         ob->softflag |= OB_SB_REDO;
2500                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2501                         allqueue(REDRAWVIEW3D, 0);
2502                 }
2503                 break;
2504         case B_DRAWLAT:
2505                 allqueue(REDRAWVIEW3D, 0);
2506                 break;
2507         case B_LATTCHANGED:
2508
2509                 lt= ob->data;
2510                 if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
2511
2512                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2513
2514                 allqueue(REDRAWVIEW3D, 0);
2515
2516                 break;
2517         }
2518 }
2519
2520 static void editing_panel_lattice_type(Object *ob, Lattice *lt)
2521 {
2522         uiBlock *block;
2523
2524         block= uiNewBlock(&curarea->uiblocks, "editing_panel_lattice_type", UI_EMBOSS, UI_HELV, curarea->win);
2525         if(uiNewPanel(curarea, block, "Lattice", "Editing", 320, 0, 318, 204)==0) return;
2526
2527
2528         uiSetButLock(lt->key!=0, "Not with VertexKeys");
2529         uiSetButLock(ob==G.obedit, "Unable to perform function in EditMode");
2530
2531         uiBlockBeginAlign(block);
2532
2533         lt->opntsu = lt->pntsu;
2534         lt->opntsv = lt->pntsv;
2535         lt->opntsw = lt->pntsw;
2536
2537         uiDefButS(block, NUM, B_RESIZELAT,      "U:",                           469, 178,100,19, &lt->opntsu, 1.0, 64.0, 0, 0, "Points in U direction");
2538         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
2539         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
2540         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
2541
2542         uiDefButS(block, NUM, B_RESIZELAT,      "V:",                           469, 156,100,19, &lt->opntsv, 1.0, 64.0, 0, 0, "Points in V direction");
2543         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 156, 40, 19, &lt->typev, 2.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
2544         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 156, 40, 19, &lt->typev, 2.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
2545         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 156, 40, 19, &lt->typev, 2.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
2546
2547         uiDefButS(block, NUM, B_RESIZELAT,      "W:",                           469, 134,100,19, &lt->opntsw, 1.0, 64.0, 0, 0, "Points in W direction");
2548         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 134, 40, 19, &lt->typew, 3.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
2549         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         613, 134, 40, 19, &lt->typew, 3.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
2550         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 134, 40, 19, &lt->typew, 3.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
2551
2552         uiBlockEndAlign(block);
2553
2554         uiDefBut(block, BUT, B_REGULARLAT,      "Make Regular",         469,98,102,31, 0, 0, 0, 0, 0, "Make Lattice regular");
2555
2556         uiClearButLock();
2557         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");
2558
2559         if(lt->key) {
2560                 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");
2561                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        469,40,120,19, &lt->key->type, 0, 0, 0, 0, "Use relative keys (instead of absolute)");
2562         }
2563
2564 }
2565
2566 /* *************************** ARMATURE ******************************** */
2567
2568 void do_armbuts(unsigned short event)
2569 {
2570         Object *ob= OBACT;
2571         
2572         switch(event) {
2573         case B_ARM_RECALCDATA:
2574                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2575                 allqueue(REDRAWVIEW3D, 1);
2576                 allqueue(REDRAWBUTSEDIT, 0);
2577                 break;
2578         case B_ARM_STRIDE:
2579                 if(ob && ob->pose) {
2580                         bPoseChannel *pchan;
2581                         bActionStrip *strip;
2582                         
2583                         for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next)
2584                                 if(pchan->flag & POSE_STRIDE)
2585                                         break;
2586                         
2587                         /* we put the stride bone name in the strips, for lookup of action channel */
2588                         for (strip=ob->nlastrips.first; strip; strip=strip->next){
2589                                 if(strip->flag & ACTSTRIP_USESTRIDE) {
2590                                         if(pchan) BLI_strncpy(strip->stridechannel, pchan->name, 32);
2591                                         else strip->stridechannel[0]= 0;
2592                                 }
2593                         }
2594                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2595                         allqueue(REDRAWVIEW3D, 1);
2596                         allqueue(REDRAWNLA, 0);
2597                         allqueue(REDRAWBUTSEDIT, 0);
2598                 }
2599                 break;
2600         }
2601 }
2602
2603 static void validate_stridebutton_cb(void *pchanv, void *poin)
2604 {
2605         Object *ob= OBACT;
2606         bPoseChannel *pchan;
2607         
2608         if(ob && ob->pose) {
2609                 for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next){
2610                         if(pchan!=pchanv)
2611                                 pchan->flag &= ~POSE_STRIDE;
2612                 }
2613         }
2614 }       
2615
2616 static int editbone_to_parnr (EditBone *bone)
2617 {
2618         EditBone *ebone;
2619         int     index;
2620
2621         for (ebone=G.edbo.first, index=0; ebone; ebone=ebone->next, index++){
2622                 if (ebone==bone)
2623                         return index;
2624         }
2625
2626         return -1;
2627 }
2628
2629
2630 /* the "IK" button in editbuttons */
2631 static void attach_bone_to_parent_cb(void *bonev, void *arg2_unused)
2632 {
2633         EditBone *ebone= bonev;
2634         
2635         if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
2636                 /* Attach this bone to its parent */
2637                 VECCOPY(ebone->head, ebone->parent->tail);
2638         }
2639 }
2640
2641 static void parnr_to_editbone(EditBone *bone)
2642 {
2643         if (bone->parNr == -1){
2644                 bone->parent = NULL;
2645                 bone->flag &= ~BONE_CONNECTED;
2646         }
2647         else{
2648                 bone->parent = BLI_findlink(&G.edbo, bone->parNr);
2649                 attach_bone_to_parent_cb(bone, NULL);
2650         }
2651 }
2652
2653 static void parnr_to_editbone_cb(void *bonev, void *arg2_unused)
2654 {
2655         EditBone *curBone= bonev;
2656         parnr_to_editbone(curBone);
2657 }
2658
2659 static void build_bonestring (char *string, EditBone *bone)
2660 {
2661         EditBone *curBone;
2662         EditBone *pBone;
2663         int             skip=0;
2664         int             index, numbones, i;
2665         char (*qsort_ptr)[32] = NULL;
2666
2667         sprintf (string, "Parent%%t| %%x%d", -1);       /* That space is there
2668                                                                                                  * for a reason
2669                                                                                                  */
2670
2671         numbones = BLI_countlist(&G.edbo);
2672
2673         /*
2674          * This will hold the bone names temporarily so we can sort them
2675          */
2676         if (numbones > 0)
2677                 qsort_ptr = MEM_callocN (numbones * sizeof (qsort_ptr[0]),
2678                                                                  "qsort_ptr");
2679
2680         numbones = 0;
2681         for (curBone = G.edbo.first, index=0; curBone;
2682                  curBone=curBone->next, index++){
2683                 /* Make sure this is a valid child */
2684                 if (curBone != bone){
2685                         skip=0;
2686                         for (pBone=curBone->parent; pBone; pBone=pBone->parent){
2687                                 if (pBone==bone){
2688                                         skip=1;
2689                                         break;
2690                                 }
2691                         }
2692
2693                         if (skip)
2694                                 continue;
2695
2696                         sprintf (qsort_ptr[numbones], "|%s%%x%d", curBone->name, index);
2697                         numbones++;
2698                 }
2699         }
2700         qsort (qsort_ptr, numbones, sizeof (qsort_ptr[0]),
2701                    ( int (*)(const void *, const void *) ) strcmp);
2702
2703         for (i=0; i < numbones; ++i) {
2704                 sprintf (string, "%s%s", string, qsort_ptr[i]);
2705         }
2706
2707         if (qsort_ptr)
2708                 MEM_freeN(qsort_ptr);
2709 }
2710
2711 /* assumes armature editmode */
2712 /* exported to drawview.c via BIF_butspace.h */
2713 void validate_editbonebutton_cb(void *bonev, void *namev)
2714 {
2715         EditBone *eBone= bonev;
2716         char oldname[32], newname[32];
2717         
2718         /* need to be on the stack */
2719         BLI_strncpy(newname, eBone->name, 32);
2720         BLI_strncpy(oldname, (char *)namev, 32);
2721         /* restore */
2722         BLI_strncpy(eBone->name, oldname, 32);
2723         
2724         armature_bone_rename(G.obedit->data, oldname, newname); // editarmature.c
2725         allqueue(REDRAWALL, 0);
2726 }
2727
2728 /* assumes armature posemode */
2729 static void validate_posebonebutton_cb(void *bonev, void *namev)
2730 {
2731         Bone *bone= bonev;
2732         Object *ob= OBACT;
2733         char oldname[32], newname[32];
2734         
2735         /* need to be on the stack */
2736         BLI_strncpy(newname, bone->name, 32);
2737         BLI_strncpy(oldname, (char *)namev, 32);
2738         /* restore */
2739         BLI_strncpy(bone->name, oldname, 32);
2740         
2741         armature_bone_rename(ob->data, oldname, newname); // editarmature.c
2742         allqueue(REDRAWALL, 0);
2743 }
2744
2745 static void armature_layer_cb(void *lay_v, void *value_v)
2746 {
2747         short *layer= lay_v;
2748         int value= (int)value_v;
2749         
2750         if(*layer==0 || G.qual==0) *layer= value;
2751         allqueue(REDRAWBUTSEDIT, 0);
2752         allqueue(REDRAWACTION, 0);
2753         allqueue(REDRAWNLA, 0);
2754 }
2755
2756 static void editing_panel_armature_type(Object *ob, bArmature *arm)
2757 {
2758         uiBlock *block;
2759         uiBut *but;
2760         int a;
2761         
2762         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_type", UI_EMBOSS, UI_HELV, curarea->win);
2763         if(uiNewPanel(curarea, block, "Armature", "Editing", 320, 0, 318, 204)==0) return;
2764
2765         uiDefBut(block, LABEL, 0, "Editing Options", 10,180,150,20, 0, 0, 0, 0, 0, "");
2766         uiBlockBeginAlign(block);
2767         uiDefButBitI(block, TOG, ARM_MIRROR_EDIT, B_DIFF, "X-Axis Mirror",  10, 160,100,20, &arm->flag, 0, 0, 0, 0, "Enable X-axis mirrored editing");
2768         uiDefButBitC(block, TOG, OB_DRAWXRAY,REDRAWVIEW3D, "X-Ray",                     110,160,100,20, &ob->dtx, 0, 0, 0, 0, "Draw armature in front of solid objects");
2769         uiDefButBitI(block, TOG, ARM_AUTO_IK, B_DIFF, "Auto IK",                        210,160,100,20, &arm->flag, 0, 0, 0, 0, "Adds temporal IK chains while grabbing Bones");
2770         uiBlockEndAlign(block);
2771         
2772         uiDefBut(block, LABEL, 0, "Display Options", 10,141,150,19, 0, 0, 0, 0, 0, "");
2773         
2774         /* layers */
2775         uiBlockBeginAlign(block);
2776         for(a=0; a<8; a++) {
2777                 short dx= 18;
2778                 but= uiDefButBitS(block, TOG, 1<<a, REDRAWVIEW3D, "", 10+a*dx, 123, dx, 15, &arm->layer, 0, 0, 0, 0, "");
2779                 uiButSetFunc(but, armature_layer_cb, &arm->layer, (void *)(1<<a));
2780         }
2781         uiBlockBeginAlign(block);
2782         for(a=8; a<16; a++) {
2783                 short dx= 18;
2784                 but= uiDefButBitS(block, TOG, 1<<a, REDRAWVIEW3D, "", 18+a*dx, 123, dx, 15, &arm->layer, 0, 0, 0, 0, "");
2785                 uiButSetFunc(but, armature_layer_cb, &arm->layer, (void *)(1<<a));
2786         }
2787         
2788         uiBlockBeginAlign(block);
2789         uiDefButI(block, ROW, REDRAWVIEW3D, "Octahedron", 10, 100,90,20, &arm->drawtype, 0, ARM_OCTA, 0, 0, "Draw bones as octahedra");
2790         uiDefButI(block, ROW, REDRAWVIEW3D, "Stick",    100, 100,55,20, &arm->drawtype, 0, ARM_LINE, 0, 0, "Draw bones as simple 2d lines with dots");
2791         uiDefButI(block, ROW, REDRAWVIEW3D, "B-Bone",   155, 100,70,20, &arm->drawtype, 0, ARM_B_BONE, 0, 0, "Draw bones as boxes, showing subdivision and b-splines");
2792         uiDefButI(block, ROW, REDRAWVIEW3D, "Envelope", 225, 100,85,20, &arm->drawtype, 0, ARM_ENVELOPE, 0, 0, "Draw bones as extruded spheres, showing deformation influence volume");
2793
2794         uiDefButBitI(block, TOG, ARM_DRAWAXES, REDRAWVIEW3D, "Draw Axes", 10, 80,100,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
2795         uiDefButBitI(block, TOG, ARM_DRAWNAMES, REDRAWVIEW3D, "Draw Names", 110,80,100,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
2796         uiDefButBitI(block, TOGN, ARM_NO_PARLINES, REDRAWVIEW3D, "Draw Offset", 210,80,100,20, &arm->flag, 0, 0, 0, 0, "Draw offsets to parent bones with dashed line");
2797         
2798         uiDefButS(block, NUM, REDRAWVIEW3D, "Ghost: ", 10,60,150,20, &arm->ghostep, 0.0f, 30.0f, 0, 0, "Draw Ghosts around current frame, for current Action");
2799         uiDefButS(block, NUM, REDRAWVIEW3D, "Step: ", 160,60,150,20, &arm->ghostsize, 1.0f, 20.0f, 0, 0, "How many frames between Ghost instances");
2800         uiBlockEndAlign(block);
2801         
2802         uiDefBut(block, LABEL, 0, "Deform Options", 10,40,150,20, 0, 0, 0, 0, 0, "");
2803         uiBlockBeginAlign(block);
2804         uiDefButBitS(block, TOG, ARM_DEF_VGROUP, B_ARM_RECALCDATA, "Vertex Groups",     10, 20,150,20, &arm->deformflag, 0, 0, 0, 0, "Enable VertexGroups defining deform (not for Modifiers)");
2805         uiDefButBitS(block, TOG, ARM_DEF_ENVELOPE, B_ARM_RECALCDATA, "Envelopes",       160,20,150,20, &arm->deformflag, 0, 0, 0, 0, "Enable Bone Envelopes defining deform (not for Modifiers)");
2806         uiDefButBitI(block, TOG, ARM_RESTPOS, B_ARM_RECALCDATA,"Rest Position",         10,0,150,20, &arm->flag, 0, 0, 0, 0, "Show armature rest position, no posing possible");
2807         uiDefButBitI(block, TOG, ARM_DELAYDEFORM, REDRAWVIEW3D, "Delay Deform",         160,0,150,20, &arm->flag, 0, 0, 0, 0, "Don't deform children when manipulating bones in pose mode");
2808         
2809 }
2810
2811 static void editing_panel_armature_bones(Object *ob, bArmature *arm)
2812 {
2813         uiBlock         *block;
2814         uiBut           *but;
2815         EditBone        *curBone;
2816         char            *boneString=NULL;
2817         int                     by=180;
2818         int                     index, a;
2819
2820         /* Draw the bone name block */
2821
2822         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_bones", UI_EMBOSS, UI_HELV, curarea->win);
2823         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
2824
2825         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2826         /* so first we make it default height */
2827         uiNewPanelHeight(block, 204);
2828
2829
2830         uiDefBut(block, LABEL, 0, "Selected Bones", 0,by,158,18, 0, 0, 0, 0, 0, "Only show in Armature Editmode");
2831         by-=20;
2832         for (curBone=G.edbo.first, index=0; curBone; curBone=curBone->next, index++){
2833                 if ((curBone->flag & BONE_SELECTED) && (curBone->layer & arm->layer)) {
2834
2835                         /*      Bone naming button */
2836                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:", -10,by,117,18, &curBone->name, 0, 24, 0, 0, "Change the bone name");
2837                         uiButSetFunc(but, validate_editbonebutton_cb, curBone, NULL);
2838                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)OBACT);
2839
2840                         uiDefBut(block, LABEL, 0, "child of", 107,by,73,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
2841
2842                         boneString = MEM_mallocN((BLI_countlist(&G.edbo) * 64)+64, "Bone str");
2843                         build_bonestring (boneString, curBone);
2844
2845                         curBone->parNr = editbone_to_parnr(curBone->parent);
2846                         but = uiDefButI(block, MENU,REDRAWVIEW3D, boneString, 180,by,120,18, &curBone->parNr, 0.0, 0.0, 0.0, 0.0, "Parent");
2847                         /* last arg NULL means button will put old string there */
2848                         uiButSetFunc(but, parnr_to_editbone_cb, curBone, NULL);
2849
2850                         MEM_freeN(boneString);
2851
2852                         /* Connect to parent flag */
2853                         if (curBone->parent){
2854                                 but=uiDefButBitI(block, TOG, BONE_CONNECTED, B_ARM_RECALCDATA, "Con", 300,by,32,18, &curBone->flag, 0.0, 0.0, 0.0, 0.0, "Connect this Bone to Parent");
2855                                 uiButSetFunc(but, attach_bone_to_parent_cb, curBone, NULL);
2856                         }
2857
2858                         /* Segment, dist and weight buttons */
2859                         uiBlockBeginAlign(block);
2860                         uiDefButS(block, NUM, B_ARM_RECALCDATA, "Segm: ", -10,by-19,117,18, &curBone->segments, 1.0, 32.0, 0.0, 0.0, "Subdivisions for B-bones");
2861                         uiDefButF(block, NUM,B_ARM_RECALCDATA, "Dist:", 110, by-19, 105, 18, &curBone->dist, 0.0, 1000.0, 10.0, 0.0, "Bone deformation distance");
2862                         uiDefButF(block, NUM,B_ARM_RECALCDATA, "Weight:", 225, by-19,105, 18, &curBone->weight, 0.0F, 1000.0F, 10.0F, 0.0F, "Bone deformation weight");
2863
2864                         /* bone types */
2865                         uiDefButBitI(block, TOG, BONE_HINGE, B_ARM_RECALCDATA, "Hinge",         -10,by-38,85,18, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Don't inherit rotation or scale from parent Bone");
2866                         uiDefButBitI(block, TOGN, BONE_NO_DEFORM, B_ARM_RECALCDATA, "Deform",   75, by-38, 85, 18, &curBone->flag, 0.0, 0.0, 0.0, 0.0, "Indicate if Bone deforms geometry");
2867                         uiDefButBitI(block, TOG, BONE_MULT_VG_ENV, B_ARM_RECALCDATA, "Mult", 160,by-38,85,18, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Multiply Bone Envelope with VertexGroup");
2868                         uiDefButBitI(block, TOG, BONE_HIDDEN_A, REDRAWVIEW3D, "Hide",   245,by-38,85,18, &curBone->flag, 0, 0, 0, 0, "Toggles display of this bone in Edit Mode");
2869                         
2870                         /* layers */
2871                         uiBlockBeginAlign(block);
2872                         for(a=0; a<8; a++) {
2873                                 short dx= 21;
2874                                 but= uiDefButBitS(block, TOG, 1<<a, REDRAWVIEW3D, "", -10+a*dx, by-57, dx, 15, &curBone->layer, 0, 0, 0, 0, "");
2875                                 uiButSetFunc(but, armature_layer_cb, &curBone->layer, (void *)(1<<a));
2876                         }
2877                         uiBlockBeginAlign(block);
2878                         for(a=8; a<16; a++) {
2879                                 short dx= 21;
2880                                 but= uiDefButBitS(block, TOG, 1<<a, REDRAWVIEW3D, "", -6+a*dx, by-57, dx, 15, &curBone->layer, 0, 0, 0, 0, "");
2881                                 uiButSetFunc(but, armature_layer_cb, &curBone->layer, (void *)(1<<a));
2882                         }
2883                         
2884                         uiBlockEndAlign(block);
2885                         by-=80;
2886                         
2887                         if(by < -200) break;    // for time being... extreme long panels are very slow
2888                 }
2889         }
2890
2891         if(by<0) {
2892                 uiNewPanelHeight(block, 204 - by);
2893         }
2894
2895 }
2896
2897 static void editing_panel_pose_bones(Object *ob, bArmature *arm)
2898 {
2899         uiBlock         *block;
2900         uiBut           *but;
2901         bPoseChannel *pchan;
2902         Bone            *curBone;
2903         int                     by=180, a;
2904         int                     index, zerodof, zerolimit;
2905         
2906         /* Draw the bone name block */
2907         
2908         block= uiNewBlock(&curarea->uiblocks, "editing_panel_pose_bones", UI_EMBOSS, UI_HELV, curarea->win);
2909         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
2910         
2911         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2912         /* so first we make it default height */
2913         uiNewPanelHeight(block, 204);
2914         
2915         uiDefBut(block, LABEL, 0, "Selected Bones", 0,by,158,18, 0, 0, 0, 0, 0, "Only show in Armature Editmode/Posemode");
2916         by-=20;
2917         for (pchan=ob->pose->chanbase.first, index=0; pchan; pchan=pchan->next, index++){
2918                 curBone= pchan->bone;
2919                 if ((curBone->flag & BONE_SELECTED) && (curBone->layer & arm->layer)) {
2920
2921                         /*      Bone naming button */
2922                         uiBlockBeginAlign(block);
2923                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:",           -10,by,117,19, &curBone->name, 0, 24, 0, 0, "Change the bone name");
2924                         uiButSetFunc(but, validate_posebonebutton_cb, curBone, NULL);
2925                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)ob);
2926                         
2927                         /* Dist and weight buttons */
2928                         uiDefButF(block, NUM,B_ARM_RECALCDATA, "Dist:",         107, by, 105, 19, &curBone->dist, 0.0, 1000.0, 10.0, 0.0, "Bone deformation distance");
2929                         uiDefButF(block, NUM,B_ARM_RECALCDATA, "Weight:",       220, by,  110, 19, &curBone->weight, 0.0F, 1000.0F, 10.0F, 0.0F, "Bone deformation weight");
2930                         
2931                         /* Segment, ease in/out buttons */
2932                         uiBlockBeginAlign(block);
2933                         uiDefButS(block, NUM, B_ARM_RECALCDATA, "Segm: ",  -10,by-19,117,19, &curBone->segments, 1.0, 32.0, 0.0, 0.0, "Subdivisions for B-bones");
2934                         uiDefButF(block, NUM,B_ARM_RECALCDATA, "In:",           107, by-19,105, 19, &curBone->ease1, 0.0, 2.0, 10.0, 0.0, "First length of Bezier handle");
2935                         uiDefButF(block, NUM,B_ARM_RECALCDATA, "Out:",          220, by-19, 110, 19, &curBone->ease2, 0.0, 2.0, 10.0, 0.0, "Second length of Bezier handle");
2936                         
2937                         /* bone types */
2938                         uiDefButBitI(block, TOG, BONE_HINGE, B_ARM_RECALCDATA, "Hinge", -10,by-38,80,19, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Don't inherit rotation or scale from parent Bone");
2939                         uiDefButBitI(block, TOGN, BONE_NO_DEFORM, B_ARM_RECALCDATA, "Deform",   70, by-38, 80, 19, &curBone->flag, 0.0, 0.0, 0.0, 0.0, "Indicate if Bone deforms geometry");
2940                         uiDefButBitI(block, TOG, BONE_MULT_VG_ENV, B_ARM_RECALCDATA, "Mult", 150,by-38,80,19, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Multiply Bone Envelope with VertexGroup");
2941                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, REDRAWVIEW3D, "OB:",      230,by-38,100,19, &pchan->custom, "Object that defines custom draw type for this Bone");
2942                         
2943                         /* layers */
2944