BGE patch: add state engine support in the logic bricks.
[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_EXPRESSION:
744                 return "Expression";
745         case CONT_PYTHON:
746                 return "Python";
747         }
748         return "unknown";
749 }
750
751 static char *controller_pup(void)
752 {
753         return "Controllers   %t|AND %x0|OR %x1|Expression %x2|Python %x3";
754 }
755
756 static char *actuator_name(int type)
757 {
758         switch (type) {
759         case ACT_SHAPEACTION:
760                 return "Shape Action";
761         case ACT_ACTION:
762                 return "Action";
763         case ACT_OBJECT:
764                 return "Motion";
765         case ACT_IPO:
766                 return "Ipo";
767         case ACT_LAMP:
768                 return "Lamp";
769         case ACT_CAMERA:
770                 return "Camera";
771         case ACT_MATERIAL:
772                 return "Material";
773         case ACT_SOUND:
774                 return "Sound";
775         case ACT_CD:
776                 return "CD";
777         case ACT_PROPERTY:
778                 return "Property";
779         case ACT_EDIT_OBJECT:
780                 return "Edit Object";
781         case ACT_CONSTRAINT:
782                 return "Constraint";
783         case ACT_SCENE:
784                 return "Scene";
785         case ACT_GROUP:
786                 return "Group";
787         case ACT_RANDOM:
788                 return "Random";
789         case ACT_MESSAGE:
790                 return "Message";
791         case ACT_GAME:
792                 return "Game";
793         case ACT_VISIBILITY:
794                 return "Visibility";
795         case ACT_2DFILTER:
796                 return "2D Filter";
797         case ACT_PARENT:
798                 return "Parent";
799         case ACT_STATE:
800                 return "State";
801         }
802         return "unknown";
803 }
804
805
806
807
808 static char *actuator_pup(Object *owner)
809 {
810         switch (owner->type)
811         {
812         case OB_ARMATURE:
813                 return "Actuators  %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
814                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
815                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
816                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
817                 break;
818
819         case OB_MESH:
820                 return "Actuators  %t|Shape Action %x21|Motion %x0|Constraint %x9|Ipo %x1"
821                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
822                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
823                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
824                 break;
825
826         default:
827                 return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
828                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
829                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
830                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
831         }
832 }
833
834
835
836 static void set_sca_ob(Object *ob)
837 {
838         bController *cont;
839         bActuator *act;
840
841         cont= ob->controllers.first;
842         while(cont) {
843                 cont->mynew= (bController *)ob;
844                 cont= cont->next;
845         }
846         act= ob->actuators.first;
847         while(act) {
848                 act->mynew= (bActuator *)ob;
849                 act= act->next;
850         }
851 }
852
853 static ID **get_selected_and_linked_obs(short *count, short scavisflag)
854 {
855         Base *base;
856         Object *ob, *obt;
857         ID **idar;
858         bSensor *sens;
859         bController *cont;
860         unsigned int lay;
861         int a, nr, doit;
862         
863         /* we need a sorted object list */
864         /* set scavisflags flags in Objects to indicate these should be evaluated */
865         /* also hide ob pointers in ->new entries of controllerss/actuators */
866         
867         *count= 0;
868         
869         if(G.scene==NULL) return NULL;
870         
871         ob= G.main->object.first;
872         while(ob) {
873                 ob->scavisflag= 0;
874                 set_sca_ob(ob);
875                 ob= ob->id.next;
876         }
877         
878         if(G.vd) lay= G.vd->lay;
879         else lay= G.scene->lay;
880         
881         base= FIRSTBASE;
882         while(base) {
883                 if(base->lay & lay) {
884                         if(base->flag & SELECT) {
885                                 if(scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
886                                 if(scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
887                                 if(scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
888                         }
889                 }
890                 base= base->next;
891         }
892
893         if(OBACT) {
894                 if(scavisflag & BUTS_SENS_ACT) OBACT->scavisflag |= OB_VIS_SENS;
895                 if(scavisflag & BUTS_CONT_ACT) OBACT->scavisflag |= OB_VIS_CONT;
896                 if(scavisflag & BUTS_ACT_ACT) OBACT->scavisflag |= OB_VIS_ACT;
897         }
898         
899         /* BUTS_XXX_STATE are similar to BUTS_XXX_LINK for selecting the object */
900         if(scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK|BUTS_SENS_STATE|BUTS_ACT_STATE)) {
901                 doit= 1;
902                 while(doit) {
903                         doit= 0;
904                         
905                         ob= G.main->object.first;
906                         while(ob) {
907                         
908                                 /* 1st case: select sensor when controller selected */
909                                 if((scavisflag & (BUTS_SENS_LINK|BUTS_SENS_STATE)) && (ob->scavisflag & OB_VIS_SENS)==0) {
910                                         sens= ob->sensors.first;
911                                         while(sens) {
912                                                 for(a=0; a<sens->totlinks; a++) {
913                                                         if(sens->links[a]) {
914                                                                 obt= (Object *)sens->links[a]->mynew;
915                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)) {
916                                                                         doit= 1;
917                                                                         ob->scavisflag |= OB_VIS_SENS;
918                                                                         break;
919                                                                 }
920                                                         }
921                                                 }
922                                                 if(doit) break;
923                                                 sens= sens->next;
924                                         }
925                                 }
926                                 
927                                 /* 2nd case: select cont when act selected */
928                                 if((scavisflag & BUTS_CONT_LINK)  && (ob->scavisflag & OB_VIS_CONT)==0) {
929                                         cont= ob->controllers.first;
930                                         while(cont) {
931                                                 for(a=0; a<cont->totlinks; a++) {
932                                                         if(cont->links[a]) {
933                                                                 obt= (Object *)cont->links[a]->mynew;
934                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)) {
935                                                                         doit= 1;
936                                                                         ob->scavisflag |= OB_VIS_CONT;
937                                                                         break;
938                                                                 }
939                                                         }
940                                                 }
941                                                 if(doit) break;
942                                                 cont= cont->next;
943                                         }
944                                 }
945                                 
946                                 /* 3rd case: select controller when sensor selected */
947                                 if((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
948                                         sens= ob->sensors.first;
949                                         while(sens) {
950                                                 for(a=0; a<sens->totlinks; a++) {
951                                                         if(sens->links[a]) {
952                                                                 obt= (Object *)sens->links[a]->mynew;
953                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)==0) {
954                                                                         doit= 1;
955                                                                         obt->scavisflag |= OB_VIS_CONT;
956                                                                 }
957                                                         }
958                                                 }
959                                                 sens= sens->next;
960                                         }
961                                 }
962                                 
963                                 /* 4th case: select actuator when controller selected */
964                                 if( (scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE))  && (ob->scavisflag & OB_VIS_CONT)) {
965                                         cont= ob->controllers.first;
966                                         while(cont) {
967                                                 for(a=0; a<cont->totlinks; a++) {
968                                                         if(cont->links[a]) {
969                                                                 obt= (Object *)cont->links[a]->mynew;
970                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)==0) {
971                                                                         doit= 1;
972                                                                         obt->scavisflag |= OB_VIS_ACT;
973                                                                 }
974                                                         }
975                                                 }
976                                                 cont= cont->next;
977                                         }
978                                         
979                                 }
980                                 ob= ob->id.next;
981                         }
982                 }
983         } 
984         
985         /* now we count */
986         ob= G.main->object.first;
987         while(ob) {
988                 if( ob->scavisflag ) (*count)++;
989                 ob= ob->id.next;
990         }
991
992         if(*count==0) return NULL;
993         if(*count>24) *count= 24;               /* temporal */
994         
995         idar= MEM_callocN( (*count)*sizeof(void *), "idar");
996         
997         ob= G.main->object.first;
998         nr= 0;
999         while(ob) {
1000                 if( ob->scavisflag ) {
1001                         idar[nr]= (ID *)ob;
1002                         nr++;
1003                 }
1004                 if(nr>=24) break;
1005                 ob= ob->id.next;
1006         }
1007         
1008         /* just to be sure... these were set in set_sca_done_ob() */
1009         clear_sca_new_poins();
1010         
1011         return idar;
1012 }
1013
1014
1015 static int get_col_sensor(int type)
1016 {
1017         switch(type) {
1018         case SENS_ALWAYS:               return TH_BUT_ACTION;
1019         case SENS_TOUCH:                return TH_BUT_NEUTRAL;
1020         case SENS_COLLISION:    return TH_BUT_SETTING;
1021         case SENS_NEAR:                 return TH_BUT_SETTING1; 
1022         case SENS_KEYBOARD:             return TH_BUT_SETTING2;
1023         case SENS_PROPERTY:             return TH_BUT_NUM;
1024         case SENS_MOUSE:                return TH_BUT_TEXTFIELD;
1025         case SENS_RADAR:                return TH_BUT_POPUP;
1026         case SENS_RANDOM:               return TH_BUT_NEUTRAL;
1027         case SENS_RAY:                  return TH_BUT_SETTING1;
1028         case SENS_MESSAGE:              return TH_BUT_SETTING2;
1029         case SENS_JOYSTICK:             return TH_BUT_NEUTRAL;
1030         default:                                return TH_BUT_NEUTRAL;
1031         }
1032 }
1033 static void set_col_sensor(int type, int medium)
1034 {
1035         int col= get_col_sensor(type);
1036         BIF_ThemeColorShade(col, medium?30:0);
1037 }
1038
1039 /**
1040  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
1041  * the value of this sensor. Operates on the shared data block of sensors.
1042  */
1043 static void draw_default_sensor_header(bSensor *sens,
1044                                                                 uiBlock *block,
1045                                                                 short x,
1046                                                                 short y,
1047                                                                 short w) 
1048 {
1049         /* Pulsing and frequency */
1050         uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP,
1051                          (short)(x + 10 + 0. * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
1052                          &sens->pulse, 0.0, 0.0, 0, 0,
1053                          "Activate TRUE level triggering (pulse mode)");
1054
1055         uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN,
1056                          (short)(x + 10 + 0.15 * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
1057                          &sens->pulse, 0.0, 0.0, 0, 0,
1058                          "Activate FALSE level triggering (pulse mode)");
1059         uiDefButS(block, NUM, 1, "f:",
1060                          (short)(x + 10 + 0.3 * (w-20)), (short)(y - 19), (short)(0.275 * (w-20)), 19,
1061                          &sens->freq, 0.0, 10000.0, 0, 0,
1062                          "Delay between repeated pulses (in logic tics, 0 = no delay)");
1063         
1064         /* value or shift? */
1065         uiDefButS(block, TOG, 1, "Inv",
1066                          (short)(x + 10 + 0.85 * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
1067                          &sens->invert, 0.0, 0.0, 0, 0,
1068                          "Invert the level (output) of this sensor");
1069 }
1070
1071 static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
1072 {
1073         bNearSensor      *ns           = NULL;
1074         bTouchSensor     *ts           = NULL;
1075         bKeyboardSensor  *ks           = NULL;
1076         bPropertySensor  *ps           = NULL;
1077         bMouseSensor     *ms           = NULL;
1078         bCollisionSensor *cs           = NULL;
1079         bRadarSensor     *rs           = NULL;
1080         bRandomSensor    *randomSensor = NULL;
1081         bRaySensor       *raySens      = NULL;
1082         bMessageSensor   *mes          = NULL;
1083         bJoystickSensor  *joy              = NULL;
1084
1085         short ysize;
1086         char *str;
1087         
1088         /* yco is at the top of the rect, draw downwards */
1089         
1090         uiBlockSetEmboss(block, UI_EMBOSSM);
1091         
1092         set_col_sensor(sens->type, 0);
1093         
1094         switch (sens->type)
1095         {
1096         case SENS_ALWAYS:
1097                 {
1098                         ysize= 24;
1099                         
1100                         glRects(xco, yco-ysize, xco+width, yco);
1101                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1102                         
1103                         draw_default_sensor_header(sens, block, xco, yco, width);
1104                         
1105                         yco-= ysize;
1106                         
1107                         break;
1108                 }
1109         case SENS_TOUCH:
1110                 {
1111                         ysize= 48; 
1112                         
1113                         glRects(xco, yco-ysize, xco+width, yco); 
1114                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1115                         
1116                         draw_default_sensor_header(sens, block, xco, yco, width);
1117                         
1118                         ts= sens->data; 
1119                         
1120                         /* uiDefBut(block, TEX, 1, "Property:", xco,yco-22,width, 19, &ts->name, 0, 31, 0, 0, "Only look for Objects with this property"); */
1121                         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"); 
1122                         ///* 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"); 
1123                         yco-= ysize; 
1124                         break; 
1125                 }
1126         case SENS_COLLISION:
1127                 {
1128                         ysize= 48;
1129                         
1130                         glRects(xco, yco-ysize, xco+width, yco);
1131                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1132                         
1133                         draw_default_sensor_header(sens, block, xco, yco, width);
1134                         cs= sens->data;
1135                         
1136                         /* The collision sensor will become a generic collision (i.e. it     */
1137                         /* absorb the old touch sensor).                                     */
1138
1139                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",(short)(xco + 10),(short)(yco - 44),
1140                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1141                                 "Toggle collision on material or property.");
1142                         
1143                         if (cs->mode & SENS_COLLISION_MATERIAL) {
1144                                 uiDefBut(block, TEX, 1, "Material:", (short)(xco + 10 + 0.20 * (width-20)),
1145                                         (short)(yco-44), (short)(0.8*(width-20)), 19, &cs->materialName, 0, 31, 0, 0,
1146                                         "Only look for Objects with this material");
1147                         } else {
1148                                 uiDefBut(block, TEX, 1, "Property:", (short)(xco + 10 + 0.20 * (width-20)), (short)(yco-44),
1149                                         (short)(0.8*(width-20)), 19, &cs->name, 0, 31, 0, 0,
1150                                         "Only look for Objects with this property");
1151                         }
1152         
1153                         /*              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"); */
1154                         
1155                         yco-= ysize;
1156                         break;
1157                 }
1158         case SENS_NEAR:
1159                 {
1160                         ysize= 72;
1161                         
1162                         glRects(xco, yco-ysize, xco+width, yco);
1163                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1164                         
1165                         draw_default_sensor_header(sens, block, xco, yco, width);
1166                         ns= sens->data;
1167                         
1168                         uiDefBut(block, TEX, 1, "Property:",(short)(10+xco),(short)(yco-44), (short)(width-20), 19,
1169                                 &ns->name, 0, 31, 0, 0, "Only look for Objects with this property");
1170                         uiDefButF(block, NUM, 1, "Dist",(short)(10+xco),(short)(yco-68),(short)((width-22)/2), 19,
1171                                 &ns->dist, 0.0, 1000.0, 1000, 0, "Trigger distance");
1172                         uiDefButF(block, NUM, 1, "Reset",(short)(10+xco+(width-22)/2), (short)(yco-68), (short)((width-22)/2), 19,
1173                                 &ns->resetdist, 0.0, 1000.0, 1000, 0, "Reset distance"); 
1174                         yco-= ysize;
1175                         break;
1176                 }
1177         case SENS_RADAR:
1178                 {
1179                         ysize= 72; 
1180                         
1181                         glRects(xco, yco-ysize, xco+width, yco);
1182                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1183                         
1184                         draw_default_sensor_header(sens, block, xco, yco, width);
1185                         
1186                         rs= sens->data;
1187                         
1188                         uiDefBut(block, TEX, 1, "Prop:",
1189                                          (short)(10+xco),(short)(yco-44), (short)(0.7 * (width-20)), 19,
1190                                          &rs->name, 0, 31, 0, 0,
1191                                          "Only look for Objects with this property");
1192
1193                         str = "Type %t|+X axis %x0|+Y axis %x1|+Z axis %x2|-X axis %x3|-Y axis %x4|-Z axis %x5"; 
1194                         uiDefButS(block, MENU, B_REDR, str,
1195                                 (short)(10+xco+0.7 * (width-20)), (short)(yco-44), (short)(0.3 * (width-22)), 19,
1196                                 &rs->axis, 2.0, 31, 0, 0,
1197                                 "Specify along which axis the radar cone is cast.");
1198                                 
1199                         uiDefButF(block, NUM, 1, "Ang:",
1200                                          (short)(10+xco), (short)(yco-68), (short)((width-20)/2), 19,
1201                                          &rs->angle, 0.0, 179.9, 10, 0,
1202                                          "Opening angle of the radar cone.");
1203                         uiDefButF(block, NUM, 1, "Dist:",
1204                                          (short)(xco+10 + (width-20)/2), (short)(yco-68), (short)((width-20)/2), 19,
1205                                          &rs->range, 0.01, 10000.0, 100, 0,
1206                                          "Depth of the radar cone");
1207                         yco-= ysize;
1208                         break;
1209                 }
1210         case SENS_KEYBOARD:
1211                 {
1212                         /* 5 lines: 120 height */
1213                         ysize= 120;
1214                         
1215                         glRects(xco, yco-ysize, xco+width, yco);
1216                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1217                         
1218                         /* header line */
1219                         draw_default_sensor_header(sens, block, xco, yco, width);
1220                         ks= sens->data;
1221                         
1222                         /* line 2: hotkey and allkeys toggle */
1223                         uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
1224                         
1225                         /* line 3: two key modifyers (qual1, qual2) */
1226                         uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
1227                         uiDefKeyevtButS(block, B_DIFF, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
1228                         
1229                         /* labels for line 1 and 2 */
1230                         uiDefBut(block, LABEL, 0, "Key",          xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
1231                         uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
1232                         
1233                         /* part of line 1 */
1234                         uiBlockSetCol(block, TH_BUT_SETTING2);
1235                         uiDefButBitS(block, TOG, 1, 0, "All keys",        xco+40+(width/2), yco-44, (width/2)-50, 19,
1236                                 &ks->type, 0, 0, 0, 0, "");
1237                         
1238                         /* line 4: toggle property for string logging mode */
1239                         uiDefBut(block, TEX, 1, "LogToggle: ",
1240                                 xco+10, yco-92, (width-20), 19,
1241                                 ks->toggleName, 0, 31, 0, 0,
1242                                 "Property that indicates whether to log "
1243                                 "keystrokes as a string.");
1244                         
1245                         /* line 5: target property for string logging mode */
1246                         uiDefBut(block, TEX, 1, "Target: ",
1247                                 xco+10, yco-116, (width-20), 19,
1248                                 ks->targetName, 0, 31, 0, 0,
1249                                 "Property that receives the keystrokes in case "
1250                                 "a string is logged.");
1251                         
1252                         yco-= ysize;
1253                         break;
1254                 }
1255         case SENS_PROPERTY:
1256                 {
1257                         ysize= 96;
1258                         
1259                         glRects(xco, yco-ysize, xco+width, yco);
1260                         uiEmboss((float)xco, (float)yco-ysize,
1261                                 (float)xco+width, (float)yco, 1);
1262                         
1263                         draw_default_sensor_header(sens, block, xco, yco, width);
1264                         ps= sens->data;
1265                         
1266                         str= "Type %t|Equal %x0|Not Equal %x1|Interval %x2|Changed %x3"; 
1267                         /* str= "Type %t|Equal %x0|Not Equal %x1"; */
1268                         uiDefButI(block, MENU, B_REDR, str,                     xco+30,yco-44,width-60, 19,
1269                                 &ps->type, 0, 31, 0, 0, "Type");
1270                         
1271                         if (ps->type != SENS_PROP_EXPRESSION)
1272                         {
1273                                 uiDefBut(block, TEX, 1, "Prop: ",                       xco+30,yco-68,width-60, 19,
1274                                         ps->name, 0, 31, 0, 0,  "Property name");
1275                         }
1276                         
1277                         if(ps->type == SENS_PROP_INTERVAL)
1278                         {
1279                                 uiDefBut(block, TEX, 1, "Min: ",                xco,yco-92,width/2, 19,
1280                                         ps->value, 0, 31, 0, 0, "test for min value");
1281                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1282                                         ps->maxvalue, 0, 31, 0, 0, "test for max value");
1283                         }
1284                         else if(ps->type == SENS_PROP_CHANGED);
1285                         else
1286                         {
1287                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-92,width-60, 19,
1288                                         ps->value, 0, 31, 0, 0, "test for value");
1289                         }
1290                         
1291                         yco-= ysize;
1292                         break;
1293                 }
1294         case SENS_MOUSE:
1295                 {
1296                         ms= sens->data;
1297                         /* Two lines: 48 pixels high. */
1298                         ysize = 48;
1299                         
1300                         glRects(xco, yco-ysize, xco+width, yco);
1301                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1302                         
1303                         /* line 1: header */
1304                         draw_default_sensor_header(sens, block, xco, yco, width);
1305                         
1306                         /* Line 2: type selection. The number are a bit mangled to get
1307                         * proper compatibility with older .blend files. */
1308                         str= "Type %t|Left button %x1|Middle button %x2|"
1309                                 "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16|Mouse over any%x32"; 
1310                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, width-20, 19,
1311                                 &ms->type, 0, 31, 0, 0,
1312                                 "Specify the type of event this mouse sensor should trigger on.");
1313                         
1314                         yco-= ysize;
1315                         break;
1316                 }
1317         case SENS_RANDOM:
1318                 {
1319                         ysize = 48;
1320                         
1321                         glRects(xco, yco-ysize, xco+width, yco);
1322                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1323                         
1324                         draw_default_sensor_header(sens, block, xco, yco, width);
1325                         randomSensor = sens->data;
1326                         /* some files were wrongly written, avoid crash now */
1327                         if (randomSensor)
1328                         {
1329                                 uiDefButI(block, NUM, 1, "Seed: ",              xco+10,yco-44,(width-20), 19,
1330                                         &randomSensor->seed, 0, 1000, 0, 0,
1331                                         "Initial seed of the generator. (Choose 0 for not random)");
1332                         }
1333                         yco-= ysize;
1334                         break;
1335                 }
1336         case SENS_RAY:
1337                 {
1338                         ysize = 72;
1339                         glRects(xco, yco-ysize, xco+width, yco);
1340                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1341                         
1342                         draw_default_sensor_header(sens, block, xco, yco, width);
1343                         raySens = sens->data;
1344                         
1345                         /* 1. property or material */
1346                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",
1347                                 xco + 10,yco - 44, 0.20 * (width-20), 19,
1348                                 &raySens->mode, 0.0, 0.0, 0, 0,
1349                                 "Toggle collision on material or property.");
1350                         
1351                         if (raySens->mode & SENS_COLLISION_MATERIAL)
1352                         {
1353                                 uiDefBut(block, TEX, 1, "Material:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1354                                         &raySens->matname, 0, 31, 0, 0,
1355                                         "Only look for Objects with this material");
1356                         }
1357                         else
1358                         {
1359                                 uiDefBut(block, TEX, 1, "Property:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1360                                         &raySens->propname, 0, 31, 0, 0,
1361                                         "Only look for Objects with this property");
1362                         }
1363                         
1364                         /* 2. sensing range */
1365                         uiDefButF(block, NUM, 1, "Range", xco+10, yco-68, 0.6 * (width-20), 19,
1366                                 &raySens->range, 0.01, 10000.0, 100, 0,
1367                                 "Sense objects no farther than this distance");
1368                         
1369                         /* 3. axis choice */
1370                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1371                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1372                                 &raySens->axisflag, 2.0, 31, 0, 0,
1373                                 "Specify along which axis the ray is cast.");
1374                         
1375                         yco-= ysize;            
1376                         break;
1377                 }
1378         case SENS_MESSAGE:
1379                 {
1380                         mes = sens->data;
1381                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1382                         
1383                         glRects(xco, yco-ysize, xco+width, yco);
1384                         uiEmboss((float)xco, (float)yco-ysize,
1385                                 (float)xco+width, (float)yco, 1);
1386                         
1387                         /* line 1: header line */
1388                         draw_default_sensor_header(sens, block, xco, yco, width);
1389                         
1390                         /* line 2: Subject filter */
1391                         uiDefBut(block, TEX, 1, "Subject: ",
1392                                 (xco+10), (yco-44), (width-20), 19,
1393                                 mes->subject, 0, 31, 0, 0,
1394                                 "Optional subject filter: only accept messages with this subject"
1395                                 ", or empty for all");
1396                         
1397                         yco -= ysize;
1398                         break;
1399                 }
1400                 case SENS_JOYSTICK:
1401                 {
1402
1403                         ysize =  72;
1404                         
1405                         glRects(xco, yco-ysize, xco+width, yco);
1406                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1407                         
1408                         /* line 1: header */
1409                         draw_default_sensor_header(sens, block, xco, yco, width);
1410
1411                         joy= sens->data;
1412                         
1413
1414                         str= "Type %t|Button %x0|Axis %x1|Hat%x2"; 
1415                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, 0.6 * (width-20), 19,
1416                                 &joy->type, 0, 31, 0, 0,
1417                                 "The type of event this joystick sensor is triggered on.");
1418                         
1419                         if(joy->type == SENS_JOY_BUTTON)
1420                         {
1421                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1422                                 &joy->button, 0, 18, 100, 0,
1423                                 "Specify which button to use");
1424                                 
1425                                 str = "Type %t|Pressed %x0|Released %x1"; 
1426                                 uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1427                                 &joy->buttonf, 2.0, 31, 0, 0,
1428                                 "Button pressed or released.");
1429                         }
1430                         else if(joy->type == SENS_JOY_AXIS)
1431                         {
1432                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1433                                 &joy->axis, 1, 2.0, 100, 0,
1434                                 "Specify which axis to use");
1435
1436                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1437                                 &joy->precision, 0, 32768.0, 100, 0,
1438                                 "Specify the precision of the axis");
1439
1440                                 str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1441                                 uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1442                                 &joy->axisf, 2.0, 31, 0, 0,
1443                                 "The direction of the axis");
1444                         }
1445                         else
1446                         {
1447                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1448                                 &joy->hat, 1, 2.0, 100, 0,
1449                                 "Specify which hat to use");
1450                                 
1451                                 uiDefButI(block, NUM, 1, "Direction:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1452                                 &joy->hatf, 0, 12, 100, 0,
1453                                 "Specify hat direction");
1454                         }
1455                         yco-= ysize;
1456                         break;
1457                 }
1458         }
1459         
1460         uiBlockSetEmboss(block, UI_EMBOSSM);
1461         uiBlockSetCol(block, TH_AUTO);
1462         
1463         return yco-4;
1464 }
1465
1466
1467
1468 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1469 {
1470         bExpressionCont *ec;
1471         bPythonCont *pc;
1472         short ysize;
1473         
1474         uiBlockSetEmboss(block, UI_EMBOSSM);
1475         
1476         switch (cont->type) {
1477         case CONT_EXPRESSION:
1478                 ysize= 28;
1479
1480                 BIF_ThemeColor(TH_BUT_SETTING);
1481                 glRects(xco, yco-ysize, xco+width, yco);
1482                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1483                 
1484                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1485                 ec= cont->data; 
1486                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1487                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1488                                  ec->str, 0, 127, 0, 0,
1489                                  "Expression"); 
1490                 
1491                 yco-= ysize;
1492                 break;
1493         case CONT_PYTHON:
1494                 ysize= 28;
1495                 
1496                 if(cont->data==NULL) init_controller(cont);
1497                 pc= cont->data;
1498                 
1499                 BIF_ThemeColor(TH_BUT_SETTING1);
1500                 glRects(xco, yco-ysize, xco+width, yco);
1501                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1502
1503                 uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Script: ", xco+45,yco-24,width-90, 19, &pc->text, "");
1504                 
1505                 yco-= ysize;
1506                 break;
1507                 
1508         default:
1509                 ysize= 4;
1510
1511                 BIF_ThemeColor(TH_BUT_NEUTRAL);
1512                 glRects(xco, yco-ysize, xco+width, yco);
1513                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1514                 
1515                 yco-= ysize;
1516         }
1517         
1518         uiBlockSetEmboss(block, UI_EMBOSSM);
1519         uiBlockSetCol(block, TH_AUTO);
1520
1521         return yco;
1522 }
1523
1524 static int get_col_actuator(int type)
1525 {
1526         switch(type) {
1527         case ACT_ACTION:                return TH_BUT_ACTION;
1528         case ACT_SHAPEACTION:   return TH_BUT_ACTION;
1529         case ACT_OBJECT:                return TH_BUT_NEUTRAL;
1530         case ACT_IPO:                   return TH_BUT_SETTING;
1531         case ACT_PROPERTY:              return TH_BUT_SETTING1;
1532         case ACT_SOUND:                 return TH_BUT_SETTING2;
1533         case ACT_CD:                    return TH_BUT_NUM;
1534         case ACT_CAMERA:                return TH_BUT_TEXTFIELD;
1535         case ACT_EDIT_OBJECT:           return TH_BUT_POPUP;
1536         case ACT_GROUP:                 return TH_BUT_ACTION;
1537         case ACT_RANDOM:                return TH_BUT_NEUTRAL;
1538         case ACT_SCENE:                 return TH_BUT_SETTING;
1539         case ACT_MESSAGE:               return TH_BUT_SETTING1;
1540         case ACT_GAME:                  return TH_BUT_SETTING2;
1541         case ACT_VISIBILITY:            return TH_BUT_NUM;
1542         case ACT_CONSTRAINT:            return TH_BUT_ACTION;
1543         case ACT_STATE:                 return TH_BUT_SETTING2;
1544         default:                                return TH_BUT_NEUTRAL;
1545         }
1546 }
1547 static void set_col_actuator(int item, int medium) 
1548 {
1549         int col= get_col_actuator(item);
1550         BIF_ThemeColorShade(col, medium?30:10);
1551         
1552 }
1553
1554 char *get_state_name(Object *ob, short bit)
1555 {
1556         bController *cont;
1557         unsigned int mask;
1558
1559         mask = (1<<bit);
1560         cont = ob->controllers.first;
1561         while (cont) {
1562                 if (cont->state_mask & mask) {
1563                         return cont->name;
1564                 }
1565                 cont = cont->next;
1566         }
1567         return (char*)"";
1568 }
1569
1570 static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
1571 {
1572         bSoundActuator      *sa      = NULL;
1573         bCDActuator                     *cda     = NULL;
1574         bObjectActuator     *oa      = NULL;
1575         bIpoActuator        *ia      = NULL;
1576         bPropertyActuator   *pa      = NULL;
1577         bCameraActuator     *ca      = NULL;
1578         bEditObjectActuator *eoa     = NULL;
1579         bConstraintActuator *coa     = NULL;
1580         bSceneActuator      *sca     = NULL;
1581         bGroupActuator      *ga      = NULL;
1582         bRandomActuator     *randAct = NULL;
1583         bMessageActuator    *ma      = NULL;
1584         bActionActuator     *aa      = NULL;
1585         bGameActuator       *gma     = NULL;
1586         bVisibilityActuator *visAct  = NULL;
1587         bTwoDFilterActuator     *tdfa    = NULL;
1588         bParentActuator     *parAct  = NULL;
1589         bStateActuator          *staAct  = NULL;
1590         
1591         float *fp;
1592         short ysize = 0, wval;
1593         char *str, name[32];
1594         int myline, stbit;
1595
1596         /* yco is at the top of the rect, draw downwards */
1597         uiBlockSetEmboss(block, UI_EMBOSSM);
1598         set_col_actuator(act->type, 0);
1599         
1600         switch (act->type)
1601         {
1602         case ACT_OBJECT:
1603                 {
1604                         ysize= 129;
1605                         
1606                         glRects(xco, yco-ysize, xco+width, yco);
1607                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1608                         
1609                         oa = act->data;
1610                         wval = (width-100)/3;
1611                         
1612                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-22, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1613                         uiDefButF(block, NUM, 0, "",            xco+45, yco-22, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1614                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-22, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1615                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-22, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1616                         
1617                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-41, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1618                         uiDefButF(block, NUM, 0, "",            xco+45, yco-41, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1619                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-41, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1620                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-41, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");
1621                         
1622                         uiDefBut(block, LABEL, 0, "dLoc",       xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the dLoc");
1623                         uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1624                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1625                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1626                         
1627                         uiDefBut(block, LABEL, 0, "dRot",       xco, yco-83, 45, 19, NULL, 0, 0, 0, 0, "Sets the dRot");
1628                         uiDefButF(block, NUM, 0, "",            xco+45, yco-83, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1629                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-83, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1630                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-83, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1631                         
1632                         uiDefBut(block, LABEL, 0, "linV",       xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1633                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1634                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1635                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1636                         
1637                         uiDefBut(block, LABEL, 0, "angV",       xco, yco-125, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1638                         uiDefButF(block, NUM, 0, "",            xco+45, yco-125, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1639                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-125, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1640                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-125, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1641                         
1642                         uiDefButBitI(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");
1643                         uiDefButBitI(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");
1644                         uiDefButBitI(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");
1645                         uiDefButBitI(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");
1646                         uiDefButBitI(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");
1647                         uiDefButBitI(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");
1648                         
1649                         uiDefButBitI(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");
1650                         
1651                         yco-= ysize;
1652                         break;
1653                 }
1654         case ACT_ACTION:
1655         case ACT_SHAPEACTION:
1656                 {
1657                         /* DrawAct */
1658 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1659                         ysize = 112;
1660 #else
1661                         ysize= 92;
1662 #endif
1663                         
1664                         glRects(xco, yco-ysize, xco+width, yco);
1665                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1666                         
1667                         aa = act->data;
1668                         wval = (width-60)/3;
1669                         
1670                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1671 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1672                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
1673 #else
1674                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1675 #endif
1676                         uiDefButS(block, MENU, B_REDR, str, xco+30, yco-24, width-60, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
1677                         uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+30, yco-44, width-60, 19, &aa->act, "Action name");
1678                         
1679                         if(aa->type == ACT_ACTION_FROM_PROP)
1680                         {
1681                                 uiDefBut(block, TEX, 0, "Prop: ",xco+30, yco-64, width-60, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
1682                         }
1683                         else
1684                         {
1685                                 uiDefButI(block, NUM, 0, "Sta: ",xco+30, yco-64, (width-60)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
1686                                 uiDefButI(block, NUM, 0, "End: ",xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
1687                         }
1688                         
1689                         
1690                         
1691                         uiDefButI(block, NUM, 0, "Blendin: ", xco+30, yco-84, (width-60)/2, 19, &aa->blendin, 0.0, MAXFRAMEF, 0.0, 0.0, "Number of frames of motion blending");
1692                         uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-84, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers");
1693                         
1694 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1695                         if(aa->type == ACT_ACTION_MOTION)
1696                         {
1697                                 uiDefButF(block, NUM, 0, "Cycle: ",xco+30, yco-104, (width-60)/2, 19, &aa->stridelength, 0.0, 2500.0, 0, 0, "Distance covered by a single cycle of the action");
1698                         }
1699 #endif
1700                         
1701                         yco-=ysize;
1702                         break;
1703                 }
1704         case ACT_IPO:
1705                 {
1706                         ia= act->data;
1707                         
1708                         ysize= 52;
1709                         
1710                         glRects(xco, yco-ysize, xco+width, yco);
1711                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1712                         
1713                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1714                         
1715                         uiDefButS(block, MENU, B_REDR, str,             xco+20, yco-24, width-40 - (width-40)/3, 19, &ia->type, 0, 0, 0, 0, "");
1716                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
1717                                 "Child",        xco+20+0.666*(width-40), yco-24, (width-40)/3, 19, 
1718                                 &ia->flag, 0, 0, 0, 0, 
1719                                 "Add all children Objects as well");
1720
1721                         if(ia->type==ACT_IPO_FROM_PROP) {
1722                                 uiDefBut(block, TEX, 0, 
1723                                         "Prop: ",               xco+20, yco-44, width-40, 19, 
1724                                         ia->name, 0.0, 31.0, 0, 0, 
1725                                         "Use this property to define the Ipo position");
1726                         }
1727                         else {
1728                                 uiDefButI(block, NUM, 0, 
1729                                         "Sta",          xco+20, yco-44, (width-100)/2, 19, 
1730                                         &ia->sta, 0.0, MAXFRAMEF, 0, 0, 
1731                                         "Start frame");
1732                                 uiDefButI(block, NUM, 0, 
1733                                         "End",          xco+18+(width-90)/2, yco-44, (width-100)/2, 19, 
1734                                         &ia->end, 0.0, MAXFRAMEF, 0, 0, 
1735                                         "End frame");
1736                                 
1737                                 uiDefButBitS(block, TOG, ACT_IPOFORCE, B_REDR, 
1738                                         "Force", xco+width-78, yco-44, 43, 19, 
1739                                         &ia->flag, 0, 0, 0, 0, 
1740                                         "Convert Ipo to force"); 
1741                                 
1742                                 /* Only show the do-force-local toggle if force is requested */
1743                                 if (ia->flag & ACT_IPOFORCE) {
1744                                         uiDefButBitS(block, TOG, ACT_IPOFORCE_LOCAL, 0, 
1745                                                 "L", xco+width-35, yco-44, 15, 19, 
1746                                                 &ia->flag, 0, 0, 0, 0, 
1747                                                 "Let the force-ipo act in local coordinates."); 
1748                                 }
1749                                 
1750                         }
1751                         yco-= ysize;
1752                         break;
1753                 }
1754         case ACT_PROPERTY:
1755                 {
1756                         ysize= 68;
1757                         
1758                         glRects(xco, yco-ysize, xco+width, yco);
1759                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1760                         
1761                         pa= act->data;
1762                         
1763                         str= "Type   %t|Assign   %x0|Add %x1|Copy %x2";
1764                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
1765                         
1766                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
1767                         
1768                         if(pa->type==ACT_PROP_COPY) {
1769                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
1770                                 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");
1771                         }
1772                         else {
1773                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-64,width-60, 19, pa->value, 0, 31, 0, 0, "change with this value");
1774                         }
1775                         yco-= ysize;
1776                         
1777                         break;
1778                 }
1779     case ACT_SOUND:
1780                 {
1781                         ysize = 70;
1782                         
1783                         sa = act->data;
1784                         sa->sndnr = 0;
1785                         
1786                         wval = (width-20)/2;
1787                         glRects(xco, yco-ysize, xco+width, yco);
1788                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1789                         
1790                         if(G.main->sound.first) {
1791                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(G.main->sound), (ID *)sa->sound, &(sa->sndnr));
1792                                 /* reset this value, it is for handling the event */
1793                                 sa->sndnr = 0;
1794                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
1795
1796                                 if(sa->sound) {
1797                                         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";
1798                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
1799                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
1800                                         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");
1801                                         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");
1802                                 }
1803                                 MEM_freeN(str);
1804                         } 
1805                         else {
1806                                 uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
1807                         }
1808                                         
1809                         yco-= ysize;
1810                         
1811                         break;
1812                 }
1813         case ACT_CD:
1814                 {
1815                         char cd_type_str[] = "Sound mode %t|Play all tracks %x0|Play one track %x1|"
1816                                 "Volume %x3|Stop %x4|Pause %x5|Resume %x6";
1817                         cda = act->data;
1818
1819                         if (cda) {
1820                                 if (cda->track == 0) {
1821                                         cda->track = 1;
1822                                         cda->volume = 1;
1823                                         cda->type = ACT_CD_PLAY_ALL;
1824                                 }
1825                                 
1826                                 if (cda->type == ACT_CD_PLAY_TRACK || cda->type == ACT_CD_LOOP_TRACK) {
1827                                         ysize = 48;
1828                                         glRects(xco, yco-ysize, xco+width, yco);
1829                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1830                                         uiDefButS(block, NUM, 0, "Track:", xco+10,yco-44,width-20, 19, &cda->track, 1, 99, 0, 0, "Select the track to be played");
1831                                 }
1832                                 else if (cda->type == ACT_CD_VOLUME) {
1833                                         ysize = 48;
1834                                         glRects(xco, yco-ysize, xco+width, yco);
1835                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1836                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-44,width-20, 19, &cda->volume, 0, 1, 0, 0, "Set the volume for CD playback");
1837                                 }
1838                                 else {
1839                                         ysize = 28;
1840                                         glRects(xco, yco-ysize, xco+width, yco);
1841                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1842                                 }
1843                                 uiDefButS(block, MENU, B_REDR, cd_type_str,xco+10,yco-22,width-20, 19, &cda->type, 0.0, 0.0, 0, 0, "");
1844                         }
1845                         yco-= ysize;
1846                         break;
1847                 }
1848         case ACT_CAMERA:
1849
1850                 ysize= 48;
1851         
1852                 glRects(xco, yco-ysize, xco+width, yco);
1853                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1854                 
1855                 ca= act->data;
1856         
1857                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
1858                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
1859                 
1860                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
1861                 
1862                 if(ca->axis==0) ca->axis= 'x';
1863                 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");
1864                 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");
1865                 
1866                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
1867
1868                 yco-= ysize;
1869         
1870          break;
1871                                 
1872         case ACT_EDIT_OBJECT:
1873                 
1874                 eoa= act->data;
1875
1876                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
1877                         int wval; /* just a temp width */
1878                         ysize = 72;
1879                         glRects(xco, yco-ysize, xco+width, yco);
1880                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1881          
1882                         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)");
1883                         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");
1884
1885                         wval= (width-60)/3;
1886                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
1887                                          NULL, 0, 0, 0, 0,
1888                                          "Velocity upon creation.");
1889                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
1890                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
1891                                          "Velocity upon creation, x component.");
1892                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
1893                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
1894                                          "Velocity upon creation, y component.");
1895                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
1896                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
1897                                          "Velocity upon creation, z component.");
1898                         uiDefButBitS(block, TOG, 2, 0, "L", xco+45+3*wval, yco-68, 15, 19,
1899                                          &eoa->localflag, 0.0, 0.0, 0, 0,
1900                                          "Apply the transformation locally");
1901
1902                 }
1903                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
1904                         ysize= 28;
1905                         glRects(xco, yco-ysize, xco+width, yco);
1906                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1907                 }
1908                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
1909                         ysize= 48;
1910                         glRects(xco, yco-ysize, xco+width, yco);
1911                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1912          
1913                         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");
1914                 }
1915                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
1916                         ysize= 48;
1917                         glRects(xco, yco-ysize, xco+width, yco);
1918                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1919          
1920                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
1921                         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");
1922                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
1923                 }
1924                 
1925                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3";
1926                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
1927
1928                 yco-= ysize;
1929         
1930         break;
1931  
1932         case ACT_CONSTRAINT:
1933         
1934                 ysize= 44;
1935         
1936                 glRects(xco, yco-ysize, xco+width, yco);
1937                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1938                 
1939                 coa= act->data;
1940                 
1941 /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
1942                 str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
1943                 uiDefButS(block, MENU, 1, str,          xco+10, yco-40, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
1944         
1945                 uiDefButS(block, NUM,           0, "Damp:",     xco+10, yco-20, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "");
1946                 uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-20, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
1947                 uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-20, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
1948
1949                 if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
1950                 else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
1951                 else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
1952                 else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
1953                 else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
1954                 else fp= coa->minrot+2;
1955                 
1956                 uiDefButF(block, NUM, 0, "",            xco+80, yco-40, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
1957                 uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-40, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
1958
1959                 yco-= ysize;
1960         
1961         break;
1962  
1963         case ACT_SCENE:
1964                 sca= act->data; 
1965                 
1966                 if(sca->type==ACT_SCENE_RESTART) { 
1967                         ysize= 28; 
1968                         glRects(xco, yco-ysize, xco+width, yco); 
1969                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1970                 } 
1971                 else if(sca->type==ACT_SCENE_CAMERA) { 
1972                         
1973                         ysize= 48; 
1974                         glRects(xco, yco-ysize, xco+width, yco); 
1975                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1976          
1977                         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"); 
1978                 } 
1979                 else if(sca->type==ACT_SCENE_SET) { 
1980                         
1981                         ysize= 48; 
1982                         glRects(xco, yco-ysize, xco+width, yco); 
1983                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1984         
1985                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene"); 
1986                 } 
1987                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
1988                         
1989                         ysize= 48; 
1990                         glRects(xco, yco-ysize, xco+width, yco); 
1991                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1992         
1993                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene"); 
1994                 } 
1995                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
1996                         
1997                         ysize= 48; 
1998                         glRects(xco, yco-ysize, xco+width, yco); 
1999                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2000         
2001                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene"); 
2002                 } 
2003                 else if(sca->type==ACT_SCENE_REMOVE) { 
2004                         
2005                         ysize= 48; 
2006                         glRects(xco, yco-ysize, xco+width, yco); 
2007                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2008         
2009                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
2010                 } 
2011                 else if(sca->type==ACT_SCENE_SUSPEND) { 
2012                         
2013                         ysize= 48; 
2014                         glRects(xco, yco-ysize, xco+width, yco); 
2015                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2016         
2017                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
2018                 } 
2019                 else if(sca->type==ACT_SCENE_RESUME) { 
2020                         
2021                         ysize= 48; 
2022                         glRects(xco, yco-ysize, xco+width, yco); 
2023                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2024         
2025                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
2026                 } 
2027
2028                 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";
2029                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
2030
2031                 yco-= ysize; 
2032                 break; 
2033         case ACT_GAME:
2034                 {
2035                         gma = act->data; 
2036                         if (gma->type == ACT_GAME_LOAD)
2037                         {
2038                                 //ysize = 68;
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                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2043 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2044                         }
2045 /*                      else if (gma->type == ACT_GAME_START)
2046                         {
2047                                 ysize = 68; 
2048                                 glRects(xco, yco-ysize, xco+width, yco); 
2049                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2050
2051                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2052                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2053                         }
2054 */                      else if (gma->type == ACT_GAME_RESTART)
2055                         {
2056                                 ysize = 28; 
2057                                 glRects(xco, yco-ysize, xco+width, yco); 
2058                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2059                         }
2060                         else if (gma->type == ACT_GAME_QUIT)
2061                         {
2062                                 ysize = 28; 
2063                                 glRects(xco, yco-ysize, xco+width, yco); 
2064                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2065                         }
2066
2067                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
2068                         str = "Scene %t|Start new game%x0|Restart this game%x2|Quit this game %x3";
2069                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
2070                         
2071                         yco -= ysize; 
2072                         break; 
2073                 }
2074         case ACT_GROUP:
2075                 ga= act->data;
2076
2077                 ysize= 52;
2078
2079                 glRects(xco, yco-ysize, xco+width, yco);
2080                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2081                 
2082                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
2083
2084                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
2085                 if(ga->type==ACT_GROUP_SET) {
2086                         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");
2087                         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");
2088                 }
2089                 else if(ga->type==ACT_GROUP_FROM_PROP) {
2090                         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");
2091                 }
2092                 else {
2093                         uiDefButI(block, NUM, 0, "Sta",         xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
2094                         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");
2095                 }
2096                 yco-= ysize;
2097                 break;
2098
2099         case ACT_VISIBILITY:
2100                 ysize = 24;
2101
2102                 glRects(xco, yco-ysize, xco+width, yco);
2103                 uiEmboss((float)xco,
2104                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2105                 
2106                 visAct = act->data;
2107
2108                 str= "Visibility %t|Visible %x0|Invisible %x1";
2109
2110                 uiDefButI(block, MENU, B_REDR, str,
2111                           xco + 10, yco - 24, width - 20, 19, &visAct->flag,
2112                           0.0, 0.0, 0, 0,
2113                           "Make the object invisible or visible.");
2114 /*
2115                 uiDefButBitI(block, TOG, ACT_VISIBILITY_INVISIBLE, 0,
2116                           "Invisible",
2117                           xco + 10, yco - 24, width - 20, 19, &visAct->flag,
2118                           0.0, 0.0, 0, 0,
2119                           "Make the object invisible or visible.");
2120 */
2121                 yco-= ysize;
2122
2123                 break;
2124                 
2125         case ACT_STATE:
2126                 ysize = 34;
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                 staAct = act->data;
2133
2134                 str= "Operation %t|Cpy %x0|Add %x1|Sub %x2|Inv %x3";
2135
2136                 uiDefButI(block, MENU, B_REDR, str,
2137                           xco + 10, yco - 24, 65, 19, &staAct->type,
2138                           0.0, 0.0, 0, 0,
2139                           "Select the bit operation on object state mask");
2140
2141                 for (wval=0; wval<15; wval+=5) {
2142                         uiBlockBeginAlign(block);
2143                         for (stbit=0; stbit<5; stbit++) {
2144                                 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)));
2145                         }
2146                         for (stbit=0; stbit<5; stbit++) {
2147                                 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)));
2148                         }
2149                 }
2150                 uiBlockEndAlign(block);
2151
2152                 yco-= ysize;
2153
2154                 break;
2155
2156         case ACT_RANDOM:
2157                 ysize  = 69;
2158
2159                 glRects(xco, yco-ysize, xco+width, yco);
2160                 uiEmboss((float)xco,
2161                                   (float)yco-ysize, (float)xco+width, (float)yco, 1);
2162                 
2163                 randAct = act->data;
2164
2165                 /* 1. seed */
2166                 uiDefButI(block, NUM, 1, "Seed: ",              (xco+10),yco-24, 0.4 *(width-20), 19,
2167                                  &randAct->seed, 0, 1000, 0, 0,
2168                                  "Initial seed of the random generator. Use Python for more freedom. "
2169                                  " (Choose 0 for not random)");
2170
2171                 /* 2. distribution type */
2172                 /* One pick per distribution. These numbers MUST match the #defines  */
2173                 /* in game.h !!!                                                     */
2174                 str= "Distribution %t|Bool Constant %x0|Bool Uniform %x1"
2175                         "|Bool Bernoulli %x2|Int Constant %x3|Int Uniform %x4"
2176                         "|Int Poisson %x5|Float Constant %x6|Float Uniform %x7"
2177                         "|Float Normal %x8|Float Neg. Exp. %x9";
2178                 uiDefButI(block, MENU, B_REDR, str, (xco+10) + 0.4 * (width-20), yco-24, 0.6 * (width-20), 19,
2179                                  &randAct->distribution, 0.0, 0.0, 0, 0,
2180                                  "Choose the type of distribution");
2181
2182                 /* 3. property */
2183                 uiDefBut(block, TEX, 1, "Property:", (xco+10), yco-44, (width-20), 19,
2184                                  &randAct->propname, 0, 31, 0, 0,
2185                                  "Assign the random value to this property"); 
2186
2187                 /*4. and 5. arguments for the distribution*/
2188                 switch (randAct->distribution) {
2189                 case ACT_RANDOM_BOOL_CONST:
2190                         uiDefButBitI(block, TOG, 1, 1, "Always true", (xco+10), yco-64, (width-20), 19,
2191                                          &randAct->int_arg_1, 2.0, 1, 0, 0,
2192                                          "Always false or always true");                        
2193                         break;
2194                 case ACT_RANDOM_BOOL_UNIFORM:
2195                         uiDefBut(block, LABEL, 0, "     Do a 50-50 pick.",      (xco+10), yco-64, (width-20), 19,
2196                                          NULL, 0, 0, 0, 0,
2197                                          "Choose between true and false, 50% chance each.");
2198                         break;
2199                 case ACT_RANDOM_BOOL_BERNOUILLI:
2200                         uiDefButF(block, NUM, 1, "Chance", (xco+10), yco-64, (width-20), 19,
2201                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2202                                          "Pick a number between 0 and 1. Success if you stay "
2203                                          "below this value");                   
2204                         break;
2205                 case ACT_RANDOM_INT_CONST:
2206                         uiDefButI(block, NUM, 1, "Value: ",             (xco+10), yco-64, (width-20), 19,
2207                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2208                                          "Always return this number");
2209                         break;
2210                 case ACT_RANDOM_INT_UNIFORM:
2211                         uiDefButI(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2212                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2213                                          "Choose a number from a range. "
2214                                          "Lower boundary of the range.");
2215                         uiDefButI(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2216                                          &randAct->int_arg_2, -1000, 1000, 0, 0,
2217                                          "Choose a number from a range. "
2218                                          "Upper boundary of the range.");
2219                         break;
2220                 case ACT_RANDOM_INT_POISSON:
2221                         uiDefButF(block, NUM, 1, "Mean: ", (xco+10), yco-64, (width-20), 19,
2222                                          &randAct->float_arg_1, 0.01, 100.0, 0, 0,
2223                                          "Expected mean value of the distribution.");                                           
2224                         break;
2225                 case ACT_RANDOM_FLOAT_CONST:
2226                         uiDefButF(block, NUM, 1, "Value: ", (xco+10), yco-64, (width-20), 19,
2227                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2228                                          "Always return this number");
2229                         break;
2230                 case ACT_RANDOM_FLOAT_UNIFORM:
2231                         uiDefButF(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2232                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2233                                          "Choose a number from a range. "
2234                                          "Lower boundary of the range.");
2235                         uiDefButF(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2236                                          &randAct->float_arg_2, -10000.0, 10000.0, 0, 0,
2237                                          "Choose a number from a range. "
2238                                          "Upper boundary of the range.");
2239                         break;
2240                 case ACT_RANDOM_FLOAT_NORMAL:
2241                         uiDefButF(block, NUM, 1, "Mean: ",              (xco+10), yco-64, (width-20)/2, 19,
2242                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2243                                          "A normal distribution. Mean of the distribution.");
2244                         uiDefButF(block, NUM, 1, "SD: ",                (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2245                                          &randAct->float_arg_2, 0.0, 10000.0, 0, 0,
2246                                          "A normal distribution. Standard deviation of the "
2247                                          "distribution.");
2248                         break;
2249                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
2250                         uiDefButF(block, NUM, 1, "Half-life time: ", (xco+10), yco-64, (width-20), 19,
2251                                          &randAct->float_arg_1, 0.001, 10000.0, 0, 0,
2252                                          "Negative exponential dropoff.");
2253                         break;
2254                 default:
2255                         ; /* don't know what this distro is... can be useful for testing */
2256                         /* though :)                                                     */
2257                 }
2258
2259                 yco-= ysize;
2260                 break;
2261         case ACT_MESSAGE:
2262                 ma = act->data;
2263
2264 #define MESSAGE_SENSOR_TO_FIELD_WORKS   /* Really?  Not really.  Don't remove this ifdef yet */
2265
2266 #ifdef MESSAGE_SENSOR_TO_FIELD_WORKS
2267                 ysize = 4 + (3 * 24); /* footer + number of lines * 24 pixels/line */
2268 #else
2269                 ysize = 4 + (2 * 24); /* footer + number of lines * 24 pixels/line */
2270 #endif
2271                 glRects(xco, yco-ysize, xco+width, yco);
2272                 uiEmboss((float)xco,        (float)yco-ysize,
2273                                  (float)xco+width,  (float)yco, 1);
2274
2275                 myline=1;
2276
2277
2278 #ifdef MESSAGE_SENSOR_TO_FIELD_WORKS
2279                 /* line 1: To */
2280                 uiDefBut(block, TEX, 1, "To: ",
2281                         (xco+10), (yco-(myline++*24)), (width-20), 19,
2282                         &ma->toPropName, 0, 31, 0, 0,
2283                         "Optional send message to objects with this name only (Prefix name with OB)"
2284                         ", or empty to broadcast");
2285
2286 #endif
2287
2288                 /* line 2: Message Subject */
2289                 uiDefBut(block, TEX, 1, "Subject: ",
2290                 (xco+10), (yco-(myline++*24)), (width-20), 19,
2291                 &ma->subject, 0, 31, 0, 0,
2292                 "Optional message subject. This is what can be filtered on.");
2293
2294                 /* line 3: Text/Property */
2295                 uiDefButBitS(block, TOG, 1, B_REDR, "T/P",
2296                         (xco+10),(yco-(myline*24)), (0.20 * (width-20)), 19,
2297                         &ma->bodyType, 0.0, 0.0, 0, 0,
2298                         "Toggle message type: either Text or a PropertyName.");
2299
2300                 if (ma->bodyType == ACT_MESG_MESG)
2301                 {
2302                 /* line 3: Message Body */
2303                 uiDefBut(block, TEX, 1, "Body: ",
2304                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2305                 &ma->body, 0, 31, 0, 0,
2306                 "Optional message body Text");
2307                 } else
2308                 {
2309                         /* line 3: Property body (set by property) */
2310                         uiDefBut(block, TEX, 1, "Propname: ",
2311                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2312                         &ma->body, 0, 31, 0, 0,
2313                         "The message body will be set by the Property Value");
2314                 }
2315                 
2316                 yco -= ysize;
2317                 break;
2318         case ACT_2DFILTER:
2319                 tdfa = act->data;
2320
2321                 ysize = 50;
2322                 if(tdfa->type == ACT_2DFILTER_CUSTOMFILTER)
2323                 {
2324                         ysize +=20;
2325                 }
2326         glRects( xco, yco-ysize, xco+width, yco ); 
2327                 uiEmboss( (float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1 );
2328
2329                 switch(tdfa->type)
2330                 {
2331                         case ACT_2DFILTER_MOTIONBLUR:
2332                                 if(!tdfa->flag)
2333                                 {
2334                                         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");
2335                                         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");
2336                                 }
2337                                 else
2338                                 {
2339                                         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");
2340                                 }
2341                                 break;
2342                         case ACT_2DFILTER_BLUR:
2343                         case ACT_2DFILTER_SHARPEN:
2344                         case ACT_2DFILTER_DILATION:
2345                         case ACT_2DFILTER_EROSION:
2346                         case ACT_2DFILTER_LAPLACIAN:
2347                         case ACT_2DFILTER_SOBEL:
2348                         case ACT_2DFILTER_PREWITT:
2349                         case ACT_2DFILTER_GRAYSCALE:
2350                         case ACT_2DFILTER_SEPIA:
2351                         case ACT_2DFILTER_INVERT:
2352                         case ACT_2DFILTER_NOFILTER:
2353                         case ACT_2DFILTER_DISABLED:
2354                         case ACT_2DFILTER_ENABLED:
2355                                 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");
2356                                 break;
2357                         case ACT_2DFILTER_CUSTOMFILTER:
2358                                 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");
2359                                 uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Script: ", xco+30,yco-64,width-60, 19, &tdfa->text, "");
2360                                 break;
2361                 }
2362                 
2363                 str= "2D Filter   %t|Motion Blur   %x1|Blur %x2|Sharpen %x3|Dilation %x4|Erosion %x5|"
2364                                 "Laplacian %x6|Sobel %x7|Prewitt %x8|Gray Scale %x9|Sepia %x10|Invert %x11|Custom Filter %x12|"
2365                                 "Enable Filter %x-2|Disable Filter %x-1|Remove Filter %x0|";
2366                 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");
2367                 
2368                 yco -= ysize;
2369         break;
2370         case ACT_PARENT:
2371                 parAct = act->data; 
2372
2373                 if(parAct->type==ACT_PARENT_SET) { 
2374                         
2375                         ysize= 48; 
2376                         glRects(xco, yco-ysize, xco+width, yco); 
2377                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2378          
2379                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+40, yco-44, (width-80), 19, &(parAct->ob), "Set this object as parent"); 
2380                 }
2381                 else if(parAct->type==ACT_PARENT_REMOVE) { 
2382                         
2383                         ysize= 28; 
2384                         glRects(xco, yco-ysize, xco+width, yco); 
2385                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2386                 }
2387
2388                 str= "Parent %t|Set Parent %x0|Remove Parent %x1";
2389                 uiDefButI(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &parAct->type, 0.0, 0.0, 0, 0, ""); 
2390
2391                 yco-= ysize; 
2392                 break; 
2393         default:
2394                 ysize= 4;
2395
2396                 glRects(xco, yco-ysize, xco+width, yco);
2397                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2398                 
2399                 yco-= ysize;
2400                 break;
2401         }
2402
2403         uiBlockSetEmboss(block, UI_EMBOSSM);
2404
2405         return yco-4;
2406 }
2407
2408 static void do_sensor_menu(void *arg, int event)
2409 {       
2410         ID **idar;
2411         Object *ob;
2412         bSensor *sens;
2413         short count, a;
2414         
2415         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2416         
2417         for(a=0; a<count; a++) {
2418                 ob= (Object *)idar[a];
2419                 if(event==0 || event==2) ob->scaflag |= OB_SHOWSENS;
2420                 else if(event==1) ob->scaflag &= ~OB_SHOWSENS;
2421         }
2422                 
2423         for(a=0; a<count; a++) {
2424                 ob= (Object *)idar[a];
2425                 sens= ob->sensors.first;
2426                 while(sens) {
2427                         if(event==2) sens->flag |= SENS_SHOW;
2428                         else if(event==3) sens->flag &= ~SENS_SHOW;
2429                         sens= sens->next;
2430                 }
2431         }
2432
2433         if(idar) MEM_freeN(idar);
2434         allqueue(REDRAWBUTSLOGIC, 0);
2435 }
2436
2437 static uiBlock *sensor_menu(void *arg_unused)
2438 {
2439         uiBlock *block;
2440         int yco=0;
2441         
2442         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2443         uiBlockSetButmFunc(block, do_sensor_menu, NULL);
2444         
2445         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2446         uiDefBut(block, BUTM, 1, "Hide Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2447         uiDefBut(block, SEPR, 0, "",    0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2448         uiDefBut(block, BUTM, 1, "Show Sensors",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
2449         uiDefBut(block, BUTM, 1, "Hide Sensors",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
2450
2451         uiBlockSetDirection(block, UI_TOP);
2452         
2453         return block;
2454 }
2455
2456 static void do_controller_menu(void *arg, int event)
2457 {       
2458         ID **idar;
2459         Object *ob;
2460         bController *cont;
2461         short count, a;
2462         
2463         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2464         
2465         for(a=0; a<count; a++) {
2466                 ob= (Object *)idar[a];
2467                 if(event==0 || event==2) ob->scaflag |= OB_SHOWCONT;
2468                 else if(event==1) ob->scaflag &= ~OB_SHOWCONT;
2469         }
2470
2471         for(a=0; a<count; a++) {
2472                 ob= (Object *)idar[a];
2473                 cont= ob->controllers.first;
2474                 while(cont) {
2475                         if(event==2) cont->flag |= CONT_SHOW;
2476                         else if(event==3) cont->flag &= ~CONT_SHOW;
2477                         cont= cont->next;
2478                 }
2479         }
2480
2481         if(idar) MEM_freeN(idar);
2482         allqueue(REDRAWBUTSLOGIC, 0);
2483 }
2484
2485 static uiBlock *controller_menu(void *arg_unused)
2486 {
2487         uiBlock *block;
2488         int yco=0;
2489         
2490         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2491         uiBlockSetButmFunc(block, do_controller_menu, NULL);
2492         
2493         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2494         uiDefBut(block, BUTM, 1, "Hide Objects",        0,(short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2495         uiDefBut(block, SEPR, 0, "",                                    0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2496         uiDefBut(block, BUTM, 1, "Show Controllers",    0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 2, 2, "");
2497         uiDefBut(block, BUTM, 1, "Hide Controllers",    0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 3, 3, "");
2498
2499         uiBlockSetDirection(block, UI_TOP);
2500         
2501         return block;
2502 }
2503
2504 static void do_actuator_menu(void *arg, int event)
2505 {       
2506         ID **idar;
2507         Object *ob;
2508         bActuator *act;
2509         short count, a;
2510         
2511         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2512         
2513         for(a=0; a<count; a++) {
2514                 ob= (Object *)idar[a];
2515                 if(event==0 || event==2) ob->scaflag |= OB_SHOWACT;
2516                 else if(event==1) ob->scaflag &= ~OB_SHOWACT;
2517         }
2518
2519         for(a=0; a<count; a++) {
2520                 ob= (Object *)idar[a];
2521                 act= ob->actuators.first;
2522                 while(act) {
2523                         if(event==2) act->flag |= ACT_SHOW;
2524                         else if(event==3) act->flag &= ~ACT_SHOW;
2525                         act= act->next;
2526                 }
2527         }
2528
2529         if(idar) MEM_freeN(idar);
2530         allqueue(REDRAWBUTSLOGIC, 0);
2531 }
2532
2533 static uiBlock *actuator_menu(void *arg_unused)
2534 {
2535         uiBlock *block;
2536         int xco=0;
2537         
2538         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2539         uiBlockSetButmFunc(block, do_actuator_menu, NULL);
2540         
2541         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2542         uiDefBut(block, BUTM, 1, "Hide Objects",        0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2543         uiDefBut(block, SEPR, 0, "",    0, (short)(xco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2544         uiDefBut(block, BUTM, 1, "Show Actuators",      0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
2545         uiDefBut(block, BUTM, 1, "Hide Actuators",      0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
2546
2547         uiBlockSetDirection(block, UI_TOP);
2548         
2549         return block;
2550 }
2551
2552
2553 void buttons_enji(uiBlock *block, Object *ob)
2554 {
2555         uiDefButBitI(block, TOG, OB_SECTOR, B_SETSECTOR, "Sector",
2556                          10,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2557                          "All game elements should be in the Sector boundbox");
2558         uiDefButBitI(block, TOG, OB_PROP, B_SETPROP, "Prop",
2559                          75,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2560                          "An Object fixed within a sector");
2561         uiBlockSetCol(block, BUTPURPLE);
2562         uiDefButBitI(block, TOG, OB_ACTOR, B_SETACTOR, "Actor",
2563                          140,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2564                          "Objects that are evaluated by the engine ");
2565         if(ob->gameflag & OB_ACTOR) {   
2566                 uiDefButBitI(block, TOG, OB_DYNAMIC, B_SETDYNA, "Dynamic",
2567                                  205,205,75,19, &ob->gameflag, 0, 0, 0, 0, 
2568                                  "Motion defined by laws of physics");
2569                 uiDefButBitI(block, TOG, OB_MAINACTOR, B_SETMAINACTOR, "MainActor",
2570                                  280,205,70,19, &ob->gameflag, 0, 0, 0, 0, "");
2571                 
2572                 if(ob->gameflag & OB_DYNAMIC) {
2573                         uiDefButBitI(block, TOG, OB_DO_FH, B_DIFF, "Do Fh",
2574                                          10,185,50,19, &ob->gameflag, 0, 0, 0, 0, 
2575                                          "Use Fh settings in Materials");
2576                         uiDefButBitI(block, TOG, OB_ROT_FH, B_DIFF, "Rot Fh",
2577                                          60,185,50,19, &ob->gameflag, 0, 0, 0, 0, 
2578                                          "Use face normal to rotate Object");
2579                 
2580                         uiBlockSetCol(block, BUTGREY);
2581                         uiDefButF(block, NUM, B_DIFF, "Mass:",
2582                                          110, 185, 120, 19, &ob->mass, 0.01, 100.0, 10, 0, 
2583                                          "The mass of the Object");
2584                         uiDefButF(block, NUM, REDRAWVIEW3D, "Size:",
2585                                          230, 185, 120, 19, &ob->inertia, 0.01, 10.0, 10, 0, 
2586                                          "Bounding sphere size");
2587                         uiDefButF(block, NUM, B_DIFF, "Damp:",
2588                                          10, 165, 100, 19, &ob->damping, 0.0, 1.0, 10, 0, 
2589                                          "General movement damping");
2590                         uiDefButF(block, NUM, B_DIFF, "RotDamp:",
2591                                          110, 165, 120, 19, &ob->rdamping, 0.0, 1.0, 10, 0, 
2592                                          "General rotation damping");
2593                 }
2594         }
2595
2596 }
2597
2598 void buttons_ketsji(uiBlock *block, Object *ob)
2599 {
2600         uiDefButBitI(block, TOG, OB_ACTOR, B_REDR, "Actor",
2601                           10,205,55,19, &ob->gameflag, 0, 0, 0, 0,
2602                           "Objects that are evaluated by the engine ");
2603         if(ob->gameflag & OB_ACTOR) {   
2604                 uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 65,205,55,19, 
2605                                   &ob->gameflag, 0, 0, 0, 0, 
2606                                   "Objects that don't restitute collisions (like a ghost)");
2607                 uiDefButBitI(block, TOG, OB_DYNAMIC, B_REDR, "Dynamic", 120,205,70,19, 
2608                                   &ob->gameflag, 0, 0, 0, 0, 
2609                                   "Motion defined by laws of physics");
2610         
2611                 if(ob->gameflag & OB_DYNAMIC) {
2612                         uiDefButBitI(block, TOG, OB_RIGID_BODY, B_REDR, "Rigid Body", 190,205,80,19, 
2613                                           &ob->gameflag, 0, 0, 0, 0, 
2614                                           "Enable rolling physics");
2615                         uiDefButBitI(block, TOG, OB_COLLISION_RESPONSE, B_REDR, "No sleeping", 270,205,80,19, 
2616                                           &ob->gameflag, 0, 0, 0, 0, 
2617                                           "Disable auto (de)activation");
2618
2619                         uiDefButBitI(block, TOG, OB_DO_FH, B_DIFF, "Do Fh", 10,185,50,19, 
2620                                           &ob->gameflag, 0, 0, 0, 0, 
2621                                           "Use Fh settings in Materials");
2622                         uiDefButBitI(block, TOG, OB_ROT_FH, B_DIFF, "Rot Fh", 60,185,50,19, 
2623                                           &ob->gameflag, 0, 0, 0, 0, 
2624                                           "Use face normal to rotate Object");
2625                         uiDefButF(block, NUM, B_DIFF, "Mass:", 110, 185, 80, 19, 
2626                                           &ob->mass, 0.01, 10000.0, 10, 0, 
2627                                           "The mass of the Object");
2628                         uiDefButF(block, NUM, REDRAWVIEW3D, "Radius:", 190, 185, 80, 19, 
2629                                           &ob->inertia, 0.01, 10.0, 10, 0, 
2630                                           "Bounding sphere radius");
2631                         uiDefButF(block, NUM, B_DIFF, "Form:", 270, 185, 80, 19, 
2632                                           &ob->formfactor, 0.01, 100.0, 10, 0, 
2633                                           "Form factor");
2634
2635                         uiDefButF(block, NUM, B_DIFF, "Damp:", 10, 165, 100, 19, 
2636                                           &ob->damping, 0.0, 1.0, 10, 0, 
2637                                           "General movement damping");
2638                         uiDefButF(block, NUM, B_DIFF, "RotDamp:", 110, 165, 120, 19, 
2639                                           &ob->rdamping, 0.0, 1.0, 10, 0, 
2640                                           "General rotation damping");
2641                         uiDefButBitI(block, TOG, OB_ANISOTROPIC_FRICTION, B_REDR, "Anisotropic", 
2642                                           230, 165, 120, 19,
2643                                           &ob->gameflag, 0.0, 1.0, 10, 0,
2644                                           "Enable anisotropic friction");                       
2645                 }
2646
2647                 if (ob->gameflag & OB_ANISOTROPIC_FRICTION) {
2648                         uiDefButF(block, NUM, B_DIFF, "x friction:", 10, 145, 114, 19,
2649                                           &ob->anisotropicFriction[0], 0.0, 1.0, 10, 0,
2650                                           "Relative friction coefficient in the x-direction.");
2651                         uiDefButF(block, NUM, B_DIFF, "y friction:", 124, 145, 113, 19,
2652                                           &ob->anisotropicFriction[1], 0.0, 1.0, 10, 0,
2653                                           "Relative friction coefficient in the y-direction.");
2654                         uiDefButF(block, NUM, B_DIFF, "z friction:", 237, 145, 113, 19,
2655                                           &ob->anisotropicFriction[2], 0.0, 1.0, 10, 0,
2656                                           "Relative friction coefficient in the z-direction.");
2657                 }
2658         }
2659
2660         if (!(ob->gameflag & OB_GHOST)) {
2661                 uiBlockBeginAlign(block);
2662                 uiDefButBitI(block, TOG, OB_BOUNDS, B_REDR, "Bounds", 10, 125, 75, 19,
2663                                 &ob->gameflag, 0, 0,0, 0,
2664                                 "Specify a bounds object for physics");
2665                 if (ob->gameflag & OB_BOUNDS) {
2666                         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull Polytope%x5|Static TriangleMesh %x4",
2667                                 85, 125, 160, 19, &ob->boundtype, 0, 0, 0, 0, "Selects the collision type");
2668                         uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Compound", 250,125,100,19, 
2669                                           &ob->gameflag, 0, 0, 0, 0, 
2670                                           "Add Children");
2671                 }
2672                 uiBlockEndAlign(block);
2673         }
2674 }
2675
2676 void buttons_bullet(uiBlock *block, Object *ob)
2677 {
2678         uiBlockBeginAlign(block);
2679         uiDefButBitI(block, TOG, OB_ACTOR, B_REDR, "Actor",
2680                           10,205,55,19, &ob->gameflag, 0, 0, 0, 0,
2681                           "Objects that are evaluated by the engine ");
2682         if(ob->gameflag & OB_ACTOR) {   
2683                 uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 65,205,55,19, 
2684                                   &ob->gameflag, 0, 0, 0, 0, 
2685                                   "Objects that don't restitute collisions (like a ghost)");
2686                 uiDefButBitI(block, TOG, OB_DYNAMIC, B_REDR, "Dynamic", 120,205,70,19, 
2687                                   &ob->gameflag, 0, 0, 0, 0, 
2688                                   "Motion defined by laws of physics");
2689         
2690                 if(ob->gameflag & OB_DYNAMIC) {
2691                         uiDefButBitI(block, TOG, OB_RIGID_BODY, B_REDR, "Rigid Body", 190,205,80,19, 
2692                                           &ob->gameflag, 0, 0, 0, 0, 
2693                                           "Enable rolling physics");
2694                         uiDefButBitI(block, TOG, OB_COLLISION_RESPONSE, B_REDR, "No sleeping", 270,205,80,19, 
2695                                           &ob->gameflag, 0, 0, 0, 0, 
2696                                           "Disable auto (de)activation");
2697
2698                         uiDefButF(block, NUM, B_DIFF, "Mass:", 10, 185, 170, 19, 
2699                                           &ob->mass, 0.01, 10000.0, 10, 2, 
2700                                           "The mass of the Object");
2701                         uiDefButF(block, NUM, REDRAWVIEW3D, "Radius:", 180, 185, 170, 19, 
2702                                           &ob->inertia, 0.01, 10.0, 10, 2, 
2703                                           "Bounding sphere radius");
2704
2705                         uiDefButF(block, NUMSLI, B_DIFF, "Damp ", 10, 165, 150, 19, 
2706                                           &ob->damping, 0.0, 1.0, 10, 0, 
2707                                           "General movement damping");
2708                         uiDefButF(block, NUMSLI, B_DIFF, "RotDamp ", 160, 165, 190, 19, 
2709                                           &ob->rdamping, 0.0, 1.0, 10, 0, 
2710                                           "General rotation damping");
2711                 }
2712         }
2713         uiBlockEndAlign(block);
2714
2715         uiBlockBeginAlign(block);
2716         uiDefButBitI(block, TOG, OB_BOUNDS, B_REDR, "Bounds", 10, 125, 75, 19,
2717                      &ob->gameflag, 0, 0,0, 0,
2718                      "Specify a bounds object for physics");
2719         if (ob->gameflag & OB_BOUNDS) {
2720                 uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull Polytope%x5|Static TriangleMesh %x4",
2721                   //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|",
2722                           85, 125, 160, 19, &ob->boundtype, 0, 0, 0, 0, "Selects the collision type");
2723                 uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Compound", 250,125,100,19, 
2724                              &ob->gameflag, 0, 0, 0, 0, 
2725                              "Add Children");
2726         }
2727         uiBlockEndAlign(block);
2728 }
2729
2730 static void check_object_state(void *arg1_but, void *arg2_mask)
2731 {
2732         unsigned int *cont_mask = arg2_mask;
2733         uiBut *but = arg1_but;
2734
2735         if (*cont_mask == 0 || !(G.qual & LR_SHIFTKEY))
2736                 *cont_mask = (1<<but->retval);
2737         but->retval = B_REDR;
2738 }
2739
2740 static void check_controller_state_mask(void *arg1_but, void *arg2_mask)
2741 {
2742         unsigned int *cont_mask = arg2_mask;
2743         uiBut *but = arg1_but;
2744         
2745         /* a controller is always in a single state */
2746         *cont_mask = (1<<but->retval);
2747         but->retval = B_REDR;
2748 }
2749
2750 static int first_bit(unsigned int mask)
2751 {
2752         int bit;
2753
2754         for (bit=0; bit<32; bit++) {
2755                 if (mask & (1<<bit))
2756                         return bit;
2757         }
2758         return -1;
2759 }
2760
2761 static uiBlock *controller_state_mask_menu(void *arg_cont)
2762 {
2763         uiBlock *block;
2764         uiBut *but;
2765         bController *cont = arg_cont;
2766         int mask;
2767
2768         short yco = 12, xco = 0, stbit, offset;
2769
2770         block= uiNewBlock(&curarea->uiblocks, "Controller state mask", UI_EMBOSS, UI_HELV, curarea->win);
2771
2772         /* use this for a fake extra empy space around the buttons */
2773         uiDefBut(block, LABEL, 0, "",                   -5, -5, 200, 34, NULL, 0, 0, 0, 0, "");
2774         
2775         for (offset=0; offset<15; offset+=5) {
2776                 uiBlockBeginAlign(block);
2777                 for (stbit=0; stbit<5; stbit++) {
2778                         but = uiDefButBitI(block, TOG, (1<<(stbit+offset)), (stbit+offset), "", (short)(xco+12*stbit+13*offset), yco, 12, 12, (int *)&(cont->state_mask), 0, 0, 0, 0, "");
2779                         uiButSetFunc(but, check_controller_state_mask, but, &(cont->state_mask));
2780                 }
2781                 for (stbit=0; stbit<5; stbit++) {
2782                         but = uiDefButBitI(block, TOG, (1<<(stbit+offset+15)), (stbit+offset+15), "",   (short)(xco+12*stbit+13*offset), yco-12, 12, 12, (int *)&(cont->state_mask), 0, 0, 0, 0, "");
2783                         uiButSetFunc(but, check_controller_state_mask, but, &(cont->state_mask));
2784                 }
2785         }