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