converted more mixed tab/space indentations to tabs. only whitespace changes.
[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         }
722         return "unknown";
723 }
724
725
726
727
728 static const char *actuator_pup(Object *owner)
729 {
730         switch (owner->type)
731         {
732         case OB_ARMATURE:
733                 return "Actuators  %t|Action %x15|Armature %x23|Motion %x0|Constraint %x9|Ipo %x1"
734                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
735                                                 "|Scene %x11|Random %x13|Message %x14|Game %x17"
736                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
737                 break;
738
739         case OB_MESH:
740                 return "Actuators  %t|Shape Action %x21|Motion %x0|Constraint %x9|Ipo %x1"
741                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
742                                                 "|Scene %x11|Random %x13|Message %x14|Game %x17"
743                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
744                 break;
745
746         default:
747                 return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
748                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
749                                                 "|Scene %x11|Random %x13|Message %x14|Game %x17"
750                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
751         }
752 }
753
754
755
756 static void set_sca_ob(Object *ob)
757 {
758         bController *cont;
759         bActuator *act;
760
761         cont= ob->controllers.first;
762         while(cont) {
763                 cont->mynew= (bController *)ob;
764                 cont= cont->next;
765         }
766         act= ob->actuators.first;
767         while(act) {
768                 act->mynew= (bActuator *)ob;
769                 act= act->next;
770         }
771 }
772
773 static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag)
774 {
775         Base *base;
776         Main *bmain= CTX_data_main(C);
777         Scene *scene= CTX_data_scene(C);
778         Object *ob, *obt, *obact= CTX_data_active_object(C);
779         ID **idar;
780         bSensor *sens;
781         bController *cont;
782         unsigned int lay;
783         int a, nr, doit;
784         
785         /* we need a sorted object list */
786         /* set scavisflags flags in Objects to indicate these should be evaluated */
787         /* also hide ob pointers in ->new entries of controllerss/actuators */
788         
789         *count= 0;
790         
791         if(scene==NULL) return NULL;
792         
793         ob= bmain->object.first;
794         while(ob) {
795                 ob->scavisflag= 0;
796                 set_sca_ob(ob);
797                 ob= ob->id.next;
798         }
799         
800         /* XXX here it checked 3d lay */
801         lay= scene->lay;
802         
803         base= FIRSTBASE;
804         while(base) {
805                 if(base->lay & lay) {
806                         if(base->flag & SELECT) {
807                                 if(scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
808                                 if(scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
809                                 if(scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
810                         }
811                 }
812                 base= base->next;
813         }
814
815         if(obact) {
816                 if(scavisflag & BUTS_SENS_ACT) obact->scavisflag |= OB_VIS_SENS;
817                 if(scavisflag & BUTS_CONT_ACT) obact->scavisflag |= OB_VIS_CONT;
818                 if(scavisflag & BUTS_ACT_ACT) obact->scavisflag |= OB_VIS_ACT;
819         }
820         
821         /* BUTS_XXX_STATE are similar to BUTS_XXX_LINK for selecting the object */
822         if(scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK|BUTS_SENS_STATE|BUTS_ACT_STATE)) {
823                 doit= 1;
824                 while(doit) {
825                         doit= 0;
826                         
827                         ob= bmain->object.first;
828                         while(ob) {
829                         
830                                 /* 1st case: select sensor when controller selected */
831                                 if((scavisflag & (BUTS_SENS_LINK|BUTS_SENS_STATE)) && (ob->scavisflag & OB_VIS_SENS)==0) {
832                                         sens= ob->sensors.first;
833                                         while(sens) {
834                                                 for(a=0; a<sens->totlinks; a++) {
835                                                         if(sens->links[a]) {
836                                                                 obt= (Object *)sens->links[a]->mynew;
837                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)) {
838                                                                         doit= 1;
839                                                                         ob->scavisflag |= OB_VIS_SENS;
840                                                                         break;
841                                                                 }
842                                                         }
843                                                 }
844                                                 if(doit) break;
845                                                 sens= sens->next;
846                                         }
847                                 }
848                                 
849                                 /* 2nd case: select cont when act selected */
850                                 if((scavisflag & BUTS_CONT_LINK)  && (ob->scavisflag & OB_VIS_CONT)==0) {
851                                         cont= ob->controllers.first;
852                                         while(cont) {
853                                                 for(a=0; a<cont->totlinks; a++) {
854                                                         if(cont->links[a]) {
855                                                                 obt= (Object *)cont->links[a]->mynew;
856                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)) {
857                                                                         doit= 1;
858                                                                         ob->scavisflag |= OB_VIS_CONT;
859                                                                         break;
860                                                                 }
861                                                         }
862                                                 }
863                                                 if(doit) break;
864                                                 cont= cont->next;
865                                         }
866                                 }
867                                 
868                                 /* 3rd case: select controller when sensor selected */
869                                 if((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
870                                         sens= ob->sensors.first;
871                                         while(sens) {
872                                                 for(a=0; a<sens->totlinks; a++) {
873                                                         if(sens->links[a]) {
874                                                                 obt= (Object *)sens->links[a]->mynew;
875                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)==0) {
876                                                                         doit= 1;
877                                                                         obt->scavisflag |= OB_VIS_CONT;
878                                                                 }
879                                                         }
880                                                 }
881                                                 sens= sens->next;
882                                         }
883                                 }
884                                 
885                                 /* 4th case: select actuator when controller selected */
886                                 if( (scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE))  && (ob->scavisflag & OB_VIS_CONT)) {
887                                         cont= ob->controllers.first;
888                                         while(cont) {
889                                                 for(a=0; a<cont->totlinks; a++) {
890                                                         if(cont->links[a]) {
891                                                                 obt= (Object *)cont->links[a]->mynew;
892                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)==0) {
893                                                                         doit= 1;
894                                                                         obt->scavisflag |= OB_VIS_ACT;
895                                                                 }
896                                                         }
897                                                 }
898                                                 cont= cont->next;
899                                         }
900                                         
901                                 }
902                                 ob= ob->id.next;
903                         }
904                 }
905         } 
906         
907         /* now we count */
908         ob= bmain->object.first;
909         while(ob) {
910                 if( ob->scavisflag ) (*count)++;
911                 ob= ob->id.next;
912         }
913
914         if(*count==0) return NULL;
915         if(*count>24) *count= 24;               /* temporal */
916         
917         idar= MEM_callocN( (*count)*sizeof(void *), "idar");
918         
919         ob= bmain->object.first;
920         nr= 0;
921
922         /* make the active object always the first one of the list */
923         if (obact) {
924                 idar[0]= (ID *)obact;
925                 nr++;
926         }
927
928         while(ob) {
929                 if( (ob->scavisflag) && (ob != obact)) {
930                         idar[nr]= (ID *)ob;
931                         nr++;
932                 }
933                 if(nr>=24) break;
934                 ob= ob->id.next;
935         }
936         
937         /* just to be sure... these were set in set_sca_done_ob() */
938         clear_sca_new_poins();
939         
940         return idar;
941 }
942
943
944 static int get_col_sensor(int type)
945 {
946         /* XXX themecolors not here */
947         
948         switch(type) {
949         case SENS_ALWAYS:               return TH_PANEL;
950         case SENS_DELAY:                return TH_PANEL;
951         case SENS_TOUCH:                return TH_PANEL;
952         case SENS_COLLISION:    return TH_PANEL;
953         case SENS_NEAR:                 return TH_PANEL; 
954         case SENS_KEYBOARD:             return TH_PANEL;
955         case SENS_PROPERTY:             return TH_PANEL;
956         case SENS_ARMATURE:             return TH_PANEL;
957         case SENS_ACTUATOR:             return TH_PANEL;
958         case SENS_MOUSE:                return TH_PANEL;
959         case SENS_RADAR:                return TH_PANEL;
960         case SENS_RANDOM:               return TH_PANEL;
961         case SENS_RAY:                  return TH_PANEL;
962         case SENS_MESSAGE:              return TH_PANEL;
963         case SENS_JOYSTICK:             return TH_PANEL;
964         default:                                return TH_PANEL;
965         }
966 }
967 static void set_col_sensor(int type, int medium)
968 {
969         int col= get_col_sensor(type);
970         UI_ThemeColorShade(col, medium?30:0);
971 }
972
973
974 static void verify_logicbutton_func(bContext *UNUSED(C), void *data1, void *data2)
975 {
976         bSensor *sens= (bSensor*)data1;
977         
978         if(sens->level && sens->tap) {
979                 if(data2 == &(sens->level))     
980                         sens->tap= 0;
981                 else
982                         sens->level= 0;
983         }
984 }
985
986 static void test_scriptpoin_but(struct bContext *C, const char *name, ID **idpp)
987 {
988         *idpp= BLI_findstring(&CTX_data_main(C)->text, name, offsetof(ID, name) + 2);
989 }
990
991 static void test_actionpoin_but(struct bContext *C, const char *name, ID **idpp)
992 {
993         *idpp= BLI_findstring(&CTX_data_main(C)->action, name, offsetof(ID, name) + 2);
994         if(*idpp)
995                 id_us_plus(*idpp);
996 }
997
998
999 static void test_obpoin_but(struct bContext *C, const char *name, ID **idpp)
1000 {
1001         *idpp= BLI_findstring(&CTX_data_main(C)->object, name, offsetof(ID, name) + 2);
1002         if(*idpp)
1003                 id_lib_extern(*idpp);   /* checks lib data, sets correct flag for saving then */
1004 }
1005
1006 static void test_meshpoin_but(struct bContext *C, const char *name, ID **idpp)
1007 {
1008         *idpp= BLI_findstring(&CTX_data_main(C)->mesh, name, offsetof(ID, name) + 2);
1009         if(*idpp)
1010                 id_us_plus(*idpp);
1011 }
1012
1013 static void test_matpoin_but(struct bContext *C, const char *name, ID **idpp)
1014 {
1015         *idpp= BLI_findstring(&CTX_data_main(C)->mat, name, offsetof(ID, name) + 2);
1016         if(*idpp)
1017                 id_us_plus(*idpp);
1018 }
1019
1020 static void test_scenepoin_but(struct bContext *C, const char *name, ID **idpp)
1021 {
1022         *idpp= BLI_findstring(&CTX_data_main(C)->scene, name, offsetof(ID, name) + 2);
1023         if(*idpp)
1024                 id_us_plus(*idpp);
1025 }
1026
1027 static void test_keyboard_event(struct bContext *UNUSED(C), void *arg_ks, void *UNUSED(arg))
1028 {
1029         bKeyboardSensor *ks= (bKeyboardSensor*)arg_ks;
1030         
1031         if(!ISKEYBOARD(ks->key))
1032                 ks->key= 0;
1033         if(!ISKEYBOARD(ks->qual))
1034                 ks->qual= 0;
1035         if(!ISKEYBOARD(ks->qual2))
1036                 ks->qual2= 0;
1037 }
1038
1039 /**
1040  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
1041  * the value of this sensor. Operates on the shared data block of sensors.
1042  */
1043 static void draw_default_sensor_header(bSensor *sens,
1044                                                                 uiBlock *block,
1045                                                                 short x,
1046                                                                 short y,
1047                                                                 short w) 
1048 {
1049         uiBut *but;
1050         
1051         /* Pulsing and frequency */
1052         uiBlockBeginAlign(block);
1053         uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP,
1054                          (short)(x + 10 + 0. * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19,
1055                          &sens->pulse, 0.0, 0.0, 0, 0,
1056                          "Activate TRUE level triggering (pulse mode)");
1057
1058         uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN,
1059                          (short)(x + 10 + 0.1 * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19,
1060                          &sens->pulse, 0.0, 0.0, 0, 0,
1061                          "Activate FALSE level triggering (pulse mode)");
1062         uiDefButS(block, NUM, 1, "f:",
1063                          (short)(x + 10 + 0.2 * (w-20)), (short)(y - 21), (short)(0.275 * (w-20)), 19,
1064                          &sens->freq, 0.0, 10000.0, 0, 0,
1065                          "Delay between repeated pulses (in logic tics, 0 = no delay)");
1066         uiBlockEndAlign(block);
1067         
1068         /* value or shift? */
1069         uiBlockBeginAlign(block);
1070         but= uiDefButS(block, TOG, 1, "Level",
1071                          (short)(x + 10 + 0.5 * (w-20)), (short)(y - 21), (short)(0.20 * (w-20)), 19,
1072                          &sens->level, 0.0, 0.0, 0, 0,
1073                          "Level detector, trigger controllers of new states (only applicable upon logic state transition)");
1074         uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->level));
1075         but= uiDefButS(block, TOG, 1, "Tap",
1076                          (short)(x + 10 + 0.702 * (w-20)), (short)(y - 21), (short)(0.12 * (w-20)), 19,
1077                          &sens->tap, 0.0, 0.0, 0, 0,
1078                          "Trigger controllers only for an instant, even while the sensor remains true");
1079         uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->tap));
1080         uiBlockEndAlign(block);
1081         
1082         uiDefButS(block, TOG, 1, "Inv",
1083                          (short)(x + 10 + 0.85 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1084                          &sens->invert, 0.0, 0.0, 0, 0,
1085                          "Invert the level (output) of this sensor");
1086 }
1087
1088 static void get_armature_bone_constraint(Object *ob, const char *posechannel, const char *constraint_name, bConstraint **constraint)
1089 {
1090         /* check that bone exist in the active object */
1091         if (ob->type == OB_ARMATURE && ob->pose) {
1092                 bPoseChannel *pchan= get_pose_channel(ob->pose, posechannel);
1093                 if(pchan) {
1094                         bConstraint *con= BLI_findstring(&pchan->constraints, constraint_name, offsetof(bConstraint, name));
1095                         if(con) {
1096                                 *constraint= con;
1097                         }
1098                 }
1099         }
1100         /* didn't find any */
1101 }
1102 static void check_armature_bone_constraint(Object *ob, char *posechannel, char *constraint)
1103 {
1104         /* check that bone exist in the active object */
1105         if (ob->type == OB_ARMATURE && ob->pose) {
1106                 bPoseChannel *pchan;
1107                 bPose *pose = ob->pose;
1108                 for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) {
1109                         if (!strcmp(pchan->name, posechannel)) {
1110                                 /* found it, now look for constraint channel */
1111                                 bConstraint *con;
1112                                 for (con=pchan->constraints.first; con; con=con->next) {
1113                                         if (!strcmp(con->name, constraint)) {
1114                                                 /* found it, all ok */
1115                                                 return;                                         
1116                                         }
1117                                 }
1118                                 /* didn't find constraint, make empty */
1119                                 constraint[0] = 0;
1120                                 return;
1121                         }
1122                 }
1123         }
1124         /* didn't find any */
1125         posechannel[0] = 0;
1126         constraint[0] = 0;
1127 }
1128
1129 static void check_armature_sensor(bContext *C, void *arg1_but, void *arg2_sens)
1130 {
1131         bArmatureSensor *sens = arg2_sens;
1132         uiBut *but = arg1_but;
1133         Object *ob= CTX_data_active_object(C);
1134
1135         /* check that bone exist in the active object */
1136         but->retval = B_REDR;
1137         check_armature_bone_constraint(ob, sens->posechannel, sens->constraint);
1138 }
1139
1140 static short draw_sensorbuttons(Object *ob, bSensor *sens, uiBlock *block, short xco, short yco, short width)
1141 {
1142         bNearSensor      *ns           = NULL;
1143         bTouchSensor     *ts           = NULL;
1144         bKeyboardSensor  *ks           = NULL;
1145         bPropertySensor  *ps           = NULL;
1146         bArmatureSensor  *arm          = NULL;
1147         bMouseSensor     *ms           = NULL;
1148         bCollisionSensor *cs           = NULL;
1149         bRadarSensor     *rs           = NULL;
1150         bRandomSensor    *randomSensor = NULL;
1151         bRaySensor       *raySens      = NULL;
1152         bMessageSensor   *mes          = NULL;
1153         bJoystickSensor  *joy              = NULL;
1154         bActuatorSensor  *as           = NULL;
1155         bDelaySensor     *ds               = NULL;
1156         uiBut *but;
1157         short ysize;
1158         const char *str;
1159         
1160         /* yco is at the top of the rect, draw downwards */
1161         
1162         set_col_sensor(sens->type, 0);
1163         
1164         switch (sens->type)
1165         {
1166         case SENS_ALWAYS:
1167                 {
1168                         ysize= 24;
1169                         
1170                         glRects(xco, yco-ysize, xco+width, yco);
1171                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1172                         
1173                         draw_default_sensor_header(sens, block, xco, yco, width);
1174                         
1175                         yco-= ysize;
1176                         
1177                         break;
1178                 }
1179         case SENS_TOUCH:
1180                 {
1181                         ysize= 48; 
1182                         
1183                         glRects(xco, yco-ysize, xco+width, yco); 
1184                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1185                         
1186                         draw_default_sensor_header(sens, block, xco, yco, width);
1187                         
1188                         ts= sens->data; 
1189                         
1190                         /* uiDefBut(block, TEX, 1, "Property:", xco,yco-22,width, 19, &ts->name, 0, 31, 0, 0, "Only look for Objects with this property"); */
1191                         uiDefIDPoinBut(block, test_matpoin_but, ID_MA, 1, "MA:",(short)(xco + 10),(short)(yco-44), (short)(width - 20), 19, &ts->ma,  "Only look for floors with this Material"); 
1192                         ///* uiDefButF(block, NUM, 1, "Margin:",        xco+width/2,yco-44,width/2, 19, &ts->dist, 0.0, 10.0, 100, 0, "Extra margin (distance) for larger sensitivity"); 
1193                         yco-= ysize; 
1194                         break; 
1195                 }
1196         case SENS_COLLISION:
1197                 {
1198                         ysize= 48;
1199                         
1200                         glRects(xco, yco-ysize, xco+width, yco);
1201                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1202                         
1203                         draw_default_sensor_header(sens, block, xco, yco, width);
1204                         cs= sens->data;
1205                         
1206                         /* The collision sensor will become a generic collision (i.e. it     */
1207                         /* absorb the old touch sensor).                                     */
1208
1209                         uiDefButBitS(block, TOG, SENS_COLLISION_PULSE, B_REDR, "Pulse",(short)(xco + 10),(short)(yco - 44),
1210                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1211                                 "Changes to the set of colliding objects generated pulses");
1212                         
1213                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",(short)(xco + 10 + (0.20 * (width-20))),(short)(yco - 44),
1214                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1215                                 "Toggle collision on material or property");
1216                         
1217                         if (cs->mode & SENS_COLLISION_MATERIAL) {
1218                                 uiDefBut(block, TEX, 1, "Material:", (short)(xco + 10 + 0.40 * (width-20)),
1219                                         (short)(yco-44), (short)(0.6*(width-20)), 19, &cs->materialName, 0, 31, 0, 0,
1220                                         "Only look for Objects with this material");
1221                         } else {
1222                                 uiDefBut(block, TEX, 1, "Property:", (short)(xco + 10 + 0.40 * (width-20)), (short)(yco-44),
1223                                         (short)(0.6*(width-20)), 19, &cs->name, 0, 31, 0, 0,
1224                                         "Only look for Objects with this property");
1225                         }
1226         
1227                         /*              uiDefButS(block, NUM, 1, "Damp:",       xco+10+width-90,yco-24, 70, 19, &cs->damp, 0, 250, 0, 0, "For 'damp' time don't detect another collision"); */
1228                         
1229                         yco-= ysize;
1230                         break;
1231                 }
1232         case SENS_NEAR:
1233                 {
1234                         ysize= 72;
1235                         
1236                         glRects(xco, yco-ysize, xco+width, yco);
1237                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1238                         
1239                         draw_default_sensor_header(sens, block, xco, yco, width);
1240                         ns= sens->data;
1241                         
1242                         uiDefBut(block, TEX, 1, "Property:",(short)(10+xco),(short)(yco-44), (short)(width-20), 19,
1243                                 &ns->name, 0, 31, 0, 0, "Only look for Objects with this property");
1244                         uiDefButF(block, NUM, 1, "Dist",(short)(10+xco),(short)(yco-68),(short)((width-22)/2), 19,
1245                                 &ns->dist, 0.0, 1000.0, 1000, 0, "Trigger distance");
1246                         uiDefButF(block, NUM, 1, "Reset",(short)(10+xco+(width-22)/2), (short)(yco-68), (short)((width-22)/2), 19,
1247                                 &ns->resetdist, 0.0, 1000.0, 1000, 0, "Reset distance"); 
1248                         yco-= ysize;
1249                         break;
1250                 }
1251         case SENS_RADAR:
1252                 {
1253                         ysize= 72; 
1254                         
1255                         glRects(xco, yco-ysize, xco+width, yco);
1256                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1257                         
1258                         draw_default_sensor_header(sens, block, xco, yco, width);
1259                         
1260                         rs= sens->data;
1261                         
1262                         uiDefBut(block, TEX, 1, "Prop:",
1263                                          (short)(10+xco),(short)(yco-44), (short)(0.7 * (width-20)), 19,
1264                                          &rs->name, 0, 31, 0, 0,
1265                                          "Only look for Objects with this property");
1266
1267                         str = "Type %t|+X axis %x0|+Y axis %x1|+Z axis %x2|-X axis %x3|-Y axis %x4|-Z axis %x5"; 
1268                         uiDefButS(block, MENU, B_REDR, str,
1269                                 (short)(10+xco+0.7 * (width-20)), (short)(yco-44), (short)(0.3 * (width-22)), 19,
1270                                 &rs->axis, 2.0, 31, 0, 0,
1271                                 "Specify along which axis the radar cone is cast");
1272                                 
1273                         uiDefButF(block, NUM, 1, "Ang:",
1274                                          (short)(10+xco), (short)(yco-68), (short)((width-20)/2), 19,
1275                                          &rs->angle, 0.0, 179.9, 10, 0,
1276                                          "Opening angle of the radar cone");
1277                         uiDefButF(block, NUM, 1, "Dist:",
1278                                          (short)(xco+10 + (width-20)/2), (short)(yco-68), (short)((width-20)/2), 19,
1279                                          &rs->range, 0.01, 10000.0, 100, 0,
1280                                          "Depth of the radar cone");
1281                         yco-= ysize;
1282                         break;
1283                 }
1284         case SENS_KEYBOARD:
1285                 {
1286                         ks= sens->data;
1287                         
1288                         /* 5 lines: 120 height */
1289                         ysize= (ks->type&1) ? 96:120;
1290                         
1291                         glRects(xco, yco-ysize, xco+width, yco);
1292                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1293                         
1294                         /* header line */
1295                         draw_default_sensor_header(sens, block, xco, yco, width);
1296                         
1297                         /* part of line 1 */
1298                         uiDefBut(block, LABEL, 0, "Key",          xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
1299                         uiDefButBitS(block, TOG, 1, B_REDR, "All keys",   xco+40+(width/2), yco-44, (width/2)-50, 19,
1300                                 &ks->type, 0, 0, 0, 0, "");
1301                         
1302                         
1303                         if ((ks->type&1)==0) { /* is All Keys option off? */
1304                                 /* line 2: hotkey and allkeys toggle */
1305                                 but= uiDefKeyevtButS(block, 0, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
1306                                 uiButSetFunc(but, test_keyboard_event, ks, NULL);
1307                                 
1308                                 /* line 3: two key modifyers (qual1, qual2) */
1309                                 uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
1310                                 but= uiDefKeyevtButS(block, 0, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
1311                                 uiButSetFunc(but, test_keyboard_event, ks, NULL);
1312                                 but= uiDefKeyevtButS(block, 0, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
1313                                 uiButSetFunc(but, test_keyboard_event, ks, NULL);
1314                         }
1315                         
1316                         /* line 4: toggle property for string logging mode */
1317                         uiDefBut(block, TEX, 1, "LogToggle: ",
1318                                 xco+10, yco-((ks->type&1) ? 68:92), (width-20), 19,
1319                                 ks->toggleName, 0, 31, 0, 0,
1320                                 "Property that indicates whether to log "
1321                                 "keystrokes as a string");
1322                         
1323                         /* line 5: target property for string logging mode */
1324                         uiDefBut(block, TEX, 1, "Target: ",
1325                                 xco+10, yco-((ks->type&1) ? 92:116), (width-20), 19,
1326                                 ks->targetName, 0, 31, 0, 0,
1327                                 "Property that receives the keystrokes in case "
1328                                 "a string is logged");
1329                         
1330                         yco-= ysize;
1331                         break;
1332                 }
1333         case SENS_PROPERTY:
1334                 {
1335                         ysize= 96;
1336                         
1337                         glRects(xco, yco-ysize, xco+width, yco);
1338                         uiEmboss((float)xco, (float)yco-ysize,
1339                                 (float)xco+width, (float)yco, 1);
1340                         
1341                         draw_default_sensor_header(sens, block, xco, yco, width);
1342                         ps= sens->data;
1343                         
1344                         str= "Type %t|Equal %x0|Not Equal %x1|Interval %x2|Changed %x3"; 
1345                         /* str= "Type %t|Equal %x0|Not Equal %x1"; */
1346                         uiDefButI(block, MENU, B_REDR, str,                     xco+30,yco-44,width-60, 19,
1347                                 &ps->type, 0, 31, 0, 0, "Type");
1348                         
1349                         if (ps->type != SENS_PROP_EXPRESSION)
1350                         {
1351                                 uiDefBut(block, TEX, 1, "Prop: ",                       xco+30,yco-68,width-60, 19,
1352                                         ps->name, 0, 31, 0, 0,  "Property name");
1353                         }
1354                         
1355                         if(ps->type == SENS_PROP_INTERVAL)
1356                         {
1357                                 uiDefBut(block, TEX, 1, "Min: ",                xco,yco-92,width/2, 19,
1358                                         ps->value, 0, 31, 0, 0, "check for min value");
1359                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1360                                         ps->maxvalue, 0, 31, 0, 0, "check for max value");
1361                         }
1362                         else if(ps->type == SENS_PROP_CHANGED);
1363                         else
1364                         {
1365                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-92,width-60, 19,
1366                                         ps->value, 0, 31, 0, 0, "check for value");
1367                         }
1368                         
1369                         yco-= ysize;
1370                         break;
1371                 }
1372         case SENS_ARMATURE:
1373                 {
1374                         ysize= 70;
1375                         
1376                         glRects(xco, yco-ysize, xco+width, yco);
1377                         uiEmboss((float)xco, (float)yco-ysize,
1378                                 (float)xco+width, (float)yco, 1);
1379                         
1380                         draw_default_sensor_header(sens, block, xco, yco, width);
1381                         arm= sens->data;
1382
1383                         if (ob->type == OB_ARMATURE) {
1384                                 uiBlockBeginAlign(block);
1385                                 but = uiDefBut(block, TEX, 1, "Bone: ",
1386                                                 (xco+10), (yco-44), (width-20)/2, 19,
1387                                                 arm->posechannel, 0, 31, 0, 0,
1388                                                 "Bone on which you want to check a constraint");
1389                                 uiButSetFunc(but, check_armature_sensor, but, arm);
1390                                 but = uiDefBut(block, TEX, 1, "Cons: ",
1391                                                 (xco+10)+(width-20)/2, (yco-44), (width-20)/2, 19,
1392                                                 arm->constraint, 0, 31, 0, 0,
1393                                                 "Name of the constraint you want to control");
1394                                 uiButSetFunc(but, check_armature_sensor, but, arm);
1395                                 uiBlockEndAlign(block);
1396
1397                                 str= "Type %t|State changed %x0|Lin error below %x1|Lin error above %x2|Rot error below %x3|Rot error above %x4"; 
1398
1399                                 uiDefButI(block, MENU, B_REDR, str,                     xco+10,yco-66,0.4*(width-20), 19,
1400                                         &arm->type, 0, 31, 0, 0, "Type");
1401                         
1402                                 if (arm->type != SENS_ARM_STATE_CHANGED)
1403                                 {
1404                                         uiDefButF(block, NUM, 1, "Value: ",             xco+10+0.4*(width-20),yco-66,0.6*(width-20), 19,
1405                                         &arm->value, -10000.0, 10000.0, 100, 0, "Test the error against this value");
1406                                 }
1407                         }
1408                         yco-= ysize;
1409                         break;
1410                 }
1411         case SENS_ACTUATOR:
1412                 {
1413                         ysize= 48;
1414                         
1415                         glRects(xco, yco-ysize, xco+width, yco);
1416                         uiEmboss((float)xco, (float)yco-ysize,
1417                                 (float)xco+width, (float)yco, 1);
1418                         
1419                         draw_default_sensor_header(sens, block, xco, yco, width);
1420                         as= sens->data;
1421                         
1422                         uiDefBut(block, TEX, 1, "Act: ",                        xco+30,yco-44,width-60, 19,
1423                                         as->name, 0, 31, 0, 0,  "Actuator name, actuator active state modifications will be detected");
1424                         yco-= ysize;
1425                         break;
1426                 }
1427         case SENS_DELAY:
1428                 {
1429                         ysize= 48;
1430                         
1431                         glRects(xco, yco-ysize, xco+width, yco);
1432                         uiEmboss((float)xco, (float)yco-ysize,
1433                                 (float)xco+width, (float)yco, 1);
1434                         
1435                         draw_default_sensor_header(sens, block, xco, yco, width);
1436                         ds = sens->data;
1437                         
1438                         uiDefButS(block, NUM, 0, "Delay",(short)(10+xco),(short)(yco-44),(short)((width-22)*0.4+10), 19,
1439                                 &ds->delay, 0.0, 5000.0, 0, 0, "Delay in number of logic tics before the positive trigger (default 60 per second)");
1440                         uiDefButS(block, NUM, 0, "Dur",(short)(10+xco+(width-22)*0.4+10),(short)(yco-44),(short)((width-22)*0.4-10), 19,
1441                                 &ds->duration, 0.0, 5000.0, 0, 0, "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
1442                         uiDefButBitS(block, TOG, SENS_DELAY_REPEAT, 0, "REP",(short)(xco + 10 + (width-22)*0.8),(short)(yco - 44),
1443                                 (short)(0.20 * (width-22)), 19, &ds->flag, 0.0, 0.0, 0, 0,
1444                                 "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
1445                         yco-= ysize;
1446                         break;
1447                 }
1448         case SENS_MOUSE:
1449                 {
1450                         ms= sens->data;
1451                         /* Two lines: 48 pixels high. */
1452                         ysize = 48;
1453                         
1454                         glRects(xco, yco-ysize, xco+width, yco);
1455                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1456                         
1457                         /* line 1: header */
1458                         draw_default_sensor_header(sens, block, xco, yco, width);
1459                         
1460                         /* Line 2: type selection. The number are a bit mangled to get
1461                         * proper compatibility with older .blend files. */
1462                         /* Any sensor type default is 0 but the ms enum starts in 1.
1463                          * Therefore the mosue sensor is initialized to 1 in sca.c */
1464                         str= "Type %t|Left button %x1|Middle button %x2|"
1465                                 "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16|Mouse over any%x32"; 
1466                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, (width*0.8f)-20, 19,
1467                                 &ms->type, 0, 31, 0, 0,
1468                                 "Specify the type of event this mouse sensor should trigger on");
1469                         
1470                         if(ms->type==32) {
1471                                 uiDefButBitS(block, TOG, SENS_MOUSE_FOCUS_PULSE, B_REDR, "Pulse",(short)(xco + 10) + (width*0.8f)-20,(short)(yco - 44),
1472                                         (short)(0.20 * (width-20)), 19, &ms->flag, 0.0, 0.0, 0, 0,
1473                                         "Moving the mouse over a different object generates a pulse");  
1474                         }
1475                         
1476                         yco-= ysize;
1477                         break;
1478                 }
1479         case SENS_RANDOM:
1480                 {
1481                         ysize = 48;
1482                         
1483                         glRects(xco, yco-ysize, xco+width, yco);
1484                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1485                         
1486                         draw_default_sensor_header(sens, block, xco, yco, width);
1487                         randomSensor = sens->data;
1488                         /* some files were wrongly written, avoid crash now */
1489                         if (randomSensor)
1490                         {
1491                                 uiDefButI(block, NUM, 1, "Seed: ",              xco+10,yco-44,(width-20), 19,
1492                                         &randomSensor->seed, 0, 1000, 0, 0,
1493                                         "Initial seed of the generator. (Choose 0 for not random)");
1494                         }
1495                         yco-= ysize;
1496                         break;
1497                 }
1498         case SENS_RAY:
1499                 {
1500                         ysize = 72;
1501                         glRects(xco, yco-ysize, xco+width, yco);
1502                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1503                         
1504                         draw_default_sensor_header(sens, block, xco, yco, width);
1505                         raySens = sens->data;
1506                         
1507                         /* 1. property or material */
1508                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",
1509                                 xco + 10,yco - 44, 0.20 * (width-20), 19,
1510                                 &raySens->mode, 0.0, 0.0, 0, 0,
1511                                 "Toggle collision on material or property");
1512                         
1513                         if (raySens->mode & SENS_COLLISION_MATERIAL)
1514                         {
1515                                 uiDefBut(block, TEX, 1, "Material:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1516                                         &raySens->matname, 0, 31, 0, 0,
1517                                         "Only look for Objects with this material");
1518                         }
1519                         else
1520                         {
1521                                 uiDefBut(block, TEX, 1, "Property:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1522                                         &raySens->propname, 0, 31, 0, 0,
1523                                         "Only look for Objects with this property");
1524                         }
1525
1526                         /* X-Ray option */
1527                         uiDefButBitS(block, TOG, SENS_RAY_XRAY, 1, "X",
1528                                 xco + 10,yco - 68, 0.10 * (width-20), 19,
1529                                 &raySens->mode, 0.0, 0.0, 0, 0,
1530                                 "Toggle X-Ray option (see through objects that don't have the property)");
1531                         /* 2. sensing range */
1532                         uiDefButF(block, NUM, 1, "Range", xco+10 + 0.10 * (width-20), yco-68, 0.5 * (width-20), 19,
1533                                 &raySens->range, 0.01, 10000.0, 100, 0,
1534                                 "Sense objects no farther than this distance");
1535                         
1536                         /* 3. axis choice */
1537                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1538                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1539                                 &raySens->axisflag, 2.0, 31, 0, 0,
1540                                 "Specify along which axis the ray is cast");
1541                         
1542                         yco-= ysize;            
1543                         break;
1544                 }
1545         case SENS_MESSAGE:
1546                 {
1547                         mes = sens->data;
1548                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1549                         
1550                         glRects(xco, yco-ysize, xco+width, yco);
1551                         uiEmboss((float)xco, (float)yco-ysize,
1552                                 (float)xco+width, (float)yco, 1);
1553                         
1554                         /* line 1: header line */
1555                         draw_default_sensor_header(sens, block, xco, yco, width);
1556                         
1557                         /* line 2: Subject filter */
1558                         uiDefBut(block, TEX, 1, "Subject: ",
1559                                 (xco+10), (yco-44), (width-20), 19,
1560                                 mes->subject, 0, 31, 0, 0,
1561                                 "Optional subject filter: only accept messages with this subject"
1562                                 ", or empty for all");
1563                         
1564                         yco -= ysize;
1565                         break;
1566                 }
1567                 case SENS_JOYSTICK:
1568                 {
1569
1570                         ysize =  72;
1571                         
1572                         glRects(xco, yco-ysize, xco+width, yco);
1573                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1574                         
1575                         /* line 1: header */
1576                         draw_default_sensor_header(sens, block, xco, yco, width);
1577
1578                         joy= sens->data;
1579
1580                         uiDefButC(block, NUM, 1, "Index:", xco+10, yco-44, 0.33 * (width-20), 19,
1581                         &joy->joyindex, 0, SENS_JOY_MAXINDEX-1, 100, 0,
1582                         "Specify which joystick to use");                       
1583
1584                         str= "Type %t|Button %x0|Axis %x1|Single Axis %x3|Hat%x2"; 
1585                         uiDefButC(block, MENU, B_REDR, str, xco+87, yco-44, 0.26 * (width-20), 19,
1586                                 &joy->type, 0, 31, 0, 0,
1587                                 "The type of event this joystick sensor is triggered on");
1588                         
1589                         if (joy->type != SENS_JOY_AXIS_SINGLE) {
1590                                 if (joy->flag & SENS_JOY_ANY_EVENT) {
1591                                         switch (joy->type) {
1592                                         case SENS_JOY_AXIS:     
1593                                                 str = "All Axis Events";
1594                                                 break;
1595                                         case SENS_JOY_BUTTON:   
1596                                                 str = "All Button Events";
1597                                                 break;
1598                                         default:
1599                                                 str = "All Hat Events";
1600                                                 break;
1601                                         }
1602                                 } else {
1603                                         str = "All";
1604                                 }
1605                                 
1606                                 uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR, str,
1607                                         xco+10 + 0.475 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.525 : 0.12) * (width-20), 19,
1608                                         &joy->flag, 0, 0, 0, 0,
1609                                         "Triggered by all events on this joysticks current type (axis/button/hat)");
1610                         }
1611                         if(joy->type == SENS_JOY_BUTTON)
1612                         {
1613                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1614                                         uiDefButI(block, NUM, 1, "Number:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1615                                         &joy->button, 0, 18, 100, 0,
1616                                         "Specify which button to use");
1617                                 }
1618                         }
1619                         else if(joy->type == SENS_JOY_AXIS)
1620                         {
1621                                 uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1622                                 &joy->axis, 1, 8.0, 100, 0,
1623                                 "Specify which axis pair to use, 1 is useually the main direction input");
1624
1625                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1626                                 &joy->precision, 0, 32768.0, 100, 0,
1627                                 "Specify the precision of the axis");
1628
1629                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1630                                         str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1631                                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1632                                         &joy->axisf, 2.0, 31, 0, 0,
1633                                         "The direction of the axis, use 'All Events' to receive events on any direction");
1634                                 }
1635                         }
1636                         else if (joy->type == SENS_JOY_HAT)
1637                         {
1638                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1639                                 &joy->hat, 1, 4.0, 100, 0,
1640                                 "Specify which hat to use");
1641                                 
1642                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1643                                         str = "Direction%t|Up%x1|Down%x4|Left%x8|Right%x2|%l|Up/Right%x3|Down/Left%x12|Up/Left%x9|Down/Right%x6"; 
1644                                         uiDefButI(block, MENU, 0, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1645                                         &joy->hatf, 2.0, 31, 0, 0,
1646                                         "The direction of the hat, use 'All Events' to receive events on any direction");
1647                                 }
1648                         }
1649                         else { /* (joy->type == SENS_JOY_AXIS_SINGLE)*/
1650                                 uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1651                                 &joy->axis_single, 1, 16.0, 100, 0,
1652                                 "Specify a single axis (verticle/horizontal/other) to detect");
1653                                 
1654                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1655                                 &joy->precision, 0, 32768.0, 100, 0,
1656                                 "Specify the precision of the axis");
1657                         }
1658                         yco-= ysize;
1659                         break;
1660                 }
1661         }
1662         
1663         return yco-4;
1664 }
1665
1666
1667
1668 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1669 {
1670         bExpressionCont *ec;
1671         bPythonCont *pc;
1672         short ysize;
1673         
1674         switch (cont->type) {
1675         case CONT_EXPRESSION:
1676                 ysize= 28;
1677
1678                 UI_ThemeColor(TH_PANEL);
1679                 glRects(xco, yco-ysize, xco+width, yco);
1680                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1681                 
1682                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1683                 ec= cont->data; 
1684                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1685                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1686                                  ec->str, 0, 127, 0, 0,
1687                                  "Expression"); 
1688                 
1689                 yco-= ysize;
1690                 break;
1691         case CONT_PYTHON:
1692                 ysize= 28;
1693                 
1694                 if(cont->data==NULL) init_controller(cont);
1695                 pc= cont->data;
1696                 
1697                 UI_ThemeColor(TH_PANEL);
1698                 glRects(xco, yco-ysize, xco+width, yco);
1699                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1700
1701         
1702                 uiBlockBeginAlign(block);
1703                 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)");
1704                 if(pc->mode==0)
1705                         uiDefIDPoinBut(block, test_scriptpoin_but, ID_TXT, 1, "", xco+70,yco-23,width-74, 19, &pc->text, "Blender textblock to run as a script");
1706                 else {
1707                         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");
1708                         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");
1709                 }
1710                 uiBlockEndAlign(block);
1711                 
1712                 yco-= ysize;
1713                 break;
1714                 
1715         default:
1716                 ysize= 4;
1717
1718                 UI_ThemeColor(TH_PANEL);
1719                 glRects(xco, yco-ysize, xco+width, yco);
1720                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1721                 
1722                 yco-= ysize;
1723         }
1724         
1725         return yco;
1726 }
1727
1728 static int get_col_actuator(int type)
1729 {
1730         switch(type) {
1731         case ACT_ACTION:                return TH_PANEL;
1732         case ACT_SHAPEACTION:   return TH_PANEL;
1733         case ACT_OBJECT:                return TH_PANEL;
1734         case ACT_IPO:                   return TH_PANEL;
1735         case ACT_PROPERTY:              return TH_PANEL;
1736         case ACT_SOUND:                 return TH_PANEL;
1737         case ACT_CAMERA:                return TH_PANEL;
1738         case ACT_EDIT_OBJECT:           return TH_PANEL;
1739         case ACT_GROUP:                 return TH_PANEL;
1740         case ACT_RANDOM:                return TH_PANEL;
1741         case ACT_SCENE:                 return TH_PANEL;
1742         case ACT_MESSAGE:               return TH_PANEL;
1743         case ACT_GAME:                  return TH_PANEL;
1744         case ACT_VISIBILITY:            return TH_PANEL;
1745         case ACT_CONSTRAINT:            return TH_PANEL;
1746         case ACT_STATE:                 return TH_PANEL;
1747         case ACT_ARMATURE:                      return TH_PANEL;
1748         default:                                return TH_PANEL;
1749         }
1750 }
1751 static void set_col_actuator(int item, int medium) 
1752 {
1753         int col= get_col_actuator(item);
1754         UI_ThemeColorShade(col, medium?30:10);
1755         
1756 }
1757
1758 static void change_object_actuator(bContext *UNUSED(C), void *act, void *UNUSED(arg))
1759 {
1760         bObjectActuator *oa = act;
1761
1762         if (oa->type != oa->otype) {
1763                 switch (oa->type) {
1764                 case ACT_OBJECT_NORMAL:
1765                         memset(oa, 0, sizeof(bObjectActuator));
1766                         oa->flag = ACT_FORCE_LOCAL|ACT_TORQUE_LOCAL|ACT_DLOC_LOCAL|ACT_DROT_LOCAL;
1767                         oa->type = ACT_OBJECT_NORMAL;
1768                         break;
1769
1770                 case ACT_OBJECT_SERVO:
1771                         memset(oa, 0, sizeof(bObjectActuator));
1772                         oa->flag = ACT_LIN_VEL_LOCAL;
1773                         oa->type = ACT_OBJECT_SERVO;
1774                         oa->forcerot[0] = 30.0f;
1775                         oa->forcerot[1] = 0.5f;
1776                         oa->forcerot[2] = 0.0f;
1777                         break;
1778                 }
1779         }
1780 }
1781
1782 static void change_ipo_actuator(bContext *UNUSED(C), void *arg1_but, void *arg2_ia)
1783 {
1784         bIpoActuator *ia = arg2_ia;
1785         uiBut *but = arg1_but;
1786
1787         if (but->retval & ACT_IPOFORCE)
1788                 ia->flag &= ~ACT_IPOADD;
1789         else if (but->retval & ACT_IPOADD)
1790                 ia->flag &= ~ACT_IPOFORCE;
1791         but->retval = B_REDR;
1792 }
1793
1794 static void update_object_actuator_PID(bContext *UNUSED(C), void *act, void *UNUSED(arg))
1795 {
1796         bObjectActuator *oa = act;
1797         oa->forcerot[0] = 60.0f*oa->forcerot[1];
1798 }
1799
1800 static char *get_state_name(Object *ob, short bit)
1801 {
1802         bController *cont;
1803         unsigned int mask;
1804
1805         mask = (1<<bit);
1806         cont = ob->controllers.first;
1807         while (cont) {
1808                 if (cont->state_mask & mask) {
1809                         return cont->name;
1810                 }
1811                 cont = cont->next;
1812         }
1813         return (char*)"";
1814 }
1815
1816 static void check_state_mask(bContext *C, void *arg1_but, void *arg2_mask)
1817 {
1818         wmWindow *win= CTX_wm_window(C);
1819         int shift= win->eventstate->shift;
1820         unsigned int *cont_mask = arg2_mask;
1821         uiBut *but = arg1_but;
1822
1823         if (*cont_mask == 0 || !(shift))
1824                 *cont_mask = (1<<but->retval);
1825         but->retval = B_REDR;
1826 }
1827
1828 static void check_armature_actuator(bContext *C, void *arg1_but, void *arg2_act)
1829 {
1830         bArmatureActuator *act = arg2_act;
1831         uiBut *but = arg1_but;
1832         Object *ob= CTX_data_active_object(C);
1833
1834         /* check that bone exist in the active object */
1835         but->retval = B_REDR;
1836         check_armature_bone_constraint(ob, act->posechannel, act->constraint);
1837 }
1838
1839
1840 static short draw_actuatorbuttons(Main *bmain, Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
1841 {
1842         bSoundActuator      *sa      = NULL;
1843         bObjectActuator     *oa      = NULL;
1844         bIpoActuator        *ia      = NULL;
1845         bPropertyActuator   *pa      = NULL;
1846         bCameraActuator     *ca      = NULL;
1847         bEditObjectActuator *eoa     = NULL;
1848         bConstraintActuator *coa     = NULL;
1849         bSceneActuator      *sca     = NULL;
1850         bGroupActuator      *ga      = NULL;
1851         bRandomActuator     *randAct = NULL;
1852         bMessageActuator    *ma      = NULL;
1853         bActionActuator     *aa      = NULL;
1854         bGameActuator       *gma     = NULL;
1855         bVisibilityActuator *visAct  = NULL;
1856         bTwoDFilterActuator     *tdfa    = NULL;
1857         bParentActuator     *parAct  = NULL;
1858         bStateActuator          *staAct  = NULL;
1859         bArmatureActuator   *armAct  = NULL;
1860         
1861         float *fp;
1862         short ysize = 0, wval;
1863         const char *str;
1864         int myline, stbit;
1865         uiBut *but;
1866
1867
1868         /* yco is at the top of the rect, draw downwards */
1869         set_col_actuator(act->type, 0);
1870         
1871         switch (act->type)
1872         {
1873         case ACT_OBJECT:
1874                 {
1875                         oa = act->data;
1876                         wval = (width-100)/3;
1877                         if (oa->type == ACT_OBJECT_NORMAL)
1878                         {
1879                                 if ( ob->gameflag & OB_DYNAMIC )
1880                                 {
1881                                         ysize= 175;
1882                                 }
1883                                 else
1884                                 {
1885                                         ysize= 72;
1886                                 }
1887
1888                                 glRects(xco, yco-ysize, xco+width, yco);
1889                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1890                                 
1891                                 uiBlockBeginAlign(block);
1892                                 uiDefBut(block, LABEL, 0, "Loc",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the location");
1893                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1894                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1895                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1896                                 uiBlockEndAlign(block);
1897                                 
1898                                 uiDefBut(block, LABEL, 0, "Rot",        xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the rotation");
1899                                 uiBlockBeginAlign(block);
1900                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1901                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1902                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1903                                 uiBlockEndAlign(block);
1904
1905                                 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");
1906                                 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");
1907         
1908                                 if ( ob->gameflag & OB_DYNAMIC )
1909                                 {
1910                                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-87, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1911                                         uiBlockBeginAlign(block);
1912                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1913                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1914                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1915                                         uiBlockEndAlign(block);
1916
1917                                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-106, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1918                                         uiBlockBeginAlign(block);
1919                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1920                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1921                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");                                
1922                                         uiBlockEndAlign(block);
1923                                 }
1924                                 
1925                                 if ( ob->gameflag & OB_DYNAMIC )
1926                                 {
1927                                         uiDefBut(block, LABEL, 0, "LinV",       xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1928                                         uiBlockBeginAlign(block);
1929                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1930                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1931                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1932                                         uiBlockEndAlign(block);
1933                                 
1934                                         uiDefBut(block, LABEL, 0, "AngV",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1935                                         uiBlockBeginAlign(block);
1936                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1937                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1938                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1939                                         uiBlockEndAlign(block);
1940                                 
1941                                         uiDefBut(block, LABEL, 0, "Damp",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity");
1942                                         uiDefButS(block, NUM, 0, "",            xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, "");
1943
1944                                         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");
1945                                         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");
1946                                         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");
1947                                         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");
1948                                 
1949                                         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");
1950                                 }                               
1951                         } else if (oa->type == ACT_OBJECT_SERVO)
1952                         {
1953                                 ysize= 195;
1954                                 
1955                                 glRects(xco, yco-ysize, xco+width, yco);
1956                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1957                                 
1958                                 uiDefBut(block, LABEL, 0, "Ref",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "");
1959                                 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");
1960                                 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");
1961                                 uiBlockBeginAlign(block);
1962                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-68, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1963                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-68, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1964                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1965                                 uiBlockEndAlign(block);
1966                                 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");
1967
1968                                 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)");
1969                                 uiBlockBeginAlign(block);
1970                                 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");
1971                                 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");
1972                                 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");
1973                                 uiBlockEndAlign(block);
1974                                 uiDefBut(block, LABEL, 0, "Max",        xco, yco-110, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
1975                                 uiDefBut(block, LABEL, 0, "Min",        xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
1976                                 if (oa->flag & ACT_SERVO_LIMIT_X) {
1977                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-110, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1978                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1979                                 }
1980                                 if (oa->flag & ACT_SERVO_LIMIT_Y) {
1981                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-110, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1982                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1983                                 }
1984                                 if (oa->flag & ACT_SERVO_LIMIT_Z) {
1985                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-110, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1986                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1987                                 }
1988                                 uiDefBut(block, LABEL, 0, "Servo",      xco, yco-152, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
1989                                 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");
1990                                 uiDefBut(block, LABEL, 0, "Slow",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
1991                                 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");
1992                                 uiButSetFunc(but, update_object_actuator_PID, oa, NULL);
1993                                 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");
1994                                 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");
1995                         }
1996                         str= "Motion Type %t|Simple motion %x0|Servo Control %x1";
1997                         but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &oa->type, 0.0, 0.0, 0, 0, "");
1998                         oa->otype = oa->type;
1999                         uiButSetFunc(but, change_object_actuator, oa, NULL);
2000                         yco-= ysize;
2001                         break;
2002                 }
2003         case ACT_ACTION:
2004         case ACT_SHAPEACTION:
2005                 {
2006                         /* DrawAct */
2007 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
2008                         ysize = 112;
2009 #else
2010                         ysize= 92;
2011 #endif
2012                         
2013                         glRects(xco, yco-ysize, xco+width, yco);
2014                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2015                         
2016                         aa = act->data;
2017                         wval = (width-60)/3;
2018                         
2019                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
2020 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
2021                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
2022 #else
2023                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
2024 #endif
2025                         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");
2026                         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");
2027                         
2028                         uiDefButBitS(block, TOGN, 1, 0, "Continue", xco+((width/3)*2)+20, yco-24, 60, 19,
2029                                          &aa->end_reset, 0.0, 0.0, 0, 0, "Restore last frame when switching on/off, otherwise play from the start each time");
2030                         
2031                         
2032                         if(aa->type == ACT_ACTION_FROM_PROP)
2033                         {
2034                                 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");
2035                         }
2036                         else
2037                         {
2038                                 uiDefButF(block, NUM, 0, "Sta: ",xco+10, yco-44, (width-20)/2, 19, &aa->sta, 1.0, MAXFRAMEF, 0, 0, "Start frame");
2039                                 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");
2040                         }
2041                                                 
2042                         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");
2043                         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");
2044                         
2045                         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");
2046
2047                         
2048 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
2049                         if(aa->type == ACT_ACTION_MOTION)
2050                         {
2051                                 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");
2052                         }
2053 #endif
2054                         
2055                         
2056                         
2057                         yco-=ysize;
2058                         break;
2059                 }
2060         case ACT_IPO:
2061                 {
2062                         ia= act->data;
2063                         
2064                         ysize= 72;
2065                         
2066                         glRects(xco, yco-ysize, xco+width, yco);
2067                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2068                         
2069                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
2070                         
2071                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-24, (width-20)/2, 19, &ia->type, 0, 0, 0, 0, "");
2072
2073                         but = uiDefButBitS(block, TOG, ACT_IPOFORCE, ACT_IPOFORCE, 
2074                                 "Force", xco+10+(width-20)/2, yco-24, (width-20)/4-10, 19, 
2075                                 &ia->flag, 0, 0, 0, 0, 
2076                                 "Apply Ipo as a global or local force depending on the local option (dynamic objects only)"); 
2077                         uiButSetFunc(but, change_ipo_actuator, but, ia);
2078
2079                         but = uiDefButBitS(block, TOG, ACT_IPOADD, ACT_IPOADD, 
2080                                 "Add", xco+3*(width-20)/4, yco-24, (width-20)/4-10, 19, 
2081                                 &ia->flag, 0, 0, 0, 0, 
2082                                 "Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag"); 
2083                         uiButSetFunc(but, change_ipo_actuator, but, ia);
2084                         
2085                         /* Only show the do-force-local toggle if force is requested */
2086                         if (ia->flag & (ACT_IPOFORCE|ACT_IPOADD)) {
2087                                 uiDefButBitS(block, TOG, ACT_IPOLOCAL, 0, 
2088                                         "L", xco+width-30, yco-24, 20, 19, 
2089                                         &ia->flag, 0, 0, 0, 0, 
2090                                         "Let the ipo acts in local coordinates, used in Force and Add mode"); 
2091                         }
2092
2093                         if(ia->type==ACT_IPO_FROM_PROP) {
2094                                 uiDefBut(block, TEX, 0, 
2095                                         "Prop: ",               xco+10, yco-44, width-80, 19, 
2096                                         ia->name, 0.0, 31.0, 0, 0, 
2097                                         "Use this property to define the Ipo position");
2098                         }
2099                         else {
2100                                 uiDefButF(block, NUM, 0, 
2101                                         "Sta",          xco+10, yco-44, (width-80)/2, 19, 
2102                                         &ia->sta, 1.0, MAXFRAMEF, 0, 0, 
2103                                         "Start frame");
2104                                 uiDefButF(block, NUM, 0, 
2105                                         "End",          xco+10+(width-80)/2, yco-44, (width-80)/2, 19, 
2106                                         &ia->end, 1.0, MAXFRAMEF, 0, 0, 
2107                                         "End frame");
2108                         }
2109                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
2110                                 "Child",        xco+10+(width-80), yco-44, 60, 19, 
2111                                 &ia->flag, 0, 0, 0, 0, 
2112                                 "Update IPO on all children Objects as well");
2113                         uiDefBut(block, TEX, 0, 
2114                                 "FrameProp: ",          xco+10, yco-64, width-20, 19, 
2115                                 ia->frameProp, 0.0, 31.0, 0, 0, 
2116                                 "Assign the action's current frame number to this property");
2117
2118                         yco-= ysize;
2119                         break;
2120                 }
2121         case ACT_PROPERTY:
2122                 {
2123                         ysize= 68;
2124                         
2125                         glRects(xco, yco-ysize, xco+width, yco);
2126                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2127                         
2128                         pa= act->data;
2129                         
2130                         str= "Type%t|Assign%x0|Add %x1|Copy %x2|Toggle (bool/int/float/timer)%x3";
2131                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
2132                         
2133                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
2134                         
2135                         
2136                         if(pa->type==ACT_PROP_TOGGLE) {
2137                                 /* no ui */
2138                                 ysize -= 22;
2139                         }
2140                         else if(pa->type==ACT_PROP_COPY) {
2141                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
2142                                 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");
2143                         }
2144                         else {
2145                                 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");
2146                         }
2147                         yco-= ysize;
2148                         
2149                         break;
2150                 }
2151         case ACT_SOUND:
2152                 {
2153                         sa = act->data;
2154                         sa->sndnr = 0;
2155                         
2156                         if(sa->flag & ACT_SND_3D_SOUND)
2157                                 ysize = 180;
2158                         else
2159                                 ysize = 92;
2160
2161                         wval = (width-20)/2;
2162                         glRects(xco, yco-ysize, xco+width, yco);
2163                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2164                         
2165                         if(bmain->sound.first) {
2166                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(bmain->sound), (ID *)sa->sound, &(sa->sndnr));
2167                                 /* reset this value, it is for handling the event */
2168                                 sa->sndnr = 0;
2169                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
2170                                 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.");
2171
2172                                 if(sa->sound) {
2173                                         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";
2174                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,wval-20,19, ((ID *)sa->sound)->name+2,    0.0, 21.0, 0, 0, "");
2175                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
2176                                         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");
2177                                         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");
2178                                         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.");
2179                                         if(sa->flag & ACT_SND_3D_SOUND)
2180                                         {
2181                                                 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.");
2182                                                 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.");
2183                                                 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.");
2184                                                 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.");
2185                                                 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.");
2186                                                 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.");
2187                                                 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.");
2188                                                 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.");
2189                                         }
2190                                 }
2191                                 MEM_freeN((void *)str);
2192                         } 
2193                         else {
2194                                 uiDefButO(block, BUT, "sound.open", 0, "Load Sound", xco+10, yco-22, width-20, 19, "Load a sound file.");
2195                         }
2196                                         
2197                         yco-= ysize;
2198                         
2199                         break;
2200                 }
2201         case ACT_CAMERA:
2202
2203                 ysize= 48;
2204
2205                 glRects(xco, yco-ysize, xco+width, yco);
2206                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2207                 
2208                 ca= act->data;
2209
2210                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
2211                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
2212                 
2213                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
2214                 
2215                 if(ca->axis==0) ca->axis= 'x';
2216                 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");
2217                 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");
2218                 
2219                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
2220
2221                 yco-= ysize;
2222
2223                 break;
2224
2225         case ACT_EDIT_OBJECT:
2226                 
2227                 eoa= act->data;
2228
2229                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
2230                         ysize = 92;
2231                         glRects(xco, yco-ysize, xco+width, yco);
2232                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2233
2234                         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)");
2235                         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");
2236
2237                         wval= (width-60)/3;
2238                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
2239                                          NULL, 0, 0, 0, 0,
2240                                          "Velocity upon creation");
2241                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
2242                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
2243                                          "Velocity upon creation, x component");
2244                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
2245                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
2246                                          "Velocity upon creation, y component");
2247                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
2248                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
2249                                          "Velocity upon creation, z component");
2250                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_LINV, 0, "L", xco+45+3*wval, yco-68, 15, 19,
2251                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2252                                          "Apply the transformation locally");
2253                         
2254                         
2255                         uiDefBut(block, LABEL, 0, "AngV",       xco,           yco-90,   45, 19,
2256                                          NULL, 0, 0, 0, 0,
2257                                          "Angular velocity upon creation");
2258                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-90, wval, 19,
2259                                          eoa->angVelocity, -10000.0, 10000.0, 10, 0,
2260                                          "Angular velocity upon creation, x component");
2261                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-90, wval, 19,
2262                                          eoa->angVelocity+1, -10000.0, 10000.0, 10, 0,
2263                                          "Angular velocity upon creation, y component");
2264                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-90, wval, 19,
2265                                          eoa->angVelocity+2, -10000.0, 10000.0, 10, 0,
2266                                          "Angular velocity upon creation, z component");
2267                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_ANGV, 0, "L", xco+45+3*wval, yco-90, 15, 19,
2268                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2269                                          "Apply the rotation locally");
2270                                          
2271
2272                 }
2273                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
2274                         ysize= 28;
2275                         glRects(xco, yco-ysize, xco+width, yco);
2276                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2277                 }
2278                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
2279                         ysize= 48;
2280                         glRects(xco, yco-ysize, xco+width, yco);
2281                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2282          
2283                         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");
2284                         
2285                         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");
2286                         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)");
2287                 }
2288                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
2289                         ysize= 48;
2290                         glRects(xco, yco-ysize, xco+width, yco);
2291                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2292          
2293                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
2294                         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");
2295                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
2296                 }
2297                 else if(eoa->type==ACT_EDOB_DYNAMICS) {
2298                         ysize= 69;
2299                         glRects(xco, yco-ysize, xco+width, yco);
2300                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2301                         
2302                         str= "Dynamic Operation %t|Restore Dynamics %x0|Suspend Dynamics %x1|Enable Rigid Body %x2|Disable Rigid Body %x3|Set Mass %x4";
2303                         uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-44, (width-80), 19,  &(eoa->dyn_operation), 0.0, 0.0, 0, 0, "");
2304                         if(eoa->dyn_operation==4) {
2305                                 uiDefButF(block, NUM, 0, "",            xco+40, yco-63, width-80, 19,
2306                                          &eoa->mass, 0.0, 10000.0, 10, 0,
2307                                          "Mass for object");
2308                         }
2309                 }
2310                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3|Dynamics %x4";
2311                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
2312
2313                  yco-= ysize;
2314
2315                 break;
2316
2317         case ACT_CONSTRAINT:
2318                 coa= act->data;
2319         
2320                 if (coa->type == ACT_CONST_TYPE_LOC) {
2321                         ysize= 69;
2322
2323                         glRects(xco, yco-ysize, xco+width, yco);
2324                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2325                         
2326         /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
2327         /*                      coa->flag &= ~(63); */
2328                         str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
2329                         coa->flag &= 7;
2330                         coa->time = 0;
2331                         uiDefButS(block, MENU, 1, str,          xco+10, yco-65, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
2332                 
2333                         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");
2334                         uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2335                         uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2336
2337                         if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
2338                         else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
2339                         else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
2340                         else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
2341                         else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
2342                         else fp= coa->minrot+2;
2343                         
2344                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
2345                         uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-65, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
2346                 } else if (coa->type == ACT_CONST_TYPE_DIST) {
2347                         ysize= 106;
2348
2349                         glRects(xco, yco-ysize, xco+width, yco);
2350                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2351                         
2352                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2353                         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");
2354                 
2355                         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");
2356                         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");
2357                         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");
2358                         uiDefButBitS(block, TOG, ACT_CONST_LOCAL, 0, "L", xco+80+(width-115), yco-45, 25, 19,
2359                                          &coa->flag, 0.0, 0.0, 0, 0, "Set ray along object's axis or global axis");
2360
2361                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2362                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2363                         else fp= coa->minloc+2;
2364
2365                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/2, 19, fp+3, 0.0, 2000.0, 10, 0, "Maximum length of ray");
2366                         if (coa->flag & ACT_CONST_DISTANCE)
2367                                 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");
2368                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2369                                          &coa->flag, 0.0, 0.0, 0, 0, "Set object axis along (local axis) or parallel (global axis) to the normal at hit position");
2370                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2371                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2372                         if (coa->flag & ACT_CONST_MATERIAL)
2373                         {
2374                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2375                                         coa->matprop, 0, 31, 0, 0,
2376                                         "Ray detects only Objects with this material");
2377                         }
2378                         else
2379                         {
2380                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2381                                         coa->matprop, 0, 31, 0, 0,
2382                                         "Ray detect only Objects with this property");
2383                         }
2384                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2385                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2386                         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");
2387                         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");
2388                 } else if (coa->type == ACT_CONST_TYPE_ORI) {
2389                         ysize= 87;
2390
2391                         glRects(xco, yco-ysize, xco+width, yco);
2392                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2393                         
2394                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4";
2395                         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");
2396                 
2397                         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");
2398                         uiDefBut(block, LABEL,                  0, "X", xco+80, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2399                         uiDefBut(block, LABEL,                  0, "Y", xco+80+(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2400                         uiDefBut(block, LABEL,                  0, "Z", xco+80+2*(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2401
2402                         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");
2403                         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");
2404                         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");
2405
2406                         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");
2407                         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");
2408                         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");
2409                 } else if (coa->type == ACT_CONST_TYPE_FH) {
2410                         ysize= 106;
2411
2412                         glRects(xco, yco-ysize, xco+width, yco);
2413                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2414                         
2415                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2416                         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)");
2417
2418                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2419                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2420                         else fp= coa->minloc+2;
2421
2422                         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");
2423                         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");
2424                         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");
2425
2426                         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");
2427                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2428                                          &coa->flag, 0.0, 0.0, 0, 0, "Add a horizontal spring force on slopes");
2429                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2430                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2431                         if (coa->flag & ACT_CONST_MATERIAL)
2432                         {
2433                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2434                                         coa->matprop, 0, 31, 0, 0,
2435                                         "Ray detects only Objects with this material");
2436                         }
2437                         else
2438                         {
2439                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2440                                         coa->matprop, 0, 31, 0, 0,
2441                                         "Ray detect only Objects with this property");
2442                         }
2443                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2444                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2445                         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");
2446                         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");
2447                 }
2448                 str= "Constraint Type %t|Location %x0|Distance %x1|Orientation %x2|Force field %x3";
2449                 but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &coa->type, 0.0, 0.0, 0, 0, "");
2450                  yco-= ysize;
2451                 break;
2452  
2453         case ACT_SCENE:
2454                 sca= act->data;
2455                 
2456                 if(sca->type==ACT_SCENE_RESTART) {
2457                         ysize= 28;
2458                         glRects(xco, yco-ysize, xco+width, yco);
2459                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2460                 }
2461                 else if(sca->type==ACT_SCENE_CAMERA) {
2462
2463                         ysize= 48;
2464                         glRects(xco, yco-ysize, xco+width, yco);
2465                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2466
2467                         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");
2468                 }
2469                 else if(sca->type==ACT_SCENE_SET) {
2470                         
2471                         ysize= 48;
2472                         glRects(xco, yco-ysize, xco+width, yco);
2473                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2474
2475                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene");
2476                 }
2477                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
2478                         
2479                         ysize= 48;
2480                         glRects(xco, yco-ysize, xco+width, yco);
2481                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2482
2483                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene");
2484                 }
2485                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
2486                         
2487                         ysize= 48;
2488                         glRects(xco, yco-ysize, xco+width, yco);
2489                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2490
2491                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene");
2492                 }
2493                 else if(sca->type==ACT_SCENE_REMOVE) { 
2494                         
2495                         ysize= 48;
2496                         glRects(xco, yco-ysize, xco+width, yco);
2497                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2498
2499                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
2500                 }
2501                 else if(sca->type==ACT_SCENE_SUSPEND) { 
2502                         
2503                         ysize= 48;
2504                         glRects(xco, yco-ysize, xco+width, yco);
2505                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2506
2507                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
2508                 }
2509                 else if(sca->type==ACT_SCENE_RESUME) { 
2510                         
2511                         ysize= 48;
2512                         glRects(xco, yco-ysize, xco+width, yco);
2513                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2514
2515                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
2516                 }
2517
2518                 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";
2519                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
2520
2521                   yco-= ysize; 
2522                   break; 
2523         case ACT_GAME:
2524                 {
2525                         gma = act->data; 
2526                         if (gma->type == ACT_GAME_LOAD)
2527                         {
2528                                 //ysize = 68;
2529                                 ysize = 48;
2530                                 glRects(xco, yco-ysize, xco+width, yco); 
2531                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2532                                    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");
2533 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2534                         }
2535 /*                      else if (gma->type == ACT_GAME_START)
2536                         {
2537                                 ysize = 68; 
2538                                 glRects(xco, yco-ysize, xco+width, yco); 
2539                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2540
2541                                    uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2542                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2543                         }
2544 */                      else if (ELEM4(gma->type, ACT_GAME_RESTART, ACT_GAME_QUIT, ACT_GAME_SAVECFG, ACT_GAME_LOADCFG))
2545                         {
2546                                 ysize = 28; 
2547                                 glRects(xco, yco-ysize, xco+width, yco); 
2548                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2549                         }
2550
2551                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
2552                         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";
2553                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
2554                         
2555                         yco -= ysize; 
2556                         break; 
2557                 }
2558         case ACT_GROUP:
2559                 ga= act->data;
2560
2561                 ysize= 52;
2562
2563                 glRects(xco, yco-ysize, xco+width, yco);
2564                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2565                 
2566                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
2567
2568                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
2569                 if(ga->type==ACT_GROUP_SET) {
2570                         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");
2571                         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");
2572                 }
2573                 else if(ga->type==ACT_GROUP_FROM_PROP) {
2574                         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");
2575                 }
2576                 else {
2577                         uiDefButI(block, NUM, 0, "State",               xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
2578               &