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