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