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