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