- replaced G.{edve,eded,edvl} with G.editMesh, atm just a structure to
[blender.git] / source / blender / src / buttons_object.c
1 /**
2  * $Id: 
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #ifdef WIN32
43 #include "BLI_winstuff.h"
44 #endif
45
46 #include "MEM_guardedalloc.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_space_types.h"
49 #include "DNA_scene_types.h"
50
51 #include "BKE_global.h"
52 #include "BKE_main.h"
53 #include "BKE_library.h"
54
55 #include "BLI_blenlib.h"
56 #include "BLI_arithb.h"
57
58 #include "BSE_filesel.h"
59
60 #include "BIF_gl.h"
61 #include "BIF_graphics.h"
62 #include "BIF_keyval.h"
63 #include "BIF_mainqueue.h"
64 #include "BIF_resources.h"
65 #include "BIF_screen.h"
66 #include "BIF_mywindow.h"
67 #include "BIF_space.h"
68 #include "BIF_glutil.h"
69 #include "BIF_interface.h"
70 #include "BIF_toolbox.h"
71 #include "BIF_editmesh.h"
72 #include "BDR_editcurve.h"
73 #include "BDR_editface.h"
74 #include "BDR_drawobject.h"
75 #include "BIF_butspace.h"
76
77 #include "mydevice.h"
78 #include "blendef.h"
79
80 /* -----includes for this file specific----- */
81
82
83 #include "DNA_action_types.h"
84 #include "DNA_armature_types.h"
85 #include "DNA_camera_types.h"
86 #include "DNA_constraint_types.h"
87 #include "DNA_curve_types.h"
88 #include "DNA_effect_types.h"
89 #include "DNA_group_types.h"
90 #include "DNA_ika_types.h"
91 #include "DNA_image_types.h"
92 #include "DNA_key_types.h"
93 #include "DNA_lamp_types.h"
94 #include "DNA_lattice_types.h"
95 #include "DNA_material_types.h"
96 #include "DNA_meta_types.h"
97 #include "DNA_mesh_types.h"
98 #include "DNA_object_types.h"
99 #include "DNA_radio_types.h"
100 #include "DNA_screen_types.h"
101 #include "DNA_sound_types.h"
102 #include "DNA_texture_types.h"
103 #include "DNA_userdef_types.h"
104 #include "DNA_vfont_types.h"
105 #include "DNA_view3d_types.h"
106 #include "DNA_world_types.h"
107
108 #include "BKE_anim.h"
109 #include "BKE_armature.h"
110 #include "BKE_constraint.h"
111 #include "BKE_curve.h"
112 #include "BKE_displist.h"
113 #include "BKE_effect.h"
114 #include "BKE_font.h"
115 #include "BKE_ika.h"
116 #include "BKE_image.h"
117 #include "BKE_ipo.h"
118 #include "BKE_lattice.h"
119 #include "BKE_material.h"
120 #include "BKE_mball.h"
121 #include "BKE_mesh.h"
122 #include "BKE_object.h"
123 #include "BKE_sound.h"
124 #include "BKE_texture.h"
125 #include "BKE_utildefines.h"
126
127 #include "BIF_editconstraint.h"
128 #include "BSE_editipo.h"
129 #include "BDR_editobject.h"
130
131 #include "butspace.h" // own module
132
133 static float hspeed=0.1, prspeed=0.0;
134 float prlen=0.0;
135
136
137
138 /* ********************* CONSTRAINT ***************************** */
139
140 static void add_influence_key_to_constraint_func (void *arg1v, void *unused)
141 {
142         bConstraint *con = arg1v;
143         add_influence_key_to_constraint(con);
144 }
145 static void activate_constraint_ipo_func (void *arg1v, void *unused)
146 {
147
148         bConstraint *con = arg1v;
149         bConstraintChannel *chan;
150         ListBase *conbase;
151
152         get_constraint_client(NULL, NULL, NULL);
153
154         conbase = get_constraint_client_channels(1);
155
156         if (!conbase)
157                 return;
158
159         /* See if this list already has an appropriate channel */
160         chan = find_constraint_channel(conbase, con->name);
161
162         if (!chan){
163                 /* Add a new constraint channel */
164                 chan = add_new_constraint_channel(con->name);
165                 BLI_addtail(conbase, chan);
166         }
167
168         /* Ensure there is an ipo to display */
169         if (!chan->ipo){
170                 chan->ipo = add_ipo(con->name, IPO_CO);
171         }
172
173         /* Make this the active channel */
174         OBACT->activecon = chan;
175
176         allqueue(REDRAWIPO, 0);
177         allqueue(REDRAWNLA, 0);
178 }
179
180 static void del_constraint_func (void *arg1v, void *arg2v)
181 {
182         bConstraint *con= arg1v;
183         Object *ob;
184
185         ListBase *lb= arg2v;
186         
187         ob=OBACT;
188         
189         if (ob->activecon && !strcmp(ob->activecon->name, con->name))
190                 ob->activecon = NULL;
191
192         free_constraint_data (con);
193
194         BLI_freelinkN(lb, con);
195
196         allqueue(REDRAWBUTSOBJECT, 0);
197         allqueue(REDRAWIPO, 0); 
198
199 }
200
201 static void verify_constraint_name_func (void *data, void *data2_unused)
202 {
203         ListBase *conlist;
204         bConstraint *con;
205         char ownerstr[64];
206         short type;
207         
208         con = (bConstraint*) data;
209         if (!con)
210                 return;
211         
212         conlist = get_constraint_client(ownerstr, &type, NULL);
213         unique_constraint_name (con, conlist);
214 }
215
216 static void constraint_changed_func (void *data, void *data2_unused)
217 {
218         bConstraint *con = (bConstraint*) data;
219
220         if (con->type == con->otype)
221                 return;
222
223         free_constraint_data (con);
224         con->data = new_constraint_data(con->type);
225
226 }
227
228 static void move_constraint_func (void *datav, void *data2_unused)
229 {
230         bConstraint *constraint_to_move= datav;
231         int val;
232         ListBase *conlist;
233         char ownerstr[64];
234         short   type;
235         bConstraint *curCon, *con, *neighbour;
236         
237         val= pupmenu("Move up%x1|Move down %x2");
238         
239         con = constraint_to_move;
240
241         if(val>0) {
242                 conlist = get_constraint_client(ownerstr, &type, NULL);
243                 for (curCon = conlist->first; curCon; curCon = curCon->next){
244                         if (curCon == con){
245                                 /* Move up */
246                                 if (val == 1 && con->prev){
247                                         neighbour = con->prev;
248                                         BLI_remlink(conlist, neighbour);
249                                         BLI_insertlink(conlist, con, neighbour);
250                                 }
251                                 /* Move down */
252                                 else if (val == 2 && con->next){
253                                         neighbour = con->next;
254                                         BLI_remlink (conlist, con);
255                                         BLI_insertlink(conlist, neighbour, con);
256                                 }
257                                 break;
258                         }
259                 }
260         }
261 }
262
263 static void get_constraint_typestring (char *str, bConstraint *con)
264 {
265         switch (con->type){
266         case CONSTRAINT_TYPE_CHILDOF:
267                 strcpy (str, "Child Of");
268                 return;
269         case CONSTRAINT_TYPE_NULL:
270                 strcpy (str, "Null");
271                 return;
272         case CONSTRAINT_TYPE_TRACKTO:
273                 strcpy (str, "Track To");
274                 return;
275         case CONSTRAINT_TYPE_KINEMATIC:
276                 strcpy (str, "IK Solver");
277                 return;
278         case CONSTRAINT_TYPE_ROTLIKE:
279                 strcpy (str, "Copy Rotation");
280                 return;
281         case CONSTRAINT_TYPE_LOCLIKE:
282                 strcpy (str, "Copy Location");
283                 return;
284         case CONSTRAINT_TYPE_ACTION:
285                 strcpy (str, "Action");
286                 return;
287         case CONSTRAINT_TYPE_LOCKTRACK:
288                 strcpy (str, "Locked Track");
289                 return;
290         case CONSTRAINT_TYPE_FOLLOWPATH:
291                 strcpy (str, "Follow Path");
292                 return;
293         default:
294                 strcpy (str, "Unknown");
295                 return;
296         }
297 }
298
299 static int get_constraint_col(bConstraint *con)
300 {
301         switch (con->type) {
302         case CONSTRAINT_TYPE_NULL:
303                 return TH_BUT_NEUTRAL;
304         case CONSTRAINT_TYPE_KINEMATIC:
305                 return TH_BUT_SETTING2;
306         case CONSTRAINT_TYPE_TRACKTO:
307                 return TH_BUT_SETTING;
308         case CONSTRAINT_TYPE_ROTLIKE:
309                 return TH_BUT_SETTING1;
310         case CONSTRAINT_TYPE_LOCLIKE:
311                 return TH_BUT_POPUP;
312         case CONSTRAINT_TYPE_ACTION:
313                 return TH_BUT_ACTION;
314         case CONSTRAINT_TYPE_LOCKTRACK:
315                 return TH_BUT_SETTING;
316         case CONSTRAINT_TYPE_FOLLOWPATH:
317                 return TH_BUT_SETTING2;
318         default:
319                 return TH_REDALERT;
320         }
321 }
322
323 static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, short *xco, short *yco, short type)
324 {
325         uiBut *but;
326         char typestr[64];
327         short height, width = 265;
328         int curCol;
329
330         get_constraint_typestring (typestr, con);
331
332         curCol = get_constraint_col(con);
333
334         /* Draw constraint header */
335         uiBlockSetEmboss(block, UI_EMBOSSN);
336         
337         uiDefIconButS(block, ICONTOG|BIT|CONSTRAINT_EXPAND_BIT, B_CONSTRAINT_REDRAW, ICON_DISCLOSURE_TRI_RIGHT, *xco-10, *yco, 20, 20, &con->flag, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Constraint");
338
339         if (con->flag & CONSTRAINT_EXPAND) {
340                 
341                 if (con->flag & CONSTRAINT_DISABLE) {
342                         BIF_ThemeColor(TH_REDALERT);
343                         uiBlockSetCol(block, TH_REDALERT);
344                 }
345                 else
346                         BIF_ThemeColor(curCol);
347
348                 /*if (type==TARGET_BONE)
349                         but = uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Bone Constraint%t|Track To%x2|IK Solver%x3|Copy Rotation%x8|Copy Location%x9|Action%x12|Null%x0", *xco+20, *yco, 100, 20, &con->type, 0.0, 0.0, 0.0, 0.0, "Constraint type"); 
350                 else
351                         but = uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Object Constraint%t|Track To%x2|Copy Rotation%x8|Copy Location%x9|Null%x0", *xco+20, *yco, 100, 20, &con->type, 0.0, 0.0, 0.0, 0.0, "Constraint type"); 
352                 */
353                 uiBlockSetEmboss(block, UI_EMBOSSX);
354                 
355                 /* rounded header */
356                 BIF_ThemeColorShade(curCol, -20);
357                 uiSetRoundBox(3);
358                 uiRoundBox((float)*xco+4, (float)*yco-18, (float)*xco+width+30, (float)*yco+6, 5.0);
359
360                 but = uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco-1, 100, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
361
362                 uiButSetFunc(but, constraint_changed_func, con, NULL);
363                 con->otype = con->type;
364                 
365                 but = uiDefBut(block, TEX, B_CONSTRAINT_REDRAW, "", *xco+120, *yco-1, 135, 19, con->name, 0.0, 32.0, 0.0, 0.0, "Constraint name"); 
366                 uiButSetFunc(but, verify_constraint_name_func, con, NULL);
367         }       
368         else{
369                 uiBlockSetEmboss(block, UI_EMBOSSN);
370
371                 if (con->flag & CONSTRAINT_DISABLE) {
372                         uiBlockSetCol(block, TH_REDALERT);
373                         BIF_ThemeColor(TH_REDALERT);
374                 }
375                 else
376                         BIF_ThemeColor(curCol);
377                         
378                 /* coloured rectangle to hold constraint controls */
379                 if (con->type!=CONSTRAINT_TYPE_NULL) glRects(*xco+3, *yco-36, *xco+width+30, *yco-15);
380         
381                 /* rounded header */
382                 BIF_ThemeColorShade(curCol, -20);
383                 uiSetRoundBox(3);
384                 uiRoundBox((float)*xco+4, (float)*yco-15, (float)*xco+width+30, (float)*yco+6, 5.0);
385                 
386                 but = uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco-1, 100, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
387                 uiButSetFunc(but, move_constraint_func, con, NULL);
388                 
389                 but = uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, *xco+120, *yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
390                 uiButSetFunc(but, move_constraint_func, con, NULL);
391         }
392
393         uiBlockSetCol(block, TH_AUTO);  
394         
395         uiBlockSetEmboss(block, UI_EMBOSSN);
396         
397         but = uiDefIconBut(block, BUT, B_CONSTRAINT_REDRAW, ICON_X, *xco+262, *yco, 19, 19, list, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
398         uiButSetFunc(but, del_constraint_func, con, list);
399
400         uiBlockSetEmboss(block, UI_EMBOSSX);
401
402
403         /* Draw constraint data*/
404         if (!(con->flag & CONSTRAINT_EXPAND)) {
405                 (*yco)-=21;
406         }
407         else {
408                 switch (con->type){
409                 case CONSTRAINT_TYPE_ACTION:
410                         {
411                                 bActionConstraint *data = con->data;
412                                 bArmature *arm;
413
414                                 height = 86;
415                                 
416                                 BIF_ThemeColor(curCol);
417                                 glRects(*xco+3, *yco-height-39, *xco+width+30, *yco-18);
418
419                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
420
421                                 /* Draw target parameters */
422                                 uiBlockBeginAlign(block);
423                                 uiDefIDPoinBut(block, test_obpoin_but, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
424
425                                 arm = get_armature(data->tar);
426                                 if (arm){
427                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
428                                 }
429                                 else
430                                         strcpy (data->subtarget, "");
431                                 uiBlockEndAlign(block);
432
433                                 /* Draw action button */
434                                 uiDefIDPoinBut(block, test_actionpoin_but, B_CONSTRAINT_CHANGETARGET, "AC:", *xco+((width/2)-117), *yco-64, 78, 18, &data->act, "Action containing the keyed motion for this bone"); 
435                                 uiDefButI(block, MENU, B_CONSTRAINT_REDRAW, "Key on%t|X Rot%x0|Y Rot%x1|Z Rot%x2", *xco+((width/2)-117), *yco-84, 78, 18, &data->type, 0, 24, 0, 0, "Specify which transformation channel from the target is used to key the action");
436
437                                 uiBlockBeginAlign(block);
438                                 uiDefButS(block, NUM, B_CONSTRAINT_CHANGETARGET, "Start:", *xco+((width/2)-36), *yco-64, 78, 18, &data->start, 1, 18000, 0.0, 0.0, "Starting frame of the keyed motion"); 
439                                 uiDefButS(block, NUM, B_CONSTRAINT_CHANGETARGET, "End:", *xco+((width/2)-36), *yco-84, 78, 18, &data->end, 1, 18000, 0.0, 0.0, "Ending frame of the keyed motion"); 
440                                 uiBlockEndAlign(block);
441                                 
442                                 uiBlockBeginAlign(block);
443                                 uiDefButF(block, NUM, B_CONSTRAINT_REDRAW, "Min:", *xco+((width/2)+45), *yco-64, 78, 18, &data->min, -180, 180, 0, 0, "Minimum value for target channel range");
444                                 uiDefButF(block, NUM, B_CONSTRAINT_REDRAW, "Max:", *xco+((width/2)+45), *yco-84, 78, 18, &data->max, -180, 180, 0, 0, "Maximum value for target channel range");
445                                 uiBlockEndAlign(block);
446                         }
447                         break;
448                 case CONSTRAINT_TYPE_LOCLIKE:
449                         {
450                                 bLocateLikeConstraint *data = con->data;
451                                 bArmature *arm;
452                                 height = 66;
453                                 
454                                 BIF_ThemeColor(curCol);
455                                 glRects(*xco+3, *yco-height-39, *xco+width+30, *yco-18);
456
457                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
458
459                                 /* Draw target parameters */
460                                 uiBlockBeginAlign(block);
461                                 uiDefIDPoinBut(block, test_obpoin_but, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
462
463                                 arm = get_armature(data->tar);
464                                 if (arm){
465                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
466                                 }
467                                 else
468                                         strcpy (data->subtarget, "");
469                                 uiBlockEndAlign(block);
470                                 
471                                 /* Draw XYZ toggles */
472                                 uiBlockBeginAlign(block);
473                                 but=uiDefButI(block, TOG|BIT|0, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
474                                 but=uiDefButI(block, TOG|BIT|1, B_CONSTRAINT_TEST, "Y", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
475                                 but=uiDefButI(block, TOG|BIT|2, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
476                                 uiBlockEndAlign(block);
477                         }
478                         break;
479                 case CONSTRAINT_TYPE_ROTLIKE:
480                         {
481                                 bRotateLikeConstraint *data = con->data;
482                                 bArmature *arm;
483                                 height = 46;
484
485                                 BIF_ThemeColor(curCol);
486                                 glRects(*xco+3, *yco-height-39, *xco+width+30, *yco-18);
487                                 
488                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
489
490                                 /* Draw target parameters */
491                                 uiBlockBeginAlign(block);
492                                 uiDefIDPoinBut(block, test_obpoin_but, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
493
494                                 arm = get_armature(data->tar);
495                                 if (arm){
496                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
497                                 }
498                                 else
499                                         strcpy (data->subtarget, "");
500                                 uiBlockEndAlign(block);
501                         }
502                         break;
503                 case CONSTRAINT_TYPE_KINEMATIC:
504                         {
505                                 bKinematicConstraint *data = con->data;
506                                 bArmature *arm;
507                                 
508                                 height = 66;
509                                 
510                                 BIF_ThemeColor(curCol);
511                                 glRects(*xco+3, *yco-height-39, *xco+width+30, *yco-18);
512                                 
513                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
514
515                                 /* Draw target parameters */
516                                 uiBlockBeginAlign(block);
517                                 uiDefIDPoinBut(block, test_obpoin_but, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
518
519                                 arm = get_armature(data->tar);
520                                 if (arm){
521                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
522                                 }
523                                 else
524                                         strcpy (data->subtarget, "");
525                                 uiBlockEndAlign(block);
526         
527                                 uiDefButF(block, NUM, B_CONSTRAINT_REDRAW, "Tolerance:", *xco+((width/2)-117), *yco-64, 120, 18, &data->tolerance, 0.0001, 1.0, 0.0, 0.0, "Maximum distance to target after solving"); 
528                                 uiDefButI(block, NUM, B_CONSTRAINT_REDRAW, "Iterations:", *xco+((width/2)+3), *yco-64, 120, 18, &data->iterations, 1, 10000, 0.0, 0.0, "Maximum number of solving iterations"); 
529                                 
530                         }
531                         break;
532                 case CONSTRAINT_TYPE_TRACKTO:
533                         {
534                                 bTrackToConstraint *data = con->data;
535                                 bArmature *arm;
536
537                                 height = 66;
538                                 
539                                 BIF_ThemeColor(curCol);
540                                 glRects(*xco+3, *yco-height-39, *xco+width+30, *yco-18);
541                                 
542                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
543
544                                 /* Draw target parameters */
545                                 uiBlockBeginAlign(block);
546                                 uiDefIDPoinBut(block, test_obpoin_but, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
547
548                                 arm = get_armature(data->tar);
549                                 if (arm){
550                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
551                                 }
552                                 else
553                                         strcpy (data->subtarget, "");
554                                 uiBlockEndAlign(block);
555
556                                 uiBlockBeginAlign(block);
557                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
558                                 
559                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"X",   *xco+39, *yco-64,17,18, &data->reserved1, 12.0, 0.0, 0, 0, "The axis that points to the target object");
560                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Y",   *xco+56, *yco-64,17,18, &data->reserved1, 12.0, 1.0, 0, 0, "The axis that points to the target object");
561                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Z",   *xco+73, *yco-64,17,18, &data->reserved1, 12.0, 2.0, 0, 0, "The axis that points to the target object");
562                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-X",  *xco+90, *yco-64,24,18, &data->reserved1, 12.0, 3.0, 0, 0, "The axis that points to the target object");
563                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-Y",  *xco+114, *yco-64,24,18, &data->reserved1, 12.0, 4.0, 0, 0, "The axis that points to the target object");
564                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-Z",  *xco+138, *yco-64,24,18, &data->reserved1, 12.0, 5.0, 0, 0, "The axis that points to the target object");
565                                 uiBlockEndAlign(block);
566                                 
567                                 uiBlockBeginAlign(block);
568                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
569                                 
570                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"X",   *xco+204, *yco-64,17,18, &data->reserved2, 13.0, 0.0, 0, 0, "The axis that points upward");
571                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Y",   *xco+221, *yco-64,17,18, &data->reserved2, 13.0, 1.0, 0, 0, "The axis that points upward");
572                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Z",   *xco+238, *yco-64,17,18, &data->reserved2, 13.0, 2.0, 0, 0, "The axis that points upward");
573                                 uiBlockEndAlign(block);
574                         }
575                         break;
576                 case CONSTRAINT_TYPE_LOCKTRACK:
577                         {
578                                 bLockTrackConstraint *data = con->data;
579                                 bArmature *arm;
580                                 height = 66;
581                                 
582                                 BIF_ThemeColor(curCol);
583                                 glRects(*xco+3, *yco-height-39, *xco+width+30, *yco-18);
584
585                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
586
587                                 /* Draw target parameters */
588                                 uiBlockBeginAlign(block);
589                                 uiDefIDPoinBut(block, test_obpoin_but, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
590
591                                 arm = get_armature(data->tar);
592                                 if (arm){
593                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
594                                 }
595                                 else
596                                         strcpy (data->subtarget, "");
597                                 uiBlockEndAlign(block);
598                                 
599                                 uiBlockBeginAlign(block);
600                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
601                                 
602                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"X",   *xco+39, *yco-64,17,18, &data->trackflag, 12.0, 0.0, 0, 0, "The axis that points to the target object");
603                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Y",   *xco+56, *yco-64,17,18, &data->trackflag, 12.0, 1.0, 0, 0, "The axis that points to the target object");
604                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Z",   *xco+73, *yco-64,17,18, &data->trackflag, 12.0, 2.0, 0, 0, "The axis that points to the target object");
605                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-X",  *xco+90, *yco-64,24,18, &data->trackflag, 12.0, 3.0, 0, 0, "The axis that points to the target object");
606                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-Y",  *xco+114, *yco-64,24,18, &data->trackflag, 12.0, 4.0, 0, 0, "The axis that points to the target object");
607                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-Z",  *xco+138, *yco-64,24,18, &data->trackflag, 12.0, 5.0, 0, 0, "The axis that points to the target object");
608                                 uiBlockEndAlign(block);
609                                 
610                                 uiBlockBeginAlign(block);
611                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Lock:", *xco+166, *yco-64, 38, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
612                                 
613                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"X",   *xco+204, *yco-64,17,18, &data->lockflag, 13.0, 0.0, 0, 0, "The axis that is locked");
614                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Y",   *xco+221, *yco-64,17,18, &data->lockflag, 13.0, 1.0, 0, 0, "The axis that is locked");
615                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Z",   *xco+238, *yco-64,17,18, &data->lockflag, 13.0, 2.0, 0, 0, "The axis that is locked");
616                                 uiBlockEndAlign(block);
617                         }
618                         break;
619                 case CONSTRAINT_TYPE_FOLLOWPATH:
620                         {
621                                 bFollowPathConstraint *data = con->data;
622
623                                 height = 66;
624                                 
625                                 BIF_ThemeColor(curCol);
626                                 glRects(*xco+3, *yco-height-39, *xco+width+30, *yco-18);
627                                 
628                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
629
630                                 /* Draw target parameters */
631                                 uiDefIDPoinBut(block, test_obpoin_but, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
632                                 
633                                 /* Draw Curve Follow toggle */
634                                 but=uiDefButI(block, TOG|BIT|0, B_CONSTRAINT_TEST, "CurveFollow", *xco+39, *yco-44, 100, 18, &data->followflag, 0, 24, 0, 0, "Object will follow the heading and banking of the curve");
635
636                                 /* Draw Offset number button */
637                                 uiDefButF(block, NUM, B_CONSTRAINT_REDRAW, "Offset:", *xco+155, *yco-44, 100, 18, &data->offset, -9000, 9000, 100.0, 0.0, "Offset from the position corresponding to the time frame"); 
638
639                                 uiBlockBeginAlign(block);
640                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Fw:", *xco+12, *yco-64, 27, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
641                                 
642                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"X",   *xco+39, *yco-64,17,18, &data->trackflag, 12.0, 0.0, 0, 0, "The axis that points forward along the path");
643                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Y",   *xco+56, *yco-64,17,18, &data->trackflag, 12.0, 1.0, 0, 0, "The axis that points forward along the path");
644                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Z",   *xco+73, *yco-64,17,18, &data->trackflag, 12.0, 2.0, 0, 0, "The axis that points forward along the path");
645                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-X",  *xco+90, *yco-64,24,18, &data->trackflag, 12.0, 3.0, 0, 0, "The axis that points forward along the path");
646                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-Y",  *xco+114, *yco-64,24,18, &data->trackflag, 12.0, 4.0, 0, 0, "The axis that points forward along the path");
647                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"-Z",  *xco+138, *yco-64,24,18, &data->trackflag, 12.0, 5.0, 0, 0, "The axis that points forward along the path");
648                                 uiBlockEndAlign(block);
649                                 
650                                 uiBlockBeginAlign(block);
651                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
652                                 
653                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"X",   *xco+204, *yco-64,17,18, &data->upflag, 13.0, 0.0, 0, 0, "The axis that points upward");
654                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Y",   *xco+221, *yco-64,17,18, &data->upflag, 13.0, 1.0, 0, 0, "The axis that points upward");
655                                 uiDefButI(block, ROW,B_CONSTRAINT_REDRAW,"Z",   *xco+238, *yco-64,17,18, &data->upflag, 13.0, 2.0, 0, 0, "The axis that points upward");
656                                 uiBlockEndAlign(block);
657                         }
658                         break;
659                 case CONSTRAINT_TYPE_NULL:
660                         {
661                                 height = 17;
662                                 
663                                 BIF_ThemeColor(curCol);
664                                 glRects(*xco+3, *yco-height-17, *xco+width+30, *yco-18);
665                                 
666                         }
667                         break;
668                 default:
669                         height = 0;
670                         break;
671                 }
672
673                 (*yco)-=(24+height);
674         }
675
676         if (con->type!=CONSTRAINT_TYPE_NULL) {
677                 uiDefButF(block, NUMSLI, B_CONSTRAINT_REDRAW, "Influence ", *xco+15, *yco, 199, 19, &(con->enforce), 0.0, 1.0, 0.0, 0.0, "Amount of influence this constraint will have on the final solution");
678                 but = uiDefBut(block, BUT, B_CONSTRAINT_REDRAW, "Edit", *xco+214, *yco, 41, 19, 0, 0.0, 1.0, 0.0, 0.0, "Show this constraint's ipo in the object's Ipo window");
679                 /* If this is on an object, add the constraint to the object */
680                 uiButSetFunc (but, activate_constraint_ipo_func, con, NULL);
681                 /* If this is on a bone, add the constraint to the action (if any) */
682                 //but = uiDefBut(block, BUT, B_CONSTRAINT_REDRAW, "Key", *xco+227, *yco, 41, 20, 0, 0.0, 1.0, 0.0, 0.0, "Add an influence keyframe to the constraint");
683                 /* Add a keyframe to the influence IPO */
684                 //uiButSetFunc (but, add_influence_key_to_constraint_func, con, NULL);
685                 (*yco)-=24;
686         } else {
687                 (*yco)-=3;
688         }
689         
690 }
691
692 static uiBlock *add_constraintmenu(void *arg_unused)
693 {
694         uiBlock *block;
695         
696         ListBase *conlist;
697         char ownerstr[64];
698         short type;
699         short yco= 0;
700         
701         conlist = get_constraint_client(ownerstr, &type, NULL);
702         
703         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
704
705         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIKE,"Copy Location",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
706         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIKE,"Copy Rotation",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
707         
708         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
709         
710         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRACKTO,"Track To",              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
711         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCKTRACK,"Locked Track",                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
712         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_FOLLOWPATH,"Follow Path",                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
713         
714         if (type==TARGET_BONE) {
715         
716                 uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
717                 
718                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_KINEMATIC,"IK Solver",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
719                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ACTION,"Action",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
720                 
721         }
722         
723         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
724         
725         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_NULL,"Null",             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
726         
727         uiTextBoundsBlock(block, 50);
728         uiBlockSetDirection(block, UI_DOWN);
729                 
730         return block;
731 }
732
733 void do_constraintbuts(unsigned short event)
734 {
735         switch(event) {
736         case B_CONSTRAINT_CHANGENAME:
737                 break;
738         case B_CONSTRAINT_TEST:
739                 test_scene_constraints();
740                 allqueue (REDRAWVIEW3D, 0);
741                 allqueue (REDRAWBUTSOBJECT, 0);
742                 break;
743         case B_CONSTRAINT_REDRAW:
744                 test_scene_constraints();
745                 allqueue (REDRAWVIEW3D, 0);
746                 allqueue (REDRAWBUTSOBJECT, 0);
747                 break;
748         case B_CONSTRAINT_CHANGETARGET:
749                 test_scene_constraints();
750                 allqueue (REDRAWVIEW3D, 0);
751                 allqueue (REDRAWBUTSOBJECT, 0);
752                 break;
753         case B_CONSTRAINT_CHANGETYPE:
754                 test_scene_constraints();
755                 allqueue (REDRAWVIEW3D, 0);
756                 allqueue (REDRAWBUTSOBJECT, 0);
757                 break;
758         case B_CONSTRAINT_ADD_NULL:
759                 {
760                         bConstraint *con;
761                         
762                         con = add_new_constraint(CONSTRAINT_TYPE_NULL);
763                         add_constraint_to_client(con);
764
765                         test_scene_constraints();
766                         allqueue (REDRAWVIEW3D, 0);
767                         allqueue (REDRAWBUTSOBJECT, 0);
768                 }
769                 break;
770         case B_CONSTRAINT_ADD_KINEMATIC:
771                 {
772                         bConstraint *con;
773                         
774                         con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC);
775                         add_constraint_to_client(con);
776
777                         test_scene_constraints();
778                         allqueue (REDRAWVIEW3D, 0);
779                         allqueue (REDRAWBUTSOBJECT, 0);
780                 }
781                 break;
782         case B_CONSTRAINT_ADD_TRACKTO:
783                 {
784                         bConstraint *con;
785
786                         con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
787                         add_constraint_to_client(con);
788
789                         test_scene_constraints();
790                         allqueue (REDRAWVIEW3D, 0);
791                         allqueue (REDRAWBUTSOBJECT, 0);
792                 }
793                 break;
794         case B_CONSTRAINT_ADD_ROTLIKE:
795                 {
796                         bConstraint *con;
797
798                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIKE);
799                         add_constraint_to_client(con);
800
801                         test_scene_constraints();
802                         allqueue (REDRAWVIEW3D, 0);
803                         allqueue (REDRAWBUTSOBJECT, 0);
804                 }
805                 break;
806         case B_CONSTRAINT_ADD_LOCLIKE:
807                 {
808                         bConstraint *con;
809
810                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIKE);
811                         add_constraint_to_client(con);
812
813                         test_scene_constraints();
814                         allqueue (REDRAWVIEW3D, 0);
815                         allqueue (REDRAWBUTSOBJECT, 0);
816                 }
817                 break;
818         case B_CONSTRAINT_ADD_ACTION:
819                 {
820                         bConstraint *con;
821
822                         con = add_new_constraint(CONSTRAINT_TYPE_ACTION);
823                         add_constraint_to_client(con);
824
825                         test_scene_constraints();
826                         allqueue (REDRAWVIEW3D, 0);
827                         allqueue (REDRAWBUTSOBJECT, 0);
828                 }
829                 break;
830         case B_CONSTRAINT_ADD_LOCKTRACK:
831                 {
832                         bConstraint *con;
833
834                         con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
835                         add_constraint_to_client(con);
836
837                         test_scene_constraints();
838                         allqueue (REDRAWVIEW3D, 0);
839                         allqueue (REDRAWBUTSOBJECT, 0);
840                 }
841                 break;
842         case B_CONSTRAINT_ADD_FOLLOWPATH:
843                 {
844                         bConstraint *con;
845
846                         con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
847                         add_constraint_to_client(con);
848
849                         test_scene_constraints();
850                         allqueue (REDRAWVIEW3D, 0);
851                         allqueue (REDRAWBUTSOBJECT, 0);
852                 }
853                 break;
854         case B_CONSTRAINT_DEL:
855                 test_scene_constraints();
856                 allqueue (REDRAWVIEW3D, 0);
857                 allqueue (REDRAWBUTSOBJECT, 0);
858                 break;
859         default:
860                 break;
861         }
862
863         clear_object_constraint_status(OBACT);
864         make_displists_by_armature (OBACT);
865 }
866
867 static void object_panel_constraint(void)
868 {
869         uiBlock *block;
870         ListBase *conlist;
871         bConstraint *curcon;
872         short xco, yco, type;
873         char ownerstr[64];
874         
875         block= uiNewBlock(&curarea->uiblocks, "object_panel_constraint", UI_EMBOSS, UI_HELV, curarea->win);
876         if(uiNewPanel(curarea, block, "Constraints", "Object", 640, 0, 318, 204)==0) return;
877
878         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
879         /* so first we make it default height */
880         uiNewPanelHeight(block, 204);
881
882         conlist = get_constraint_client(ownerstr, &type, NULL);
883         
884         if (conlist) {
885                  
886                 uiDefBlockBut(block, add_constraintmenu, NULL, "Add Constraint|>> ", 0, 190, 130, 20, "Add a new constraint");
887                 
888                 /* print active object or bone */
889                 {
890                         short type;
891                         void *data=NULL;
892                         char str[64];
893                         
894                         str[0]= 0;
895                         get_constraint_client(NULL, &type, &data);
896                         if (data && type==TARGET_BONE){
897                                 sprintf(str, "To Bone: %s", ((Bone*)data)->name);
898                         }
899                         else if(OBACT) {
900                                 Object *ob= OBACT;
901                                 sprintf(str, "To Object: %s", ob->id.name+2);
902                         }
903                         uiDefBut(block, LABEL, 1, str,  150, 190, 150, 20, NULL, 0.0, 0.0, 0, 0, "Displays Active Object or Bone name");
904                 }
905                 
906                 /* Go through the list of constraints and draw them */
907                 xco = 10;
908                 yco = 160;
909                 // local panel coords
910                 uiPanelPush(block);
911                 
912                 for (curcon = conlist->first; curcon; curcon=curcon->next) {
913                         /* Draw default constraint header */                    
914                         draw_constraint(block, conlist, curcon, &xco, &yco, type);      
915                 }
916                 
917                 uiPanelPop(block);
918                 
919                 if(yco < 0) uiNewPanelHeight(block, 204-yco);
920                 
921         }
922 }
923
924
925
926
927 /* *************** */
928
929
930 #include "BLI_editVert.h"
931 extern ListBase editNurb;
932
933 void do_common_editbuts(unsigned short event) // old name, is a mix of object and editing events.... 
934 {
935         EditMesh *em = G.editMesh;
936         EditVlak *evl;
937         Base *base;
938         Object *ob;
939         Mesh *me;
940         Nurb *nu;
941         Curve *cu;
942         BezTriple *bezt;
943         BPoint *bp;
944         unsigned int local;
945         int a, bit, index= -1;
946
947         switch(event) {
948                 
949         case B_MATWICH:
950                 if(G.obedit && G.obedit->actcol>0) {
951                         if(G.obedit->type == OB_MESH) {
952                                 evl= em->faces.first;
953                                 while(evl) {
954                                         if( vlakselectedAND(evl, 1) ) {
955                                                 if(index== -1) index= evl->mat_nr;
956                                                 else if(index!=evl->mat_nr) {
957                                                         error("Mixed colors");
958                                                         return;
959                                                 }
960                                         }
961                                         evl= evl->next;
962                                 }
963                         }
964                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
965                                 nu= editNurb.first;
966                                 while(nu) {
967                                         if( isNurbsel(nu) ) {
968                                                 if(index== -1) index= nu->mat_nr;
969                                                 else if(index!=nu->mat_nr) {
970                                                         error("Mixed colors");
971                                                         return;
972                                                 }
973                                         }
974                                         nu= nu->next;
975                                 }                               
976                         }
977                         if(index>=0) {
978                                 G.obedit->actcol= index+1;
979                                 scrarea_queue_winredraw(curarea);
980                         }
981                 }
982                 break;
983         case B_MATNEW:
984                 new_material_to_objectdata((G.scene->basact) ? (G.scene->basact->object) : 0);
985                 scrarea_queue_winredraw(curarea);
986                 allqueue(REDRAWVIEW3D_Z, 0);
987                 break;
988         case B_MATDEL:
989                 delete_material_index();
990                 scrarea_queue_winredraw(curarea);
991                 allqueue(REDRAWVIEW3D_Z, 0);
992                 break;
993         case B_MATASS:
994                 if(G.obedit && G.obedit->actcol>0) {
995                         if(G.obedit->type == OB_MESH) {
996                                 undo_push_mesh("Assign material index");
997                                 evl= em->faces.first;
998                                 while(evl) {
999                                         if( vlakselectedAND(evl, 1) )
1000                                                 evl->mat_nr= G.obedit->actcol-1;
1001                                         evl= evl->next;
1002                                 }
1003                                 allqueue(REDRAWVIEW3D_Z, 0);
1004                                 makeDispList(G.obedit);
1005                         }
1006                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
1007                                 nu= editNurb.first;
1008                                 while(nu) {
1009                                         if( isNurbsel(nu) )
1010                                                 nu->mat_nr= G.obedit->actcol-1;
1011                                         nu= nu->next;
1012                                 }
1013                         }
1014                 }
1015                 break;
1016         case B_MATSEL:
1017         case B_MATDESEL:
1018                 if(G.obedit) {
1019                         if(G.obedit->type == OB_MESH) {
1020                                 if (event==B_MATSEL) {
1021                                         editmesh_select_by_material(G.obedit->actcol-1);
1022                                 } else {
1023                                         editmesh_deselect_by_material(G.obedit->actcol-1);
1024                                 }
1025                                 allqueue(REDRAWVIEW3D, 0);
1026                         }
1027                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
1028                                 nu= editNurb.first;
1029                                 while(nu) {
1030                                         if(nu->mat_nr==G.obedit->actcol-1) {
1031                                                 if(nu->bezt) {
1032                                                         a= nu->pntsu;
1033                                                         bezt= nu->bezt;
1034                                                         while(a--) {
1035                                                                 if(bezt->hide==0) {
1036                                                                         if(event==B_MATSEL) {
1037                                                                                 bezt->f1 |= 1;
1038                                                                                 bezt->f2 |= 1;
1039                                                                                 bezt->f3 |= 1;
1040                                                                         }
1041                                                                         else {
1042                                                                                 bezt->f1 &= ~1;
1043                                                                                 bezt->f2 &= ~1;
1044                                                                                 bezt->f3 &= ~1;
1045                                                                         }
1046                                                                 }
1047                                                                 bezt++;
1048                                                         }
1049                                                 }
1050                                                 else if(nu->bp) {
1051                                                         a= nu->pntsu*nu->pntsv;
1052                                                         bp= nu->bp;
1053                                                         while(a--) {
1054                                                                 if(bp->hide==0) {
1055                                                                         if(event==B_MATSEL) bp->f1 |= 1;
1056                                                                         else bp->f1 &= ~1;
1057                                                                 }
1058                                                                 bp++;
1059                                                         }
1060                                                 }
1061                                         }
1062                                         nu= nu->next;
1063                                 }
1064                                 allqueue(REDRAWVIEW3D, 0);
1065                         }
1066                 }
1067                 break;
1068         case B_HIDE:
1069                 if(G.obedit) {
1070                         if(G.obedit->type == OB_MESH) hide_mesh(0);
1071                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) hideNurb(0);
1072                 }
1073                 break;
1074         case B_REVEAL:
1075                 if(G.obedit) {
1076                         if(G.obedit->type == OB_MESH) reveal_mesh();
1077                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) revealNurb();
1078                 }
1079                 else if(G.f & G_FACESELECT) reveal_tface();
1080                 
1081                 break;
1082         case B_SELSWAP:
1083                 if(G.obedit) {
1084                         if(G.obedit->type == OB_MESH) selectswap_mesh();
1085                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) selectswapNurb();
1086                 }
1087                 break;
1088         case B_AUTOTEX:
1089                 ob= OBACT;
1090                 if(ob && G.obedit==0) {
1091                         if(ob->type==OB_MESH) tex_space_mesh(ob->data);
1092                         else if(ob->type==OB_MBALL) ;
1093                         else tex_space_curve(ob->data);
1094                 }
1095                 break;
1096         case B_DOCENTRE:
1097                 docentre();
1098                 break;
1099         case B_DOCENTRENEW:
1100                 docentre_new();
1101                 break;
1102         case B_DOCENTRECURSOR:
1103                 docentre_cursor();
1104                 break;
1105         case B_SETSMOOTH:
1106         case B_SETSOLID:
1107                 if(G.obedit) {
1108                         if(G.obedit->type == OB_MESH) {
1109                                 evl= em->faces.first;
1110                                 if (event == B_SETSMOOTH) undo_push_mesh("Set Smooth");
1111                                 else if (event==B_SETSOLID) undo_push_mesh("Set Solid");
1112                                 while(evl) {
1113                                         if( vlakselectedAND(evl, 1) ) {
1114                                                 if(event==B_SETSMOOTH) evl->flag |= ME_SMOOTH;
1115                                                 else evl->flag &= ~ME_SMOOTH;
1116                                         }
1117                                         evl= evl->next;
1118                                 }
1119
1120                                 makeDispList(G.obedit);
1121                                 allqueue(REDRAWVIEW3D, 0);
1122                         }
1123                         else {
1124                                 nu= editNurb.first;
1125                                 while(nu) {
1126                                         if(isNurbsel(nu)) {
1127                                                 if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
1128                                                 else nu->flag &= ~ME_SMOOTH;
1129                                         }
1130                                         nu= nu->next;
1131                                 }
1132                                 
1133                         }
1134                 }
1135                 else {
1136                         base= FIRSTBASE;
1137                         while(base) {
1138                                 if(TESTBASELIB(base)) {
1139                                         if(base->object->type==OB_MESH) {
1140                                                 me= base->object->data;
1141                                                 mesh_set_smooth_flag(me, (event==B_SETSMOOTH));
1142                                                 makeDispList(base->object);
1143                                         }
1144                                         else if ELEM(base->object->type, OB_SURF, OB_CURVE) {
1145                                                 cu= base->object->data;
1146                                                 nu= cu->nurb.first;
1147                                                 while(nu) {
1148                                                         if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
1149                                                         else nu->flag &= ~ME_SMOOTH;
1150                                                         nu= nu->next;
1151                                                 }
1152                                         }
1153                                 }
1154                                 base= base->next;
1155                         }
1156                         allqueue(REDRAWVIEW3D, 0);
1157                 }
1158                 break;
1159
1160         default:
1161                 if(event>=B_OBLAY && event<=B_OBLAY+31) {
1162                         local= BASACT->lay & 0xFF000000;
1163                         BASACT->lay -= local;
1164                         if(BASACT->lay==0 || (G.qual & LR_SHIFTKEY)==0) {
1165                                 bit= event-B_OBLAY;
1166                                 BASACT->lay= 1<<bit;
1167                                 scrarea_queue_winredraw(curarea);
1168                         }
1169                         BASACT->lay += local;
1170                         /* optimal redraw */
1171                         if( (OBACT->lay & G.vd->lay) && (BASACT->lay & G.vd->lay) );
1172                         else if( (OBACT->lay & G.vd->lay)==0 && (BASACT->lay & G.vd->lay)==0 );
1173                         else allqueue(REDRAWVIEW3D, 0);
1174                         
1175                         OBACT->lay= BASACT->lay;
1176                 }
1177         }
1178
1179 }
1180
1181 void object_panel_draw(Object *ob)
1182 {
1183         ID *id;
1184         uiBlock *block;
1185         int xco, a, dx, dy;
1186         
1187         block= uiNewBlock(&curarea->uiblocks, "object_panel_draw", UI_EMBOSS, UI_HELV, curarea->win);
1188         if(uiNewPanel(curarea, block, "Draw", "Object", 320, 0, 318, 204)==0) return;
1189
1190         /* LAYERS */
1191         xco= 151;
1192         dx= 32;
1193         dy= 30;
1194
1195         uiBlockBeginAlign(block);
1196         for(a=0; a<5; a++)
1197                 uiDefButI(block, TOG|BIT|(a), B_OBLAY+a, "",    (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), &(BASACT->lay), 0, 0, 0, 0, "");
1198         for(a=0; a<5; a++)
1199                 uiDefButI(block, TOG|BIT|(a+10), B_OBLAY+a+10, "",      (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), &(BASACT->lay), 0, 0, 0, 0, "");
1200                 
1201         xco+= 5;
1202         uiBlockBeginAlign(block);
1203         for(a=5; a<10; a++)
1204                 uiDefButI(block, TOG|BIT|(a), B_OBLAY+a, "",    (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), &(BASACT->lay), 0, 0, 0, 0, "");
1205         for(a=5; a<10; a++)
1206                 uiDefButI(block, TOG|BIT|(a+10), B_OBLAY+a+10, "",      (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), &(BASACT->lay), 0, 0, 0, 0, "");
1207
1208         uiBlockEndAlign(block);
1209
1210         id= ob->data;
1211         if(id && id->lib) uiSetButLock(1, "Can't edit library data");
1212
1213         uiDefBut(block, LABEL, 0, "Drawtype",                                           28,200,100,18, 0, 0, 0, 0, 0, "");
1214         uiDefButC(block, MENU, REDRAWVIEW3D, "Drawtype%t|Bounds %x1|Wire %x2|Solid %x3|Shaded %x4",     
1215                                                                                                                                 28,180,100,18, &ob->dt, 0, 0, 0, 0, "Sets the drawing type of the active object");
1216         uiDefBut(block, LABEL, 0, "Draw Extra",                                         28,160,100,18, 0, 0, 0, 0, 0, "");
1217         uiBlockBeginAlign(block);
1218         uiDefButC(block, TOG|BIT|0, REDRAWVIEW3D, "Bounds",             28, 140, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
1219         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder",
1220                                                                                                                         28, 120, 100, 18, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
1221         uiDefButBitC(block, TOG, OB_DRAWWIRE, REDRAWVIEW3D, "Wire",             28, 100, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's wireframe in shaded drawing modes");
1222         uiDefButBitC(block, TOG, OB_AXIS, REDRAWVIEW3D, "Axis",         28, 80, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's centre and axis");
1223         uiDefButBitC(block, TOG, OB_TEXSPACE, REDRAWVIEW3D, "TexSpace", 28, 60, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
1224         uiDefButBitC(block, TOG, OB_DRAWNAME, REDRAWVIEW3D, "Name",             28, 40, 100, 18, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
1225         
1226         
1227 }
1228
1229
1230
1231
1232 void do_object_panels(unsigned short event)
1233 {
1234         Object *ob;
1235         Base *base;
1236         Effect *eff, *effn;
1237         int type;
1238         
1239         ob= OBACT;
1240
1241         switch(event) {
1242                 
1243         case B_RECALCPATH:
1244                 calc_curvepath(OBACT);
1245                 allqueue(REDRAWVIEW3D, 0);
1246                 break;
1247         case B_AUTOTIMEOFS:
1248                 auto_timeoffs();
1249                 break;
1250         case B_FRAMEMAP:
1251                 G.scene->r.framelen= G.scene->r.framapto;
1252                 G.scene->r.framelen/= G.scene->r.images;
1253                 break;
1254         case B_NEWEFFECT:
1255                 if(ob) {
1256                         if (BLI_countlist(&ob->effect)==MAX_EFFECT)
1257                                 error("Unable to add: effect limit reached");
1258                         else
1259                                 copy_act_effect(ob);
1260                 }
1261                 allqueue(REDRAWBUTSOBJECT, 0);
1262                 break;
1263         case B_DELEFFECT:
1264                 if(ob==0 || ob->type!=OB_MESH) break;
1265                 eff= ob->effect.first;
1266                 while(eff) {
1267                         effn= eff->next;
1268                         if(eff->flag & SELECT) {
1269                                 BLI_remlink(&ob->effect, eff);
1270                                 free_effect(eff);
1271                                 break;
1272                         }
1273                         eff= effn;
1274                 }
1275                 allqueue(REDRAWBUTSOBJECT, 0);
1276                 allqueue(REDRAWVIEW3D, 0);
1277                 break;
1278         case B_NEXTEFFECT:
1279                 if(ob==0 || ob->type!=OB_MESH) break;
1280                 eff= ob->effect.first;
1281                 while(eff) {
1282                         if(eff->flag & SELECT) {
1283                                 if(eff->next) {
1284                                         eff->flag &= ~SELECT;
1285                                         eff->next->flag |= SELECT;
1286                                 }
1287                                 break;
1288                         }
1289                         eff= eff->next;
1290                 }
1291                 allqueue(REDRAWBUTSOBJECT, 0);
1292                 break;
1293         case B_PREVEFFECT:
1294                 if(ob==0 || ob->type!=OB_MESH) break;
1295                 eff= ob->effect.first;
1296                 while(eff) {
1297                         if(eff->flag & SELECT) {
1298                                 if(eff->prev) {
1299                                         eff->flag &= ~SELECT;
1300                                         eff->prev->flag |= SELECT;
1301                                 }
1302                                 break;
1303                         }
1304                         eff= eff->next;
1305                 }
1306                 allqueue(REDRAWBUTSOBJECT, 0);
1307                 break;
1308         case B_CHANGEEFFECT:
1309                 if(ob==0 || ob->type!=OB_MESH) break;
1310                 eff= ob->effect.first;
1311                 while(eff) {
1312                         if(eff->flag & SELECT) {
1313                                 if(eff->type!=eff->buttype) {
1314                                         BLI_remlink(&ob->effect, eff);
1315                                         type= eff->buttype;
1316                                         free_effect(eff);
1317                                         eff= add_effect(type);
1318                                         BLI_addtail(&ob->effect, eff);
1319                                 }
1320                                 break;
1321                         }
1322                         eff= eff->next;
1323                 }
1324                 allqueue(REDRAWBUTSOBJECT, 0);
1325                 allqueue(REDRAWVIEW3D, 0);
1326                 break;
1327         case B_CALCEFFECT:
1328                 if(ob==0 || ob->type!=OB_MESH) break;
1329                 eff= ob->effect.first;
1330                 while(eff) {
1331                         if(eff->flag & SELECT) {
1332                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
1333                                 else if(eff->type==EFF_WAVE) object_wave(ob);
1334                         }
1335                         eff= eff->next;
1336                 }
1337                 allqueue(REDRAWVIEW3D, 0);
1338                 allqueue(REDRAWBUTSOBJECT, 0);
1339                 break;
1340         case B_RECALCAL:
1341                 base= FIRSTBASE;
1342                 while(base) {
1343                         if(base->lay & G.vd->lay) {
1344                                 ob= base->object;
1345                                 eff= ob->effect.first;
1346                                 while(eff) {
1347                                         if(eff->flag & SELECT) {
1348                                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
1349                                         }
1350                                         eff= eff->next;
1351                                 }
1352                         }
1353                         base= base->next;
1354                 }
1355                 allqueue(REDRAWVIEW3D, 0);
1356                 break;
1357         case B_PRINTSPEED:
1358                 ob= OBACT;
1359                 if(ob) {
1360                         float vec[3];
1361                         CFRA++;
1362                         do_ob_ipo(ob);
1363                         where_is_object(ob);
1364                         VECCOPY(vec, ob->obmat[3]);
1365                         CFRA--;
1366                         do_ob_ipo(ob);
1367                         where_is_object(ob);
1368                         VecSubf(vec, vec, ob->obmat[3]);
1369                         prspeed= Normalise(vec);
1370                         scrarea_queue_winredraw(curarea);
1371                 }
1372                 break;
1373         case B_PRINTLEN:
1374                 ob= OBACT;
1375                 if(ob && ob->type==OB_CURVE) {
1376                         Curve *cu=ob->data;
1377                         
1378                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
1379                         scrarea_queue_winredraw(curarea);
1380                 } 
1381                 break;
1382         case B_RELKEY:
1383                 allspace(REMAKEIPO, 0);
1384                 allqueue(REDRAWBUTSOBJECT, 0);
1385                 allqueue(REDRAWIPO, 0);
1386                 break;
1387                 
1388         default:
1389                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
1390                         ob= OBACT;
1391                         if(ob) {
1392                                 int a=B_SELEFFECT;
1393                                 
1394                                 eff= ob->effect.first;
1395                                 while(eff) {
1396                                         if(event==a) eff->flag |= SELECT;
1397                                         else eff->flag &= ~SELECT;
1398                                         
1399                                         a++;
1400                                         eff= eff->next;
1401                                 }
1402                                 allqueue(REDRAWBUTSOBJECT, 0);
1403                         }
1404                 }
1405         }
1406
1407 }
1408
1409 void object_panel_effects(Object *ob)
1410 {
1411         Effect *eff;
1412         uiBlock *block;
1413         int a;
1414         short x, y;
1415         
1416         block= uiNewBlock(&curarea->uiblocks, "object_panel_effects", UI_EMBOSS, UI_HELV, curarea->win);
1417         uiNewPanelTabbed("Constraints", "Object");
1418         if(uiNewPanel(curarea, block, "Effects", "Object", 640, 0, 418, 204)==0) return;
1419
1420         /* EFFECTS */
1421         
1422         if (ob->type == OB_MESH) {
1423                 uiBlockBeginAlign(block);
1424                 uiDefBut(block, BUT, B_NEWEFFECT, "NEW Effect", 550,187,124,27, 0, 0, 0, 0, 0, "Create a new effect");
1425                 uiDefBut(block, BUT, B_DELEFFECT, "Delete", 676,187,62,27, 0, 0, 0, 0, 0, "Delete the effect");
1426                 uiBlockEndAlign(block);
1427         }
1428
1429         /* select effs */
1430         eff= ob->effect.first;
1431         a= 0;
1432         while(eff) {
1433                 
1434                 x= 15 * a + 550;
1435                 y= 172; // - 12*( abs(a/10) ) ;
1436                 uiDefButS(block, TOG|BIT|0, B_SELEFFECT+a, "", x, y, 15, 12, &eff->flag, 0, 0, 0, 0, "");
1437                 
1438                 a++;
1439                 if(a==MAX_EFFECT) break;
1440                 eff= eff->next;
1441         }
1442         
1443         eff= ob->effect.first;
1444         while(eff) {
1445                 if(eff->flag & SELECT) break;
1446                 eff= eff->next;
1447         }
1448         
1449         if(eff) {
1450                 uiDefButS(block, MENU, B_CHANGEEFFECT, "Build %x0|Particles %x1|Wave %x2", 895,187,107,27, &eff->buttype, 0, 0, 0, 0, "Start building the effect");
1451                 
1452                 if(eff->type==EFF_BUILD) {
1453                         BuildEff *bld;
1454                         
1455                         bld= (BuildEff *)eff;
1456                         
1457                         uiDefButF(block, NUM, 0, "Len:",                        649,138,95,21, &bld->len, 1.0, 9000.0, 100, 0, "Specify the total time the building requires");
1458                         uiDefButF(block, NUM, 0, "Sfra:",                       746,138,94,22, &bld->sfra, 1.0, 9000.0, 100, 0, "Specify the startframe of the effect");
1459                 }
1460                 else if(eff->type==EFF_WAVE) {
1461                         WaveEff *wav;
1462                         
1463                         wav= (WaveEff *)eff;
1464                         uiBlockBeginAlign(block);
1465                         uiDefButS(block, TOG|BIT|1, B_CALCEFFECT, "X",          782,135,54,23, &wav->flag, 0, 0, 0, 0, "Enable X axis");
1466                         uiDefButS(block, TOG|BIT|2, B_CALCEFFECT, "Y",          840,135,47,23, &wav->flag, 0, 0, 0, 0, "Enable Y axis");
1467                         uiDefButS(block, TOG|BIT|3, B_CALCEFFECT, "Cycl",       890,135,111,23, &wav->flag, 0, 0, 0, 0, "Enable cyclic wave efefct");
1468                         uiBlockBeginAlign(block);
1469                         uiDefButF(block, NUM, B_CALCEFFECT, "Sta x:",           550,135,113,24, &wav->startx, -100.0, 100.0, 100, 0, "Starting position for the X axis");
1470                         uiDefButF(block, NUM, B_CALCEFFECT, "Sta y:",           665,135,104,24, &wav->starty, -100.0, 100.0, 100, 0, "Starting position for the Y axis");
1471                         uiBlockBeginAlign(block);
1472                         uiDefButF(block, NUMSLI, B_CALCEFFECT, "Speed:",        550,100,216,20, &wav->speed, -2.0, 2.0, 0, 0, "Specify the wave speed");
1473                         uiDefButF(block, NUMSLI, B_CALCEFFECT, "Heigth:",       550,80,216,20, &wav->height, -2.0, 2.0, 0, 0, "Specify the amplitude of the wave");
1474                         uiDefButF(block, NUMSLI, B_CALCEFFECT, "Width:",        550,60,216,20, &wav->width, 0.0, 5.0, 0, 0, "Specify the width of the wave");
1475                         uiDefButF(block, NUMSLI, B_CALCEFFECT, "Narrow:",       550,40,216,20, &wav->narrow, 0.0, 10.0, 0, 0, "Specify how narrow the wave follows");
1476                         uiBlockBeginAlign(block);
1477                         uiDefButF(block, NUM, B_CALCEFFECT, "Time sta:",        780,100,219,20, &wav->timeoffs, -1000.0, 1000.0, 100, 0, "Specify startingframe of the wave");
1478
1479                         uiDefButF(block, NUM, B_CALCEFFECT, "Lifetime:",        780,80,219,20, &wav->lifetime,  -1000.0, 1000.0, 100, 0, "Specify the lifespan of the wave");
1480                         uiDefButF(block, NUM, B_CALCEFFECT, "Damptime:",        780,60,219,20, &wav->damp,  -1000.0, 1000.0, 100, 0, "Specify the dampingtime of the wave");
1481                         uiBlockEndAlign(block);
1482                 }
1483                 else if(eff->type==EFF_PARTICLE) {
1484                         PartEff *paf;
1485                         
1486                         paf= (PartEff *)eff;
1487                         
1488                         uiDefBut(block, BUT, B_RECALCAL, "RecalcAll", 741,187,67,27, 0, 0, 0, 0, 0, "Update the particle system");
1489                         uiDefButS(block, TOG|BIT|2, B_CALCEFFECT, "Static",     825,187,67,27, &paf->flag, 0, 0, 0, 0, "Make static particles");
1490                         
1491                         uiBlockBeginAlign(block);
1492                         uiDefButI(block, NUM, B_CALCEFFECT, "Tot:",                     550,146,91,20, &paf->totpart, 1.0, 100000.0, 0, 0, "Set the total number of particles");
1493                         if(paf->flag & PAF_STATIC) {
1494                                 uiDefButS(block, NUM, REDRAWVIEW3D, "Step:",    644,146,84+97,20, &paf->staticstep, 1.0, 100.0, 10, 0, "");
1495                         }
1496                         else {
1497                                 uiDefButF(block, NUM, B_CALCEFFECT, "Sta:",             644,146,84,20, &paf->sta, -250.0, 9000.0, 100, 0, "Specify the startframe");
1498                                 uiDefButF(block, NUM, B_CALCEFFECT, "End:",             731,146,97,20, &paf->end, 1.0, 9000.0, 100, 0, "Specify the endframe");
1499                         }
1500                         uiDefButF(block, NUM, B_CALCEFFECT, "Life:",            831,146,88,20, &paf->lifetime, 1.0, 9000.0, 100, 0, "Specify the life span of the particles");
1501                         uiDefButI(block, NUM, B_CALCEFFECT, "Keys:",            922,146,80,20, &paf->totkey, 1.0, 32.0, 0, 0, "Specify the number of key positions");
1502                         
1503                         uiDefButS(block, NUM, B_REDR,           "CurMul:",              550,124,91,20, &paf->curmult, 0.0, 3.0, 0, 0, "Multiply the particles");
1504                         uiDefButS(block, NUM, B_CALCEFFECT, "Mat:",                     644,124,84,20, paf->mat+paf->curmult, 1.0, 8.0, 0, 0, "Specify the material used for the particles");
1505                         uiDefButF(block, NUM, B_CALCEFFECT, "Mult:",            730,124,98,20, paf->mult+paf->curmult, 0.0, 1.0, 10, 0, "Probability \"dying\" particle spawns a new one.");
1506                         uiDefButF(block, NUM, B_CALCEFFECT, "Life:",            831,124,89,20, paf->life+paf->curmult, 1.0, 600.0, 100, 0, "Specify the lifespan of the next generation particles");
1507                         uiDefButS(block, NUM, B_CALCEFFECT, "Child:",           922,124,80,20, paf->child+paf->curmult, 1.0, 600.0, 100, 0, "Specify the number of children of a particle that multiply itself");
1508                         
1509                         uiBlockBeginAlign(block);
1510                         uiDefButF(block, NUM, B_CALCEFFECT, "Randlife:",        550,96,96,20, &paf->randlife, 0.0, 2.0, 10, 0, "Give the particlelife a random variation");
1511                         uiDefButI(block, NUM, B_CALCEFFECT, "Seed:",            652,96,80,20, &paf->seed, 0.0, 255.0, 0, 0, "Set an offset in the random table");
1512
1513                         uiDefButS(block, TOG|BIT|3, B_CALCEFFECT, "Face",               735,96,46,20, &paf->flag, 0, 0, 0, 0, "Emit particles also from faces");
1514                         uiDefButS(block, TOG|BIT|1, B_CALCEFFECT, "Bspline",    782,96,54,20, &paf->flag, 0, 0, 0, 0, "Use B spline formula for particle interpolation");
1515                         uiDefButS(block, TOG, REDRAWVIEW3D, "Vect",                             837,96,45,20, &paf->stype, 0, 0, 0, 0, "Give the particles a rotation direction");
1516                         uiDefButF(block, NUM, B_DIFF,                   "VectSize",             885,96,116,20, &paf->vectsize, 0.0, 1.0, 10, 0, "Set the speed for Vect");      
1517
1518                         uiBlockBeginAlign(block);
1519                         uiBlockSetCol(block, TH_BUT_SETTING2);
1520                         uiDefButF(block, NUM, B_CALCEFFECT, "Norm:",            550,67,96,20, &paf->normfac, -2.0, 2.0, 10, 0, "Let the mesh give the particle a starting speed");
1521                         uiDefButF(block, NUM, B_CALCEFFECT, "Ob:",              649,67,86,20, &paf->obfac, -1.0, 1.0, 10, 0, "Let the object give the particle a starting speed");
1522                         uiDefButF(block, NUM, B_CALCEFFECT, "Rand:",            738,67,86,20, &paf->randfac, 0.0, 2.0, 10, 0, "Give the startingspeed a random variation");
1523                         uiDefButF(block, NUM, B_CALCEFFECT, "Tex:",             826,67,85,20, &paf->texfac, 0.0, 2.0, 10, 0, "Let the texture give the particle a starting speed");
1524                         uiDefButF(block, NUM, B_CALCEFFECT, "Damp:",            913,67,89,20, &paf->damp, 0.0, 1.0, 10, 0, "Specify the damping factor");
1525                         uiBlockSetCol(block, TH_AUTO);
1526                         
1527                         uiBlockBeginAlign(block);
1528                         uiDefButF(block, NUM, B_CALCEFFECT, "X:",               550,31,72,20, paf->force, -1.0, 1.0, 1, 0, "Specify the X axis of a continues force");
1529                         uiDefButF(block, NUM, B_CALCEFFECT, "Y:",               624,31,78,20, paf->force+1,-1.0, 1.0, 1, 0, "Specify the Y axis of a continues force");
1530                         uiDefBut(block, LABEL, 0, "Force:",                             550,9,72,20, 0, 1.0, 0, 0, 0, "");
1531                         uiDefButF(block, NUM, B_CALCEFFECT, "Z:",               623,9,79,20, paf->force+2, -1.0, 1.0, 1, 0, "Specify the Z axis of a continues force");
1532
1533                         uiBlockBeginAlign(block);
1534                         uiDefButF(block, NUM, B_CALCEFFECT, "X:",               722,31,74,20, paf->defvec, -1.0, 1.0, 1, 0, "Specify the X axis of a force, determined by the texture");
1535                         uiDefButF(block, NUM, B_CALCEFFECT, "Y:",               798,31,74,20, paf->defvec+1,-1.0, 1.0, 1, 0, "Specify the Y axis of a force, determined by the texture");
1536                         uiDefBut(block, LABEL, 0, "Texture:",                   722,9,74,20, 0, 1.0, 0, 0, 0, "");
1537                         uiDefButF(block, NUM, B_CALCEFFECT, "Z:",               797,9,75,20, paf->defvec+2, -1.0, 1.0, 1, 0, "Specify the Z axis of a force, determined by the texture");
1538                         uiBlockEndAlign(block);
1539
1540                         uiDefButS(block, ROW, B_CALCEFFECT, "Int",              875,9,32,43, &paf->texmap, 14.0, 0.0, 0, 0, "Use texture intensity as a factor for texture force");
1541
1542                         uiBlockBeginAlign(block);
1543                         uiDefButS(block, ROW, B_CALCEFFECT, "RGB",              911,31,45,20, &paf->texmap, 14.0, 1.0, 0, 0, "Use RGB values as a factor for particle speed");
1544                         uiDefButS(block, ROW, B_CALCEFFECT, "Grad",             958,31,44,20, &paf->texmap, 14.0, 2.0, 0, 0, "Use texture gradient as a factor for particle speed");
1545                         uiDefButF(block, NUM, B_CALCEFFECT, "Nabla:",           911,9,91,20, &paf->nabla, 0.0001, 1.0, 1, 0, "Specify the dimension of the area for gradient calculation");
1546
1547                 }
1548         }
1549 }
1550
1551 static void object_panel_anim(Object *ob)
1552 {
1553         uiBlock *block;
1554         char str[32];
1555         
1556         block= uiNewBlock(&curarea->uiblocks, "object_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
1557         if(uiNewPanel(curarea, block, "Anim settings", "Object", 0, 0, 318, 204)==0) return;
1558         
1559         uiBlockBeginAlign(block);
1560         uiDefButC(block, ROW,REDRAWVIEW3D,"TrackX",     27,190,58,19, &ob->trackflag, 12.0, 0.0, 0, 0, "Specify the axis that points to another object");
1561         uiDefButC(block, ROW,REDRAWVIEW3D,"Y",          85,190,19,19, &ob->trackflag, 12.0, 1.0, 0, 0, "Specify the axis that points to another object");
1562         uiDefButC(block, ROW,REDRAWVIEW3D,"Z",          104,190,19,19, &ob->trackflag, 12.0, 2.0, 0, 0, "Specify the axis that points to another object");
1563         uiDefButC(block, ROW,REDRAWVIEW3D,"-X",         124,190,24,19, &ob->trackflag, 12.0, 3.0, 0, 0, "Specify the axis that points to another object");
1564         uiDefButC(block, ROW,REDRAWVIEW3D,"-Y",         150,190,24,19, &ob->trackflag, 12.0, 4.0, 0, 0, "Specify the axis that points to another object");
1565         uiDefButC(block, ROW,REDRAWVIEW3D,"-Z",         177,190,24,19, &ob->trackflag, 12.0, 5.0, 0, 0, "Specify the axis that points to another object");
1566         uiBlockBeginAlign(block);
1567         uiDefButC(block, ROW,REDRAWVIEW3D,"UpX",        226,190,45,19, &ob->upflag, 13.0, 0.0, 0, 0, "Specify the axis that points up");
1568         uiDefButC(block, ROW,REDRAWVIEW3D,"Y",          274,190,20,19, &ob->upflag, 13.0, 1.0, 0, 0, "Specify the axis that points up");
1569         uiDefButC(block, ROW,REDRAWVIEW3D,"Z",          297,190,19,19, &ob->upflag, 13.0, 2.0, 0, 0, "Specify the axis that points up");
1570         uiBlockBeginAlign(block);
1571         uiDefButC(block, TOG|BIT|0, REDRAWVIEW3D, "Draw Key",           25,160,70,19, &ob->ipoflag, 0, 0, 0, 0, "Draw object as key position");
1572         uiDefButC(block, TOG|BIT|1, REDRAWVIEW3D, "Draw Key Sel",       97,160,81,19, &ob->ipoflag, 0, 0, 0, 0, "Limit the drawing of object keys");
1573         uiDefButC(block, TOG|BIT|7, REDRAWVIEW3D, "Powertrack",         180,160,78,19, &ob->transflag, 0, 0, 0, 0, "Switch objects rotation off");
1574         uiDefButS(block, TOG|BIT|4, 0, "SlowPar",                                       261,160,56,19, &ob->partype, 0, 0, 0, 0, "Create a delay in the parent relationship");
1575         uiBlockBeginAlign(block);
1576         uiDefButC(block, TOG|BIT|3, REDRAWVIEW3D, "DupliFrames",        24,128,88,19, &ob->transflag, 0, 0, 0, 0, "Make copy of object for every frame");
1577         uiDefButC(block, TOG|BIT|4, REDRAWVIEW3D, "DupliVerts",         114,128,82,19, &ob->transflag, 0, 0, 0, 0, "Duplicate child objects on all vertices");
1578         uiDefButC(block, TOG|BIT|5, REDRAWVIEW3D, "Rot",                200,128,31,19, &ob->transflag, 0, 0, 0, 0, "Rotate dupli according to facenormal");
1579         uiDefButC(block, TOG|BIT|6, REDRAWVIEW3D, "No Speed",   234,128,82,19, &ob->transflag, 0, 0, 0, 0, "Set dupliframes to still, regardless of frame");
1580         uiBlockBeginAlign(block);
1581         uiDefButS(block, NUM, REDRAWVIEW3D, "DupSta:",          24,105,141,19, &ob->dupsta, 1.0, 17999.0, 0, 0, "Specify startframe for Dupliframes");
1582         uiDefButS(block, NUM, REDRAWVIEW3D, "DupOn:",           169,105,146,19, &ob->dupon, 1.0, 1500.0, 0, 0, "");
1583         uiDefButS(block, NUM, REDRAWVIEW3D, "DupEnd",           24,82,140,19, &ob->dupend, 1.0, 18000.0, 0, 0, "Specify endframe for Dupliframes");
1584         uiDefButS(block, NUM, REDRAWVIEW3D, "DupOff",           169,82,145,19, &ob->dupoff, 0.0, 1500.0, 0, 0, "");
1585         uiBlockBeginAlign(block);
1586         uiDefButC(block, TOG|BIT|2, REDRAWALL, "Offs Ob",                       23,51,56,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on its own objectipo");
1587         uiDefButC(block, TOG|BIT|6, REDRAWALL, "Offs Par",                      82,51,56,20 , &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the parent");
1588         uiDefButC(block, TOG|BIT|7, REDRAWALL, "Offs Particle",         141,51,103,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the particle effect");
1589         
1590         uiBlockBeginAlign(block);
1591         uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 23,17,114,30, &ob->sf, -9000.0, 9000.0, 100, 0, "Specify an offset in frames");
1592         uiDefBut(block, BUT, B_AUTOTIMEOFS, "Automatic Time",   139,17,104,31, 0, 0, 0, 0, 0, "Generate automatic timeoffset values for all selected frames");
1593         uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      246,17,67,31, 0, 0, 0, 0, 0, "Print objectspeed");
1594         uiBlockEndAlign(block);
1595         
1596         sprintf(str, "%.4f", prspeed);
1597         uiDefBut(block, LABEL, 0, str,                                                  247,40,63,31, 0, 1.0, 0, 0, 0, "");
1598         
1599 }
1600
1601 void object_panels()
1602 {
1603         Object *ob;
1604
1605         /* check context here */
1606         ob= OBACT;
1607         if(ob) {
1608                 object_panel_anim(ob);
1609                 object_panel_draw(ob);
1610                 object_panel_constraint();
1611                 if(ob->type==OB_MESH) object_panel_effects(ob);
1612         }
1613 }
1614