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