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