svn merge -r 16077:16174 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[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, "Lvl",
1058                          (short)(x + 10 + 0.70 * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
1059                          &sens->level, 0.0, 0.0, 0, 0,
1060                          "Level detector versus edge detector (only applicable in case of 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, "test for min value");
1274                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1275                                         ps->maxvalue, 0, 31, 0, 0, "test 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, "test 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                         /* 2. sensing range */
1395                         uiDefButF(block, NUM, 1, "Range", xco+10, yco-68, 0.6 * (width-20), 19,
1396                                 &raySens->range, 0.01, 10000.0, 100, 0,
1397                                 "Sense objects no farther than this distance");
1398                         
1399                         /* 3. axis choice */
1400                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1401                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1402                                 &raySens->axisflag, 2.0, 31, 0, 0,
1403                                 "Specify along which axis the ray is cast.");
1404                         
1405                         yco-= ysize;            
1406                         break;
1407                 }
1408         case SENS_MESSAGE:
1409                 {
1410                         mes = sens->data;
1411                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1412                         
1413                         glRects(xco, yco-ysize, xco+width, yco);
1414                         uiEmboss((float)xco, (float)yco-ysize,
1415                                 (float)xco+width, (float)yco, 1);
1416                         
1417                         /* line 1: header line */
1418                         draw_default_sensor_header(sens, block, xco, yco, width);
1419                         
1420                         /* line 2: Subject filter */
1421                         uiDefBut(block, TEX, 1, "Subject: ",
1422                                 (xco+10), (yco-44), (width-20), 19,
1423                                 mes->subject, 0, 31, 0, 0,
1424                                 "Optional subject filter: only accept messages with this subject"
1425                                 ", or empty for all");
1426                         
1427                         yco -= ysize;
1428                         break;
1429                 }
1430                 case SENS_JOYSTICK:
1431                 {
1432
1433                         ysize =  72;
1434                         
1435                         glRects(xco, yco-ysize, xco+width, yco);
1436                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1437                         
1438                         /* line 1: header */
1439                         draw_default_sensor_header(sens, block, xco, yco, width);
1440
1441                         joy= sens->data;
1442                         
1443
1444                         str= "Type %t|Button %x0|Axis %x1|Hat%x2"; 
1445                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, 0.6 * (width-20), 19,
1446                                 &joy->type, 0, 31, 0, 0,
1447                                 "The type of event this joystick sensor is triggered on.");
1448                         
1449                         if(joy->type == SENS_JOY_BUTTON)
1450                         {
1451                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1452                                 &joy->button, 0, 18, 100, 0,
1453                                 "Specify which button to use");
1454                                 
1455                                 str = "Type %t|Pressed %x0|Released %x1"; 
1456                                 uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1457                                 &joy->buttonf, 2.0, 31, 0, 0,
1458                                 "Button pressed or released.");
1459                         }
1460                         else if(joy->type == SENS_JOY_AXIS)
1461                         {
1462                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1463                                 &joy->axis, 1, 2.0, 100, 0,
1464                                 "Specify which axis to use");
1465
1466                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1467                                 &joy->precision, 0, 32768.0, 100, 0,
1468                                 "Specify the precision of the axis");
1469
1470                                 str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1471                                 uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1472                                 &joy->axisf, 2.0, 31, 0, 0,
1473                                 "The direction of the axis");
1474                         }
1475                         else
1476                         {
1477                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1478                                 &joy->hat, 1, 2.0, 100, 0,
1479                                 "Specify which hat to use");
1480                                 
1481                                 uiDefButI(block, NUM, 1, "Direction:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1482                                 &joy->hatf, 0, 12, 100, 0,
1483                                 "Specify hat direction");
1484                         }
1485                         yco-= ysize;
1486                         break;
1487                 }
1488         }
1489         
1490         uiBlockSetEmboss(block, UI_EMBOSSM);
1491         uiBlockSetCol(block, TH_AUTO);
1492         
1493         return yco-4;
1494 }
1495
1496
1497
1498 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1499 {
1500         bExpressionCont *ec;
1501         bPythonCont *pc;
1502         short ysize;
1503         
1504         uiBlockSetEmboss(block, UI_EMBOSSM);
1505         
1506         switch (cont->type) {
1507         case CONT_EXPRESSION:
1508                 ysize= 28;
1509
1510                 BIF_ThemeColor(TH_BUT_SETTING);
1511                 glRects(xco, yco-ysize, xco+width, yco);
1512                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1513                 
1514                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1515                 ec= cont->data; 
1516                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1517                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1518                                  ec->str, 0, 127, 0, 0,
1519                                  "Expression"); 
1520                 
1521                 yco-= ysize;
1522                 break;
1523         case CONT_PYTHON:
1524                 ysize= 28;
1525                 
1526                 if(cont->data==NULL) init_controller(cont);
1527                 pc= cont->data;
1528                 
1529                 BIF_ThemeColor(TH_BUT_SETTING1);
1530                 glRects(xco, yco-ysize, xco+width, yco);
1531                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1532
1533                 uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Script: ", xco+45,yco-24,width-90, 19, &pc->text, "");
1534                 
1535                 yco-= ysize;
1536                 break;
1537                 
1538         default:
1539                 ysize= 4;
1540
1541                 BIF_ThemeColor(TH_BUT_NEUTRAL);
1542                 glRects(xco, yco-ysize, xco+width, yco);
1543                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1544                 
1545                 yco-= ysize;
1546         }
1547         
1548         uiBlockSetEmboss(block, UI_EMBOSSM);
1549         uiBlockSetCol(block, TH_AUTO);
1550
1551         return yco;
1552 }
1553
1554 static int get_col_actuator(int type)
1555 {
1556         switch(type) {
1557         case ACT_ACTION:                return TH_BUT_ACTION;
1558         case ACT_SHAPEACTION:   return TH_BUT_ACTION;
1559         case ACT_OBJECT:                return TH_BUT_NEUTRAL;
1560         case ACT_IPO:                   return TH_BUT_SETTING;
1561         case ACT_PROPERTY:              return TH_BUT_SETTING1;
1562         case ACT_SOUND:                 return TH_BUT_SETTING2;
1563         case ACT_CD:                    return TH_BUT_NUM;
1564         case ACT_CAMERA:                return TH_BUT_TEXTFIELD;
1565         case ACT_EDIT_OBJECT:           return TH_BUT_POPUP;
1566         case ACT_GROUP:                 return TH_BUT_ACTION;
1567         case ACT_RANDOM:                return TH_BUT_NEUTRAL;
1568         case ACT_SCENE:                 return TH_BUT_SETTING;
1569         case ACT_MESSAGE:               return TH_BUT_SETTING1;
1570         case ACT_GAME:                  return TH_BUT_SETTING2;
1571         case ACT_VISIBILITY:            return TH_BUT_NUM;
1572         case ACT_CONSTRAINT:            return TH_BUT_ACTION;
1573         case ACT_STATE:                 return TH_BUT_SETTING2;
1574         default:                                return TH_BUT_NEUTRAL;
1575         }
1576 }
1577 static void set_col_actuator(int item, int medium) 
1578 {
1579         int col= get_col_actuator(item);
1580         BIF_ThemeColorShade(col, medium?30:10);
1581         
1582 }
1583
1584 static void change_object_actuator(void *act, void *arg)
1585 {
1586         bObjectActuator *oa = act;
1587
1588         if (oa->type != oa->otype) {
1589                 switch (oa->type) {
1590                 case ACT_OBJECT_NORMAL:
1591                         memset(oa, 0, sizeof(bObjectActuator));
1592                         oa->flag = ACT_FORCE_LOCAL|ACT_TORQUE_LOCAL|ACT_DLOC_LOCAL|ACT_DROT_LOCAL;
1593                         oa->type = ACT_OBJECT_NORMAL;
1594                         break;
1595
1596                 case ACT_OBJECT_SERVO:
1597                         memset(oa, 0, sizeof(bObjectActuator));
1598                         oa->flag = ACT_LIN_VEL_LOCAL;
1599                         oa->type = ACT_OBJECT_SERVO;
1600                         oa->forcerot[0] = 30.0f;
1601                         oa->forcerot[1] = 0.5f;
1602                         oa->forcerot[2] = 0.0f;
1603                         break;
1604                 }
1605         }
1606 }
1607
1608 static void change_ipo_actuator(void *arg1_but, void *arg2_ia)
1609 {
1610         bIpoActuator *ia = arg2_ia;
1611         uiBut *but = arg1_but;
1612
1613         if (but->retval & ACT_IPOFORCE)
1614                 ia->flag &= ~ACT_IPOADD;
1615         else if (but->retval & ACT_IPOADD)
1616                 ia->flag &= ~ACT_IPOFORCE;
1617         but->retval = B_REDR;
1618 }
1619
1620 void update_object_actuator_PID(void *act, void *arg)
1621 {
1622         bObjectActuator *oa = act;
1623         oa->forcerot[0] = 60.0f*oa->forcerot[1];
1624 }
1625
1626 char *get_state_name(Object *ob, short bit)
1627 {
1628         bController *cont;
1629         unsigned int mask;
1630
1631         mask = (1<<bit);
1632         cont = ob->controllers.first;
1633         while (cont) {
1634                 if (cont->state_mask & mask) {
1635                         return cont->name;
1636                 }
1637                 cont = cont->next;
1638         }
1639         return (char*)"";
1640 }
1641
1642 static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
1643 {
1644         bSoundActuator      *sa      = NULL;
1645         bCDActuator                     *cda     = NULL;
1646         bObjectActuator     *oa      = NULL;
1647         bIpoActuator        *ia      = NULL;
1648         bPropertyActuator   *pa      = NULL;
1649         bCameraActuator     *ca      = NULL;
1650         bEditObjectActuator *eoa     = NULL;
1651         bConstraintActuator *coa     = NULL;
1652         bSceneActuator      *sca     = NULL;
1653         bGroupActuator      *ga      = NULL;
1654         bRandomActuator     *randAct = NULL;
1655         bMessageActuator    *ma      = NULL;
1656         bActionActuator     *aa      = NULL;
1657         bGameActuator       *gma     = NULL;
1658         bVisibilityActuator *visAct  = NULL;
1659         bTwoDFilterActuator     *tdfa    = NULL;
1660         bParentActuator     *parAct  = NULL;
1661         bStateActuator          *staAct  = NULL;
1662         
1663         float *fp;
1664         short ysize = 0, wval;
1665         char *str;
1666         int myline, stbit;
1667         uiBut *but;
1668
1669         /* yco is at the top of the rect, draw downwards */
1670         uiBlockSetEmboss(block, UI_EMBOSSM);
1671         set_col_actuator(act->type, 0);
1672         
1673         switch (act->type)
1674         {
1675         case ACT_OBJECT:
1676                 {
1677                         oa = act->data;
1678                         wval = (width-100)/3;
1679                         if (oa->type == ACT_OBJECT_NORMAL)
1680                         {
1681                                 if ( ob->gameflag & OB_DYNAMIC )
1682                                 {
1683                                         ysize= 175;
1684                                 }
1685                                 else
1686                                 {
1687                                         ysize= 72;
1688                                 }
1689
1690                                 glRects(xco, yco-ysize, xco+width, yco);
1691                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1692                                 
1693                                 uiDefBut(block, LABEL, 0, "Loc",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the location");
1694                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1695                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1696                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1697                                 
1698                                 uiDefBut(block, LABEL, 0, "Rot",        xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the rotation");
1699                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1700                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1701                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1702
1703                                 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");
1704                                 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");
1705         
1706                                 if ( ob->gameflag & OB_DYNAMIC )
1707                                 {
1708                                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-87, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1709                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1710                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1711                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1712                                 
1713                                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-106, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1714                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1715                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1716                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");                                
1717                                 }
1718                                 
1719                                 if ( ob->gameflag & OB_DYNAMIC )
1720                                 {
1721                                         uiDefBut(block, LABEL, 0, "LinV",       xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1722                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1723                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1724                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1725                                 
1726                                         uiDefBut(block, LABEL, 0, "AngV",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1727                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1728                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1729                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1730                                 
1731                                         uiDefBut(block, LABEL, 0, "Damp",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity");
1732                                         uiDefButS(block, NUM, 0, "",            xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, "");
1733
1734                                         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");
1735                                         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");
1736                                         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");
1737                                         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");
1738                                 
1739                                         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");
1740                                 }                               
1741                         } else if (oa->type == ACT_OBJECT_SERVO)
1742                         {
1743                                 ysize= 172;
1744                                 
1745                                 glRects(xco, yco-ysize, xco+width, yco);
1746                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1747                                 
1748                                 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");
1749                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1750                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1751                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1752                                 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");
1753
1754                                 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)");
1755                                 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");
1756                                 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");
1757                                 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");
1758                                 uiDefBut(block, LABEL, 0, "Max",        xco, yco-87, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
1759                                 uiDefBut(block, LABEL, 0, "Min",        xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
1760                                 if (oa->flag & ACT_SERVO_LIMIT_X) {
1761                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1762                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1763                                 }
1764                                 if (oa->flag & ACT_SERVO_LIMIT_Y) {
1765                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1766                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1767                                 }
1768                                 if (oa->flag & ACT_SERVO_LIMIT_Z) {
1769                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1770                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1771                                 }
1772                                 uiDefBut(block, LABEL, 0, "Servo",      xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
1773                                 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");
1774                                 uiDefBut(block, LABEL, 0, "Slow",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
1775                                 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");
1776                                 uiButSetFunc(but, update_object_actuator_PID, oa, NULL);
1777                                 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");
1778                                 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");
1779                         }
1780                         str= "Motion Type %t|Simple motion %x0|Servo Control %x1";
1781                         but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &oa->type, 0.0, 0.0, 0, 0, "");
1782                         oa->otype = oa->type;
1783                         uiButSetFunc(but, change_object_actuator, oa, NULL);
1784                         yco-= ysize;
1785                         break;
1786                 }
1787         case ACT_ACTION:
1788         case ACT_SHAPEACTION:
1789                 {
1790                         /* DrawAct */
1791 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1792                         ysize = 112;
1793 #else
1794                         ysize= 92;
1795 #endif
1796                         
1797                         glRects(xco, yco-ysize, xco+width, yco);
1798                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1799                         
1800                         aa = act->data;
1801                         wval = (width-60)/3;
1802                         
1803                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1804 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1805                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
1806 #else
1807                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1808 #endif
1809                         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");
1810                         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");
1811                         
1812                         uiDefButBitS(block, TOGN, 1, 0, "Continue", xco+((width/3)*2)+20, yco-24, 60, 19,
1813                                          &aa->end_reset, 0.0, 0.0, 0, 0, "Restore last frame when switching on/off, otherwise play from the start each time");
1814                         
1815                         
1816                         if(aa->type == ACT_ACTION_FROM_PROP)
1817                         {
1818                                 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");
1819                         }
1820                         else
1821                         {
1822                                 uiDefButI(block, NUM, 0, "Sta: ",xco+10, yco-44, (width-20)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
1823                                 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");
1824                         }
1825                                                 
1826                         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");
1827                         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");
1828                         
1829                         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");                  
1830
1831                         
1832 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1833                         if(aa->type == ACT_ACTION_MOTION)
1834                         {
1835                                 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");
1836                         }
1837 #endif
1838                         
1839                         
1840                         
1841                         yco-=ysize;
1842                         break;
1843                 }
1844         case ACT_IPO:
1845                 {
1846                         ia= act->data;
1847                         
1848                         ysize= 52;
1849                         
1850                         glRects(xco, yco-ysize, xco+width, yco);
1851                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1852                         
1853                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1854                         
1855                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-24, (width-20)/2, 19, &ia->type, 0, 0, 0, 0, "");
1856
1857                         but = uiDefButBitS(block, TOG, ACT_IPOFORCE, ACT_IPOFORCE, 
1858                                 "Force", xco+10+(width-20)/2, yco-24, (width-20)/4-10, 19, 
1859                                 &ia->flag, 0, 0, 0, 0, 
1860                                 "Convert Ipo to force. Force is applied in global or local coordinate according to Local flag"); 
1861                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1862
1863                         but = uiDefButBitS(block, TOG, ACT_IPOADD, ACT_IPOADD, 
1864                                 "Add", xco+3*(width-20)/4, yco-24, (width-20)/4-10, 19, 
1865                                 &ia->flag, 0, 0, 0, 0, 
1866                                 "Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag"); 
1867                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1868                         
1869                         /* Only show the do-force-local toggle if force is requested */
1870                         if (ia->flag & (ACT_IPOFORCE|ACT_IPOADD)) {
1871                                 uiDefButBitS(block, TOG, ACT_IPOLOCAL, 0, 
1872                                         "L", xco+width-30, yco-24, 20, 19, 
1873                                         &ia->flag, 0, 0, 0, 0, 
1874                                         "Let the ipo acts in local coordinates, used in Force and Add mode."); 
1875                         }
1876
1877                         if(ia->type==ACT_IPO_FROM_PROP) {
1878                                 uiDefBut(block, TEX, 0, 
1879                                         "Prop: ",               xco+10, yco-44, width-80, 19, 
1880                                         ia->name, 0.0, 31.0, 0, 0, 
1881                                         "Use this property to define the Ipo position");
1882                         }
1883                         else {
1884                                 uiDefButI(block, NUM, 0, 
1885                                         "Sta",          xco+10, yco-44, (width-80)/2, 19, 
1886                                         &ia->sta, 0.0, MAXFRAMEF, 0, 0, 
1887                                         "Start frame, (subtract 1 to match blenders frame numbers)");
1888                                 uiDefButI(block, NUM, 0, 
1889                                         "End",          xco+10+(width-80)/2, yco-44, (width-80)/2, 19, 
1890                                         &ia->end, 0.0, MAXFRAMEF, 0, 0, 
1891                                         "End frame, (subtract 1 to match blenders frame numbers)");
1892                         }
1893                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
1894                                 "Child",        xco+10+(width-80), yco-44, 60, 19, 
1895                                 &ia->flag, 0, 0, 0, 0, 
1896                                 "Update IPO on all children Objects as well");
1897
1898                         yco-= ysize;
1899                         break;
1900                 }
1901         case ACT_PROPERTY:
1902                 {
1903                         ysize= 68;
1904                         
1905                         glRects(xco, yco-ysize, xco+width, yco);
1906                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1907                         
1908                         pa= act->data;
1909                         
1910                         str= "Type   %t|Assign   %x0|Add %x1|Copy %x2";
1911                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
1912                         
1913                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
1914                         
1915                         if(pa->type==ACT_PROP_COPY) {
1916                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
1917                                 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");
1918                         }
1919                         else {
1920                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-64,width-60, 19, pa->value, 0, 31, 0, 0, "change with this value");
1921                         }
1922                         yco-= ysize;
1923                         
1924                         break;
1925                 }
1926     case ACT_SOUND:
1927                 {
1928                         ysize = 70;
1929                         
1930                         sa = act->data;
1931                         sa->sndnr = 0;
1932                         
1933                         wval = (width-20)/2;
1934                         glRects(xco, yco-ysize, xco+width, yco);
1935                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1936                         
1937                         if(G.main->sound.first) {
1938                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(G.main->sound), (ID *)sa->sound, &(sa->sndnr));
1939                                 /* reset this value, it is for handling the event */
1940                                 sa->sndnr = 0;
1941                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
1942
1943                                 if(sa->sound) {
1944                                         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";
1945                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
1946                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
1947                                         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");
1948                                         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");
1949                                 }
1950                                 MEM_freeN(str);
1951                         } 
1952                         else {
1953                                 uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
1954                         }
1955                                         
1956                         yco-= ysize;
1957                         
1958                         break;
1959                 }
1960         case ACT_CD:
1961                 {
1962                         char cd_type_str[] = "Sound mode %t|Play all tracks %x0|Play one track %x1|"
1963                                 "Volume %x3|Stop %x4|Pause %x5|Resume %x6";
1964                         cda = act->data;
1965
1966                         if (cda) {
1967                                 if (cda->track == 0) {
1968                                         cda->track = 1;
1969                                         cda->volume = 1;
1970                                         cda->type = ACT_CD_PLAY_ALL;
1971                                 }
1972                                 
1973                                 if (cda->type == ACT_CD_PLAY_TRACK || cda->type == ACT_CD_LOOP_TRACK) {
1974                                         ysize = 48;
1975                                         glRects(xco, yco-ysize, xco+width, yco);
1976                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1977                                         uiDefButS(block, NUM, 0, "Track:", xco+10,yco-44,width-20, 19, &cda->track, 1, 99, 0, 0, "Select the track to be played");
1978                                 }
1979                                 else if (cda->type == ACT_CD_VOLUME) {
1980                                         ysize = 48;
1981                                         glRects(xco, yco-ysize, xco+width, yco);
1982                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1983                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-44,width-20, 19, &cda->volume, 0, 1, 0, 0, "Set the volume for CD playback");
1984                                 }
1985                                 else {
1986                                         ysize = 28;
1987                                         glRects(xco, yco-ysize, xco+width, yco);
1988                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1989                                 }
1990                                 uiDefButS(block, MENU, B_REDR, cd_type_str,xco+10,yco-22,width-20, 19, &cda->type, 0.0, 0.0, 0, 0, "");
1991                         }
1992                         yco-= ysize;
1993                         break;
1994                 }
1995         case ACT_CAMERA:
1996
1997                 ysize= 48;
1998         
1999                 glRects(xco, yco-ysize, xco+width, yco);
2000                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2001                 
2002                 ca= act->data;
2003         
2004                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
2005                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
2006                 
2007                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
2008                 
2009                 if(ca->axis==0) ca->axis= 'x';
2010                 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");
2011                 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");
2012                 
2013                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
2014
2015                 yco-= ysize;
2016         
2017          break;
2018                                 
2019         case ACT_EDIT_OBJECT:
2020                 
2021                 eoa= act->data;
2022
2023                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
2024                         int wval; /* just a temp width */
2025                         ysize = 72;
2026                         glRects(xco, yco-ysize, xco+width, yco);
2027                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2028          
2029                         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)");
2030                         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");
2031
2032                         wval= (width-60)/3;
2033                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
2034                                          NULL, 0, 0, 0, 0,
2035                                          "Velocity upon creation.");
2036                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
2037                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
2038                                          "Velocity upon creation, x component.");
2039                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
2040                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
2041                                          "Velocity upon creation, y component.");
2042                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
2043                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
2044                                          "Velocity upon creation, z component.");
2045                         uiDefButBitS(block, TOG, 2, 0, "L", xco+45+3*wval, yco-68, 15, 19,
2046                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2047                                          "Apply the transformation locally");
2048
2049                 }
2050                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
2051                         ysize= 28;
2052                         glRects(xco, yco-ysize, xco+width, yco);
2053                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2054                 }
2055                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
2056                         ysize= 48;
2057                         glRects(xco, yco-ysize, xco+width, yco);
2058                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2059          
2060                         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");
2061                 }
2062                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
2063                         ysize= 48;
2064                         glRects(xco, yco-ysize, xco+width, yco);
2065                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2066          
2067                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
2068                         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");
2069                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
2070                 }
2071                 else if(eoa->type==ACT_EDOB_DYNAMICS) {
2072                         ysize= 48;
2073                         glRects(xco, yco-ysize, xco+width, yco);
2074                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2075                         
2076                         str= "Dynamic Operation %t|Restore Dynamics %x0|Suspend Dynamics %x1|Enable Rigid Body %x2|Disable Rigid Body %x3";
2077                         uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-44, (width-80), 19,  &(eoa->dyn_operation), 0.0, 0.0, 0, 0, "");
2078                 }
2079                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3|Dynamics %x4";
2080                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
2081
2082                 yco-= ysize;
2083         
2084         break;
2085  
2086         case ACT_CONSTRAINT:
2087                 coa= act->data;
2088         
2089                 if (coa->type == ACT_CONST_TYPE_LOC) {
2090                         ysize= 69;
2091         
2092                         glRects(xco, yco-ysize, xco+width, yco);
2093                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2094                         
2095         /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
2096         /*                      coa->flag &= ~(63); */
2097                         str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
2098                         coa->flag &= ~(7);
2099                         coa->time = 0;
2100                         uiDefButS(block, MENU, 1, str,          xco+10, yco-65, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
2101                 
2102                         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");
2103                         uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2104                         uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2105
2106                         if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
2107                         else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
2108                         else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
2109                         else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
2110                         else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
2111                         else fp= coa->minrot+2;
2112                         
2113                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
2114                         uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-65, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
2115                 } else if (coa->type == ACT_CONST_TYPE_DIST) {
2116                         ysize= 106;
2117
2118                         glRects(xco, yco-ysize, xco+width, yco);
2119                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2120                         
2121                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2122                         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");
2123                 
2124                         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");
2125                         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");
2126                         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");
2127
2128                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2129                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2130                         else fp= coa->minloc+2;
2131
2132                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/2, 19, fp+3, 0.0, 2000.0, 10, 0, "Maximum length of ray");
2133                         if (coa->flag & ACT_CONST_DISTANCE)
2134                                 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");
2135                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2136                                          &coa->flag, 0.0, 0.0, 0, 0, "Set object axis along the normal at hit position");
2137                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2138                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2139                         if (coa->flag & ACT_CONST_MATERIAL)
2140                         {
2141                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2142                                         coa->matprop, 0, 31, 0, 0,
2143                                         "Ray detects only Objects with this material");
2144                         }
2145                         else
2146                         {
2147                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2148                                         coa->matprop, 0, 31, 0, 0,
2149                                         "Ray detect only Objects with this property");
2150                         }
2151                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2152                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2153                         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");
2154                         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");
2155                 } else if (coa->type == ACT_CONST_TYPE_ORI) {
2156                         ysize= 87;
2157
2158                         glRects(xco, yco-ysize, xco+width, yco);
2159                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2160                         
2161                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4";
2162                         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");
2163                 
2164                         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");
2165                         uiDefBut(block, LABEL,                  0, "X", xco+80, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2166                         uiDefBut(block, LABEL,                  0, "Y", xco+80+(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2167                         uiDefBut(block, LABEL,                  0, "Z", xco+80+2*(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2168
2169                         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");
2170                         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");
2171                         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");
2172
2173                         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");
2174                         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");
2175                         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");
2176                 }
2177                 str= "Constraint Type %t|Location %x0|Distance %x1|Orientation %x2";
2178                 but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &coa->type, 0.0, 0.0, 0, 0, "");
2179                 yco-= ysize;
2180         break;
2181  
2182         case ACT_SCENE:
2183                 sca= act->data; 
2184                 
2185                 if(sca->type==ACT_SCENE_RESTART) { 
2186                         ysize= 28; 
2187                         glRects(xco, yco-ysize, xco+width, yco); 
2188                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2189                 } 
2190                 else if(sca->type==ACT_SCENE_CAMERA) { 
2191                         
2192                         ysize= 48; 
2193                         glRects(xco, yco-ysize, xco+width, yco); 
2194                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2195          
2196                         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"); 
2197                 } 
2198                 else if(sca->type==ACT_SCENE_SET) { 
2199                         
2200                         ysize= 48; 
2201                         glRects(xco, yco-ysize, xco+width, yco); 
2202                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2203         
2204                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene"); 
2205                 } 
2206                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
2207                         
2208                         ysize= 48; 
2209                         glRects(xco, yco-ysize, xco+width, yco); 
2210                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2211         
2212                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene"); 
2213                 } 
2214                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
2215                         
2216                         ysize= 48; 
2217                         glRects(xco, yco-ysize, xco+width, yco); 
2218                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2219         
2220                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene"); 
2221                 } 
2222                 else if(sca->type==ACT_SCENE_REMOVE) { 
2223                         
2224                         ysize= 48; 
2225                         glRects(xco, yco-ysize, xco+width, yco); 
2226                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2227         
2228                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
2229                 } 
2230                 else if(sca->type==ACT_SCENE_SUSPEND) { 
2231                         
2232                         ysize= 48; 
2233                         glRects(xco, yco-ysize, xco+width, yco); 
2234                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2235         
2236                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
2237                 } 
2238                 else if(sca->type==ACT_SCENE_RESUME) { 
2239                         
2240                         ysize= 48; 
2241                         glRects(xco, yco-ysize, xco+width, yco); 
2242                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2243         
2244                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
2245                 } 
2246
2247                 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";
2248                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
2249
2250                 yco-= ysize; 
2251                 break; 
2252         case ACT_GAME:
2253                 {
2254                         gma = act->data; 
2255                         if (gma->type == ACT_GAME_LOAD)
2256                         {
2257                                 //ysize = 68;
2258                                 ysize = 48;
2259                                 glRects(xco, yco-ysize, xco+width, yco); 
2260                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2261                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2262 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2263                         }
2264 /*                      else if (gma->type == ACT_GAME_START)
2265                         {
2266                                 ysize = 68; 
2267                                 glRects(xco, yco-ysize, xco+width, yco); 
2268                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2269
2270                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2271                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2272                         }
2273 */                      else if (gma->type == ACT_GAME_RESTART)
2274                         {
2275                                 ysize = 28; 
2276                                 glRects(xco, yco-ysize, xco+width, yco); 
2277                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2278                         }
2279                         else if (gma->type == ACT_GAME_QUIT)
2280                         {
2281                                 ysize = 28; 
2282                                 glRects(xco, yco-ysize, xco+width, yco); 
2283                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2284                         }
2285
2286                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
2287                         str = "Scene %t|Start new game%x0|Restart this game%x2|Quit this game %x3";
2288                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
2289                         
2290                         yco -= ysize; 
2291                         break; 
2292                 }
2293         case ACT_GROUP:
2294                 ga= act->data;
2295
2296                 ysize= 52;
2297
2298                 glRects(xco, yco-ysize, xco+width, yco);
2299                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2300                 
2301                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
2302
2303                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
2304                 if(ga->type==ACT_GROUP_SET) {
2305                         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");
2306                         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");
2307                 }
2308                 else if(ga->type==ACT_GROUP_FROM_PROP) {
2309                         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");
2310                 }
2311                 else {
2312                         uiDefButI(block, NUM, 0, "State",               xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
2313                         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");
2314                 }
2315                 yco-= ysize;
2316                 break;
2317
2318         case ACT_VISIBILITY:
2319                 ysize = 24;
2320
2321                 glRects(xco, yco-ysize, xco+width, yco);
2322                 uiEmboss((float)xco,
2323                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2324                 
2325                 visAct = act->data;
2326
2327                 str= "Visibility %t|Visible %x0|Invisible %x1";
2328
2329                 uiDefButI(block, MENU, B_REDR, str,
2330                           xco + 10, yco - 24, width - 20, 19, &visAct->flag,
2331                           0.0, 0.0, 0, 0,
2332                           "Make the object invisible or visible.");
2333 /*
2334                 uiDefButBitI(block, TOG, ACT_VISIBILITY_INVISIBLE, 0,
2335                           "Invisible",
2336                           xco + 10, yco - 24, width - 20, 19, &visAct->flag,
2337                           0.0, 0.0, 0, 0,
2338                           "Make the object invisible or visible.");
2339 */
2340                 yco-= ysize;
2341
2342                 break;
2343                 
2344         case ACT_STATE:
2345                 ysize = 34;
2346
2347                 glRects(xco, yco-ysize, xco+width, yco);
2348                 uiEmboss((float)xco,
2349                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2350                 
2351                 staAct = act->data;
2352
2353                 str= "Operation %t|Cpy %x0|Add %x1|Sub %x2|Inv %x3";
2354
2355                 uiDefButI(block, MENU, B_REDR, str,
2356                           xco + 10, yco - 24, 65, 19, &staAct->type,
2357                           0.0, 0.0, 0, 0,
2358                           "Select the bit operation on object state mask");
2359
2360                 for (wval=0; wval<15; wval+=5) {
2361                         uiBlockBeginAlign(block);
2362                         for (stbit=0; stbit<5; stbit++) {
2363                                 uiDefButBitI(block, TOG, (1<<(stbit+wval)), 0, "",      (short)(xco+85+12*stbit+13*wval), yco-17, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(wval+stbit)));
2364                         }
2365                         for (stbit=0; stbit<5; stbit++) {
2366                                 uiDefButBitI(block, TOG, (1<<(stbit+wval+15)), 0, "",   (short)(xco+85+12*stbit+13*wval), yco-29, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(wval+stbit+15)));
2367                         }
2368                 }
2369                 uiBlockEndAlign(block);
2370
2371                 yco-= ysize;
2372
2373                 break;
2374
2375         case ACT_RANDOM:
2376                 ysize  = 69;
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                 randAct = act->data;
2383
2384                 /* 1. seed */
2385                 uiDefButI(block, NUM, 1, "Seed: ",              (xco+10),yco-24, 0.4 *(width-20), 19,
2386                                  &randAct->seed, 0, 1000, 0, 0,
2387                                  "Initial seed of the random generator. Use Python for more freedom. "
2388                                  " (Choose 0 for not random)");
2389
2390                 /* 2. distribution type */
2391                 /* One pick per distribution. These numbers MUST match the #defines  */
2392                 /* in game.h !!!                                                     */
2393                 str= "Distribution %t|Bool Constant %x0|Bool Uniform %x1"
2394                         "|Bool Bernoulli %x2|Int Constant %x3|Int Uniform %x4"
2395                         "|Int Poisson %x5|Float Constant %x6|Float Uniform %x7"
2396                         "|Float Normal %x8|Float Neg. Exp. %x9";
2397                 uiDefButI(block, MENU, B_REDR, str, (xco+10) + 0.4 * (width-20), yco-24, 0.6 * (width-20), 19,
2398                                  &randAct->distribution, 0.0, 0.0, 0, 0,
2399                                  "Choose the type of distribution");
2400
2401                 /* 3. property */
2402                 uiDefBut(block, TEX, 1, "Property:", (xco+10), yco-44, (width-20), 19,
2403                                  &randAct->propname, 0, 31, 0, 0,
2404                                  "Assign the random value to this property"); 
2405
2406                 /*4. and 5. arguments for the distribution*/
2407                 switch (randAct->distribution) {
2408                 case ACT_RANDOM_BOOL_CONST:
2409                         uiDefButBitI(block, TOG, 1, 1, "Always true", (xco+10), yco-64, (width-20), 19,
2410                                          &randAct->int_arg_1, 2.0, 1, 0, 0,
2411                                          "Always false or always true");                        
2412                         break;
2413                 case ACT_RANDOM_BOOL_UNIFORM:
2414                         uiDefBut(block, LABEL, 0, "     Do a 50-50 pick.",      (xco+10), yco-64, (width-20), 19,
2415                                          NULL, 0, 0, 0, 0,
2416                                          "Choose between true and false, 50% chance each.");
2417                         break;
2418                 case ACT_RANDOM_BOOL_BERNOUILLI:
2419                         uiDefButF(block, NUM, 1, "Chance", (xco+10), yco-64, (width-20), 19,
2420                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2421                                          "Pick a number between 0 and 1. Success if you stay "
2422                                          "below this value");                   
2423                         break;
2424                 case ACT_RANDOM_INT_CONST:
2425                         uiDefButI(block, NUM, 1, "Value: ",             (xco+10), yco-64, (width-20), 19,
2426                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2427                                          "Always return this number");
2428                         break;
2429                 case ACT_RANDOM_INT_UNIFORM:
2430                         uiDefButI(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2431                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2432                                          "Choose a number from a range. "
2433                                          "Lower boundary of the range.");
2434                         uiDefButI(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2435                                          &randAct->int_arg_2, -1000, 1000, 0, 0,
2436                                          "Choose a number from a range. "
2437                                          "Upper boundary of the range.");
2438                         break;
2439                 case ACT_RANDOM_INT_POISSON:
2440                         uiDefButF(block, NUM, 1, "Mean: ", (xco+10), yco-64, (width-20), 19,
2441                                          &randAct->float_arg_1, 0.01, 100.0, 0, 0,
2442                                          "Expected mean value of the distribution.");                                           
2443                         break;
2444                 case ACT_RANDOM_FLOAT_CONST:
2445                         uiDefButF(block, NUM, 1, "Value: ", (xco+10), yco-64, (width-20), 19,
2446                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2447                                          "Always return this number");
2448                         break;
2449                 case ACT_RANDOM_FLOAT_UNIFORM:
2450                         uiDefButF(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2451                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2452                                          "Choose a number from a range. "
2453                                          "Lower boundary of the range.");
2454                         uiDefButF(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2455                                          &randAct->float_arg_2, -10000.0, 10000.0, 0, 0,
2456                                          "Choose a number from a range. "
2457                                          "Upper boundary of the range.");
2458                         break;
2459                 case ACT_RANDOM_FLOAT_NORMAL:
2460                         uiDefButF(block, NUM, 1, "Mean: ",              (xco+10), yco-64, (width-20)/2, 19,
2461                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2462                                          "A normal distribution. Mean of the distribution.");
2463                         uiDefButF(block, NUM, 1, "SD: ",                (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2464                                          &randAct->float_arg_2, 0.0, 10000.0, 0, 0,
2465                                          "A normal distribution. Standard deviation of the "
2466                                          "distribution.");
2467                         break;
2468                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
2469                         uiDefButF(block, NUM, 1, "Half-life time: ", (xco+10), yco-64, (width-20), 19,
2470                                          &randAct->float_arg_1, 0.001, 10000.0, 0, 0,
2471                                          "Negative exponential dropoff.");
2472                         break;
2473                 default:
2474                         ; /* don't know what this distro is... can be useful for testing */
2475                         /* though :)                                                     */
2476                 }
2477
2478                 yco-= ysize;
2479                 break;
2480         case ACT_MESSAGE:
2481                 ma = act->data;
2482
2483 #define MESSAGE_SENSOR_TO_FIELD_WORKS   /* Really?  Not really.  Don't remove this ifdef yet */
2484
2485 #ifdef MESSAGE_SENSOR_TO_FIELD_WORKS
2486                 ysize = 4 + (3 * 24); /* footer + number of lines * 24 pixels/line */
2487 #else
2488                 ysize = 4 + (2 * 24); /* footer + number of lines * 24 pixels/line */
2489 #endif
2490                 glRects(xco, yco-ysize, xco+width, yco);
2491                 uiEmboss((float)xco,        (float)yco-ysize,
2492                                  (float)xco+width,  (float)yco, 1);
2493
2494                 myline=1;
2495
2496
2497 #ifdef MESSAGE_SENSOR_TO_FIELD_WORKS
2498                 /* line 1: To */
2499                 uiDefBut(block, TEX, 1, "To: ",
2500                         (xco+10), (yco-(myline++*24)), (width-20), 19,
2501                         &ma->toPropName, 0, 31, 0, 0,
2502                         "Optional send message to objects with this name only (Prefix name with OB)"
2503                         ", or empty to broadcast");
2504
2505 #endif
2506
2507                 /* line 2: Message Subject */
2508                 uiDefBut(block, TEX, 1, "Subject: ",
2509                 (xco+10), (yco-(myline++*24)), (width-20), 19,
2510                 &ma->subject, 0, 31, 0, 0,
2511                 "Optional message subject. This is what can be filtered on.");
2512
2513                 /* line 3: Text/Property */
2514                 uiDefButBitS(block, TOG, 1, B_REDR, "T/P",
2515                         (xco+10),(yco-(myline*24)), (0.20 * (width-20)), 19,
2516                         &ma->bodyType, 0.0, 0.0, 0, 0,
2517                         "Toggle message type: either Text or a PropertyName.");
2518
2519                 if (ma->bodyType == ACT_MESG_MESG)
2520                 {
2521                 /* line 3: Message Body */
2522                 uiDefBut(block, TEX, 1, "Body: ",
2523                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2524                 &ma->body, 0, 31, 0, 0,
2525                 "Optional message body Text");
2526                 } else
2527                 {
2528                         /* line 3: Property body (set by property) */
2529                         uiDefBut(block, TEX, 1, "Propname: ",
2530                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2531                         &ma->body, 0, 31, 0, 0,
2532                         "The message body will be set by the Property Value");
2533                 }
2534                 
2535                 yco -= ysize;
2536                 break;
2537         case ACT_2DFILTER:
2538                 tdfa = act->data;
2539
2540                 ysize = 50;
2541                 if(tdfa->type == ACT_2DFILTER_CUSTOMFILTER)
2542                 {
2543                         ysize +=20;
2544                 }
2545         glRects( xco, yco-ysize, xco+width, yco ); 
2546                 uiEmboss( (float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1 );
2547
2548                 switch(tdfa->type)
2549                 {
2550                         case ACT_2DFILTER_MOTIONBLUR:
2551                                 if(!tdfa->flag)
2552                                 {
2553                                         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");
2554                                         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");
2555                                 }
2556                                 else
2557                                 {
2558                                         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");
2559                                 }
2560                                 break;
2561                         case ACT_2DFILTER_BLUR:
2562                         case ACT_2DFILTER_SHARPEN:
2563                         case ACT_2DFILTER_DILATION:
2564                         case ACT_2DFILTER_EROSION:
2565                         case ACT_2DFILTER_LAPLACIAN:
2566                         case ACT_2DFILTER_SOBEL:
2567                         case ACT_2DFILTER_PREWITT:
2568                         case ACT_2DFILTER_GRAYSCALE:
2569                         case ACT_2DFILTER_SEPIA:
2570                         case ACT_2DFILTER_INVERT:
2571                         case ACT_2DFILTER_NOFILTER:
2572                         case ACT_2DFILTER_DISABLED:
2573                         case ACT_2DFILTER_ENABLED:
2574                                 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");
2575                                 break;
2576                         case ACT_2DFILTER_CUSTOMFILTER:
2577                                 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");
2578                                 uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Script: ", xco+30,yco-64,width-60, 19, &tdfa->text, "");
2579                                 break;
2580                 }
2581                 
2582                 str= "2D Filter   %t|Motion Blur   %x1|Blur %x2|Sharpen %x3|Dilation %x4|Erosion %x5|"
2583                                 "Laplacian %x6|Sobel %x7|Prewitt %x8|Gray Scale %x9|Sepia %x10|Invert %x11|Custom Filter %x12|"
2584                                 "Enable Filter %x-2|Disable Filter %x-1|Remove Filter %x0|";
2585                 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");
2586                 
2587                 yco -= ysize;
2588         break;
2589         case ACT_PARENT:
2590                 parAct = act->data; 
2591
2592                 if(parAct->type==ACT_PARENT_SET) { 
2593                         
2594                         ysize= 48; 
2595                         glRects(xco, yco-ysize, xco+width, yco); 
2596                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2597          
2598                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+40, yco-44, (width-80), 19, &(parAct->ob), "Set this object as parent"); 
2599                 }
2600                 else if(parAct->type==ACT_PARENT_REMOVE) { 
2601                         
2602                         ysize= 28; 
2603                         glRects(xco, yco-ysize, xco+width, yco); 
2604                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2605                 }
2606
2607                 str= "Parent %t|Set Parent %x0|Remove Parent %x1";
2608                 uiDefButI(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &parAct->type, 0.0, 0.0, 0, 0, ""); 
2609
2610                 yco-= ysize; 
2611                 break; 
2612         default:
2613                 ysize= 4;
2614
2615                 glRects(xco, yco-ysize, xco+width, yco);
2616                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2617                 
2618                 yco-= ysize;
2619                 break;
2620         }
2621
2622         uiBlockSetEmboss(block, UI_EMBOSSM);
2623
2624         return yco-4;
2625 }
2626
2627 static void do_sensor_menu(void *arg, int event)
2628 {       
2629         ID **idar;
2630         Object *ob;
2631         bSensor *sens;
2632         short count, a;
2633         
2634         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2635         
2636         for(a=0; a<count; a++) {
2637                 ob= (Object *)idar[a];
2638                 if(event==0 || event==2) ob->scaflag |= OB_SHOWSENS;
2639                 else if(event==1) ob->scaflag &= ~OB_SHOWSENS;
2640         }
2641                 
2642         for(a=0; a<count; a++) {
2643                 ob= (Object *)idar[a];
2644                 sens= ob->sensors.first;
2645                 while(sens) {
2646                         if(event==2) sens->flag |= SENS_SHOW;
2647                         else if(event==3) sens->flag &= ~SENS_SHOW;
2648                         sens= sens->next;
2649                 }
2650         }
2651
2652         if(idar) MEM_freeN(idar);
2653         allqueue(REDRAWBUTSLOGIC, 0);
2654 }
2655
2656 static uiBlock *sensor_menu(void *arg_unused)
2657 {
2658         uiBlock *block;
2659         int yco=0;
2660         
2661         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2662         uiBlockSetButmFunc(block, do_sensor_menu, NULL);
2663         
2664         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2665         uiDefBut(block, BUTM, 1, "Hide Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2666         uiDefBut(block, SEPR, 0, "",    0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2667         uiDefBut(block, BUTM, 1, "Show Sensors",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
2668         uiDefBut(block, BUTM, 1, "Hide Sensors",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
2669
2670         uiBlockSetDirection(block, UI_TOP);
2671         
2672         return block;
2673 }
2674
2675 static void do_controller_menu(void *arg, int event)
2676 {       
2677         ID **idar;
2678         Object *ob;
2679         bController *cont;
2680         short count, a;
2681         
2682         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2683         
2684         for(a=0; a<count; a++) {
2685                 ob= (Object *)idar[a];
2686                 if(event==0 || event==2) ob->scaflag |= OB_SHOWCONT;
2687                 else if(event==1) ob->scaflag &= ~OB_SHOWCONT;
2688         }
2689
2690         for(a=0; a<count; a++) {
2691                 ob= (Object *)idar[a];
2692                 cont= ob->controllers.first;
2693                 while(cont) {
2694                         if(event==2) cont->flag |= CONT_SHOW;
2695                         else if(event==3) cont->flag &= ~CONT_SHOW;
2696                         cont= cont->next;
2697                 }
2698         }
2699
2700         if(idar) MEM_freeN(idar);
2701         allqueue(REDRAWBUTSLOGIC, 0);
2702 }
2703
2704 static uiBlock *controller_menu(void *arg_unused)
2705 {
2706         uiBlock *block;
2707         int yco=0;
2708         
2709         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2710         uiBlockSetButmFunc(block, do_controller_menu, NULL);
2711         
2712         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2713         uiDefBut(block, BUTM, 1, "Hide Objects",        0,(short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2714         uiDefBut(block, SEPR, 0, "",                                    0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2715         uiDefBut(block, BUTM, 1, "Show Controllers",    0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 2, 2, "");
2716         uiDefBut(block, BUTM, 1, "Hide Controllers",    0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 3, 3, "");
2717
2718         uiBlockSetDirection(block, UI_TOP);
2719         
2720         return block;
2721 }
2722
2723 static void do_actuator_menu(void *arg, int event)
2724 {       
2725         ID **idar;
2726         Object *ob;
2727         bActuator *act;
2728         short count, a;
2729         
2730         idar= get_selected_and_linked_obs(&coun