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