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