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