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