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