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