0dcdc36fdcdda1eed2483a1a31dfc73f7494b6fe
[blender.git] / source / blender / src / buttons_logic.c
1 /**
2  * $Id$ 
3  *
4  * ***** BEGIN GPL 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.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <stdlib.h>
31 #include <math.h>
32 #include <string.h>
33
34 #ifndef WIN32
35 #include <unistd.h>
36 #else
37 #include <io.h>
38 #endif   
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_arithb.h"
44
45 #include "DNA_action_types.h"
46 #include "DNA_material_types.h"
47 #include "DNA_sensor_types.h"
48 #include "DNA_actuator_types.h"
49 #include "DNA_controller_types.h"
50 #include "DNA_property_types.h"
51 #include "DNA_object_types.h"
52 #include "DNA_object_force.h"
53 #include "DNA_screen_types.h"
54 #include "DNA_space_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_sound_types.h"
57 #include "DNA_text_types.h"
58 #include "DNA_userdef_types.h"
59 #include "DNA_view3d_types.h"
60 #include "DNA_mesh_types.h"
61 #include "DNA_world_types.h"
62
63 #include "BKE_library.h"
64 #include "BKE_global.h"
65 #include "BKE_main.h"
66 #include "BKE_sca.h"
67 #include "BKE_property.h"
68 #include "BKE_property.h"
69 #include "BKE_utildefines.h"
70 #include "BKE_bullet.h"
71
72 #include "BIF_gl.h"
73 #include "BIF_resources.h"
74 #include "BIF_space.h"
75 #include "BIF_interface.h"
76 #include "BIF_butspace.h"
77 #include "BIF_screen.h"
78 #include "BIF_keyval.h"
79 #include "BIF_editsound.h"
80
81 #include "BIF_editsca.h"
82
83
84 #include "BDR_editcurve.h"
85 #include "BDR_editobject.h"
86 #include "BSE_headerbuttons.h"
87 #include "BSE_filesel.h"
88
89 #include "blendef.h"
90 #include "mydevice.h"
91 #include "nla.h"        /* For __NLA : Important, do not remove */
92 #include "butspace.h" // own module
93 #include "interface.h"
94
95 /* internals */
96 static void buttons_enji(uiBlock *, Object *);
97 static void buttons_ketsji(uiBlock *, Object *);
98 static void buttons_bullet(uiBlock *, Object *);
99
100 /****/
101
102 static ID **get_selected_and_linked_obs(short *count, short scavisflag);
103 static char *actuator_pup(Object *owner);
104
105 /****/
106
107
108 static void del_property(void *selpropv, void *data2_unused)
109 {
110         bProperty *prop, *selprop= selpropv;
111         Object *ob;
112         int a=0;
113                 
114         ob= OBACT;
115         if(ob==NULL) return;
116
117         prop= ob->prop.first;
118         while(prop) {
119                 if(prop==selprop) {
120                         if (strcmp(prop->name,"Text") == 0) {
121                                 allqueue(REDRAWVIEW3D, 0);
122                         }
123                         BLI_remlink(&ob->prop, prop);
124                         free_property(prop);
125                         break;
126                 }
127                 a++;
128                 prop= prop->next;
129         }
130         BIF_undo_push("Delete property");
131         allqueue(REDRAWBUTSLOGIC, 0);
132         
133 }
134
135 static int vergname(const void *v1, const void *v2)
136 {
137         char **x1, **x2;
138         
139         x1= (char **)v1;
140         x2= (char **)v2;
141         
142         return strcmp(*x1, *x2);
143 }
144
145 void make_unique_prop_names(char *str)
146 {
147         Object *ob;
148         bProperty *prop;
149         bSensor *sens;
150         bController *cont;
151         bActuator *act;
152         ID **idar;
153         short a, obcount, propcount=0, nr;
154         char **names;
155         
156         /* this function is called by a Button, and gives the current
157          * stringpointer as an argument, this is the one that can change
158          */
159
160         idar= get_selected_and_linked_obs(&obcount, BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_CONT_SEL|BUTS_CONT_ACT);
161         
162         /* for each object, make properties and sca names unique */
163         
164         /* count total names */
165         for(a=0; a<obcount; a++) {
166                 ob= (Object *)idar[a];
167                 propcount+= BLI_countlist(&ob->prop);
168                 propcount+= BLI_countlist(&ob->sensors);
169                 propcount+= BLI_countlist(&ob->controllers);
170                 propcount+= BLI_countlist(&ob->actuators);
171         }       
172         if(propcount==0) {
173                 if(idar) MEM_freeN(idar);
174                 return;
175         }
176         
177         /* make names array for sorting */
178         names= MEM_callocN(propcount*sizeof(void *), "names");
179
180         /* count total names */
181         nr= 0;
182         for(a=0; a<obcount; a++) {
183                 ob= (Object *)idar[a];
184                 prop= ob->prop.first;
185                 while(prop) {
186                         names[nr++]= prop->name;
187                         prop= prop->next;
188                 }
189                 sens= ob->sensors.first;
190                 while(sens) {
191                         names[nr++]= sens->name;
192                         sens= sens->next;
193                 }
194                 cont= ob->controllers.first;
195                 while(cont) {
196                         names[nr++]= cont->name;
197                         cont= cont->next;
198                 }
199                 act= ob->actuators.first;
200                 while(act) {
201                         names[nr++]= act->name;
202                         act= act->next;
203                 }
204         }
205
206         qsort(names, propcount, sizeof(void *), vergname);
207         
208         /* now we check for double names, and change them */
209         
210         for(nr=0; nr<propcount; nr++) {
211                 if(names[nr]!=str && strcmp( names[nr], str )==0 ) {
212                         BLI_newname(str, +1);
213                 }
214         }
215         
216         MEM_freeN(idar);
217         MEM_freeN(names);
218 }
219
220 static void make_unique_prop_names_cb(void *strv, void *redraw_view3d_flagv)
221 {
222         char *str= strv;
223         int redraw_view3d_flag= GET_INT_FROM_POINTER(redraw_view3d_flagv);
224
225         make_unique_prop_names(str);
226         if (redraw_view3d_flag) allqueue(REDRAWVIEW3D, 0);
227 }
228
229 static void sca_move_sensor(void *datav, void *data2_unused)
230 {
231         bSensor *sens_to_delete= datav;
232         int val;
233         Base *base;
234         bSensor *sens, *tmp;
235         
236         val= pupmenu("Move up%x1|Move down %x2");
237         
238         if(val>0) {
239                 /* now find out which object has this ... */
240                 base= FIRSTBASE;
241                 while(base) {
242                 
243                         sens= base->object->sensors.first;
244                         while(sens) {
245                                 if(sens == sens_to_delete) break;
246                                 sens= sens->next;
247                         }
248                         
249                         if(sens) {
250                                 if( val==1 && sens->prev) {
251                                         for (tmp=sens->prev; tmp; tmp=tmp->prev) {
252                                                 if (tmp->flag & SENS_VISIBLE)
253                                                         break;
254                                         }
255                                         if (tmp) {
256                                                 BLI_remlink(&base->object->sensors, sens);
257                                                 BLI_insertlinkbefore(&base->object->sensors, tmp, sens);
258                                         }
259                                 }
260                                 else if( val==2 && sens->next) {
261                                         for (tmp=sens->next; tmp; tmp=tmp->next) {
262                                                 if (tmp->flag & SENS_VISIBLE)
263                                                         break;
264                                         }
265                                         if (tmp) {
266                                                 BLI_remlink(&base->object->sensors, sens);
267                                                 BLI_insertlink(&base->object->sensors, tmp, sens);
268                                         }
269                                 }
270                                 BIF_undo_push("Move sensor");
271                                 allqueue(REDRAWBUTSLOGIC, 0);
272                                 break;
273                         }
274                         
275                         base= base->next;
276                 }
277         }
278 }
279
280 static void sca_move_controller(void *datav, void *data2_unused)
281 {
282         bController *controller_to_del= datav;
283         int val;
284         Base *base;
285         bController *cont, *tmp;
286         
287         val= pupmenu("Move up%x1|Move down %x2");
288         
289         if(val>0) {
290                 /* now find out which object has this ... */
291                 base= FIRSTBASE;
292                 while(base) {
293                 
294                         cont= base->object->controllers.first;
295                         while(cont) {
296                                 if(cont == controller_to_del) break;
297                                 cont= cont->next;
298                         }
299                         
300                         if(cont) {
301                                 if( val==1 && cont->prev) {
302                                         /* locate the controller that has the same state mask but is earlier in the list */
303                                         tmp = cont->prev;
304                                         while(tmp) {
305                                                 if(tmp->state_mask & cont->state_mask) 
306                                                         break;
307                                                 tmp = tmp->prev;
308                                         }
309                                         if (tmp) {
310                                                 BLI_remlink(&base->object->controllers, cont);
311                                                 BLI_insertlinkbefore(&base->object->controllers, tmp, cont);
312                                         }
313                                 }
314                                 else if( val==2 && cont->next) {
315                                         tmp = cont->next;
316                                         while(tmp) {
317                                                 if(tmp->state_mask & cont->state_mask) 
318                                                         break;
319                                                 tmp = tmp->next;
320                                         }
321                                         BLI_remlink(&base->object->controllers, cont);
322                                         BLI_insertlink(&base->object->controllers, tmp, cont);
323                                 }
324                                 BIF_undo_push("Move controller");
325                                 allqueue(REDRAWBUTSLOGIC, 0);
326                                 break;
327                         }
328                         
329                         base= base->next;
330                 }
331         }
332 }
333
334 static void sca_move_actuator(void *datav, void *data2_unused)
335 {
336         bActuator *actuator_to_move= datav;
337         int val;
338         Base *base;
339         bActuator *act, *tmp;
340         
341         val= pupmenu("Move up%x1|Move down %x2");
342         
343         if(val>0) {
344                 /* now find out which object has this ... */
345                 base= FIRSTBASE;
346                 while(base) {
347                 
348                         act= base->object->actuators.first;
349                         while(act) {
350                                 if(act == actuator_to_move) break;
351                                 act= act->next;
352                         }
353                         
354                         if(act) {
355                                 if( val==1 && act->prev) {
356                                         /* locate the first visible actuators before this one */
357                                         for (tmp = act->prev; tmp; tmp=tmp->prev) {
358                                                 if (tmp->flag & ACT_VISIBLE)
359                                                         break;
360                                         }
361                                         if (tmp) {
362                                                 BLI_remlink(&base->object->actuators, act);
363                                                 BLI_insertlinkbefore(&base->object->actuators, tmp, act);
364                                         }
365                                 }
366                                 else if( val==2 && act->next) {
367                                         for (tmp=act->next; tmp; tmp=tmp->next) {
368                                                 if (tmp->flag & ACT_VISIBLE)
369                                                         break;
370                                         }
371                                         if (tmp) {
372                                                 BLI_remlink(&base->object->actuators, act);
373                                                 BLI_insertlink(&base->object->actuators, tmp, act);
374                                         }
375                                 }
376                                 BIF_undo_push("Move actuator");
377                                 allqueue(REDRAWBUTSLOGIC, 0);
378                                 break;
379                         }
380                         
381                         base= base->next;
382                 }
383         }
384 }
385
386 void do_logic_buts(unsigned short event)
387 {
388         bProperty *prop;
389         bSensor *sens;
390         bController *cont;
391         bActuator *act;
392         Object *ob;
393         int didit, bit;
394         
395         ob= OBACT;
396         if(ob==0) return;
397         
398         switch(event) {
399
400         case B_SETSECTOR:
401                 /* check for inconsistant types */
402                 ob->gameflag &= ~(OB_PROP|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
403                 ob->dtx |= OB_BOUNDBOX;
404                 allqueue(REDRAWBUTSGAME, 0);
405                 allqueue(REDRAWVIEW3D, 0);
406                 break;
407                 
408         case B_SETPROP:
409                 /* check for inconsistant types */
410                 ob->gameflag &= ~(OB_SECTOR|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
411                 allqueue(REDRAWBUTSGAME, 0);
412                 allqueue(REDRAWVIEW3D, 0);
413                 break;
414
415         case B_SETACTOR:
416         case B_SETDYNA:
417         case B_SETMAINACTOR:
418                 ob->gameflag &= ~(OB_SECTOR|OB_PROP);
419                 allqueue(REDRAWBUTSGAME, 0);
420                 allqueue(REDRAWVIEW3D, 0);
421                 break;
422
423
424         case B_ADD_PROP:
425                 prop= new_property(PROP_FLOAT);
426                 make_unique_prop_names(prop->name);
427                 BLI_addtail(&ob->prop, prop);
428                 BIF_undo_push("Add property");
429                 allqueue(REDRAWBUTSLOGIC, 0);
430                 break;
431         
432         case B_CHANGE_PROP:
433                 prop= ob->prop.first;
434                 while(prop) {
435                         if(prop->type!=prop->otype) {
436                                 init_property(prop);
437                                 if (strcmp(prop->name, "Text") == 0) {
438                                         allqueue(REDRAWVIEW3D, 0);
439                                 }
440                         }
441                         prop= prop->next;
442                 }
443                 allqueue(REDRAWBUTSLOGIC, 0);
444                 break;
445         
446         case B_ADD_SENS:
447                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
448                         if(ob->scaflag & OB_ADDSENS) {
449                                 ob->scaflag &= ~OB_ADDSENS;
450                                 sens= new_sensor(SENS_ALWAYS);
451                                 BLI_addtail(&(ob->sensors), sens);
452                                 make_unique_prop_names(sens->name);
453                                 ob->scaflag |= OB_SHOWSENS;
454                         }
455                 }
456                 
457                 BIF_undo_push("Add sensor");
458                 allqueue(REDRAWBUTSLOGIC, 0);
459                 break;
460
461         case B_CHANGE_SENS:
462                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
463                         sens= ob->sensors.first;
464                         while(sens) {
465                                 if(sens->type != sens->otype) {
466                                         init_sensor(sens);
467                                         sens->otype= sens->type;
468                                         break;
469                                 }
470                                 sens= sens->next;
471                         }
472                 }
473                 allqueue(REDRAWBUTSLOGIC, 0);
474                 break;
475         
476         case B_DEL_SENS:
477                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
478                         sens= ob->sensors.first;
479                         while(sens) {
480                                 if(sens->flag & SENS_DEL) {
481                                         BLI_remlink(&(ob->sensors), sens);
482                                         free_sensor(sens);
483                                         break;
484                                 }
485                                 sens= sens->next;
486                         }
487                 }
488                 BIF_undo_push("Delete sensor");
489                 allqueue(REDRAWBUTSLOGIC, 0);
490                 break;
491         
492         case B_ADD_CONT:
493                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
494                         if(ob->scaflag & OB_ADDCONT) {
495                                 ob->scaflag &= ~OB_ADDCONT;
496                                 cont= new_controller(CONT_LOGIC_AND);
497                                 make_unique_prop_names(cont->name);
498                                 ob->scaflag |= OB_SHOWCONT;
499                                 BLI_addtail(&(ob->controllers), cont);
500                                 /* set the controller state mask from the current object state.
501                                    A controller is always in a single state, so select the lowest bit set
502                                    from the object state */
503                                 for (bit=0; bit<32; bit++) {
504                                         if (ob->state & (1<<bit))
505                                                 break;
506                                 }
507                                 cont->state_mask = (1<<bit);
508                                 if (cont->state_mask == 0) {
509                                         /* shouldn't happen, object state is never 0 */
510                                         cont->state_mask = 1;
511                                 }
512                         }
513                 }
514                 BIF_undo_push("Add controller");
515                 allqueue(REDRAWBUTSLOGIC, 0);
516                 break;
517
518         case B_SET_STATE_BIT:
519                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
520                         if(ob->scaflag & OB_SETSTBIT) {
521                                 ob->scaflag &= ~OB_SETSTBIT;
522                                 ob->state = 0x3FFFFFFF;
523                         }
524                 }
525                 allqueue(REDRAWBUTSLOGIC, 0);
526                 break;
527
528         case B_INIT_STATE_BIT:
529                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
530                         if(ob->scaflag & OB_INITSTBIT) {
531                                 ob->scaflag &= ~OB_INITSTBIT;
532                                 ob->state = ob->init_state;
533                                 if (!ob->state)
534                                         ob->state = 1;
535                         }
536                 }
537                 allqueue(REDRAWBUTSLOGIC, 0);
538                 break;
539
540         case B_CHANGE_CONT:
541                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
542                         cont= ob->controllers.first;
543                         while(cont) {
544                                 if(cont->type != cont->otype) {
545                                         init_controller(cont);
546                                         cont->otype= cont->type;
547                                         break;
548                                 }
549                                 cont= cont->next;
550                         }
551                 }
552                 allqueue(REDRAWBUTSLOGIC, 0);
553                 break;
554         
555
556         case B_DEL_CONT:
557                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
558                         cont= ob->controllers.first;
559                         while(cont) {
560                                 if(cont->flag & CONT_DEL) {
561                                         BLI_remlink(&(ob->controllers), cont);
562                                         unlink_controller(cont);
563                                         free_controller(cont);
564                                         break;
565                                 }
566                                 cont= cont->next;
567                         }
568                 }
569                 BIF_undo_push("Delete controller");
570                 allqueue(REDRAWBUTSLOGIC, 0);
571                 break;
572
573         case B_ADD_ACT:
574                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
575                         if(ob->scaflag & OB_ADDACT) {
576                                 ob->scaflag &= ~OB_ADDACT;
577                                 act= new_actuator(ACT_OBJECT);
578                                 make_unique_prop_names(act->name);
579                                 BLI_addtail(&(ob->actuators), act);
580                                 ob->scaflag |= OB_SHOWACT;
581                         }
582                 }
583                 BIF_undo_push("Add actuator");
584                 allqueue(REDRAWBUTSLOGIC, 0);
585                 break;
586
587         case B_CHANGE_ACT:
588                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
589                         act= ob->actuators.first;
590                         while(act) {
591                                 if(act->type != act->otype) {
592                                         init_actuator(act);
593                                         act->otype= act->type;
594                                         break;
595                                 }
596                                 act= act->next;
597                         }
598                 }
599                 allqueue(REDRAWBUTSLOGIC, 0);
600                 break;
601
602         case B_DEL_ACT:
603                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
604                         act= ob->actuators.first;
605                         while(act) {
606                                 if(act->flag & ACT_DEL) {
607                                         BLI_remlink(&(ob->actuators), act);
608                                         unlink_actuator(act);
609                                         free_actuator(act);
610                                         break;
611                                 }
612                                 act= act->next;
613                         }
614                 }
615                 BIF_undo_push("Delete actuator");
616                 allqueue(REDRAWBUTSLOGIC, 0);
617                 break;
618         
619         case B_SOUNDACT_BROWSE:
620                 /* since we don't know which... */
621                 didit= 0;
622                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
623                         act= ob->actuators.first;
624                         while(act)
625                         {
626                                 if(act->type==ACT_SOUND)
627                                 {
628                                         bSoundActuator *sa= act->data;
629                                         if(sa->sndnr)
630                                         {
631                                                 bSound *sound= G.main->sound.first;
632                                                 int nr= 1;
633
634                                                 if(sa->sndnr == -2) {
635                                                         activate_databrowse((ID *)G.main->sound.first, ID_SO, 0, B_SOUNDACT_BROWSE,
636                                                                                         &sa->sndnr, do_logic_buts);
637                                                         break;
638                                                 }
639
640                                                 while(sound)
641                                                 {
642                                                         if(nr==sa->sndnr)
643                                                                 break;
644                                                         nr++;
645                                                         sound= sound->id.next;
646                                                 }
647                                                 
648                                                 if(sa->sound)
649                                                         sa->sound->id.us--;
650                                                 
651                                                 sa->sound= sound;
652                                                 
653                                                 if(sound)
654                                                         sound->id.us++;
655                                                 
656                                                 sa->sndnr= 0;
657                                                 didit= 1;
658                                         }
659                                 }
660                                 act= act->next;
661                         }
662                         if(didit)
663                                 break;
664                 }
665                 allqueue(REDRAWBUTSLOGIC, 0);
666                 allqueue(REDRAWSOUND, 0);
667
668                 break;
669         }
670 }
671
672
673 static char *sensor_name(int type)
674 {
675         switch (type) {
676         case SENS_ALWAYS:
677                 return "Always";
678         case SENS_TOUCH:
679                 return "Touch";
680         case SENS_NEAR:
681                 return "Near";
682         case SENS_KEYBOARD:
683                 return "Keyboard";
684         case SENS_PROPERTY:
685                 return "Property";
686         case SENS_ACTUATOR:
687                 return "Actuator";
688         case SENS_DELAY:
689                 return "Delay";
690         case SENS_MOUSE:
691                 return "Mouse";
692         case SENS_COLLISION:
693                 return "Collision";
694         case SENS_RADAR:
695                 return "Radar";
696         case SENS_RANDOM:
697                 return "Random";
698         case SENS_RAY:
699                 return "Ray";
700         case SENS_MESSAGE:
701                 return "Message";
702         case SENS_JOYSTICK:
703                 return "Joystick";
704         }
705         return "unknown";
706 }
707
708 static char *sensor_pup(void)
709 {
710         /* the number needs to match defines in game.h */
711         return "Sensors %t|Always %x0|Delay %x13|Keyboard %x3|Mouse %x5|"
712                 "Touch %x1|Collision %x6|Near %x2|Radar %x7|"
713                 "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11|Actuator %x12";
714 }
715
716 static char *controller_name(int type)
717 {
718         switch (type) {
719         case CONT_LOGIC_AND:
720                 return "AND";
721         case CONT_LOGIC_OR:
722                 return "OR";
723         case CONT_LOGIC_NAND:
724                 return "NAND";
725         case CONT_LOGIC_NOR:
726                 return "NOR";
727         case CONT_LOGIC_XOR:
728                 return "XOR";
729         case CONT_LOGIC_XNOR:
730                 return "XNOR";
731         case CONT_EXPRESSION:
732                 return "Expression";
733         case CONT_PYTHON:
734                 return "Python";
735         }
736         return "unknown";
737 }
738
739 static char *controller_pup(void)
740 {
741         return "Controllers   %t|AND %x0|OR %x1|XOR %x6|NAND %x4|NOR %x5|XNOR %x7|Expression %x2|Python %x3";
742 }
743
744 static char *actuator_name(int type)
745 {
746         switch (type) {
747         case ACT_SHAPEACTION:
748                 return "Shape Action";
749         case ACT_ACTION:
750                 return "Action";
751         case ACT_OBJECT:
752                 return "Motion";
753         case ACT_IPO:
754                 return "Ipo";
755         case ACT_LAMP:
756                 return "Lamp";
757         case ACT_CAMERA:
758                 return "Camera";
759         case ACT_MATERIAL:
760                 return "Material";
761         case ACT_SOUND:
762                 return "Sound";
763         case ACT_CD:
764                 return "CD";
765         case ACT_PROPERTY:
766                 return "Property";
767         case ACT_EDIT_OBJECT:
768                 return "Edit Object";
769         case ACT_CONSTRAINT:
770                 return "Constraint";
771         case ACT_SCENE:
772                 return "Scene";
773         case ACT_GROUP:
774                 return "Group";
775         case ACT_RANDOM:
776                 return "Random";
777         case ACT_MESSAGE:
778                 return "Message";
779         case ACT_GAME:
780                 return "Game";
781         case ACT_VISIBILITY:
782                 return "Visibility";
783         case ACT_2DFILTER:
784                 return "2D Filter";
785         case ACT_PARENT:
786                 return "Parent";
787         case ACT_STATE:
788                 return "State";
789         }
790         return "unknown";
791 }
792
793
794
795
796 static char *actuator_pup(Object *owner)
797 {
798         switch (owner->type)
799         {
800         case OB_ARMATURE:
801                 return "Actuators  %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
802                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
803                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
804                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
805                 break;
806
807         case OB_MESH:
808                 return "Actuators  %t|Shape Action %x21|Motion %x0|Constraint %x9|Ipo %x1"
809                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
810                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
811                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
812                 break;
813
814         default:
815                 return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
816                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
817                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
818                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
819         }
820 }
821
822
823
824 static void set_sca_ob(Object *ob)
825 {
826         bController *cont;
827         bActuator *act;
828
829         cont= ob->controllers.first;
830         while(cont) {
831                 cont->mynew= (bController *)ob;
832                 cont= cont->next;
833         }
834         act= ob->actuators.first;
835         while(act) {
836                 act->mynew= (bActuator *)ob;
837                 act= act->next;
838         }
839 }
840
841 static ID **get_selected_and_linked_obs(short *count, short scavisflag)
842 {
843         Base *base;
844         Object *ob, *obt;
845         ID **idar;
846         bSensor *sens;
847         bController *cont;
848         unsigned int lay;
849         int a, nr, doit;
850         
851         /* we need a sorted object list */
852         /* set scavisflags flags in Objects to indicate these should be evaluated */
853         /* also hide ob pointers in ->new entries of controllerss/actuators */
854         
855         *count= 0;
856         
857         if(G.scene==NULL) return NULL;
858         
859         ob= G.main->object.first;
860         while(ob) {
861                 ob->scavisflag= 0;
862                 set_sca_ob(ob);
863                 ob= ob->id.next;
864         }
865         
866         if(G.vd) lay= G.vd->lay;
867         else lay= G.scene->lay;
868         
869         base= FIRSTBASE;
870         while(base) {
871                 if(base->lay & lay) {
872                         if(base->flag & SELECT) {
873                                 if(scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
874                                 if(scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
875                                 if(scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
876                         }
877                 }
878                 base= base->next;
879         }
880
881         if(OBACT) {
882                 if(scavisflag & BUTS_SENS_ACT) OBACT->scavisflag |= OB_VIS_SENS;
883                 if(scavisflag & BUTS_CONT_ACT) OBACT->scavisflag |= OB_VIS_CONT;
884                 if(scavisflag & BUTS_ACT_ACT) OBACT->scavisflag |= OB_VIS_ACT;
885         }
886         
887         /* BUTS_XXX_STATE are similar to BUTS_XXX_LINK for selecting the object */
888         if(scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK|BUTS_SENS_STATE|BUTS_ACT_STATE)) {
889                 doit= 1;
890                 while(doit) {
891                         doit= 0;
892                         
893                         ob= G.main->object.first;
894                         while(ob) {
895                         
896                                 /* 1st case: select sensor when controller selected */
897                                 if((scavisflag & (BUTS_SENS_LINK|BUTS_SENS_STATE)) && (ob->scavisflag & OB_VIS_SENS)==0) {
898                                         sens= ob->sensors.first;
899                                         while(sens) {
900                                                 for(a=0; a<sens->totlinks; a++) {
901                                                         if(sens->links[a]) {
902                                                                 obt= (Object *)sens->links[a]->mynew;
903                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)) {
904                                                                         doit= 1;
905                                                                         ob->scavisflag |= OB_VIS_SENS;
906                                                                         break;
907                                                                 }
908                                                         }
909                                                 }
910                                                 if(doit) break;
911                                                 sens= sens->next;
912                                         }
913                                 }
914                                 
915                                 /* 2nd case: select cont when act selected */
916                                 if((scavisflag & BUTS_CONT_LINK)  && (ob->scavisflag & OB_VIS_CONT)==0) {
917                                         cont= ob->controllers.first;
918                                         while(cont) {
919                                                 for(a=0; a<cont->totlinks; a++) {
920                                                         if(cont->links[a]) {
921                                                                 obt= (Object *)cont->links[a]->mynew;
922                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)) {
923                                                                         doit= 1;
924                                                                         ob->scavisflag |= OB_VIS_CONT;
925                                                                         break;
926                                                                 }
927                                                         }
928                                                 }
929                                                 if(doit) break;
930                                                 cont= cont->next;
931                                         }
932                                 }
933                                 
934                                 /* 3rd case: select controller when sensor selected */
935                                 if((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
936                                         sens= ob->sensors.first;
937                                         while(sens) {
938                                                 for(a=0; a<sens->totlinks; a++) {
939                                                         if(sens->links[a]) {
940                                                                 obt= (Object *)sens->links[a]->mynew;
941                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)==0) {
942                                                                         doit= 1;
943                                                                         obt->scavisflag |= OB_VIS_CONT;
944                                                                 }
945                                                         }
946                                                 }
947                                                 sens= sens->next;
948                                         }
949                                 }
950                                 
951                                 /* 4th case: select actuator when controller selected */
952                                 if( (scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE))  && (ob->scavisflag & OB_VIS_CONT)) {
953                                         cont= ob->controllers.first;
954                                         while(cont) {
955                                                 for(a=0; a<cont->totlinks; a++) {
956                                                         if(cont->links[a]) {
957                                                                 obt= (Object *)cont->links[a]->mynew;
958                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)==0) {
959                                                                         doit= 1;
960                                                                         obt->scavisflag |= OB_VIS_ACT;
961                                                                 }
962                                                         }
963                                                 }
964                                                 cont= cont->next;
965                                         }
966                                         
967                                 }
968                                 ob= ob->id.next;
969                         }
970                 }
971         } 
972         
973         /* now we count */
974         ob= G.main->object.first;
975         while(ob) {
976                 if( ob->scavisflag ) (*count)++;
977                 ob= ob->id.next;
978         }
979
980         if(*count==0) return NULL;
981         if(*count>24) *count= 24;               /* temporal */
982         
983         idar= MEM_callocN( (*count)*sizeof(void *), "idar");
984         
985         ob= G.main->object.first;
986         nr= 0;
987         while(ob) {
988                 if( ob->scavisflag ) {
989                         idar[nr]= (ID *)ob;
990                         nr++;
991                 }
992                 if(nr>=24) break;
993                 ob= ob->id.next;
994         }
995         
996         /* just to be sure... these were set in set_sca_done_ob() */
997         clear_sca_new_poins();
998         
999         return idar;
1000 }
1001
1002
1003 static int get_col_sensor(int type)
1004 {
1005         switch(type) {
1006         case SENS_ALWAYS:               return TH_BUT_ACTION;
1007         case SENS_DELAY:                return TH_BUT_ACTION;
1008         case SENS_TOUCH:                return TH_BUT_NEUTRAL;
1009         case SENS_COLLISION:    return TH_BUT_SETTING;
1010         case SENS_NEAR:                 return TH_BUT_SETTING1; 
1011         case SENS_KEYBOARD:             return TH_BUT_SETTING2;
1012         case SENS_PROPERTY:             return TH_BUT_NUM;
1013         case SENS_ACTUATOR:             return TH_BUT_NUM;
1014         case SENS_MOUSE:                return TH_BUT_TEXTFIELD;
1015         case SENS_RADAR:                return TH_BUT_POPUP;
1016         case SENS_RANDOM:               return TH_BUT_NEUTRAL;
1017         case SENS_RAY:                  return TH_BUT_SETTING1;
1018         case SENS_MESSAGE:              return TH_BUT_SETTING2;
1019         case SENS_JOYSTICK:             return TH_BUT_NEUTRAL;
1020         default:                                return TH_BUT_NEUTRAL;
1021         }
1022 }
1023 static void set_col_sensor(int type, int medium)
1024 {
1025         int col= get_col_sensor(type);
1026         BIF_ThemeColorShade(col, medium?30:0);
1027 }
1028
1029 /**
1030  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
1031  * the value of this sensor. Operates on the shared data block of sensors.
1032  */
1033 static void draw_default_sensor_header(bSensor *sens,
1034                                                                 uiBlock *block,
1035                                                                 short x,
1036                                                                 short y,
1037                                                                 short w) 
1038 {
1039         /* Pulsing and frequency */
1040         uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP,
1041                          (short)(x + 10 + 0. * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1042                          &sens->pulse, 0.0, 0.0, 0, 0,
1043                          "Activate TRUE level triggering (pulse mode)");
1044
1045         uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN,
1046                          (short)(x + 10 + 0.15 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1047                          &sens->pulse, 0.0, 0.0, 0, 0,
1048                          "Activate FALSE level triggering (pulse mode)");
1049         uiDefButS(block, NUM, 1, "f:",
1050                          (short)(x + 10 + 0.3 * (w-20)), (short)(y - 21), (short)(0.275 * (w-20)), 19,
1051                          &sens->freq, 0.0, 10000.0, 0, 0,
1052                          "Delay between repeated pulses (in logic tics, 0 = no delay)");
1053         
1054         /* value or shift? */
1055         uiDefButS(block, TOG, 1, "Inv",
1056                          (short)(x + 10 + 0.85 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1057                          &sens->invert, 0.0, 0.0, 0, 0,
1058                          "Invert the level (output) of this sensor");
1059         uiDefButS(block, TOG, 1, "Level",
1060                          (short)(x + 10 + 0.65 * (w-20)), (short)(y - 21), (short)(0.20 * (w-20)), 19,
1061                          &sens->level, 0.0, 0.0, 0, 0,
1062                          "Level detector, trigger controllers of new states (only applicable upon logic state transition)");
1063 }
1064
1065 static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
1066 {
1067         bNearSensor      *ns           = NULL;
1068         bTouchSensor     *ts           = NULL;
1069         bKeyboardSensor  *ks           = NULL;
1070         bPropertySensor  *ps           = NULL;
1071         bMouseSensor     *ms           = NULL;
1072         bCollisionSensor *cs           = NULL;
1073         bRadarSensor     *rs           = NULL;
1074         bRandomSensor    *randomSensor = NULL;
1075         bRaySensor       *raySens      = NULL;
1076         bMessageSensor   *mes          = NULL;
1077         bJoystickSensor  *joy              = NULL;
1078         bActuatorSensor  *as           = NULL;
1079         bDelaySensor     *ds               = NULL;
1080         short ysize;
1081         char *str;
1082         
1083         /* yco is at the top of the rect, draw downwards */
1084         
1085         uiBlockSetEmboss(block, UI_EMBOSSM);
1086         
1087         set_col_sensor(sens->type, 0);
1088         
1089         switch (sens->type)
1090         {
1091         case SENS_ALWAYS:
1092                 {
1093                         ysize= 24;
1094                         
1095                         glRects(xco, yco-ysize, xco+width, yco);
1096                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1097                         
1098                         draw_default_sensor_header(sens, block, xco, yco, width);
1099                         
1100                         yco-= ysize;
1101                         
1102                         break;
1103                 }
1104         case SENS_TOUCH:
1105                 {
1106                         ysize= 48; 
1107                         
1108                         glRects(xco, yco-ysize, xco+width, yco); 
1109                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1110                         
1111                         draw_default_sensor_header(sens, block, xco, yco, width);
1112                         
1113                         ts= sens->data; 
1114                         
1115                         /* uiDefBut(block, TEX, 1, "Property:", xco,yco-22,width, 19, &ts->name, 0, 31, 0, 0, "Only look for Objects with this property"); */
1116                         uiDefIDPoinBut(block, test_matpoin_but, ID_MA, 1, "MA:",(short)(xco + 10),(short)(yco-44), (short)(width - 20), 19, &ts->ma,  "Only look for floors with this Material"); 
1117                         ///* uiDefButF(block, NUM, 1, "Margin:",        xco+width/2,yco-44,width/2, 19, &ts->dist, 0.0, 10.0, 100, 0, "Extra margin (distance) for larger sensitivity"); 
1118                         yco-= ysize; 
1119                         break; 
1120                 }
1121         case SENS_COLLISION:
1122                 {
1123                         ysize= 48;
1124                         
1125                         glRects(xco, yco-ysize, xco+width, yco);
1126                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1127                         
1128                         draw_default_sensor_header(sens, block, xco, yco, width);
1129                         cs= sens->data;
1130                         
1131                         /* The collision sensor will become a generic collision (i.e. it     */
1132                         /* absorb the old touch sensor).                                     */
1133
1134                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",(short)(xco + 10),(short)(yco - 44),
1135                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1136                                 "Toggle collision on material or property.");
1137                         
1138                         if (cs->mode & SENS_COLLISION_MATERIAL) {
1139                                 uiDefBut(block, TEX, 1, "Material:", (short)(xco + 10 + 0.20 * (width-20)),
1140                                         (short)(yco-44), (short)(0.8*(width-20)), 19, &cs->materialName, 0, 31, 0, 0,
1141                                         "Only look for Objects with this material");
1142                         } else {
1143                                 uiDefBut(block, TEX, 1, "Property:", (short)(xco + 10 + 0.20 * (width-20)), (short)(yco-44),
1144                                         (short)(0.8*(width-20)), 19, &cs->name, 0, 31, 0, 0,
1145                                         "Only look for Objects with this property");
1146                         }
1147         
1148                         /*              uiDefButS(block, NUM, 1, "Damp:",       xco+10+width-90,yco-24, 70, 19, &cs->damp, 0, 250, 0, 0, "For 'damp' time don't detect another collision"); */
1149                         
1150                         yco-= ysize;
1151                         break;
1152                 }
1153         case SENS_NEAR:
1154                 {
1155                         ysize= 72;
1156                         
1157                         glRects(xco, yco-ysize, xco+width, yco);
1158                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1159                         
1160                         draw_default_sensor_header(sens, block, xco, yco, width);
1161                         ns= sens->data;
1162                         
1163                         uiDefBut(block, TEX, 1, "Property:",(short)(10+xco),(short)(yco-44), (short)(width-20), 19,
1164                                 &ns->name, 0, 31, 0, 0, "Only look for Objects with this property");
1165                         uiDefButF(block, NUM, 1, "Dist",(short)(10+xco),(short)(yco-68),(short)((width-22)/2), 19,
1166                                 &ns->dist, 0.0, 1000.0, 1000, 0, "Trigger distance");
1167                         uiDefButF(block, NUM, 1, "Reset",(short)(10+xco+(width-22)/2), (short)(yco-68), (short)((width-22)/2), 19,
1168                                 &ns->resetdist, 0.0, 1000.0, 1000, 0, "Reset distance"); 
1169                         yco-= ysize;
1170                         break;
1171                 }
1172         case SENS_RADAR:
1173                 {
1174                         ysize= 72; 
1175                         
1176                         glRects(xco, yco-ysize, xco+width, yco);
1177                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1178                         
1179                         draw_default_sensor_header(sens, block, xco, yco, width);
1180                         
1181                         rs= sens->data;
1182                         
1183                         uiDefBut(block, TEX, 1, "Prop:",
1184                                          (short)(10+xco),(short)(yco-44), (short)(0.7 * (width-20)), 19,
1185                                          &rs->name, 0, 31, 0, 0,
1186                                          "Only look for Objects with this property");
1187
1188                         str = "Type %t|+X axis %x0|+Y axis %x1|+Z axis %x2|-X axis %x3|-Y axis %x4|-Z axis %x5"; 
1189                         uiDefButS(block, MENU, B_REDR, str,
1190                                 (short)(10+xco+0.7 * (width-20)), (short)(yco-44), (short)(0.3 * (width-22)), 19,
1191                                 &rs->axis, 2.0, 31, 0, 0,
1192                                 "Specify along which axis the radar cone is cast.");
1193                                 
1194                         uiDefButF(block, NUM, 1, "Ang:",
1195                                          (short)(10+xco), (short)(yco-68), (short)((width-20)/2), 19,
1196                                          &rs->angle, 0.0, 179.9, 10, 0,
1197                                          "Opening angle of the radar cone.");
1198                         uiDefButF(block, NUM, 1, "Dist:",
1199                                          (short)(xco+10 + (width-20)/2), (short)(yco-68), (short)((width-20)/2), 19,
1200                                          &rs->range, 0.01, 10000.0, 100, 0,
1201                                          "Depth of the radar cone");
1202                         yco-= ysize;
1203                         break;
1204                 }
1205         case SENS_KEYBOARD:
1206                 {
1207                         ks= sens->data;
1208                         
1209                         /* 5 lines: 120 height */
1210                         ysize= (ks->type&1) ? 96:120;
1211                         
1212                         glRects(xco, yco-ysize, xco+width, yco);
1213                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1214                         
1215                         /* header line */
1216                         draw_default_sensor_header(sens, block, xco, yco, width);
1217                         
1218                         /* part of line 1 */
1219                         uiBlockSetCol(block, TH_BUT_SETTING2);
1220                         uiDefBut(block, LABEL, 0, "Key",          xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
1221                         uiDefButBitS(block, TOG, 1, B_REDR, "All keys",   xco+40+(width/2), yco-44, (width/2)-50, 19,
1222                                 &ks->type, 0, 0, 0, 0, "");
1223                         
1224                         
1225                         if ((ks->type&1)==0) { /* is All Keys option off? */
1226                                 /* line 2: hotkey and allkeys toggle */
1227                                 uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
1228                                 
1229                                 /* line 3: two key modifyers (qual1, qual2) */
1230                                 uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
1231                                 uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
1232                                 uiDefKeyevtButS(block, B_DIFF, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
1233                         }
1234                         
1235                         /* line 4: toggle property for string logging mode */
1236                         uiDefBut(block, TEX, 1, "LogToggle: ",
1237                                 xco+10, yco-((ks->type&1) ? 68:92), (width-20), 19,
1238                                 ks->toggleName, 0, 31, 0, 0,
1239                                 "Property that indicates whether to log "
1240                                 "keystrokes as a string.");
1241                         
1242                         /* line 5: target property for string logging mode */
1243                         uiDefBut(block, TEX, 1, "Target: ",
1244                                 xco+10, yco-((ks->type&1) ? 92:116), (width-20), 19,
1245                                 ks->targetName, 0, 31, 0, 0,
1246                                 "Property that receives the keystrokes in case "
1247                                 "a string is logged.");
1248                         
1249                         yco-= ysize;
1250                         break;
1251                 }
1252         case SENS_PROPERTY:
1253                 {
1254                         ysize= 96;
1255                         
1256                         glRects(xco, yco-ysize, xco+width, yco);
1257                         uiEmboss((float)xco, (float)yco-ysize,
1258                                 (float)xco+width, (float)yco, 1);
1259                         
1260                         draw_default_sensor_header(sens, block, xco, yco, width);
1261                         ps= sens->data;
1262                         
1263                         str= "Type %t|Equal %x0|Not Equal %x1|Interval %x2|Changed %x3"; 
1264                         /* str= "Type %t|Equal %x0|Not Equal %x1"; */
1265                         uiDefButI(block, MENU, B_REDR, str,                     xco+30,yco-44,width-60, 19,
1266                                 &ps->type, 0, 31, 0, 0, "Type");
1267                         
1268                         if (ps->type != SENS_PROP_EXPRESSION)
1269                         {
1270                                 uiDefBut(block, TEX, 1, "Prop: ",                       xco+30,yco-68,width-60, 19,
1271                                         ps->name, 0, 31, 0, 0,  "Property name");
1272                         }
1273                         
1274                         if(ps->type == SENS_PROP_INTERVAL)
1275                         {
1276                                 uiDefBut(block, TEX, 1, "Min: ",                xco,yco-92,width/2, 19,
1277                                         ps->value, 0, 31, 0, 0, "check for min value");
1278                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1279                                         ps->maxvalue, 0, 31, 0, 0, "check for max value");
1280                         }
1281                         else if(ps->type == SENS_PROP_CHANGED);
1282                         else
1283                         {
1284                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-92,width-60, 19,
1285                                         ps->value, 0, 31, 0, 0, "check for value");
1286                         }
1287                         
1288                         yco-= ysize;
1289                         break;
1290                 }
1291         case SENS_ACTUATOR:
1292                 {
1293                         ysize= 48;
1294                         
1295                         glRects(xco, yco-ysize, xco+width, yco);
1296                         uiEmboss((float)xco, (float)yco-ysize,
1297                                 (float)xco+width, (float)yco, 1);
1298                         
1299                         draw_default_sensor_header(sens, block, xco, yco, width);
1300                         as= sens->data;
1301                         
1302                         uiDefBut(block, TEX, 1, "Act: ",                        xco+30,yco-44,width-60, 19,
1303                                         as->name, 0, 31, 0, 0,  "Actuator name, actuator active state modifications will be detected");
1304                         yco-= ysize;
1305                         break;
1306                 }
1307         case SENS_DELAY:
1308                 {
1309                         ysize= 48;
1310                         
1311                         glRects(xco, yco-ysize, xco+width, yco);
1312                         uiEmboss((float)xco, (float)yco-ysize,
1313                                 (float)xco+width, (float)yco, 1);
1314                         
1315                         draw_default_sensor_header(sens, block, xco, yco, width);
1316                         ds = sens->data;
1317                         
1318                         uiDefButS(block, NUM, 0, "Delay",(short)(10+xco),(short)(yco-44),(short)((width-22)*0.4+10), 19,
1319                                 &ds->delay, 0.0, 5000.0, 0, 0, "Delay in number of logic tics before the positive trigger (default 60 per second)");
1320                         uiDefButS(block, NUM, 0, "Dur",(short)(10+xco+(width-22)*0.4+10),(short)(yco-44),(short)((width-22)*0.4-10), 19,
1321                                 &ds->duration, 0.0, 5000.0, 0, 0, "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
1322                         uiDefButBitS(block, TOG, SENS_DELAY_REPEAT, 0, "REP",(short)(xco + 10 + (width-22)*0.8),(short)(yco - 44),
1323                                 (short)(0.20 * (width-22)), 19, &ds->flag, 0.0, 0.0, 0, 0,
1324                                 "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
1325                         yco-= ysize;
1326                         break;
1327                 }
1328         case SENS_MOUSE:
1329                 {
1330                         ms= sens->data;
1331                         /* Two lines: 48 pixels high. */
1332                         ysize = 48;
1333                         
1334                         glRects(xco, yco-ysize, xco+width, yco);
1335                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1336                         
1337                         /* line 1: header */
1338                         draw_default_sensor_header(sens, block, xco, yco, width);
1339                         
1340                         /* Line 2: type selection. The number are a bit mangled to get
1341                         * proper compatibility with older .blend files. */
1342                         str= "Type %t|Left button %x1|Middle button %x2|"
1343                                 "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16|Mouse over any%x32"; 
1344                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, width-20, 19,
1345                                 &ms->type, 0, 31, 0, 0,
1346                                 "Specify the type of event this mouse sensor should trigger on.");
1347                         
1348                         yco-= ysize;
1349                         break;
1350                 }
1351         case SENS_RANDOM:
1352                 {
1353                         ysize = 48;
1354                         
1355                         glRects(xco, yco-ysize, xco+width, yco);
1356                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1357                         
1358                         draw_default_sensor_header(sens, block, xco, yco, width);
1359                         randomSensor = sens->data;
1360                         /* some files were wrongly written, avoid crash now */
1361                         if (randomSensor)
1362                         {
1363                                 uiDefButI(block, NUM, 1, "Seed: ",              xco+10,yco-44,(width-20), 19,
1364                                         &randomSensor->seed, 0, 1000, 0, 0,
1365                                         "Initial seed of the generator. (Choose 0 for not random)");
1366                         }
1367                         yco-= ysize;
1368                         break;
1369                 }
1370         case SENS_RAY:
1371                 {
1372                         ysize = 72;
1373                         glRects(xco, yco-ysize, xco+width, yco);
1374                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1375                         
1376                         draw_default_sensor_header(sens, block, xco, yco, width);
1377                         raySens = sens->data;
1378                         
1379                         /* 1. property or material */
1380                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",
1381                                 xco + 10,yco - 44, 0.20 * (width-20), 19,
1382                                 &raySens->mode, 0.0, 0.0, 0, 0,
1383                                 "Toggle collision on material or property.");
1384                         
1385                         if (raySens->mode & SENS_COLLISION_MATERIAL)
1386                         {
1387                                 uiDefBut(block, TEX, 1, "Material:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1388                                         &raySens->matname, 0, 31, 0, 0,
1389                                         "Only look for Objects with this material");
1390                         }
1391                         else
1392                         {
1393                                 uiDefBut(block, TEX, 1, "Property:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1394                                         &raySens->propname, 0, 31, 0, 0,
1395                                         "Only look for Objects with this property");
1396                         }
1397
1398                         /* X-Ray option */
1399                         uiDefButBitS(block, TOG, SENS_RAY_XRAY, 1, "X",
1400                                 xco + 10,yco - 68, 0.10 * (width-20), 19,
1401                                 &raySens->mode, 0.0, 0.0, 0, 0,
1402                                 "Toggle X-Ray option (see through objects that don't have the property)");
1403                         /* 2. sensing range */
1404                         uiDefButF(block, NUM, 1, "Range", xco+10 + 0.10 * (width-20), yco-68, 0.5 * (width-20), 19,
1405                                 &raySens->range, 0.01, 10000.0, 100, 0,
1406                                 "Sense objects no farther than this distance");
1407                         
1408                         /* 3. axis choice */
1409                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1410                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1411                                 &raySens->axisflag, 2.0, 31, 0, 0,
1412                                 "Specify along which axis the ray is cast.");
1413                         
1414                         yco-= ysize;            
1415                         break;
1416                 }
1417         case SENS_MESSAGE:
1418                 {
1419                         mes = sens->data;
1420                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1421                         
1422                         glRects(xco, yco-ysize, xco+width, yco);
1423                         uiEmboss((float)xco, (float)yco-ysize,
1424                                 (float)xco+width, (float)yco, 1);
1425                         
1426                         /* line 1: header line */
1427                         draw_default_sensor_header(sens, block, xco, yco, width);
1428                         
1429                         /* line 2: Subject filter */
1430                         uiDefBut(block, TEX, 1, "Subject: ",
1431                                 (xco+10), (yco-44), (width-20), 19,
1432                                 mes->subject, 0, 31, 0, 0,
1433                                 "Optional subject filter: only accept messages with this subject"
1434                                 ", or empty for all");
1435                         
1436                         yco -= ysize;
1437                         break;
1438                 }
1439                 case SENS_JOYSTICK:
1440                 {
1441
1442                         ysize =  72;
1443                         
1444                         glRects(xco, yco-ysize, xco+width, yco);
1445                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1446                         
1447                         /* line 1: header */
1448                         draw_default_sensor_header(sens, block, xco, yco, width);
1449
1450                         joy= sens->data;
1451
1452                         uiDefButC(block, NUM, 1, "Index:", xco+10, yco-44, 0.33 * (width-20), 19,
1453                         &joy->joyindex, 0, SENS_JOY_MAXINDEX-1, 100, 0,
1454                         "Specify which joystick to use");                       
1455
1456                         str= "Type %t|Button %x0|Axis %x1|Hat%x2"; 
1457                         uiDefButC(block, MENU, B_REDR, str, xco+87, yco-44, 0.26 * (width-20), 19,
1458                                 &joy->type, 0, 31, 0, 0,
1459                                 "The type of event this joystick sensor is triggered on.");
1460                         
1461                         if (joy->flag & SENS_JOY_ANY_EVENT) {
1462                                 switch (joy->type) {
1463                                 case SENS_JOY_AXIS:     
1464                                         str = "All Axis Events";
1465                                         break;
1466                                 case SENS_JOY_BUTTON:   
1467                                         str = "All Button Events";
1468                                         break;
1469                                 default:
1470                                         str = "All Hat Events";
1471                                         break;
1472                                 }
1473                         } else {
1474                                 str = "All";
1475                         }
1476                         
1477                         uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR, str,
1478                                 xco+10 + 0.475 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.525 : 0.12) * (width-20), 19,
1479                                 &joy->flag, 0, 0, 0, 0,
1480                                 "Triggered by all events on this joysticks current type (axis/button/hat)");
1481                         
1482                         if(joy->type == SENS_JOY_BUTTON)
1483                         {
1484                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1485                                         uiDefButI(block, NUM, 1, "Number:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1486                                         &joy->button, 0, 18, 100, 0,
1487                                         "Specify which button to use");
1488                                 }
1489                         }
1490                         else if(joy->type == SENS_JOY_AXIS)
1491                         {
1492                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1493                                 &joy->axis, 1, 2.0, 100, 0,
1494                                 "Specify which axis pair to use, 1 is useually the main direction input.");
1495
1496                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1497                                 &joy->precision, 0, 32768.0, 100, 0,
1498                                 "Specify the precision of the axis");
1499
1500                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1501                                         str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1502                                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1503                                         &joy->axisf, 2.0, 31, 0, 0,
1504                                         "The direction of the axis, use 'All Events' to recieve events on any direction");
1505                                 }
1506                         }
1507                         else
1508                         {
1509                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1510                                 &joy->hat, 1, 2.0, 100, 0,
1511                                 "Specify which hat to use");
1512                                 
1513                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1514                                         uiDefButI(block, NUM, 1, "Direction:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1515                                         &joy->hatf, 0, 12, 100, 0,
1516                                         "Specify hat direction");
1517                                 }
1518                         }
1519                         yco-= ysize;
1520                         break;
1521                 }
1522         }
1523         
1524         uiBlockSetEmboss(block, UI_EMBOSSM);
1525         uiBlockSetCol(block, TH_AUTO);
1526         
1527         return yco-4;
1528 }
1529
1530
1531
1532 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1533 {
1534         bExpressionCont *ec;
1535         bPythonCont *pc;
1536         short ysize;
1537         
1538         uiBlockSetEmboss(block, UI_EMBOSSM);
1539         
1540         switch (cont->type) {
1541         case CONT_EXPRESSION:
1542                 ysize= 28;
1543
1544                 BIF_ThemeColor(TH_BUT_SETTING);
1545                 glRects(xco, yco-ysize, xco+width, yco);
1546                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1547                 
1548                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1549                 ec= cont->data; 
1550                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1551                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1552                                  ec->str, 0, 127, 0, 0,
1553                                  "Expression"); 
1554                 
1555                 yco-= ysize;
1556                 break;
1557         case CONT_PYTHON:
1558                 ysize= 28;
1559                 
1560                 if(cont->data==NULL) init_controller(cont);
1561                 pc= cont->data;
1562                 
1563                 BIF_ThemeColor(TH_BUT_SETTING1);
1564                 glRects(xco, yco-ysize, xco+width, yco);
1565                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1566
1567                 uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Script: ", xco+45,yco-24,width-90, 19, &pc->text, "");
1568                 
1569                 yco-= ysize;
1570                 break;
1571                 
1572         default:
1573                 ysize= 4;
1574
1575                 BIF_ThemeColor(TH_BUT_NEUTRAL);
1576                 glRects(xco, yco-ysize, xco+width, yco);
1577                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1578                 
1579                 yco-= ysize;
1580         }
1581         
1582         uiBlockSetEmboss(block, UI_EMBOSSM);
1583         uiBlockSetCol(block, TH_AUTO);
1584
1585         return yco;
1586 }
1587
1588 static int get_col_actuator(int type)
1589 {
1590         switch(type) {
1591         case ACT_ACTION:                return TH_BUT_ACTION;
1592         case ACT_SHAPEACTION:   return TH_BUT_ACTION;
1593         case ACT_OBJECT:                return TH_BUT_NEUTRAL;
1594         case ACT_IPO:                   return TH_BUT_SETTING;
1595         case ACT_PROPERTY:              return TH_BUT_SETTING1;
1596         case ACT_SOUND:                 return TH_BUT_SETTING2;
1597         case ACT_CD:                    return TH_BUT_NUM;
1598         case ACT_CAMERA:                return TH_BUT_TEXTFIELD;
1599         case ACT_EDIT_OBJECT:           return TH_BUT_POPUP;
1600         case ACT_GROUP:                 return TH_BUT_ACTION;
1601         case ACT_RANDOM:                return TH_BUT_NEUTRAL;
1602         case ACT_SCENE:                 return TH_BUT_SETTING;
1603         case ACT_MESSAGE:               return TH_BUT_SETTING1;
1604         case ACT_GAME:                  return TH_BUT_SETTING2;
1605         case ACT_VISIBILITY:            return TH_BUT_NUM;
1606         case ACT_CONSTRAINT:            return TH_BUT_ACTION;
1607         case ACT_STATE:                 return TH_BUT_SETTING2;
1608         default:                                return TH_BUT_NEUTRAL;
1609         }
1610 }
1611 static void set_col_actuator(int item, int medium) 
1612 {
1613         int col= get_col_actuator(item);
1614         BIF_ThemeColorShade(col, medium?30:10);
1615         
1616 }
1617
1618 static void change_object_actuator(void *act, void *arg)
1619 {
1620         bObjectActuator *oa = act;
1621
1622         if (oa->type != oa->otype) {
1623                 switch (oa->type) {
1624                 case ACT_OBJECT_NORMAL:
1625                         memset(oa, 0, sizeof(bObjectActuator));
1626                         oa->flag = ACT_FORCE_LOCAL|ACT_TORQUE_LOCAL|ACT_DLOC_LOCAL|ACT_DROT_LOCAL;
1627                         oa->type = ACT_OBJECT_NORMAL;
1628                         break;
1629
1630                 case ACT_OBJECT_SERVO:
1631                         memset(oa, 0, sizeof(bObjectActuator));
1632                         oa->flag = ACT_LIN_VEL_LOCAL;
1633                         oa->type = ACT_OBJECT_SERVO;
1634                         oa->forcerot[0] = 30.0f;
1635                         oa->forcerot[1] = 0.5f;
1636                         oa->forcerot[2] = 0.0f;
1637                         break;
1638                 }
1639         }
1640 }
1641
1642 static void change_ipo_actuator(void *arg1_but, void *arg2_ia)
1643 {
1644         bIpoActuator *ia = arg2_ia;
1645         uiBut *but = arg1_but;
1646
1647         if (but->retval & ACT_IPOFORCE)
1648                 ia->flag &= ~ACT_IPOADD;
1649         else if (but->retval & ACT_IPOADD)
1650                 ia->flag &= ~ACT_IPOFORCE;
1651         but->retval = B_REDR;
1652 }
1653
1654 void update_object_actuator_PID(void *act, void *arg)
1655 {
1656         bObjectActuator *oa = act;
1657         oa->forcerot[0] = 60.0f*oa->forcerot[1];
1658 }
1659
1660 char *get_state_name(Object *ob, short bit)
1661 {
1662         bController *cont;
1663         unsigned int mask;
1664
1665         mask = (1<<bit);
1666         cont = ob->controllers.first;
1667         while (cont) {
1668                 if (cont->state_mask & mask) {
1669                         return cont->name;
1670                 }
1671                 cont = cont->next;
1672         }
1673         return (char*)"";
1674 }
1675
1676 static void check_state_mask(void *arg1_but, void *arg2_mask)
1677 {
1678         unsigned int *cont_mask = arg2_mask;
1679         uiBut *but = arg1_but;
1680
1681         if (*cont_mask == 0 || !(G.qual & LR_SHIFTKEY))
1682                 *cont_mask = (1<<but->retval);
1683         but->retval = B_REDR;
1684 }
1685
1686 static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
1687 {
1688         bSoundActuator      *sa      = NULL;
1689         bCDActuator                     *cda     = NULL;
1690         bObjectActuator     *oa      = NULL;
1691         bIpoActuator        *ia      = NULL;
1692         bPropertyActuator   *pa      = NULL;
1693         bCameraActuator     *ca      = NULL;
1694         bEditObjectActuator *eoa     = NULL;
1695         bConstraintActuator *coa     = NULL;
1696         bSceneActuator      *sca     = NULL;
1697         bGroupActuator      *ga      = NULL;
1698         bRandomActuator     *randAct = NULL;
1699         bMessageActuator    *ma      = NULL;
1700         bActionActuator     *aa      = NULL;
1701         bGameActuator       *gma     = NULL;
1702         bVisibilityActuator *visAct  = NULL;
1703         bTwoDFilterActuator     *tdfa    = NULL;
1704         bParentActuator     *parAct  = NULL;
1705         bStateActuator          *staAct  = NULL;
1706         
1707         float *fp;
1708         short ysize = 0, wval;
1709         char *str;
1710         int myline, stbit;
1711         uiBut *but;
1712
1713
1714         /* yco is at the top of the rect, draw downwards */
1715         uiBlockSetEmboss(block, UI_EMBOSSM);
1716         set_col_actuator(act->type, 0);
1717         
1718         switch (act->type)
1719         {
1720         case ACT_OBJECT:
1721                 {
1722                         oa = act->data;
1723                         wval = (width-100)/3;
1724                         if (oa->type == ACT_OBJECT_NORMAL)
1725                         {
1726                                 if ( ob->gameflag & OB_DYNAMIC )
1727                                 {
1728                                         ysize= 175;
1729                                 }
1730                                 else
1731                                 {
1732                                         ysize= 72;
1733                                 }
1734
1735                                 glRects(xco, yco-ysize, xco+width, yco);
1736                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1737                                 
1738                                 uiDefBut(block, LABEL, 0, "Loc",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the location");
1739                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1740                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1741                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1742                                 
1743                                 uiDefBut(block, LABEL, 0, "Rot",        xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the rotation");
1744                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1745                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1746                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1747
1748                                 uiDefButBitS(block, TOG, ACT_DLOC_LOCAL, 0, "L",                xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1749                                 uiDefButBitS(block, TOG, ACT_DROT_LOCAL, 0, "L",                xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1750         
1751                                 if ( ob->gameflag & OB_DYNAMIC )
1752                                 {
1753                                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-87, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1754                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1755                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1756                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1757                                 
1758                                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-106, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1759                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1760                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1761                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");                                
1762                                 }
1763                                 
1764                                 if ( ob->gameflag & OB_DYNAMIC )
1765                                 {
1766                                         uiDefBut(block, LABEL, 0, "LinV",       xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1767                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1768                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1769                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1770                                 
1771                                         uiDefBut(block, LABEL, 0, "AngV",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1772                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1773                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1774                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1775                                 
1776                                         uiDefBut(block, LABEL, 0, "Damp",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity");
1777                                         uiDefButS(block, NUM, 0, "",            xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, "");
1778
1779                                         uiDefButBitS(block, TOG, ACT_FORCE_LOCAL, 0, "L",               xco+45+3*wval, yco-87, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1780                                         uiDefButBitS(block, TOG, ACT_TORQUE_LOCAL, 0, "L",              xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1781                                         uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-129, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1782                                         uiDefButBitS(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-148, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1783                                 
1784                                         uiDefButBitS(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-129, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV");
1785                                 }                               
1786                         } else if (oa->type == ACT_OBJECT_SERVO)
1787                         {
1788                                 ysize= 172;
1789                                 
1790                                 glRects(xco, yco-ysize, xco+width, yco);
1791                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1792                                 
1793                                 uiDefBut(block, LABEL, 0, "linV",       xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the target linear velocity, it will be achieve by automatic application of force. Null velocity is a valid target");
1794                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1795                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1796                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1797                                 uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Velocity is defined in local coordinates");
1798
1799                                 uiDefBut(block, LABEL, 0, "Limit",      xco, yco-68, 45, 19, NULL, 0, 0, 0, 0, "Select if the force need to be limited along certain axis (local or global depending on LinV Local flag)");
1800                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_X, B_REDR, "X",                xco+45, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the X axis");
1801                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Y, B_REDR, "Y",                xco+45+wval, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Y axis");
1802                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Z, B_REDR, "Z",                xco+45+2*wval, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Z axis");
1803                                 uiDefBut(block, LABEL, 0, "Max",        xco, yco-87, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
1804                                 uiDefBut(block, LABEL, 0, "Min",        xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
1805                                 if (oa->flag & ACT_SERVO_LIMIT_X) {
1806                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1807                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1808                                 }
1809                                 if (oa->flag & ACT_SERVO_LIMIT_Y) {
1810                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1811                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1812                                 }
1813                                 if (oa->flag & ACT_SERVO_LIMIT_Z) {
1814                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1815                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1816                                 }
1817                                 uiDefBut(block, LABEL, 0, "Servo",      xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
1818                                 uiDefButF(block, NUMSLI, B_REDR, "P: ",         xco+45, yco-129, wval*3, 19, oa->forcerot, 0.00, 200.0, 100, 0, "Proportional coefficient, typical value is 60x Integral coefficient");
1819                                 uiDefBut(block, LABEL, 0, "Slow",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
1820                                 but = uiDefButF(block, NUMSLI, B_REDR, " I : ",         xco+45, yco-148, wval*3, 19, oa->forcerot+1, 0.0, 3.0, 1, 0, "Integral coefficient, low value (0.01) for slow response, high value (0.5) for fast response");
1821                                 uiButSetFunc(but, update_object_actuator_PID, oa, NULL);
1822                                 uiDefBut(block, LABEL, 0, "Fast",       xco+45+3*wval, yco-148, 45, 19, NULL, 0, 0, 0, 0, "High value of I coefficient correspond to fast response");
1823                                 uiDefButF(block, NUMSLI, B_REDR, "D: ",         xco+45, yco-167, wval*3, 19, oa->forcerot+2, -100.0, 100.0, 100, 0, "Derivate coefficient, not required, high values can cause instability");
1824                         }
1825                         str= "Motion Type %t|Simple motion %x0|Servo Control %x1";
1826                         but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &oa->type, 0.0, 0.0, 0, 0, "");
1827                         oa->otype = oa->type;
1828                         uiButSetFunc(but, change_object_actuator, oa, NULL);
1829                         yco-= ysize;
1830                         break;
1831                 }
1832         case ACT_ACTION:
1833         case ACT_SHAPEACTION:
1834                 {
1835                         /* DrawAct */
1836 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1837                         ysize = 112;
1838 #else
1839                         ysize= 92;
1840 #endif
1841                         
1842                         glRects(xco, yco-ysize, xco+width, yco);
1843                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1844                         
1845                         aa = act->data;
1846                         wval = (width-60)/3;
1847                         
1848                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1849 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1850                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
1851 #else
1852                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1853 #endif
1854                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-24, width/3, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
1855                         uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+10+ (width/3), yco-24, ((width/3)*2) - (20 + 60), 19, &aa->act, "Action name");
1856                         
1857                         uiDefButBitS(block, TOGN, 1, 0, "Continue", xco+((width/3)*2)+20, yco-24, 60, 19,
1858                                          &aa->end_reset, 0.0, 0.0, 0, 0, "Restore last frame when switching on/off, otherwise play from the start each time");
1859                         
1860                         
1861                         if(aa->type == ACT_ACTION_FROM_PROP)
1862                         {
1863                                 uiDefBut(block, TEX, 0, "Prop: ",xco+10, yco-44, width-20, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
1864                         }
1865                         else
1866                         {
1867                                 uiDefButI(block, NUM, 0, "Sta: ",xco+10, yco-44, (width-20)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
1868                                 uiDefButI(block, NUM, 0, "End: ",xco+10+(width-20)/2, yco-44, (width-20)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
1869                         }
1870                                                 
1871                         uiDefButS(block, NUM, 0, "Blendin: ", xco+10, yco-64, (width-20)/2, 19, &aa->blendin, 0.0, 32767, 0.0, 0.0, "Number of frames of motion blending");
1872                         uiDefButS(block, NUM, 0, "Priority: ", xco+10+(width-20)/2, yco-64, (width-20)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers, With 2 or more actions at once, the overriding channels must be lower in the stack");
1873                         
1874                         uiDefBut(block, TEX, 0, "FrameProp: ",xco+10, yco-84, width-20, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign this property this actions current frame number");                  
1875
1876                         
1877 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1878                         if(aa->type == ACT_ACTION_MOTION)
1879                         {
1880                                 uiDefButF(block, NUM, 0, "Cycle: ",xco+30, yco-84, (width-60)/2, 19, &aa->stridelength, 0.0, 2500.0, 0, 0, "Distance covered by a single cycle of the action");
1881                         }
1882 #endif
1883                         
1884                         
1885                         
1886                         yco-=ysize;
1887                         break;
1888                 }
1889         case ACT_IPO:
1890                 {
1891                         ia= act->data;
1892                         
1893                         ysize= 72;
1894                         
1895                         glRects(xco, yco-ysize, xco+width, yco);
1896                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1897                         
1898                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1899                         
1900                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-24, (width-20)/2, 19, &ia->type, 0, 0, 0, 0, "");
1901
1902                         but = uiDefButBitS(block, TOG, ACT_IPOFORCE, ACT_IPOFORCE, 
1903                                 "Force", xco+10+(width-20)/2, yco-24, (width-20)/4-10, 19, 
1904                                 &ia->flag, 0, 0, 0, 0, 
1905                                 "Apply Ipo as a global or local force depending on the local option (dynamic objects only)"); 
1906                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1907
1908                         but = uiDefButBitS(block, TOG, ACT_IPOADD, ACT_IPOADD, 
1909                                 "Add", xco+3*(width-20)/4, yco-24, (width-20)/4-10, 19, 
1910                                 &ia->flag, 0, 0, 0, 0, 
1911                                 "Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag"); 
1912                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1913                         
1914                         /* Only show the do-force-local toggle if force is requested */
1915                         if (ia->flag & (ACT_IPOFORCE|ACT_IPOADD)) {
1916                                 uiDefButBitS(block, TOG, ACT_IPOLOCAL, 0, 
1917                                         "L", xco+width-30, yco-24, 20, 19, 
1918                                         &ia->flag, 0, 0, 0, 0, 
1919                                         "Let the ipo acts in local coordinates, used in Force and Add mode."); 
1920                         }
1921
1922                         if(ia->type==ACT_IPO_FROM_PROP) {
1923                                 uiDefBut(block, TEX, 0, 
1924                                         "Prop: ",               xco+10, yco-44, width-80, 19, 
1925                                         ia->name, 0.0, 31.0, 0, 0, 
1926                                         "Use this property to define the Ipo position");
1927                         }
1928                         else {
1929                                 uiDefButI(block, NUM, 0, 
1930                                         "Sta",          xco+10, yco-44, (width-80)/2, 19, 
1931                                         &ia->sta, 1.0, MAXFRAMEF, 0, 0, 
1932                                         "Start frame");
1933                                 uiDefButI(block, NUM, 0, 
1934                                         "End",          xco+10+(width-80)/2, yco-44, (width-80)/2, 19, 
1935                                         &ia->end, 1.0, MAXFRAMEF, 0, 0, 
1936                                         "End frame");
1937                         }
1938                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
1939                                 "Child",        xco+10+(width-80), yco-44, 60, 19, 
1940                                 &ia->flag, 0, 0, 0, 0, 
1941                                 "Update IPO on all children Objects as well");
1942                         uiDefBut(block, TEX, 0, 
1943                                 "FrameProp: ",          xco+10, yco-64, width-20, 19, 
1944                                 ia->frameProp, 0.0, 31.0, 0, 0, 
1945                                 "Assign this property this action current frame number");
1946
1947                         yco-= ysize;
1948                         break;
1949                 }
1950         case ACT_PROPERTY:
1951                 {
1952                         ysize= 68;
1953                         
1954                         glRects(xco, yco-ysize, xco+width, yco);
1955                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1956                         
1957                         pa= act->data;
1958                         
1959                         str= "Type   %t|Assign   %x0|Add %x1|Copy %x2";
1960                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
1961                         
1962                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
1963                         
1964                         if(pa->type==ACT_PROP_COPY) {
1965                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
1966                                 uiDefBut(block, TEX, 1, "Prop: ",               xco+10+(width-20)/2, yco-64, (width-20)/2, 19, pa->value, 0, 31, 0, 0, "Copy this property");
1967                         }
1968                         else {
1969                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-64,width-60, 19, pa->value, 0, 31, 0, 0, "change with this value, use \"\" around strings");
1970                         }
1971                         yco-= ysize;
1972                         
1973                         break;
1974                 }
1975     case ACT_SOUND:
1976                 {
1977                         ysize = 70;
1978                         
1979                         sa = act->data;
1980                         sa->sndnr = 0;
1981                         
1982                         wval = (width-20)/2;
1983                         glRects(xco, yco-ysize, xco+width, yco);
1984                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1985                         
1986                         if(G.main->sound.first) {
1987                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(G.main->sound), (ID *)sa->sound, &(sa->sndnr));
1988                                 /* reset this value, it is for handling the event */
1989                                 sa->sndnr = 0;
1990                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
1991
1992                                 if(sa->sound) {
1993                                         char dummy_str[] = "Sound mode %t|Play Stop %x0|Play End %x1|Loop Stop %x2|Loop End %x3|Loop Ping Pong Stop %x5|Loop Ping Pong %x4";
1994                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
1995                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
1996                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->sound->volume, 0.0,  1.0, 0, 0, "Sets the volume of this sound");
1997                                         uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->sound->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound");
1998                                 }
1999                                 MEM_freeN(str);
2000                         } 
2001                         else {
2002                                 uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
2003                         }
2004                                         
2005                         yco-= ysize;
2006                         
2007                         break;
2008                 }
2009         case ACT_CD:
2010                 {
2011                         char cd_type_str[] = "Sound mode %t|Play all tracks %x0|Play one track %x1|"
2012                                 "Volume %x3|Stop %x4|Pause %x5|Resume %x6";
2013                         cda = act->data;
2014
2015                         if (cda) {
2016                                 if (cda->track == 0) {
2017                                         cda->track = 1;
2018                                         cda->volume = 1;
2019                                         cda->type = ACT_CD_PLAY_ALL;
2020                                 }
2021                                 
2022                                 if (cda->type == ACT_CD_PLAY_TRACK || cda->type == ACT_CD_LOOP_TRACK) {
2023                                         ysize = 48;
2024                                         glRects(xco, yco-ysize, xco+width, yco);
2025                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2026                                         uiDefButS(block, NUM, 0, "Track:", xco+10,yco-44,width-20, 19, &cda->track, 1, 99, 0, 0, "Select the track to be played");
2027                                 }
2028                                 else if (cda->type == ACT_CD_VOLUME) {
2029                                         ysize = 48;
2030                                         glRects(xco, yco-ysize, xco+width, yco);
2031                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2032                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-44,width-20, 19, &cda->volume, 0, 1, 0, 0, "Set the volume for CD playback");
2033                                 }
2034                                 else {
2035                                         ysize = 28;
2036                                         glRects(xco, yco-ysize, xco+width, yco);
2037                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2038                                 }
2039                                 uiDefButS(block, MENU, B_REDR, cd_type_str,xco+10,yco-22,width-20, 19, &cda->type, 0.0, 0.0, 0, 0, "");
2040                         }
2041                         yco-= ysize;
2042                         break;
2043                 }
2044         case ACT_CAMERA:
2045
2046                 ysize= 48;
2047         
2048                 glRects(xco, yco-ysize, xco+width, yco);
2049                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2050                 
2051                 ca= act->data;
2052         
2053                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
2054                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
2055                 
2056                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
2057                 
2058                 if(ca->axis==0) ca->axis= 'x';
2059                 uiDefButS(block, ROW, 0, "X",   xco+10+(width-60)/2, yco-44, 20, 19, &ca->axis, 4.0, (float)'x', 0, 0, "Camera tries to get behind the X axis");
2060                 uiDefButS(block, ROW, 0, "Y",   xco+30+(width-60)/2, yco-44, 20, 19, &ca->axis, 4.0, (float)'y', 0, 0, "Camera tries to get behind the Y axis");
2061                 
2062                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
2063
2064                 yco-= ysize;
2065         
2066          break;
2067                                 
2068         case ACT_EDIT_OBJECT:
2069                 
2070                 eoa= act->data;
2071
2072                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
2073                         int wval; /* just a temp width */
2074                         ysize = 92;
2075                         glRects(xco, yco-ysize, xco+width, yco);
2076                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2077          
2078                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Add this Object and all its children (cant be on an visible layer)");
2079                         uiDefButI(block, NUM, 0, "Time:",       xco+10+(width-20)/2, yco-44, (width-20)/2, 19, &eoa->time, 0.0, 2000.0, 0, 0, "Duration the new Object lives");
2080
2081                         wval= (width-60)/3;
2082                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
2083                                          NULL, 0, 0, 0, 0,
2084                                          "Velocity upon creation.");
2085                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
2086                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
2087                                          "Velocity upon creation, x component.");
2088                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
2089                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
2090                                          "Velocity upon creation, y component.");
2091                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
2092                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
2093                                          "Velocity upon creation, z component.");
2094                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_LINV, 0, "L", xco+45+3*wval, yco-68, 15, 19,
2095                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2096                                          "Apply the transformation locally");
2097                         
2098                         
2099                         uiDefBut(block, LABEL, 0, "AngV",       xco,           yco-90,   45, 19,
2100                                          NULL, 0, 0, 0, 0,
2101                                          "Angular velocity upon creation.");
2102                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-90, wval, 19,
2103                                          eoa->angVelocity, -10000.0, 10000.0, 10, 0,
2104                                          "Angular velocity upon creation, x component.");
2105                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-90, wval, 19,
2106                                          eoa->angVelocity+1, -10000.0, 10000.0, 10, 0,
2107                                          "Angular velocity upon creation, y component.");
2108                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-90, wval, 19,
2109                                          eoa->angVelocity+2, -10000.0, 10000.0, 10, 0,
2110                                          "Angular velocity upon creation, z component.");
2111                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_ANGV, 0, "L", xco+45+3*wval, yco-90, 15, 19,
2112                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2113                                          "Apply the rotation locally");
2114                                          
2115
2116                 }
2117                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
2118                         ysize= 28;
2119                         glRects(xco, yco-ysize, xco+width, yco);
2120                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2121                 }
2122                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
2123                         ysize= 48;
2124                         glRects(xco, yco-ysize, xco+width, yco);
2125                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2126          
2127                         uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, 1, "ME:",               xco+40, yco-44, (width-80), 19, &(eoa->me), "replace the existing mesh with this one");
2128                 }
2129                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
2130                         ysize= 48;
2131                         glRects(xco, yco-ysize, xco+width, yco);
2132                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2133          
2134                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
2135                         uiDefButI(block, NUM, 0, "Time:",       xco+10+(width-20)/2, yco-44, (width-20)/2-40, 19, &eoa->time, 0.0, 2000.0, 0, 0, "Duration the tracking takes");
2136                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
2137                 }
2138                 else if(eoa->type==ACT_EDOB_DYNAMICS) {
2139                         ysize= 48;
2140                         glRects(xco, yco-ysize, xco+width, yco);
2141                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2142                         
2143                         str= "Dynamic Operation %t|Restore Dynamics %x0|Suspend Dynamics %x1|Enable Rigid Body %x2|Disable Rigid Body %x3";
2144                         uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-44, (width-80), 19,  &(eoa->dyn_operation), 0.0, 0.0, 0, 0, "");
2145                 }
2146                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3|Dynamics %x4";
2147                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
2148
2149                 yco-= ysize;
2150         
2151         break;
2152  
2153         case ACT_CONSTRAINT:
2154                 coa= act->data;
2155         
2156                 if (coa->type == ACT_CONST_TYPE_LOC) {
2157                         ysize= 69;
2158         
2159                         glRects(xco, yco-ysize, xco+width, yco);
2160                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2161                         
2162         /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
2163         /*                      coa->flag &= ~(63); */
2164                         str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
2165                         coa->flag &= 7;
2166                         coa->time = 0;
2167                         uiDefButS(block, MENU, 1, str,          xco+10, yco-65, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
2168                 
2169                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2170                         uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2171                         uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2172
2173                         if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
2174                         else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
2175                         else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
2176                         else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
2177                         else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
2178                         else fp= coa->minrot+2;
2179                         
2180                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
2181                         uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-65, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
2182                 } else if (coa->type == ACT_CONST_TYPE_DIST) {
2183                         ysize= 106;
2184
2185                         glRects(xco, yco-ysize, xco+width, yco);
2186                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2187                         
2188                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2189                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Set the direction of the ray");
2190                 
2191                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2192                         uiDefBut(block, LABEL,                  0, "Range",     xco+80, yco-45, (width-115)/2, 19, NULL, 0.0, 0.0, 0, 0, "Set the maximum length of ray");
2193                         uiDefButBitS(block, TOG, ACT_CONST_DISTANCE, B_REDR, "Dist",    xco+80+(width-115)/2, yco-45, (width-115)/2, 19, &coa->flag, 0.0, 0.0, 0, 0, "Force distance of object to point of impact of ray");
2194                         uiDefButBitS(block, TOG, ACT_CONST_LOCAL, 0, "L", xco+80+(width-115), yco-45, 25, 19,
2195                                          &coa->flag, 0.0, 0.0, 0, 0, "Set ray along object's axis or global axis");
2196
2197                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2198                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2199                         else fp= coa->minloc+2;
2200
2201                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/2, 19, fp+3, 0.0, 2000.0, 10, 0, "Maximum length of ray");
2202                         if (coa->flag & ACT_CONST_DISTANCE)
2203                                 uiDefButF(block, NUM, 0, "",            xco+80+(width-115)/2, yco-65, (width-115)/2, 19, fp, -2000.0, 2000.0, 10, 0, "Keep this distance to target");
2204                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2205                                          &coa->flag, 0.0, 0.0, 0, 0, "Set object axis along (local axis) or parallel (global axis) to the normal at hit position");
2206                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2207                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2208                         if (coa->flag & ACT_CONST_MATERIAL)
2209                         {
2210                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2211                                         coa->matprop, 0, 31, 0, 0,
2212                                         "Ray detects only Objects with this material");
2213                         }
2214                         else
2215                         {
2216                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2217                                         coa->matprop, 0, 31, 0, 0,
2218                                         "Ray detect only Objects with this property");
2219                         }
2220                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2221                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2222                         uiDefButS(block, NUM, 0, "time", xco+50, yco-103, (width-60)/2, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2223                         uiDefButS(block, NUM, 0, "rotDamp", xco+50+(width-60)/2, yco-103, (width-60)/2, 19, &(coa->rotdamp), 0.0, 100.0, 0, 0, "Use a different damping for orientation");
2224                 } else if (coa->type == ACT_CONST_TYPE_ORI) {
2225                         ysize= 87;
2226
2227                         glRects(xco, yco-ysize, xco+width, yco);
2228                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2229                         
2230                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4";
2231                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Select the axis to be aligned along the reference direction");
2232                 
2233                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2234                         uiDefBut(block, LABEL,                  0, "X", xco+80, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2235                         uiDefBut(block, LABEL,                  0, "Y", xco+80+(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2236                         uiDefBut(block, LABEL,                  0, "Z", xco+80+2*(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2237
2238                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/3, 19, &coa->maxrot[0], -2000.0, 2000.0, 10, 0, "X component of reference direction");
2239                         uiDefButF(block, NUM, 0, "",            xco+80+(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[1], -2000.0, 2000.0, 10, 0, "Y component of reference direction");
2240                         uiDefButF(block, NUM, 0, "",            xco+80+2*(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[2], -2000.0, 2000.0, 10, 0, "Z component of reference direction");
2241
2242                         uiDefButS(block, NUM, 0, "time", xco+10, yco-84, 70, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2243                         uiDefButF(block, NUM, 0, "min", xco+80, yco-84, (width-115)/2, 19, &(coa->minloc[0]), 0.0, 180.0, 10, 1, "Minimum angle (in degree) to maintain with target direction. No correction is done if angle with target direction is between min and max");
2244                         uiDefButF(block, NUM, 0, "max", xco+80+(width-115)/2, yco-84, (width-115)/2, 19, &(coa->maxloc[0]), 0.0, 180.0, 10, 1, "Maximum angle (in degree) allowed with target direction. No correction is done if angle with target direction is between min and max");
2245                 } else if (coa->type == ACT_CONST_TYPE_FH) {
2246                         ysize= 106;
2247
2248                         glRects(xco, yco-ysize, xco+width, yco);
2249                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2250                         
2251                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2252                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Set the direction of the ray (in world coordinate)");
2253
2254                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2255                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2256                         else fp= coa->minloc+2;
2257
2258                         uiDefButF(block, NUM,           0, "damp",      xco+10, yco-45, (width-70)/2, 19, &coa->maxrot[0], 0.0, 1.0, 1, 0, "Damping factor of the Fh spring force");
2259                         uiDefButF(block, NUM,           0, "dist",      xco+10+(width-70)/2, yco-45, (width-70)/2, 19, fp, 0.010, 2000.0, 10, 0, "Height of the Fh area");
2260                         uiDefButBitS(block, TOG, ACT_CONST_DOROTFH, 0, "Rot Fh",        xco+10+(width-70), yco-45, 50, 19, &coa->flag, 0.0, 0.0, 0, 0, "Keep object axis parallel to normal");
2261
2262                         uiDefButF(block, NUMSLI, 0, "Fh ",              xco+80, yco-65, (width-115), 19, fp+3, 0.0, 1.0, 0, 0, "Spring force within the Fh area");
2263                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2264                                          &coa->flag, 0.0, 0.0, 0, 0, "Add a horizontal spring force on slopes");
2265                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2266                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2267                         if (coa->flag & ACT_CONST_MATERIAL)
2268                         {
2269                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2270                                         coa->matprop, 0, 31, 0, 0,
2271                                         "Ray detects only Objects with this material");
2272                         }
2273                         else
2274                         {
2275                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2276                                         coa->matprop, 0, 31, 0, 0,
2277                                         "Ray detect only Objects with this property");
2278                         }
2279                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2280                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2281                         uiDefButS(block, NUM, 0, "time", xco+50, yco-103, 90, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2282                         uiDefButF(block, NUM, 0, "rotDamp", xco+140, yco-103, (width-150), 19, &coa->maxrot[1], 0.0, 1.0, 1, 0, "Use a different damping for rotation");
2283                 }
2284                 str= "Constraint Type %t|Location %x0|Distance %x1|Orientation %x2|Force field %x3";
2285                 but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &coa->type, 0.0, 0.0, 0, 0, "");
2286                 yco-= ysize;
2287         break;
2288  
2289         case ACT_SCENE:
2290                 sca= act->data; 
2291                 
2292                 if(sca->type==ACT_SCENE_RESTART) { 
2293                         ysize= 28; 
2294                         glRects(xco, yco-ysize, xco+width, yco); 
2295                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2296                 } 
2297                 else if(sca->type==ACT_SCENE_CAMERA) { 
2298                         
2299                         ysize= 48; 
2300                         glRects(xco, yco-ysize, xco+width, yco); 
2301                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2302          
2303                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+40, yco-44, (width-80), 19, &(sca->camera), "Set this Camera. Leave empty to refer to self object"); 
2304                 } 
2305                 else if(sca->type==ACT_SCENE_SET) { 
2306                         
2307                         ysize= 48; 
2308                         glRects(xco, yco-ysize, xco+width, yco); 
2309                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2310         
2311                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene"); 
2312                 } 
2313                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
2314                         
2315                         ysize= 48; 
2316                         glRects(xco, yco-ysize, xco+width, yco); 
2317                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2318         
2319                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene"); 
2320                 } 
2321                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
2322                         
2323                         ysize= 48; 
2324                         glRects(xco, yco-ysize, xco+width, yco); 
2325                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2326         
2327                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene"); 
2328                 } 
2329                 else if(sca->type==ACT_SCENE_REMOVE) { 
2330                         
2331                         ysize= 48; 
2332                         glRects(xco, yco-ysize, xco+width, yco); 
2333                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2334         
2335                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
2336                 } 
2337                 else if(sca->type==ACT_SCENE_SUSPEND) { 
2338                         
2339                         ysize= 48; 
2340                         glRects(xco, yco-ysize, xco+width, yco); 
2341                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2342         
2343                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
2344                 } 
2345                 else if(sca->type==ACT_SCENE_RESUME) { 
2346                         
2347                         ysize= 48; 
2348                         glRects(xco, yco-ysize, xco+width, yco); 
2349                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2350         
2351                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
2352                 } 
2353
2354                 str= "Scene %t|Restart %x0|Set Scene %x1|Set Camera %x2|Add OverlayScene %x3|Add BackgroundScene %x4|Remove Scene %x5|Suspend Scene %x6|Resume Scene %x7";
2355                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
2356
2357                 yco-= ysize; 
2358                 break; 
2359         case ACT_GAME:
2360                 {
2361                         gma = act->data; 
2362                         if (gma->type == ACT_GAME_LOAD)
2363                         {
2364                                 //ysize = 68;
2365                                 ysize = 48;
2366                                 glRects(xco, yco-ysize, xco+width, yco); 
2367                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2368                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2369 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2370                         }
2371 /*                      else if (gma->type == ACT_GAME_START)
2372                         {
2373                                 ysize = 68; 
2374                                 glRects(xco, yco-ysize, xco+width, yco); 
2375                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2376
2377                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2378                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2379                         }
2380 */                      else if (ELEM4(gma->type, ACT_GAME_RESTART, ACT_GAME_QUIT, ACT_GAME_SAVECFG, ACT_GAME_LOADCFG))
2381                         {
2382                                 ysize = 28; 
2383                                 glRects(xco, yco-ysize, xco+width, yco); 
2384                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2385                         }
2386
2387                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
2388                         str = "Scene %t|Start new game%x0|Restart this game%x2|Quit this game %x3|Save GameLogic.globalDict %x4|Load GameLogic.globalDict %x5";
2389                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
2390                         
2391                         yco -= ysize; 
2392                         break; 
2393                 }
2394         case ACT_GROUP:
2395                 ga= act->data;
2396
2397                 ysize= 52;
2398
2399                 glRects(xco, yco-ysize, xco+width, yco);
2400                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2401                 
2402                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
2403
2404                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
2405                 if(ga->type==ACT_GROUP_SET) {
2406                         uiDefBut(block, TEX, 0, "Key: ",                xco+20, yco-44, (width-10)/2, 19, ga->name, 0.0, 31.0, 0, 0, "This name defines groupkey to be set");
2407                         uiDefButI(block, NUM, 0, "Frame:",      xco+20+(width-10)/2, yco-44, (width-70)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Set this frame");
2408                 }
2409                 else if(ga->type==ACT_GROUP_FROM_PROP) {
2410                         uiDefBut(block, TEX, 0, "Prop: ",               xco+20, yco-44, width-40, 19, ga->name, 0.0, 31.0, 0, 0, "Use this property to define the Group position");
2411                 }
2412                 else {
2413                         uiDefButI(block, NUM, 0, "State",               xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
2414                         uiDefButI(block, NUM, 0, "End",         xco+20+(width-40)/2, yco-44, (width-40)/2, 19, &ga->end, 0.0, 2500.0, 0, 0, "End frame");
2415                 }
2416                 yco-= ysize;
2417                 break;
2418
2419         case ACT_VISIBILITY:
2420                 ysize = 24;
2421
2422                 glRects(xco, yco-ysize, xco+width, yco);
2423                 uiEmboss((float)xco,
2424                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2425                 
2426                 visAct = act->data;
2427
2428                 uiBlockBeginAlign(block);
2429                 uiDefButBitI(block, TOGN, ACT_VISIBILITY_INVISIBLE, B_REDR,
2430                           "Visible",
2431                           xco + 10, yco - 20, (width - 20)/3, 19, &visAct->flag,
2432                           0.0, 0.0, 0, 0,
2433                           "Set the objects visible. Initialized from the objects render restriction toggle (access in the outliner)");
2434                 uiDefButBitI(block, TOG, ACT_VISIBILITY_INVISIBLE, B_REDR,
2435                           "Invisible",
2436                           xco + 10 + ((width - 20)/3), yco - 20, (width - 20)/3, 19, &visAct->flag,
2437                           0.0, 0.0, 0, 0,
2438                           "Set the object invisible. Initialized from the objects render restriction toggle (access in the outliner)");
2439                 uiBlockEndAlign(block);
2440                 
2441                 uiDefButBitI(block, TOG, ACT_VISIBILITY_RECURSIVE, B_NOP,
2442                           "Children",
2443                           xco + 10 + (((width - 20)/3)*2)+10, yco - 20, ((width - 20)/3)-10, 19, &visAct->flag,
2444                           0.0, 0.0, 0, 0,
2445                           "Sets all the children of this object to the same visibility recursively");
2446
2447                 yco-= ysize;
2448
2449                 break;
2450                 
2451         case ACT_STATE:
2452                 ysize = 34;
2453
2454                 glRects(xco, yco-ysize, xco+width, yco);
2455                 uiEmboss((float)xco,
2456                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2457                 
2458                 staAct = act->data;
2459
2460                 str= "Operation %t|Cpy %x0|Add %x1|Sub %x2|Inv %x3";
2461
2462                 uiDefButI(block, MENU, B_REDR, str,
2463                           xco + 10, yco - 24, 65, 19, &staAct->type,
2464                           0.0, 0.0, 0, 0,
2465                           "Select the bit operation on object state mask");
2466
2467                 for (wval=0; wval<15; wval+=5) {
2468                         uiBlockBeginAlign(block);
2469                         for (stbit=0; stbit<5; stbit++) {
2470                                 but = uiDefButBitI(block,  TOG, 1<<(stbit+wval), stbit+wval, "",        (short)(xco+85+12*stbit+13*wval), yco-17, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+wval)));
2471                                 uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
2472                         }
2473                         for (stbit=0; stbit<5; stbit++) {
2474                                 but = uiDefButBitI(block, TOG, 1<<(stbit+wval+15), stbit+wval+15, "",   (short)(xco+85+12*stbit+13*wval), yco-29, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+wval+15)));
2475                                 uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
2476                         }
2477                 }
2478                 uiBlockEndAlign(block);
2479
2480                 yco-= ysize;
2481
2482                 break;
2483
2484         case ACT_RANDOM:
2485                 ysize  = 69;
2486
2487                 glRects(xco, yco-ysize, xco+width, yco);
2488                 uiEmboss((float)xco,
2489                                   (float)yco-ysize, (float)xco+width, (float)yco, 1);
2490                 
2491                 randAct = act->data;
2492
2493                 /* 1. seed */
2494                 uiDefButI(block, NUM, 1, "Seed: ",              (xco+10),yco-24, 0.4 *(width-20), 19,
2495                                  &randAct->seed, 0, 1000, 0, 0,
2496                                  "Initial seed of the random generator. Use Python for more freedom. "
2497                                  " (Choose 0 for not random)");
2498
2499                 /* 2. distribution type */
2500                 /* One pick per distribution. These numbers MUST match the #defines  */
2501                 /* in game.h !!!                                                     */
2502                 str= "Distribution %t|Bool Constant %x0|Bool Uniform %x1"
2503                         "|Bool Bernoulli %x2|Int Constant %x3|Int Uniform %x4"
2504                         "|Int Poisson %x5|Float Constant %x6|Float Uniform %x7"
2505                         "|Float Normal %x8|Float Neg. Exp. %x9";
2506                 uiDefButI(block, MENU, B_REDR, str, (xco+10) + 0.4 * (width-20), yco-24, 0.6 * (width-20), 19,
2507                                  &randAct->distribution, 0.0, 0.0, 0, 0,
2508                                  "Choose the type of distribution");
2509
2510                 /* 3. property */
2511                 uiDefBut(block, TEX, 1, "Property:", (xco+10), yco-44, (width-20), 19,
2512                                  &randAct->propname, 0, 31, 0, 0,
2513                                  "Assign the random value to this property"); 
2514
2515                 /*4. and 5. arguments for the distribution*/
2516                 switch (randAct->distribution) {
2517                 case ACT_RANDOM_BOOL_CONST:
2518                         uiDefButBitI(block, TOG, 1, 1, "Always true", (xco+10), yco-64, (width-20), 19,
2519                                          &randAct->int_arg_1, 2.0, 1, 0, 0,
2520                                          "Always false or always true");                        
2521                         break;
2522                 case ACT_RANDOM_BOOL_UNIFORM:
2523                         uiDefBut(block, LABEL, 0, "     Do a 50-50 pick.",      (xco+10), yco-64, (width-20), 19,
2524                                          NULL, 0, 0, 0, 0,
2525                                          "Choose between true and false, 50% chance each.");
2526                         break;
2527                 case ACT_RANDOM_BOOL_BERNOUILLI:
2528                         uiDefButF(block, NUM, 1, "Chance", (xco+10), yco-64, (width-20), 19,
2529                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2530                                          "Pick a number between 0 and 1. Success if you stay "
2531                                          "below this value");                   
2532                         break;
2533                 case ACT_RANDOM_INT_CONST:
2534                         uiDefButI(block, NUM, 1, "Value: ",             (xco+10), yco-64, (width-20), 19,
2535                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2536                                          "Always return this number");
2537                         break;
2538                 case ACT_RANDOM_INT_UNIFORM:
2539                         uiDefButI(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2540                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2541                                          "Choose a number from a range. "
2542                                          "Lower boundary of the range.");
2543                         uiDefButI(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2544                                          &randAct->int_arg_2, -1000, 1000, 0, 0,
2545                                          "Choose a number from a range. "
2546                                          "Upper boundary of the range.");
2547                         break;
2548                 case ACT_RANDOM_INT_POISSON:
2549                         uiDefButF(block, NUM, 1, "Mean: ", (xco+10), yco-64, (width-20), 19,
2550                                          &randAct->float_arg_1, 0.01, 100.0, 0, 0,
2551                                          "Expected mean value of the distribution.");                                           
2552                         break;
2553                 case ACT_RANDOM_FLOAT_CONST:
2554                         uiDefButF(block, NUM, 1, "Value: ", (xco+10), yco-64, (width-20), 19,
2555                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2556                                          "Always return this number");
2557                         break;
2558                 case ACT_RANDOM_FLOAT_UNIFORM:
2559                         uiDefButF(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2560                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2561                                          "Choose a number from a range. "
2562                                          "Lower boundary of the range.");
2563                         uiDefButF(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2564                                          &randAct->float_arg_2, -10000.0, 10000.0, 0, 0,
2565                                          "Choose a number from a range. "
2566                                          "Upper boundary of the range.");
2567                         break;
2568                 case ACT_RANDOM_FLOAT_NORMAL:
2569                         uiDefButF(block, NUM, 1, "Mean: ",              (xco+10), yco-64, (width-20)/2, 19,
2570                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2571                                          "A normal distribution. Mean of the distribution.");
2572                         uiDefButF(block, NUM, 1, "SD: ",                (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2573                                          &randAct->float_arg_2, 0.0, 10000.0, 0, 0,
2574                                          "A normal distribution. Standard deviation of the "
2575                                          "distribution.");
2576                         break;
2577                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
2578                         uiDefButF(block, NUM, 1, "Half-life time: ", (xco+10), yco-64, (width-20), 19,
2579                                          &randAct->float_arg_1, 0.001, 10000.0, 0, 0,
2580                                          "Negative exponential dropoff.");
2581                         break;
2582                 default:
2583                         ; /* don't know what this distro is... can be useful for testing */
2584                         /* though :)                                                     */
2585                 }
2586
2587                 yco-= ysize;
2588                 break;
2589         case ACT_MESSAGE:
2590                 ma = act->data;
2591
2592                 ysize = 4 + (3 * 24); /* footer + number of lines * 24 pixels/line */
2593         
2594                 glRects(xco, yco-ysize, xco+width, yco);
2595                 uiEmboss((float)xco,        (float)yco-ysize,
2596                                  (float)xco+width,  (float)yco, 1);
2597
2598                 myline=1;
2599
2600                 /* line 1: To */
2601                 uiDefBut(block, TEX, 1, "To: ",
2602                         (xco+10), (yco-(myline++*24)), (width-20), 19,
2603                         &ma->toPropName, 0, 31, 0, 0,
2604                         "Optional send message to objects with this name only, or empty to broadcast");
2605
2606                 /* line 2: Message Subject */
2607                 uiDefBut(block, TEX, 1, "Subject: ",
2608                 (xco+10), (yco-(myline++*24)), (width-20), 19,
2609                 &ma->subject, 0, 31, 0, 0,
2610                 "Optional message subject. This is what can be filtered on.");
2611
2612                 /* line 3: Text/Property */
2613                 uiDefButBitS(block, TOG, 1, B_REDR, "T/P",
2614                         (xco+10),(yco-(myline*24)), (0.20 * (width-20)), 19,
2615                         &ma->bodyType, 0.0, 0.0, 0, 0,
2616                         "Toggle message type: either Text or a PropertyName.");
2617
2618                 if (ma->bodyType == ACT_MESG_MESG)
2619                 {
2620                 /* line 3: Message Body */
2621                 uiDefBut(block, TEX, 1, "Body: ",
2622                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2623                 &ma->body, 0, 31, 0, 0,
2624                 "Optional message body Text");
2625                 } else
2626                 {
2627                         /* line 3: Property body (set by property) */
2628                         uiDefBut(block, TEX, 1, "Propname: ",
2629                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2630                         &ma->body, 0, 31, 0, 0,
2631                         "The message body will be set by the Property Value");
2632                 }
2633                 
2634                 yco -= ysize;
2635                 break;
2636         case ACT_2DFILTER:
2637                 tdfa = act->data;
2638
2639                 ysize = 50;
2640                 if(tdfa->type == ACT_2DFILTER_CUSTOMFILTER)
2641                 {
2642                         ysize +=20;
2643                 }
2644         glRects( xco, yco-ysize, xco+width, yco ); 
2645                 uiEmboss( (float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1 );
2646
2647                 switch(tdfa->type)
2648                 {
2649                         case ACT_2DFILTER_MOTIONBLUR:
2650                                 if(!tdfa->flag)
2651                                 {
2652                                         uiDefButS(block, TOG, B_REDR, "D",      xco+30,yco-44,19, 19, &tdfa->flag, 0.0, 0.0, 0.0, 0.0, "Disable Motion Blur");
2653                                         uiDefButF(block, NUM, B_REDR, "Value:", xco+52,yco-44,width-82,19,&tdfa->float_arg,0.0,1.0,0.0,0.0,"Set motion blur value");
2654                                 }
2655                                 else
2656                                 {
2657                                         uiDefButS(block, TOG, B_REDR, "Disabled",       xco+30,yco-44,width-60, 19, &tdfa->flag, 0.0, 0.0, 0.0, 0.0, "Enable Motion Blur");
2658                                 }
2659                                 break;
2660                         case ACT_2DFILTER_BLUR:
2661                         case ACT_2DFILTER_SHARPEN:
2662                         case ACT_2DFILTER_DILATION:
2663                         case ACT_2DFILTER_EROSION:
2664                         case ACT_2DFILTER_LAPLACIAN:
2665                         case ACT_2DFILTER_SOBEL:
2666                         case ACT_2DFILTER_PREWITT:
2667                         case ACT_2DFILTER_GRAYSCALE:
2668                         case ACT_2DFILTER_SEPIA:
2669                         case ACT_2DFILTER_INVERT:
2670                         case ACT_2DFILTER_NOFILTER:
2671                         case ACT_2DFILTER_DISABLED:
2672                         case ACT_2DFILTER_ENABLED:
2673                                 uiDefButI(block, NUM, B_REDR, "Pass Number:", xco+30,yco-44,width-60,19,&tdfa->int_arg,0.0,MAX_RENDER_PASS-1,0.0,0.0,"Set motion blur value");
2674                                 break;
2675                         case ACT_2DFILTER_CUSTOMFILTER:
2676                                 uiDefButI(block, NUM, B_REDR, "Pass Number:", xco+30,yco-44,width-60,19,&tdfa->int_arg,0.0,MAX_RENDER_PASS-1,0.0,0.0,"Set motion blur value");
2677                                 uiDefID