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