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