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