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