- got rid of silly #define ..._BIT, #define ... (1<<..._BIT) stuff
[blender.git] / source / blender / src / buttons_logic.c
1 /**
2  * $Id: 
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <stdlib.h>
34 #include <math.h>
35 #include <string.h>
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 #ifndef WIN32
42 #include <unistd.h>
43 #else
44 #include <io.h>
45 #endif   
46
47 #include "MEM_guardedalloc.h"
48
49 #include "BLI_blenlib.h"
50 #include "BLI_arithb.h"
51
52 #include "DNA_action_types.h"
53 #include "DNA_material_types.h"
54 #include "DNA_sensor_types.h"
55 #include "DNA_actuator_types.h"
56 #include "DNA_controller_types.h"
57 #include "DNA_property_types.h"
58 #include "DNA_object_types.h"
59 #include "DNA_screen_types.h"
60 #include "DNA_space_types.h"
61 #include "DNA_scene_types.h"
62 #include "DNA_sound_types.h"
63 #include "DNA_text_types.h"
64 #include "DNA_userdef_types.h"
65 #include "DNA_view3d_types.h"
66 #include "DNA_mesh_types.h"
67 #include "DNA_world_types.h"
68
69 #include "BKE_library.h"
70 #include "BKE_global.h"
71 #include "BKE_main.h"
72 #include "BKE_sca.h"
73 #include "BKE_property.h"
74
75 #include "BIF_gl.h"
76 #include "BIF_resources.h"
77 #include "BIF_space.h"
78 #include "BIF_interface.h"
79 #include "BIF_butspace.h"
80 #include "BIF_screen.h"
81 #include "BIF_keyval.h"
82 #include "BIF_editsound.h"
83
84 #include "BIF_editsca.h"
85
86
87 #include "BDR_editcurve.h"
88 #include "BSE_buttons.h"
89 #include "BSE_headerbuttons.h"
90 #include "BSE_filesel.h"
91
92 #include "blendef.h"
93 #include "mydevice.h"
94 #include "nla.h"        /* For __NLA : Important, do not remove */
95 #include "butspace.h" // own module
96
97 /* internals */
98 void buttons_enji(uiBlock *, Object *);
99 void buttons_ketsji(uiBlock *, Object *);
100
101 /****/
102
103 static ID **get_selected_and_linked_obs(short *count, short scavisflag);
104 static char *actuator_pup(Object *owner);
105
106 /****/
107
108
109 static void del_property(void *selpropv, void *data2_unused)
110 {
111         bProperty *prop, *selprop= selpropv;
112         Object *ob;
113         int a=0;
114                 
115         ob= OBACT;
116         if(ob==NULL) return;
117
118         prop= ob->prop.first;
119         while(prop) {
120                 if(prop==selprop) {
121                         if (strcmp(prop->name,"Text") == 0) {
122                                 allqueue(REDRAWVIEW3D, 0);
123                         }
124                         BLI_remlink(&ob->prop, prop);
125                         free_property(prop);
126                         break;
127                 }
128                 a++;
129                 prop= prop->next;
130         }
131         BIF_undo_push("Delete property");
132         allqueue(REDRAWBUTSLOGIC, 0);
133         
134 }
135
136 static int vergname(const void *v1, const void *v2)
137 {
138         char **x1, **x2;
139         
140         x1= (char **)v1;
141         x2= (char **)v2;
142         
143         return strcmp(*x1, *x2);
144 }
145
146 void make_unique_prop_names(char *str)
147 {
148         Object *ob;
149         bProperty *prop;
150         bSensor *sens;
151         bController *cont;
152         bActuator *act;
153         ID **idar;
154         short a, obcount, propcount=0, nr;
155         char **names;
156         
157         /* this function is called by a Button, and gives the current
158          * stringpointer as an argument, this is the one that can change
159          */
160
161         idar= get_selected_and_linked_obs(&obcount, BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_CONT_SEL|BUTS_CONT_ACT);
162         
163         /* for each object, make properties and sca names unique */
164         
165         /* count total names */
166         for(a=0; a<obcount; a++) {
167                 ob= (Object *)idar[a];
168                 propcount+= BLI_countlist(&ob->prop);
169                 propcount+= BLI_countlist(&ob->sensors);
170                 propcount+= BLI_countlist(&ob->controllers);
171                 propcount+= BLI_countlist(&ob->actuators);
172         }       
173         if(propcount==0) {
174                 if(idar) MEM_freeN(idar);
175                 return;
176         }
177         
178         /* make names array for sorting */
179         names= MEM_callocN(propcount*sizeof(void *), "names");
180
181         /* count total names */
182         nr= 0;
183         for(a=0; a<obcount; a++) {
184                 ob= (Object *)idar[a];
185                 prop= ob->prop.first;
186                 while(prop) {
187                         names[nr++]= prop->name;
188                         prop= prop->next;
189                 }
190                 sens= ob->sensors.first;
191                 while(sens) {
192                         names[nr++]= sens->name;
193                         sens= sens->next;
194                 }
195                 cont= ob->controllers.first;
196                 while(cont) {
197                         names[nr++]= cont->name;
198                         cont= cont->next;
199                 }
200                 act= ob->actuators.first;
201                 while(act) {
202                         names[nr++]= act->name;
203                         act= act->next;
204                 }
205         }
206
207         qsort(names, propcount, sizeof(void *), vergname);
208         
209         /* now we check for double names, and change them */
210         
211         for(nr=0; nr<propcount; nr++) {
212                 if(names[nr]!=str && strcmp( names[nr], str )==0 ) {
213                         BLI_newname(str, +1);
214                 }
215         }
216         
217         MEM_freeN(idar);
218         MEM_freeN(names);
219 }
220
221 static void make_unique_prop_names_cb(void *strv, void *redraw_view3d_flagv)
222 {
223         char *str= strv;
224         int redraw_view3d_flag= (int) redraw_view3d_flagv;
225
226         make_unique_prop_names(str);
227         if (redraw_view3d_flag) allqueue(REDRAWVIEW3D, 0);
228 }
229
230 static void sca_move_sensor(void *datav, void *data2_unused)
231 {
232         bSensor *sens_to_delete= datav;
233         int val;
234         Base *base;
235         bSensor *sens;
236         
237         val= pupmenu("Move up%x1|Move down %x2");
238         
239         if(val>0) {
240                 /* now find out which object has this ... */
241                 base= FIRSTBASE;
242                 while(base) {
243                 
244                         sens= base->object->sensors.first;
245                         while(sens) {
246                                 if(sens == sens_to_delete) break;
247                                 sens= sens->next;
248                         }
249                         
250                         if(sens) {
251                                 if( val==1 && sens->prev) {
252                                         BLI_remlink(&base->object->sensors, sens);
253                                         BLI_insertlinkbefore(&base->object->sensors, sens->prev, sens);
254                                 }
255                                 else if( val==2 && sens->next) {
256                                         BLI_remlink(&base->object->sensors, sens);
257                                         BLI_insertlink(&base->object->sensors, sens->next, sens);
258                                 }
259                                 BIF_undo_push("Move sensor");
260                                 allqueue(REDRAWBUTSLOGIC, 0);
261                                 break;
262                         }
263                         
264                         base= base->next;
265                 }
266         }
267 }
268
269 static void sca_move_controller(void *datav, void *data2_unused)
270 {
271         bController *controller_to_del= datav;
272         int val;
273         Base *base;
274         bController *cont;
275         
276         val= pupmenu("Move up%x1|Move down %x2");
277         
278         if(val>0) {
279                 /* now find out which object has this ... */
280                 base= FIRSTBASE;
281                 while(base) {
282                 
283                         cont= base->object->controllers.first;
284                         while(cont) {
285                                 if(cont == controller_to_del) break;
286                                 cont= cont->next;
287                         }
288                         
289                         if(cont) {
290                                 if( val==1 && cont->prev) {
291                                         BLI_remlink(&base->object->controllers, cont);
292                                         BLI_insertlinkbefore(&base->object->controllers, cont->prev, cont);
293                                 }
294                                 else if( val==2 && cont->next) {
295                                         BLI_remlink(&base->object->controllers, cont);
296                                         BLI_insertlink(&base->object->controllers, cont->next, cont);
297                                 }
298                                 BIF_undo_push("Move controller");
299                                 allqueue(REDRAWBUTSLOGIC, 0);
300                                 break;
301                         }
302                         
303                         base= base->next;
304                 }
305         }
306 }
307
308 static void sca_move_actuator(void *datav, void *data2_unused)
309 {
310         bActuator *actuator_to_move= datav;
311         int val;
312         Base *base;
313         bActuator *act;
314         
315         val= pupmenu("Move up%x1|Move down %x2");
316         
317         if(val>0) {
318                 /* now find out which object has this ... */
319                 base= FIRSTBASE;
320                 while(base) {
321                 
322                         act= base->object->actuators.first;
323                         while(act) {
324                                 if(act == actuator_to_move) break;
325                                 act= act->next;
326                         }
327                         
328                         if(act) {
329                                 if( val==1 && act->prev) {
330                                         BLI_remlink(&base->object->actuators, act);
331                                         BLI_insertlinkbefore(&base->object->actuators, act->prev, act);
332                                 }
333                                 else if( val==2 && act->next) {
334                                         BLI_remlink(&base->object->actuators, act);
335                                         BLI_insertlink(&base->object->actuators, act->next, act);
336                                 }
337                                 BIF_undo_push("Move actuator");
338                                 allqueue(REDRAWBUTSLOGIC, 0);
339                                 break;
340                         }
341                         
342                         base= base->next;
343                 }
344         }
345 }
346
347 void do_logic_buts(unsigned short event)
348 {
349         bProperty *prop;
350         bSensor *sens;
351         bController *cont;
352         bActuator *act;
353         Base *base;
354         Object *ob;
355         int didit;
356         
357         ob= OBACT;
358         if(ob==0) return;
359         
360         switch(event) {
361
362         case B_SETSECTOR:
363                 /* check for inconsistant types */
364                 ob->gameflag &= ~(OB_PROP|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
365                 ob->dtx |= OB_BOUNDBOX;
366                 allqueue(REDRAWBUTSGAME, 0);
367                 allqueue(REDRAWVIEW3D, 0);
368                 break;
369                 
370         case B_SETPROP:
371                 /* check for inconsistant types */
372                 ob->gameflag &= ~(OB_SECTOR|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
373                 allqueue(REDRAWBUTSGAME, 0);
374                 allqueue(REDRAWVIEW3D, 0);
375                 break;
376
377         case B_SETACTOR:
378         case B_SETDYNA:
379         case B_SETMAINACTOR:
380                 ob->gameflag &= ~(OB_SECTOR|OB_PROP);
381                 allqueue(REDRAWBUTSGAME, 0);
382                 allqueue(REDRAWVIEW3D, 0);
383                 break;
384
385
386         case B_ADD_PROP:
387                 prop= new_property(PROP_FLOAT);
388                 make_unique_prop_names(prop->name);
389                 BLI_addtail(&ob->prop, prop);
390                 BIF_undo_push("Add property");
391                 allqueue(REDRAWBUTSLOGIC, 0);
392                 break;
393         
394         case B_CHANGE_PROP:
395                 prop= ob->prop.first;
396                 while(prop) {
397                         if(prop->type!=prop->otype) {
398                                 init_property(prop);
399                                 if (strcmp(prop->name, "Text") == 0) {
400                                         allqueue(REDRAWVIEW3D, 0);
401                                 }
402                         }
403                         prop= prop->next;
404                 }
405                 allqueue(REDRAWBUTSLOGIC, 0);
406                 break;
407         
408         case B_ADD_SENS:
409                 base= FIRSTBASE;
410                 while(base) {
411                         if(base->object->scaflag & OB_ADDSENS) {
412                                 base->object->scaflag &= ~OB_ADDSENS;
413                                 sens= new_sensor(SENS_ALWAYS);
414                                 BLI_addtail(&(base->object->sensors), sens);
415                                 make_unique_prop_names(sens->name);
416                                 base->object->scaflag |= OB_SHOWSENS;
417                         }
418                         base= base->next;
419                 }
420                 
421                 BIF_undo_push("Add sensor");
422                 allqueue(REDRAWBUTSLOGIC, 0);
423                 break;
424
425         case B_CHANGE_SENS:
426                 base= FIRSTBASE;
427                 while(base) {
428                         sens= base->object->sensors.first;
429                         while(sens) {
430                                 if(sens->type != sens->otype) {
431                                         init_sensor(sens);
432                                         sens->otype= sens->type;
433                                         break;
434                                 }
435                                 sens= sens->next;
436                         }
437                         base= base->next;
438                 }
439                 allqueue(REDRAWBUTSLOGIC, 0);
440                 break;
441         
442         case B_DEL_SENS:
443                 base= FIRSTBASE;
444                 while(base) {
445                         sens= base->object->sensors.first;
446                         while(sens) {
447                                 if(sens->flag & SENS_DEL) {
448                                         BLI_remlink(&(base->object->sensors), sens);
449                                         free_sensor(sens);
450                                         break;
451                                 }
452                                 sens= sens->next;
453                         }
454                         base= base->next;
455                 }
456                 BIF_undo_push("Delete sensor");
457                 allqueue(REDRAWBUTSLOGIC, 0);
458                 break;
459         
460         case B_ADD_CONT:
461                 base= FIRSTBASE;
462                 while(base) {
463                         if(base->object->scaflag & OB_ADDCONT) {
464                                 base->object->scaflag &= ~OB_ADDCONT;
465                                 cont= new_controller(CONT_LOGIC_AND);
466                                 make_unique_prop_names(cont->name);
467                                 base->object->scaflag |= OB_SHOWCONT;
468                                 BLI_addtail(&(base->object->controllers), cont);
469                         }
470                         base= base->next;
471                 }
472                 BIF_undo_push("Add controller");
473                 allqueue(REDRAWBUTSLOGIC, 0);
474                 break;
475
476         case B_CHANGE_CONT:
477                 base= FIRSTBASE;
478                 while(base) {
479                         cont= base->object->controllers.first;
480                         while(cont) {
481                                 if(cont->type != cont->otype) {
482                                         init_controller(cont);
483                                         cont->otype= cont->type;
484                                         break;
485                                 }
486                                 cont= cont->next;
487                         }
488                         base= base->next;
489                 }
490                 allqueue(REDRAWBUTSLOGIC, 0);
491                 break;
492         
493
494         case B_DEL_CONT:
495                 base= FIRSTBASE;
496                 while(base) {
497                         cont= base->object->controllers.first;
498                         while(cont) {
499                                 if(cont->flag & CONT_DEL) {
500                                         BLI_remlink(&(base->object->controllers), cont);
501                                         unlink_controller(cont);
502                                         free_controller(cont);
503                                         break;
504                                 }
505                                 cont= cont->next;
506                         }
507                         base= base->next;
508                 }
509                 BIF_undo_push("Delete controller");
510                 allqueue(REDRAWBUTSLOGIC, 0);
511                 break;
512         
513         case B_ADD_ACT:
514                 base= FIRSTBASE;
515                 while(base) {
516                         if(base->object->scaflag & OB_ADDACT) {
517                                 base->object->scaflag &= ~OB_ADDACT;
518                                 act= new_actuator(ACT_OBJECT);
519                                 make_unique_prop_names(act->name);
520                                 BLI_addtail(&(base->object->actuators), act);
521                                 base->object->scaflag |= OB_SHOWACT;
522                         }
523                         base= base->next;
524                 }
525                 BIF_undo_push("Add actuator");
526                 allqueue(REDRAWBUTSLOGIC, 0);
527                 break;
528
529         case B_CHANGE_ACT:
530                 base= FIRSTBASE;
531                 while(base) {
532                         act= base->object->actuators.first;
533                         while(act) {
534                                 if(act->type != act->otype) {
535                                         init_actuator(act);
536                                         act->otype= act->type;
537                                         break;
538                                 }
539                                 act= act->next;
540                         }
541                         base= base->next;
542                 }
543                 allqueue(REDRAWBUTSLOGIC, 0);
544                 break;
545
546         case B_DEL_ACT:
547                 base= FIRSTBASE;
548                 while(base) {
549                         act= base->object->actuators.first;
550                         while(act) {
551                                 if(act->flag & ACT_DEL) {
552                                         BLI_remlink(&(base->object->actuators), act);
553                                         unlink_actuator(act);
554                                         free_actuator(act);
555                                         break;
556                                 }
557                                 act= act->next;
558                         }
559                         base= base->next;
560                 }
561                 BIF_undo_push("Delete actuator");
562                 allqueue(REDRAWBUTSLOGIC, 0);
563                 break;
564         
565         case B_SOUNDACT_BROWSE:
566                 /* since we don't know which... */
567                 didit= 0;
568                 base= FIRSTBASE;
569                 while(base)
570                 {
571                         act= base->object->actuators.first;
572                         while(act)
573                         {
574                                 if(act->type==ACT_SOUND)
575                                 {
576                                         bSoundActuator *sa= act->data;
577                                         if(sa->sndnr)
578                                         {
579                                                 bSound *sound= G.main->sound.first;
580                                                 int nr= 1;
581
582                                                 if(sa->sndnr == -2) {
583                                                         activate_databrowse((ID *)G.main->sound.first, ID_SO, 0, B_SOUNDACT_BROWSE,
584                                                                                         &sa->sndnr, do_logic_buts);
585                                                         break;
586                                                 }
587
588                                                 while(sound)
589                                                 {
590                                                         if(nr==sa->sndnr)
591                                                                 break;
592                                                         nr++;
593                                                         sound= sound->id.next;
594                                                 }
595                                                 
596                                                 if(sa->sound)
597                                                         sa->sound->id.us--;
598                                                 
599                                                 sa->sound= sound;
600                                                 
601                                                 if(sound)
602                                                         sound->id.us++;
603                                                 
604                                                 sa->sndnr= 0;
605                                                 didit= 1;
606                                         }
607                                 }
608                                 act= act->next;
609                         }
610                         if(didit)
611                                 break;
612                         base= base->next;
613                 }
614                 allqueue(REDRAWBUTSLOGIC, 0);
615                 allqueue(REDRAWSOUND, 0);
616
617                 break;
618         }
619 }
620
621
622 static char *sensor_name(int type)
623 {
624         switch (type) {
625         case SENS_ALWAYS:
626                 return "Always";
627         case SENS_TOUCH:
628                 return "Touch";
629         case SENS_NEAR:
630                 return "Near";
631         case SENS_KEYBOARD:
632                 return "Keyboard";
633         case SENS_PROPERTY:
634                 return "Property";
635         case SENS_MOUSE:
636                 return "Mouse";
637         case SENS_COLLISION:
638                 return "Collision";
639         case SENS_RADAR:
640                 return "Radar";
641         case SENS_RANDOM:
642                 return "Random";
643         case SENS_RAY:
644                 return "Ray";
645         case SENS_MESSAGE:
646                 return "Message";
647         case SENS_JOYSTICK:
648                 return "Joystick";
649         }
650         return "unknown";
651 }
652
653 static char *sensor_pup(void)
654 {
655         /* the number needs to match defines in game.h */
656         return "Sensors %t|Always %x0|Keyboard %x3|Mouse %x5|"
657                 "Touch %x1|Collision %x6|Near %x2|Radar %x7|"
658                 "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11";
659 }
660
661 static char *controller_name(int type)
662 {
663         switch (type) {
664         case CONT_LOGIC_AND:
665                 return "AND";
666         case CONT_LOGIC_OR:
667                 return "OR";
668         case CONT_EXPRESSION:
669                 return "Expression";
670         case CONT_PYTHON:
671                 return "Python";
672         }
673         return "unknown";
674 }
675
676 static char *controller_pup(void)
677 {
678         return "Controllers   %t|AND %x0|OR %x1|Expression %x2|Python %x3";
679 }
680
681 static char *actuator_name(int type)
682 {
683         switch (type) {
684         case ACT_ACTION:
685                 return "Action";
686         case ACT_OBJECT:
687                 return "Motion";
688         case ACT_IPO:
689                 return "Ipo";
690         case ACT_LAMP:
691                 return "Lamp";
692         case ACT_CAMERA:
693                 return "Camera";
694         case ACT_MATERIAL:
695                 return "Material";
696         case ACT_SOUND:
697                 return "Sound";
698         case ACT_CD:
699                 return "CD";
700         case ACT_PROPERTY:
701                 return "Property";
702         case ACT_EDIT_OBJECT:
703                 return "Edit Object";
704         case ACT_CONSTRAINT:
705                 return "Constraint";
706         case ACT_SCENE:
707                 return "Scene";
708         case ACT_GROUP:
709                 return "Group";
710         case ACT_RANDOM:
711                 return "Random";
712         case ACT_MESSAGE:
713                 return "Message";
714         case ACT_GAME:
715                 return "Game";
716         case ACT_VISIBILITY:
717                 return "Game";
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|Motion %x0|Constraint %x9|Ipo %x1"
731                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
732                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
733                         "|Visibility %x18";
734                 break;
735         default:
736                 return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
737                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
738                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
739                         "|Visibility %x18";
740         }
741 }
742
743
744
745 static void set_sca_ob(Object *ob)
746 {
747         bController *cont;
748         bActuator *act;
749
750         cont= ob->controllers.first;
751         while(cont) {
752                 cont->mynew= (bController *)ob;
753                 cont= cont->next;
754         }
755         act= ob->actuators.first;
756         while(act) {
757                 act->mynew= (bActuator *)ob;
758                 act= act->next;
759         }
760 }
761
762 static ID **get_selected_and_linked_obs(short *count, short scavisflag)
763 {
764         Base *base;
765         Object *ob, *obt;
766         ID **idar;
767         bSensor *sens;
768         bController *cont;
769         unsigned int lay;
770         int a, nr, doit;
771         
772         /* we need a sorted object list */
773         /* set scavisflags flags in Objects to indicate these should be evaluated */
774         /* also hide ob pointers in ->new entries of controllerss/actuators */
775         
776         *count= 0;
777         
778         if(G.scene==NULL) return NULL;
779         
780         ob= G.main->object.first;
781         while(ob) {
782                 ob->scavisflag= 0;
783                 set_sca_ob(ob);
784                 ob= ob->id.next;
785         }
786         
787         if(G.vd) lay= G.vd->lay;
788         else lay= G.scene->lay;
789         
790         base= FIRSTBASE;
791         while(base) {
792                 if(base->lay & lay) {
793                         if(base->flag & SELECT) {
794                                 if(scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
795                                 if(scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
796                                 if(scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
797                         }
798                 }
799                 base= base->next;
800         }
801
802         if(OBACT) {
803                 if(scavisflag & BUTS_SENS_ACT) OBACT->scavisflag |= OB_VIS_SENS;
804                 if(scavisflag & BUTS_CONT_ACT) OBACT->scavisflag |= OB_VIS_CONT;
805                 if(scavisflag & BUTS_ACT_ACT) OBACT->scavisflag |= OB_VIS_ACT;
806         }
807         
808         if(scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK)) {
809                 doit= 1;
810                 while(doit) {
811                         doit= 0;
812                         
813                         ob= G.main->object.first;
814                         while(ob) {
815                         
816                                 /* 1st case: select sensor when controller selected */
817                                 if((scavisflag & BUTS_SENS_LINK) && (ob->scavisflag & OB_VIS_SENS)==0) {
818                                         sens= ob->sensors.first;
819                                         while(sens) {
820                                                 for(a=0; a<sens->totlinks; a++) {
821                                                         if(sens->links[a]) {
822                                                                 obt= (Object *)sens->links[a]->mynew;
823                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)) {
824                                                                         doit= 1;
825                                                                         ob->scavisflag |= OB_VIS_SENS;
826                                                                         break;
827                                                                 }
828                                                         }
829                                                 }
830                                                 if(doit) break;
831                                                 sens= sens->next;
832                                         }
833                                 }
834                                 
835                                 /* 2nd case: select cont when act selected */
836                                 if((scavisflag & BUTS_CONT_LINK)  && (ob->scavisflag & OB_VIS_CONT)==0) {
837                                         cont= ob->controllers.first;
838                                         while(cont) {
839                                                 for(a=0; a<cont->totlinks; a++) {
840                                                         if(cont->links[a]) {
841                                                                 obt= (Object *)cont->links[a]->mynew;
842                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)) {
843                                                                         doit= 1;
844                                                                         ob->scavisflag |= OB_VIS_CONT;
845                                                                         break;
846                                                                 }
847                                                         }
848                                                 }
849                                                 if(doit) break;
850                                                 cont= cont->next;
851                                         }
852                                 }
853                                 
854                                 /* 3rd case: select controller when sensor selected */
855                                 if((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
856                                         sens= ob->sensors.first;
857                                         while(sens) {
858                                                 for(a=0; a<sens->totlinks; a++) {
859                                                         if(sens->links[a]) {
860                                                                 obt= (Object *)sens->links[a]->mynew;
861                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)==0) {
862                                                                         doit= 1;
863                                                                         obt->scavisflag |= OB_VIS_CONT;
864                                                                 }
865                                                         }
866                                                 }
867                                                 sens= sens->next;
868                                         }
869                                 }
870                                 
871                                 /* 4th case: select actuator when controller selected */
872                                 if( (scavisflag & BUTS_ACT_LINK)  && (ob->scavisflag & OB_VIS_CONT)) {
873                                         cont= ob->controllers.first;
874                                         while(cont) {
875                                                 for(a=0; a<cont->totlinks; a++) {
876                                                         if(cont->links[a]) {
877                                                                 obt= (Object *)cont->links[a]->mynew;
878                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)==0) {
879                                                                         doit= 1;
880                                                                         obt->scavisflag |= OB_VIS_ACT;
881                                                                 }
882                                                         }
883                                                 }
884                                                 cont= cont->next;
885                                         }
886                                         
887                                 }
888                                 ob= ob->id.next;
889                         }
890                 }
891         } 
892         
893         /* now we count */
894         ob= G.main->object.first;
895         while(ob) {
896                 if( ob->scavisflag ) (*count)++;
897                 ob= ob->id.next;
898         }
899
900         if(*count==0) return NULL;
901         if(*count>24) *count= 24;               /* temporal */
902         
903         idar= MEM_callocN( (*count)*sizeof(void *), "idar");
904         
905         ob= G.main->object.first;
906         nr= 0;
907         while(ob) {
908                 if( ob->scavisflag ) {
909                         idar[nr]= (ID *)ob;
910                         nr++;
911                 }
912                 if(nr>=24) break;
913                 ob= ob->id.next;
914         }
915         
916         /* just to be sure... these were set in set_sca_done_ob() */
917         clear_sca_new_poins();
918         
919         return idar;
920 }
921
922
923 static int get_col_sensor(int type)
924 {
925         switch(type) {
926         case SENS_ALWAYS:               return TH_BUT_ACTION;
927         case SENS_TOUCH:                return TH_BUT_NEUTRAL;
928         case SENS_COLLISION:    return TH_BUT_SETTING;
929         case SENS_NEAR:                 return TH_BUT_SETTING1; 
930         case SENS_KEYBOARD:             return TH_BUT_SETTING2;
931         case SENS_PROPERTY:             return TH_BUT_NUM;
932         case SENS_MOUSE:                return TH_BUT_TEXTFIELD;
933         case SENS_RADAR:                return TH_BUT_POPUP;
934         case SENS_RANDOM:               return TH_BUT_NEUTRAL;
935         case SENS_RAY:                  return TH_BUT_SETTING1;
936         case SENS_MESSAGE:              return TH_BUT_SETTING2;
937         case SENS_JOYSTICK:             return TH_BUT_NEUTRAL;
938         default:                                return TH_BUT_NEUTRAL;
939         }
940 }
941 static void set_col_sensor(int type, int medium)
942 {
943         int col= get_col_sensor(type);
944         BIF_ThemeColorShade(col, medium?30:0);
945 }
946
947 /**
948  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
949  * the value of this sensor. Operates on the shared data block of sensors.
950  */
951 static void draw_default_sensor_header(bSensor *sens,
952                                                                 uiBlock *block,
953                                                                 short x,
954                                                                 short y,
955                                                                 short w) 
956 {
957         /* Pulsing and frequency */
958         uiDefIconButBitS(block, TOG, SENS_PULSE_CONT, 1, ICON_DOTSUP,
959                          (short)(x + 10), (short)(y - 19), (short)(0.15 * (w-20)), 19,
960                          &sens->pulse, 0.0, 0.0, 0, 0,
961                          "Activate TRUE pulse mode");
962         uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN,
963                          (short)(x + 10 + 0.15 * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
964                          &sens->pulse, 0.0, 0.0, 0, 0,
965                          "Activate FALSE pulse mode");
966         uiDefButS(block, NUM, 1, "f:",
967                          (short)(x + 10 + 0.3 * (w-20)), (short)(y - 19), (short)(0.275 * (w-20)), 19,
968                          &sens->freq, 0.0, 10000.0, 0, 0,
969                          "Frequency of pulses (in 1/50 sec)");
970         
971         /* value or shift? */
972         uiDefButS(block, TOG, 1, "Inv",
973                          (short)(x + 10 + 0.85 * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
974                          &sens->invert, 0.0, 0.0, 0, 0,
975                          "Invert the output of this sensor");
976 }
977
978 static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
979 {
980         bNearSensor      *ns           = NULL;
981         bTouchSensor     *ts           = NULL;
982         bKeyboardSensor  *ks           = NULL;
983         bPropertySensor  *ps           = NULL;
984         bMouseSensor     *ms           = NULL;
985         bCollisionSensor *cs           = NULL;
986         bRadarSensor     *rs           = NULL;
987         bRandomSensor    *randomSensor = NULL;
988         bRaySensor       *raySens      = NULL;
989         bMessageSensor   *mes          = NULL;
990         bJoystickSensor  *joy              = NULL;
991
992         short ysize;
993         char *str;
994         
995         /* yco is at the top of the rect, draw downwards */
996         
997         uiBlockSetEmboss(block, UI_EMBOSSM);
998         
999         set_col_sensor(sens->type, 0);
1000         
1001         switch (sens->type)
1002         {
1003         case SENS_ALWAYS:
1004                 {
1005                         ysize= 24;
1006                         
1007                         glRects(xco, yco-ysize, xco+width, yco);
1008                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1009                         
1010                         draw_default_sensor_header(sens, block, xco, yco, width);
1011                         
1012                         yco-= ysize;
1013                         
1014                         break;
1015                 }
1016         case SENS_TOUCH:
1017                 {
1018                         ysize= 48; 
1019                         
1020                         glRects(xco, yco-ysize, xco+width, yco); 
1021                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1022                         
1023                         draw_default_sensor_header(sens, block, xco, yco, width);
1024                         
1025                         ts= sens->data; 
1026                         
1027                         /* uiDefBut(block, TEX, 1, "Property:", xco,yco-22,width, 19, &ts->name, 0, 31, 0, 0, "Only look for Objects with this property"); */
1028                         uiDefIDPoinBut(block, test_matpoin_but, 1, "MA:",(short)(xco + 10),(short)(yco-44), (short)(width - 20), 19, &ts->ma,  "Only look for floors with this Material"); 
1029                         ///* 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"); 
1030                         yco-= ysize; 
1031                         break; 
1032                 }
1033         case SENS_COLLISION:
1034                 {
1035                         ysize= 48;
1036                         
1037                         glRects(xco, yco-ysize, xco+width, yco);
1038                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1039                         
1040                         draw_default_sensor_header(sens, block, xco, yco, width);
1041                         cs= sens->data;
1042                         
1043                         /* The collision sensor will become a generic collision (i.e. it     */
1044                         /* absorb the old touch sensor).                                     */
1045
1046                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",(short)(xco + 10),(short)(yco - 44),
1047                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1048                                 "Toggle collision on material or property.");
1049                         
1050                         if (cs->mode & SENS_COLLISION_MATERIAL) {
1051                                 uiDefBut(block, TEX, 1, "Material:", (short)(xco + 10 + 0.20 * (width-20)),
1052                                         (short)(yco-44), (short)(0.8*(width-20)), 19, &cs->materialName, 0, 31, 0, 0,
1053                                         "Only look for Objects with this material");
1054                         } else {
1055                                 uiDefBut(block, TEX, 1, "Property:", (short)(xco + 10 + 0.20 * (width-20)), (short)(yco-44),
1056                                         (short)(0.8*(width-20)), 19, &cs->name, 0, 31, 0, 0,
1057                                         "Only look for Objects with this property");
1058                         }
1059         
1060                         /*              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"); */
1061                         
1062                         yco-= ysize;
1063                         break;
1064                 }
1065         case SENS_NEAR:
1066                 {
1067                         ysize= 72;
1068                         
1069                         glRects(xco, yco-ysize, xco+width, yco);
1070                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1071                         
1072                         draw_default_sensor_header(sens, block, xco, yco, width);
1073                         ns= sens->data;
1074                         
1075                         uiDefBut(block, TEX, 1, "Property:",(short)(10+xco),(short)(yco-44), (short)(width-20), 19,
1076                                 &ns->name, 0, 31, 0, 0, "Only look for Objects with this property");
1077                         uiDefButF(block, NUM, 1, "Dist",(short)(10+xco),(short)(yco-68),(short)((width-22)/2), 19,
1078                                 &ns->dist, 0.0, 1000.0, 1000, 0, "Trigger distance");
1079                         uiDefButF(block, NUM, 1, "Reset",(short)(10+xco+(width-22)/2), (short)(yco-68), (short)((width-22)/2), 19,
1080                                 &ns->resetdist, 0.0, 1000.0, 1000, 0, "Reset distance"); 
1081                         yco-= ysize;
1082                         break;
1083                 }
1084         case SENS_RADAR:
1085                 {
1086                         ysize= 72; 
1087                         
1088                         glRects(xco, yco-ysize, xco+width, yco);
1089                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1090                         
1091                         draw_default_sensor_header(sens, block, xco, yco, width);
1092                         
1093                         rs= sens->data;
1094                         
1095                         uiDefBut(block, TEX, 1, "Prop:",
1096                                          (short)(10+xco),(short)(yco-44), (short)(0.7 * (width-20)), 19,
1097                                          &rs->name, 0, 31, 0, 0,
1098                                          "Only look for Objects with this property");
1099                         uiDefButS(block, ROW, 1, "X",
1100                                          (short)(10+xco+0.7 * (width-20)),(short)(yco-44), (short)(0.1 * (width-22)),19,
1101                                          &rs->axis, 2.0, 0, 0, 0,
1102                                          "Cast the cone along the object's positive x-axis");
1103                         uiDefButS(block, ROW, 1, "Y",
1104                                          (short)(10+xco+0.8 * (width-20)),(short)(yco-44),(short)(0.1 * (width-22)), 19,
1105                                          &rs->axis, 2.0, 1, 0, 0,
1106                                          "Cast the cone along the object's positive y-axis");
1107                         uiDefButS(block, ROW, 1, "Z",
1108                                          (short)(10+xco+0.9 * (width-20)), (short)(yco-44), (short)(0.1 * (width-22)), 19,
1109                                          &rs->axis, 2.0, 2, 0, 0,
1110                                          "Cast the cone along the object's positive z-axis");
1111                         uiDefButF(block, NUM, 1, "Ang:",
1112                                          (short)(10+xco), (short)(yco-68), (short)((width-20)/2), 19,
1113                                          &rs->angle, 0.0, 179.9, 10, 0,
1114                                          "Opening angle of the radar cone.");
1115                         uiDefButF(block, NUM, 1, "Dist:",
1116                                          (short)(xco+10 + (width-20)/2), (short)(yco-68), (short)((width-20)/2), 19,
1117                                          &rs->range, 0.01, 10000.0, 100, 0,
1118                                          "Depth of the radar cone");
1119                         yco-= ysize;
1120                         break;
1121                 }
1122         case SENS_KEYBOARD:
1123                 {
1124                         /* 5 lines: 120 height */
1125                         ysize= 120;
1126                         
1127                         glRects(xco, yco-ysize, xco+width, yco);
1128                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1129                         
1130                         /* header line */
1131                         draw_default_sensor_header(sens, block, xco, yco, width);
1132                         ks= sens->data;
1133                         
1134                         /* line 2: hotkey and allkeys toggle */
1135                         uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
1136                         
1137                         /* line 3: two key modifyers (qual1, qual2) */
1138                         uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
1139                         uiDefKeyevtButS(block, B_DIFF, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
1140                         
1141                         /* labels for line 1 and 2 */
1142                         uiDefBut(block, LABEL, 0, "Key",          xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
1143                         uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
1144                         
1145                         /* part of line 1 */
1146                         uiBlockSetCol(block, TH_BUT_SETTING2);
1147                         uiDefButBitS(block, TOG, 1, 0, "All keys",        xco+40+(width/2), yco-44, (width/2)-50, 19,
1148                                 &ks->type, 0, 0, 0, 0, "");
1149                         
1150                         /* line 4: toggle property for string logging mode */
1151                         uiDefBut(block, TEX, 1, "LogToggle: ",
1152                                 xco+10, yco-92, (width-20), 19,
1153                                 ks->toggleName, 0, 31, 0, 0,
1154                                 "Property that indicates whether to log "
1155                                 "keystrokes as a string.");
1156                         
1157                         /* line 5: target property for string logging mode */
1158                         uiDefBut(block, TEX, 1, "Target: ",
1159                                 xco+10, yco-116, (width-20), 19,
1160                                 ks->targetName, 0, 31, 0, 0,
1161                                 "Property that receives the keystrokes in case "
1162                                 "a string is logged.");
1163                         
1164                         yco-= ysize;
1165                         break;
1166                 }
1167         case SENS_PROPERTY:
1168                 {
1169                         ysize= 96;
1170                         
1171                         glRects(xco, yco-ysize, xco+width, yco);
1172                         uiEmboss((float)xco, (float)yco-ysize,
1173                                 (float)xco+width, (float)yco, 1);
1174                         
1175                         draw_default_sensor_header(sens, block, xco, yco, width);
1176                         ps= sens->data;
1177                         
1178                         str= "Type %t|Equal %x0|Not Equal %x1|Interval %x2|Changed %x3"; 
1179                         /* str= "Type %t|Equal %x0|Not Equal %x1"; */
1180                         uiDefButI(block, MENU, B_REDR, str,                     xco+30,yco-44,width-60, 19,
1181                                 &ps->type, 0, 31, 0, 0, "Type");
1182                         
1183                         if (ps->type != SENS_PROP_EXPRESSION)
1184                         {
1185                                 uiDefBut(block, TEX, 1, "Prop: ",                       xco+30,yco-68,width-60, 19,
1186                                         ps->name, 0, 31, 0, 0,  "Property name");
1187                         }
1188                         
1189                         if(ps->type == SENS_PROP_INTERVAL)
1190                         {
1191                                 uiDefBut(block, TEX, 1, "Min: ",                xco,yco-92,width/2, 19,
1192                                         ps->value, 0, 31, 0, 0, "test for min value");
1193                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1194                                         ps->maxvalue, 0, 31, 0, 0, "test for max value");
1195                         }
1196                         else if(ps->type == SENS_PROP_CHANGED);
1197                         else
1198                         {
1199                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-92,width-60, 19,
1200                                         ps->value, 0, 31, 0, 0, "test for value");
1201                         }
1202                         
1203                         yco-= ysize;
1204                         break;
1205                 }
1206         case SENS_MOUSE:
1207                 {
1208                         ms= sens->data;
1209                         /* Two lines: 48 pixels high. */
1210                         ysize = 48;
1211                         
1212                         glRects(xco, yco-ysize, xco+width, yco);
1213                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1214                         
1215                         /* line 1: header */
1216                         draw_default_sensor_header(sens, block, xco, yco, width);
1217                         
1218                         /* Line 2: type selection. The number are a bit mangled to get
1219                         * proper compatibility with older .blend files. */
1220                         str= "Type %t|Left button %x1|Middle button %x2|"
1221                                 "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16"; 
1222                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, width-20, 19,
1223                                 &ms->type, 0, 31, 0, 0,
1224                                 "Specify the type of event this mouse sensor should trigger on.");
1225                         
1226                         yco-= ysize;
1227                         break;
1228                 }
1229         case SENS_RANDOM:
1230                 {
1231                         ysize = 48;
1232                         
1233                         glRects(xco, yco-ysize, xco+width, yco);
1234                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1235                         
1236                         draw_default_sensor_header(sens, block, xco, yco, width);
1237                         randomSensor = sens->data;
1238                         /* some files were wrongly written, avoid crash now */
1239                         if (randomSensor)
1240                         {
1241                                 uiDefButI(block, NUM, 1, "Seed: ",              xco+10,yco-44,(width-20), 19,
1242                                         &randomSensor->seed, 0, 1000, 0, 0,
1243                                         "Initial seed of the generator. (Choose 0 for not random)");
1244                         }
1245                         yco-= ysize;
1246                         break;
1247                 }
1248         case SENS_RAY:
1249                 {
1250                         ysize = 72;
1251                         glRects(xco, yco-ysize, xco+width, yco);
1252                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1253                         
1254                         draw_default_sensor_header(sens, block, xco, yco, width);
1255                         raySens = sens->data;
1256                         
1257                         /* 1. property or material */
1258                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",
1259                                 xco + 10,yco - 44, 0.20 * (width-20), 19,
1260                                 &raySens->mode, 0.0, 0.0, 0, 0,
1261                                 "Toggle collision on material or property.");
1262                         
1263                         if (raySens->mode & SENS_COLLISION_MATERIAL)
1264                         {
1265                                 uiDefBut(block, TEX, 1, "Material:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1266                                         &raySens->matname, 0, 31, 0, 0,
1267                                         "Only look for Objects with this material");
1268                         }
1269                         else
1270                         {
1271                                 uiDefBut(block, TEX, 1, "Property:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1272                                         &raySens->propname, 0, 31, 0, 0,
1273                                         "Only look for Objects with this property");
1274                         }
1275                         
1276                         /* 2. sensing range */
1277                         uiDefButF(block, NUM, 1, "Range", xco+10, yco-68, 0.6 * (width-20), 19,
1278                                 &raySens->range, 0.01, 10000.0, 100, 0,
1279                                 "Sense objects no farther than this distance");
1280                         
1281                         /* 3. axis choice */
1282                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1283                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1284                                 &raySens->axisflag, 2.0, 31, 0, 0,
1285                                 "Specify along which axis the ray is cast.");
1286                         
1287                         yco-= ysize;            
1288                         break;
1289                 }
1290         case SENS_MESSAGE:
1291                 {
1292                         mes = sens->data;
1293                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1294                         
1295                         glRects(xco, yco-ysize, xco+width, yco);
1296                         uiEmboss((float)xco, (float)yco-ysize,
1297                                 (float)xco+width, (float)yco, 1);
1298                         
1299                         /* line 1: header line */
1300                         draw_default_sensor_header(sens, block, xco, yco, width);
1301                         
1302                         /* line 2: Subject filter */
1303                         uiDefBut(block, TEX, 1, "Subject: ",
1304                                 (xco+10), (yco-44), (width-20), 19,
1305                                 mes->subject, 0, 31, 0, 0,
1306                                 "Optional subject filter: only accept messages with this subject"
1307                                 ", or empty for all");
1308                         
1309                         yco -= ysize;
1310                         break;
1311                 }
1312                 case SENS_JOYSTICK:
1313                 {
1314
1315                         ysize =  72;
1316                         
1317                         glRects(xco, yco-ysize, xco+width, yco);
1318                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1319                         
1320                         /* line 1: header */
1321                         draw_default_sensor_header(sens, block, xco, yco, width);
1322
1323                         joy= sens->data;
1324                         
1325
1326                         str= "Type %t|Button %x0|Axis %x1|Hat%x2"; 
1327                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, 0.6 * (width-20), 19,
1328                                 &joy->type, 0, 31, 0, 0,
1329                                 "The type of event this joystick sensor is triggered on.");
1330                         
1331                         if(joy->type == SENS_JOY_BUTTON)
1332                         {
1333                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1334                                 &joy->button, 0, 18, 100, 0,
1335                                 "Specify which button to use");
1336                                 
1337                                 str = "Type %t|Pressed %x0|Released %x1"; 
1338                                 uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1339                                 &joy->buttonf, 2.0, 31, 0, 0,
1340                                 "Button pressed or released.");
1341                         }
1342                         else if(joy->type == SENS_JOY_AXIS)
1343                         {
1344                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1345                                 &joy->axis, 1, 2.0, 100, 0,
1346                                 "Specify which axis to use");
1347
1348                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1349                                 &joy->precision, 0, 32768.0, 100, 0,
1350                                 "Specify the precision of the axis");
1351
1352                                 str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1353                                 uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1354                                 &joy->axisf, 2.0, 31, 0, 0,
1355                                 "The direction of the axis");
1356                         }
1357                         else
1358                         {
1359                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1360                                 &joy->hat, 1, 2.0, 100, 0,
1361                                 "Specify which hat to use");
1362                                 
1363                                 uiDefButI(block, NUM, 1, "Direction:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1364                                 &joy->hatf, 0, 12, 100, 0,
1365                                 "Specify hat direction");
1366                         }
1367                         yco-= ysize;
1368                         break;
1369                 }
1370         }
1371         
1372         uiBlockSetEmboss(block, UI_EMBOSSM);
1373         uiBlockSetCol(block, TH_AUTO);
1374         
1375         return yco-4;
1376 }
1377
1378
1379
1380 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1381 {
1382         bExpressionCont *ec;
1383         bPythonCont *pc;
1384         short ysize;
1385         
1386         uiBlockSetEmboss(block, UI_EMBOSSM);
1387         
1388         switch (cont->type) {
1389         case CONT_EXPRESSION:
1390                 ysize= 28;
1391
1392                 BIF_ThemeColor(TH_BUT_SETTING);
1393                 glRects(xco, yco-ysize, xco+width, yco);
1394                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1395                 
1396                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1397                 ec= cont->data; 
1398                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1399                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1400                                  ec->str, 0, 127, 0, 0,
1401                                  "Expression"); 
1402                 
1403                 yco-= ysize;
1404                 break;
1405         case CONT_PYTHON:
1406                 ysize= 28;
1407                 
1408                 if(cont->data==NULL) init_controller(cont);
1409                 pc= cont->data;
1410                 
1411                 BIF_ThemeColor(TH_BUT_SETTING1);
1412                 glRects(xco, yco-ysize, xco+width, yco);
1413                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1414
1415                 uiDefIDPoinBut(block, test_scriptpoin_but, 1, "Script: ", xco+45,yco-24,width-90, 19, &pc->text, "");
1416                 
1417                 yco-= ysize;
1418                 break;
1419                 
1420         default:
1421                 ysize= 4;
1422
1423                 BIF_ThemeColor(TH_BUT_NEUTRAL);
1424                 glRects(xco, yco-ysize, xco+width, yco);
1425                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1426                 
1427                 yco-= ysize;
1428         }
1429         
1430         uiBlockSetEmboss(block, UI_EMBOSSM);
1431         uiBlockSetCol(block, TH_AUTO);
1432
1433         return yco;
1434 }
1435
1436 static int get_col_actuator(int type)
1437 {
1438         switch(type) {
1439         case ACT_ACTION:                return TH_BUT_ACTION;
1440         case ACT_OBJECT:                return TH_BUT_NEUTRAL;
1441         case ACT_IPO:                   return TH_BUT_SETTING;
1442         case ACT_PROPERTY:              return TH_BUT_SETTING1;
1443         case ACT_SOUND:                 return TH_BUT_SETTING2;
1444         case ACT_CD:                    return TH_BUT_NUM;
1445         case ACT_CAMERA:                return TH_BUT_TEXTFIELD;
1446         case ACT_EDIT_OBJECT:   return TH_BUT_POPUP;
1447         case ACT_GROUP:                 return TH_BUT_ACTION;
1448         case ACT_RANDOM:                return TH_BUT_NEUTRAL;
1449         case ACT_SCENE:                 return TH_BUT_SETTING;
1450         case ACT_MESSAGE:               return TH_BUT_SETTING1;
1451         case ACT_GAME:                  return TH_BUT_SETTING2;
1452         case ACT_VISIBILITY:    return TH_BUT_NUM;
1453         case ACT_CONSTRAINT:    return TH_BUT_ACTION;
1454         default:                                return TH_BUT_NEUTRAL;
1455         }
1456 }
1457 static void set_col_actuator(int item, int medium) 
1458 {
1459         int col= get_col_actuator(item);
1460         BIF_ThemeColorShade(col, medium?30:10);
1461         
1462 }
1463
1464 static short draw_actuatorbuttons(bActuator *act, uiBlock *block, short xco, short yco, short width)
1465 {
1466         bSoundActuator      *sa      = NULL;
1467         bCDActuator                     *cda     = NULL;
1468         bObjectActuator     *oa      = NULL;
1469         bIpoActuator        *ia      = NULL;
1470         bPropertyActuator   *pa      = NULL;
1471         bCameraActuator     *ca      = NULL;
1472         bEditObjectActuator *eoa     = NULL;
1473         bConstraintActuator *coa     = NULL;
1474         bSceneActuator      *sca     = NULL;
1475         bGroupActuator      *ga      = NULL;
1476         bRandomActuator     *randAct = NULL;
1477         bMessageActuator    *ma      = NULL;
1478         bActionActuator     *aa      = NULL;
1479         bGameActuator       *gma     = NULL;
1480         bVisibilityActuator *visAct  = NULL;
1481         
1482         float *fp;
1483         short ysize = 0, wval;
1484         char *str;
1485         int myline;
1486
1487         /* yco is at the top of the rect, draw downwards */
1488         uiBlockSetEmboss(block, UI_EMBOSSM);
1489         set_col_actuator(act->type, 0);
1490         
1491         switch (act->type)
1492         {
1493         case ACT_OBJECT:
1494                 {
1495                         ysize= 129;
1496                         
1497                         glRects(xco, yco-ysize, xco+width, yco);
1498                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1499                         
1500                         oa = act->data;
1501                         wval = (width-100)/3;
1502                         
1503                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-22, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1504                         uiDefButF(block, NUM, 0, "",            xco+45, yco-22, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1505                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-22, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1506                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-22, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1507                         
1508                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-41, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1509                         uiDefButF(block, NUM, 0, "",            xco+45, yco-41, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1510                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-41, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1511                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-41, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");
1512                         
1513                         uiDefBut(block, LABEL, 0, "dLoc",       xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the dLoc");
1514                         uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1515                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1516                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1517                         
1518                         uiDefBut(block, LABEL, 0, "dRot",       xco, yco-83, 45, 19, NULL, 0, 0, 0, 0, "Sets the dRot");
1519                         uiDefButF(block, NUM, 0, "",            xco+45, yco-83, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1520                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-83, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1521                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-83, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1522                         
1523                         uiDefBut(block, LABEL, 0, "linV",       xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1524                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1525                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1526                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1527                         
1528                         uiDefBut(block, LABEL, 0, "angV",       xco, yco-125, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1529                         uiDefButF(block, NUM, 0, "",            xco+45, yco-125, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1530                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-125, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1531                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-125, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1532                         
1533                         uiDefButBitI(block, TOG, ACT_FORCE_LOCAL, 0, "L",               xco+45+3*wval, yco-22, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1534                         uiDefButBitI(block, TOG, ACT_TORQUE_LOCAL, 0, "L",              xco+45+3*wval, yco-41, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1535                         uiDefButBitI(block, TOG, ACT_DLOC_LOCAL, 0, "L",                xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1536                         uiDefButBitI(block, TOG, ACT_DROT_LOCAL, 0, "L",                xco+45+3*wval, yco-83, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1537                         uiDefButBitI(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1538                         uiDefButBitI(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-125, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1539                         
1540                         uiDefButBitI(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-106, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV");
1541                         
1542                         yco-= ysize;
1543                         break;
1544                 }
1545         case ACT_ACTION:
1546                 {
1547                         /* DrawAct */
1548 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1549                         ysize = 112;
1550 #else
1551                         ysize= 92;
1552 #endif
1553                         
1554                         glRects(xco, yco-ysize, xco+width, yco);
1555                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1556                         
1557                         aa = act->data;
1558                         wval = (width-60)/3;
1559                         
1560                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1561 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1562                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
1563 #else
1564                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1565 #endif
1566                         uiDefButS(block, MENU, B_REDR, str, xco+30, yco-24, width-60, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
1567                         uiDefIDPoinBut(block, test_actionpoin_but, 1, "AC: ", xco+30, yco-44, width-60, 19, &aa->act, "Action name");
1568                         
1569                         if(aa->type == ACT_ACTION_FROM_PROP)
1570                         {
1571                                 uiDefBut(block, TEX, 0, "Prop: ",xco+30, yco-64, width-60, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
1572                         }
1573                         else
1574                         {
1575                                 uiDefButS(block, NUM, 0, "Sta: ",xco+30, yco-64, (width-60)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
1576                                 uiDefButS(block, NUM, 0, "End: ",xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
1577                         }
1578                         
1579                         
1580                         
1581                         uiDefButS(block, NUM, 0, "Blendin: ", xco+30, yco-84, (width-60)/2, 19, &aa->blendin, 0.0, MAXFRAMEF, 0.0, 0.0, "Number of frames of motion blending");
1582                         uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-84, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers");
1583                         
1584 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1585                         if(aa->type == ACT_ACTION_MOTION)
1586                         {
1587                                 uiDefButF(block, NUM, 0, "Cycle: ",xco+30, yco-104, (width-60)/2, 19, &aa->stridelength, 0.0, 2500.0, 0, 0, "Distance covered by a single cycle of the action");
1588                         }
1589 #endif
1590                         
1591                         yco-=ysize;
1592                         break;
1593                 }
1594         case ACT_IPO:
1595                 {
1596                         ia= act->data;
1597                         
1598                         ysize= 52;
1599                         
1600                         glRects(xco, yco-ysize, xco+width, yco);
1601                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1602                         
1603                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1604                         
1605                         uiDefButS(block, MENU, B_REDR, str,             xco+20, yco-24, width-40 - (width-40)/3, 19, &ia->type, 0, 0, 0, 0, "");
1606                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
1607                                 "Child",        xco+20+0.666*(width-40), yco-24, (width-40)/3, 19, 
1608                                 &ia->flag, 0, 0, 0, 0, 
1609                                 "Add all children Objects as well");
1610
1611                         if(ia->type==ACT_IPO_FROM_PROP) {
1612                                 uiDefBut(block, TEX, 0, 
1613                                         "Prop: ",               xco+20, yco-44, width-40, 19, 
1614                                         ia->name, 0.0, 31.0, 0, 0, 
1615                                         "Use this property to define the Ipo position");
1616                         }
1617                         else {
1618                                 uiDefButS(block, NUM, 0, 
1619                                         "Sta",          xco+20, yco-44, (width-100)/2, 19, 
1620                                         &ia->sta, 0.0, MAXFRAMEF, 0, 0, 
1621                                         "Start frame");
1622                                 uiDefButS(block, NUM, 0, 
1623                                         "End",          xco+18+(width-90)/2, yco-44, (width-100)/2, 19, 
1624                                         &ia->end, 0.0, MAXFRAMEF, 0, 0, 
1625                                         "End frame");
1626                                 
1627                                 uiDefButBitS(block, TOG, ACT_IPOFORCE, B_REDR, 
1628                                         "Force", xco+width-78, yco-44, 43, 19, 
1629                                         &ia->flag, 0, 0, 0, 0, 
1630                                         "Convert Ipo to force"); 
1631                                 
1632                                 /* Only show the do-force-local toggle if force is requested */
1633                                 if (ia->flag & ACT_IPOFORCE) {
1634                                         uiDefButBitS(block, TOG, ACT_IPOFORCE_LOCAL, 0, 
1635                                                 "L", xco+width-35, yco-44, 15, 19, 
1636                                                 &ia->flag, 0, 0, 0, 0, 
1637                                                 "Let the force-ipo act in local coordinates."); 
1638                                 }
1639                                 
1640                         }
1641                         yco-= ysize;
1642                         break;
1643                 }
1644         case ACT_PROPERTY:
1645                 {
1646                         ysize= 68;
1647                         
1648                         glRects(xco, yco-ysize, xco+width, yco);
1649                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1650                         
1651                         pa= act->data;
1652                         
1653                         str= "Type   %t|Assign   %x0|Add %x1|Copy %x2";
1654                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
1655                         
1656                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
1657                         
1658                         if(pa->type==ACT_PROP_COPY) {
1659                                 uiDefIDPoinBut(block, test_obpoin_but, 1, "OB:",        xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
1660                                 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");
1661                         }
1662                         else {
1663                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-64,width-60, 19, pa->value, 0, 31, 0, 0, "change with this value");
1664                         }
1665                         yco-= ysize;
1666                         
1667                         break;
1668                 }
1669     case ACT_SOUND:
1670                 {
1671                         ysize = 70;
1672                         
1673                         sa = act->data;
1674                         sa->sndnr = 0;
1675                         
1676                         wval = (width-20)/2;
1677                         glRects(xco, yco-ysize, xco+width, yco);
1678                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1679                         
1680                         if(G.main->sound.first) {
1681                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(G.main->sound), (ID *)sa->sound, &(sa->sndnr));
1682                                 /* reset this value, it is for handling the event */
1683                                 sa->sndnr = 0;
1684                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
1685
1686                                 if(sa->sound) {
1687                                         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";
1688                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 18.0, 0, 0, "");
1689                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
1690                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->sound->volume, 0.0,  1.0, 0, 0, "Sets the volume of this sound");
1691                                         uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->sound->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound");
1692                                 }
1693                                 MEM_freeN(str);
1694                         } 
1695                         else {
1696                                 uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
1697                         }
1698                                         
1699                         yco-= ysize;
1700                         
1701                         break;
1702                 }
1703         case ACT_CD:
1704                 {
1705                         char cd_type_str[] = "Sound mode %t|Play all tracks %x0|Play one track %x1|"
1706                                 "Volume %x3|Stop %x4|Pause %x5|Resume %x6";
1707                         cda = act->data;
1708
1709                         if (cda) {
1710                                 if (cda->track == 0) {
1711                                         cda->track = 1;
1712                                         cda->volume = 1;
1713                                         cda->type = ACT_CD_PLAY_ALL;
1714                                 }
1715                                 
1716                                 if (cda->type == ACT_CD_PLAY_TRACK || cda->type == ACT_CD_LOOP_TRACK) {
1717                                         ysize = 48;
1718                                         glRects(xco, yco-ysize, xco+width, yco);
1719                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1720                                         uiDefButS(block, NUM, 0, "Track:", xco+10,yco-44,width-20, 19, &cda->track, 1, 99, 0, 0, "Select the track to be played");
1721                                 }
1722                                 else if (cda->type == ACT_CD_VOLUME) {
1723                                         ysize = 48;
1724                                         glRects(xco, yco-ysize, xco+width, yco);
1725                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1726                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-44,width-20, 19, &cda->volume, 0, 1, 0, 0, "Set the volume for CD playback");
1727                                 }
1728                                 else {
1729                                         ysize = 28;
1730                                         glRects(xco, yco-ysize, xco+width, yco);
1731                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1732                                 }
1733                                 uiDefButS(block, MENU, B_REDR, cd_type_str,xco+10,yco-22,width-20, 19, &cda->type, 0.0, 0.0, 0, 0, "");
1734                         }
1735                         yco-= ysize;
1736                         break;
1737                 }
1738         case ACT_CAMERA:
1739
1740                 ysize= 48;
1741         
1742                 glRects(xco, yco-ysize, xco+width, yco);
1743                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1744                 
1745                 ca= act->data;
1746         
1747                 uiDefIDPoinBut(block, test_obpoin_but, 1, "OB:",                xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
1748                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
1749                 
1750                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
1751                 
1752                 if(ca->axis==0) ca->axis= 'x';
1753                 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");
1754                 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");
1755                 
1756                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
1757
1758                 yco-= ysize;
1759         
1760          break;
1761                                 
1762         case ACT_EDIT_OBJECT:
1763                 
1764                 eoa= act->data;
1765
1766                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
1767                         int wval; /* just a temp width */
1768                         ysize = 72;
1769                         glRects(xco, yco-ysize, xco+width, yco);
1770                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1771          
1772                         uiDefIDPoinBut(block, test_obpoin_but, 1, "OB:",                xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Add this Object");
1773                         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");
1774
1775                         wval= (width-60)/3;
1776                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
1777                                          NULL, 0, 0, 0, 0,
1778                                          "Velocity upon creation.");
1779                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
1780                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
1781                                          "Velocity upon creation, x component.");
1782                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
1783                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
1784                                          "Velocity upon creation, y component.");
1785                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
1786                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
1787                                          "Velocity upon creation, z component.");
1788                         uiDefButBitS(block, TOG, 2, 0, "L", xco+45+3*wval, yco-68, 15, 19,
1789                                          &eoa->localflag, 0.0, 0.0, 0, 0,
1790                                          "Apply the transformation locally");
1791
1792                 }
1793                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
1794                         ysize= 28;
1795                         glRects(xco, yco-ysize, xco+width, yco);
1796                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1797                 }
1798                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
1799                         ysize= 48;
1800                         glRects(xco, yco-ysize, xco+width, yco);
1801                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1802          
1803                         uiDefIDPoinBut(block, test_meshpoin_but, 1, "ME:",              xco+40, yco-44, (width-80), 19, &(eoa->me), "Add this Object");
1804                 }
1805                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
1806                         ysize= 48;
1807                         glRects(xco, yco-ysize, xco+width, yco);
1808                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1809          
1810                         uiDefIDPoinBut(block, test_obpoin_but, 1, "OB:",                xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
1811                         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");
1812                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
1813                 }
1814                 
1815                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3";
1816                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
1817
1818                 yco-= ysize;
1819         
1820         break;
1821  
1822         case ACT_CONSTRAINT:
1823         
1824                 ysize= 44;
1825         
1826                 glRects(xco, yco-ysize, xco+width, yco);
1827                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1828                 
1829                 coa= act->data;
1830                 
1831 /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
1832                 str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
1833                 uiDefButS(block, MENU, 1, str,          xco+10, yco-40, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
1834         
1835                 uiDefButS(block, NUM,           0, "Damp:",     xco+10, yco-20, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "");
1836                 uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-20, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
1837                 uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-20, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
1838
1839                 if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
1840                 else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
1841                 else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
1842                 else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
1843                 else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
1844                 else fp= coa->minrot+2;
1845                 
1846                 uiDefButF(block, NUM, 0, "",            xco+80, yco-40, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
1847                 uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-40, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
1848
1849                 yco-= ysize;
1850         
1851         break;
1852  
1853         case ACT_SCENE:
1854                 sca= act->data; 
1855                 
1856                 if(sca->type==ACT_SCENE_RESTART) { 
1857                         ysize= 28; 
1858                         glRects(xco, yco-ysize, xco+width, yco); 
1859                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1860                 } 
1861                 else if(sca->type==ACT_SCENE_CAMERA) { 
1862                         
1863                         ysize= 48; 
1864                         glRects(xco, yco-ysize, xco+width, yco); 
1865                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1866          
1867                         uiDefIDPoinBut(block, test_obpoin_but, 1, "OB:",                xco+40, yco-44, (width-80), 19, &(sca->camera), "Set this Camera"); 
1868                 } 
1869                 else if(sca->type==ACT_SCENE_SET) { 
1870                         
1871                         ysize= 48; 
1872                         glRects(xco, yco-ysize, xco+width, yco); 
1873                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1874         
1875                         uiDefIDPoinBut(block, test_scenepoin_but, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene"); 
1876                 } 
1877                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
1878                         
1879                         ysize= 48; 
1880                         glRects(xco, yco-ysize, xco+width, yco); 
1881                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1882         
1883                         uiDefIDPoinBut(block, test_scenepoin_but, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene"); 
1884                 } 
1885                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
1886                         
1887                         ysize= 48; 
1888                         glRects(xco, yco-ysize, xco+width, yco); 
1889                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1890         
1891                         uiDefIDPoinBut(block, test_scenepoin_but, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene"); 
1892                 } 
1893                 else if(sca->type==ACT_SCENE_REMOVE) { 
1894                         
1895                         ysize= 48; 
1896                         glRects(xco, yco-ysize, xco+width, yco); 
1897                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1898         
1899                         uiDefIDPoinBut(block, test_scenepoin_but, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
1900                 } 
1901                 else if(sca->type==ACT_SCENE_SUSPEND) { 
1902                         
1903                         ysize= 48; 
1904                         glRects(xco, yco-ysize, xco+width, yco); 
1905                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1906         
1907                         uiDefIDPoinBut(block, test_scenepoin_but, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
1908                 } 
1909                 else if(sca->type==ACT_SCENE_RESUME) { 
1910                         
1911                         ysize= 48; 
1912                         glRects(xco, yco-ysize, xco+width, yco); 
1913                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1914         
1915                         uiDefIDPoinBut(block, test_scenepoin_but, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
1916                 } 
1917
1918                 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";
1919                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
1920
1921                 yco-= ysize; 
1922                 break; 
1923         case ACT_GAME:
1924                 {
1925                         gma = act->data; 
1926                         if (gma->type == ACT_GAME_LOAD)
1927                         {
1928                                 //ysize = 68;
1929                                 ysize = 48;
1930                                 glRects(xco, yco-ysize, xco+width, yco); 
1931                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1932                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
1933 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
1934                         }
1935 /*                      else if (gma->type == ACT_GAME_START)
1936                         {
1937                                 ysize = 68; 
1938                                 glRects(xco, yco-ysize, xco+width, yco); 
1939                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1940
1941                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
1942                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
1943                         }
1944 */                      else if (gma->type == ACT_GAME_RESTART)
1945                         {
1946                                 ysize = 28; 
1947                                 glRects(xco, yco-ysize, xco+width, yco); 
1948                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1949                         }
1950                         else if (gma->type == ACT_GAME_QUIT)
1951                         {
1952                                 ysize = 28; 
1953                                 glRects(xco, yco-ysize, xco+width, yco); 
1954                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1955                         }
1956
1957                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
1958                         str = "Scene %t|Start new game%x0|Restart this game%x2|Quit this game %x3";
1959                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
1960                         
1961                         yco -= ysize; 
1962                         break; 
1963                 }
1964         case ACT_GROUP:
1965                 ga= act->data;
1966
1967                 ysize= 52;
1968
1969                 glRects(xco, yco-ysize, xco+width, yco);
1970                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1971                 
1972                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
1973
1974                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
1975                 if(ga->type==ACT_GROUP_SET) {
1976                         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");
1977                         uiDefButS(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");
1978                 }
1979                 else if(ga->type==ACT_GROUP_FROM_PROP) {
1980                         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");
1981                 }
1982                 else {
1983                         uiDefButS(block, NUM, 0, "Sta",         xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
1984                         uiDefButS(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");
1985                 }
1986                 yco-= ysize;
1987                 break;
1988
1989         case ACT_VISIBILITY:
1990                 ysize = 24;
1991
1992                 glRects(xco, yco-ysize, xco+width, yco);
1993                 uiEmboss((float)xco,
1994                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
1995                 
1996                 visAct = act->data;
1997
1998                 str= "Visibility %t|Visible %x0|Invisible %x1";
1999
2000                 uiDefButI(block, MENU, B_REDR, str,
2001                           xco + 10, yco - 24, width - 20, 19, &visAct->flag,
2002                           0.0, 0.0, 0, 0,
2003                           "Make the object invisible or visible.");
2004 /*
2005                 uiDefButBitI(block, TOG, ACT_VISIBILITY_INVISIBLE, 0,
2006                           "Invisible",
2007                           xco + 10, yco - 24, width - 20, 19, &visAct->flag,
2008                           0.0, 0.0, 0, 0,
2009                           "Make the object invisible or visible.");
2010 */
2011                 yco-= ysize;
2012
2013                 break;
2014                 
2015         case ACT_RANDOM:
2016                 ysize  = 69;
2017
2018                 glRects(xco, yco-ysize, xco+width, yco);
2019                 uiEmboss((float)xco,
2020                                   (float)yco-ysize, (float)xco+width, (float)yco, 1);
2021                 
2022                 randAct = act->data;
2023
2024                 /* 1. seed */
2025                 uiDefButI(block, NUM, 1, "Seed: ",              (xco+10),yco-24, 0.4 *(width-20), 19,
2026                                  &randAct->seed, 0, 1000, 0, 0,
2027                                  "Initial seed of the random generator. Use Python for more freedom. "
2028                                  " (Choose 0 for not random)");
2029
2030                 /* 2. distribution type */
2031                 /* One pick per distribution. These numbers MUST match the #defines  */
2032                 /* in game.h !!!                                                     */
2033                 str= "Distribution %t|Bool Constant %x0|Bool Uniform %x1"
2034                         "|Bool Bernoulli %x2|Int Constant %x3|Int Uniform %x4"
2035                         "|Int Poisson %x5|Float Constant %x6|Float Uniform %x7"
2036                         "|Float Normal %x8|Float Neg. Exp. %x9";
2037                 uiDefButI(block, MENU, B_REDR, str, (xco+10) + 0.4 * (width-20), yco-24, 0.6 * (width-20), 19,
2038                                  &randAct->distribution, 0.0, 0.0, 0, 0,
2039                                  "Choose the type of distribution");
2040
2041                 /* 3. property */
2042                 uiDefBut(block, TEX, 1, "Property:", (xco+10), yco-44, (width-20), 19,
2043                                  &randAct->propname, 0, 31, 0, 0,
2044                                  "Assign the random value to this property"); 
2045
2046                 /*4. and 5. arguments for the distribution*/
2047                 switch (randAct->distribution) {
2048                 case ACT_RANDOM_BOOL_CONST:
2049                         uiDefButBitI(block, TOG, 1, 1, "Always true", (xco+10), yco-64, (width-20), 19,
2050                                          &randAct->int_arg_1, 2.0, 1, 0, 0,
2051                                          "Always false or always true");                        
2052                         break;
2053                 case ACT_RANDOM_BOOL_UNIFORM:
2054                         uiDefBut(block, LABEL, 0, "     Do a 50-50 pick.",      (xco+10), yco-64, (width-20), 19,
2055                                          NULL, 0, 0, 0, 0,
2056                                          "Choose between true and false, 50% chance each.");
2057                         break;
2058                 case ACT_RANDOM_BOOL_BERNOUILLI:
2059                         uiDefButF(block, NUM, 1, "Chance", (xco+10), yco-64, (width-20), 19,
2060                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2061                                          "Pick a number between 0 and 1. Success if you stay "
2062                                          "below this value");                   
2063                         break;
2064                 case ACT_RANDOM_INT_CONST:
2065                         uiDefButI(block, NUM, 1, "Value: ",             (xco+10), yco-64, (width-20), 19,
2066                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2067                                          "Always return this number");
2068                         break;
2069                 case ACT_RANDOM_INT_UNIFORM:
2070                         uiDefButI(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2071                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2072                                          "Choose a number from a range. "
2073                                          "Lower boundary of the range.");
2074                         uiDefButI(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2075                                          &randAct->int_arg_2, -1000, 1000, 0, 0,
2076                                          "Choose a number from a range. "
2077                                          "Upper boundary of the range.");
2078                         break;
2079                 case ACT_RANDOM_INT_POISSON:
2080                         uiDefButF(block, NUM, 1, "Mean: ", (xco+10), yco-64, (width-20), 19,
2081                                          &randAct->float_arg_1, 0.01, 100.0, 0, 0,
2082                                          "Expected mean value of the distribution.");                                           
2083                         break;
2084                 case ACT_RANDOM_FLOAT_CONST:
2085                         uiDefButF(block, NUM, 1, "Value: ", (xco+10), yco-64, (width-20), 19,
2086                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2087                                          "Always return this number");
2088                         break;
2089                 case ACT_RANDOM_FLOAT_UNIFORM:
2090                         uiDefButF(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2091                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2092                                          "Choose a number from a range. "
2093                                          "Lower boundary of the range.");
2094                         uiDefButF(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2095                                          &randAct->float_arg_2, -10000.0, 10000.0, 0, 0,
2096                                          "Choose a number from a range. "
2097                                          "Upper boundary of the range.");
2098                         break;
2099                 case ACT_RANDOM_FLOAT_NORMAL:
2100                         uiDefButF(block, NUM, 1, "Mean: ",              (xco+10), yco-64, (width-20)/2, 19,
2101                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2102                                          "A normal distribution. Mean of the distribution.");
2103                         uiDefButF(block, NUM, 1, "SD: ",                (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2104                                          &randAct->float_arg_2, 0.0, 10000.0, 0, 0,
2105                                          "A normal distribution. Standard deviation of the "
2106                                          "distribution.");
2107                         break;
2108                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
2109                         uiDefButF(block, NUM, 1, "Half-life time: ", (xco+10), yco-64, (width-20), 19,
2110                                          &randAct->float_arg_1, 0.001, 10000.0, 0, 0,
2111                                          "Negative exponential dropoff.");
2112                         break;
2113                 default:
2114                         ; /* don't know what this distro is... can be useful for testing */
2115                         /* though :)                                                     */
2116                 }
2117
2118                 yco-= ysize;
2119                 break;
2120         case ACT_MESSAGE:
2121                 ma = act->data;
2122
2123 #define MESSAGE_SENSOR_TO_FIELD_WORKS   /* Really?  Not really.  Don't remove this ifdef yet */
2124
2125 #ifdef MESSAGE_SENSOR_TO_FIELD_WORKS
2126                 ysize = 4 + (3 * 24); /* footer + number of lines * 24 pixels/line */
2127 #else
2128                 ysize = 4 + (2 * 24); /* footer + number of lines * 24 pixels/line */
2129 #endif
2130                 glRects(xco, yco-ysize, xco+width, yco);
2131                 uiEmboss((float)xco,        (float)yco-ysize,
2132                                  (float)xco+width,  (float)yco, 1);
2133
2134                 myline=1;
2135
2136
2137 #ifdef MESSAGE_SENSOR_TO_FIELD_WORKS
2138                 /* line 1: To */
2139                 uiDefBut(block, TEX, 1, "To: ",
2140                         (xco+10), (yco-(myline++*24)), (width-20), 19,
2141                         &ma->toPropName, 0, 31, 0, 0,
2142                         "Optional send message to objects with this name only"
2143                         ", or empty to broadcast");
2144
2145 #endif
2146
2147                 /* line 2: Message Subject */
2148                 uiDefBut(block, TEX, 1, "Subject: ",
2149                 (xco+10), (yco-(myline++*24)), (width-20), 19,
2150                 &ma->subject, 0, 31, 0, 0,
2151                 "Optional message subject. This is what can be filtered on.");
2152
2153                 /* line 3: Text/Property */
2154                 uiDefButBitS(block, TOG, 1, B_REDR, "T/P",
2155                         (xco+10),(yco-(myline*24)), (0.20 * (width-20)), 19,
2156                         &ma->bodyType, 0.0, 0.0, 0, 0,
2157                         "Toggle message type: either Text or a PropertyName.");
2158
2159                 if (ma->bodyType == ACT_MESG_MESG)
2160                 {
2161                 /* line 3: Message Body */
2162                 uiDefBut(block, TEX, 1, "Body: ",
2163                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2164                 &ma->body, 0, 31, 0, 0,
2165                 "Optional message body Text");
2166                 } else
2167                 {
2168                         /* line 3: Property body (set by property) */
2169                         uiDefBut(block, TEX, 1, "Propname: ",
2170                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2171                         &ma->body, 0, 31, 0, 0,
2172                         "The message body will be set by the Property Value");
2173                 }
2174                 
2175                 yco -= ysize;
2176                 break;
2177         default:
2178                 ysize= 4;
2179
2180                 glRects(xco, yco-ysize, xco+width, yco);
2181                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2182                 
2183                 yco-= ysize;
2184                 break;
2185         }
2186
2187         uiBlockSetEmboss(block, UI_EMBOSSM);
2188
2189         return yco-4;
2190 }
2191
2192 static void do_sensor_menu(void *arg, int event)
2193 {       
2194         ID **idar;
2195         Object *ob;
2196         bSensor *sens;
2197         short count, a;
2198         
2199         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2200         
2201         for(a=0; a<count; a++) {
2202                 ob= (Object *)idar[a];
2203                 if(event==0 || event==2) ob->scaflag |= OB_SHOWSENS;
2204                 else if(event==1) ob->scaflag &= ~OB_SHOWSENS;
2205         }
2206                 
2207         for(a=0; a<count; a++) {
2208                 ob= (Object *)idar[a];
2209                 sens= ob->sensors.first;
2210                 while(sens) {
2211                         if(event==2) sens->flag |= SENS_SHOW;
2212                         else if(event==3) sens->flag &= ~SENS_SHOW;
2213                         sens= sens->next;
2214                 }
2215         }
2216
2217         if(idar) MEM_freeN(idar);
2218         allqueue(REDRAWBUTSLOGIC, 0);
2219 }
2220
2221 static uiBlock *sensor_menu(void *arg_unused)
2222 {
2223         uiBlock *block;
2224         int yco=0;
2225         
2226         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2227         uiBlockSetButmFunc(block, do_sensor_menu, NULL);
2228         
2229         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2230         uiDefBut(block, BUTM, 1, "Hide Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2231         uiDefBut(block, SEPR, 0, "",    0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2232         uiDefBut(block, BUTM, 1, "Show Sensors",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
2233         uiDefBut(block, BUTM, 1, "Hide Sensors",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
2234
2235         uiBlockSetDirection(block, UI_TOP);
2236         
2237         return block;
2238 }
2239
2240 static void do_controller_menu(void *arg, int event)
2241 {       
2242         ID **idar;
2243         Object *ob;
2244         bController *cont;
2245         short count, a;
2246         
2247         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2248         
2249         for(a=0; a<count; a++) {
2250                 ob= (Object *)idar[a];
2251                 if(event==0 || event==2) ob->scaflag |= OB_SHOWCONT;
2252                 else if(event==1) ob->scaflag &= ~OB_SHOWCONT;
2253         }
2254
2255         for(a=0; a<count; a++) {
2256                 ob= (Object *)idar[a];
2257                 cont= ob->controllers.first;
2258                 while(cont) {
2259                         if(event==2) cont->flag |= CONT_SHOW;
2260                         else if(event==3) cont->flag &= ~CONT_SHOW;
2261                         cont= cont->next;
2262                 }
2263         }
2264
2265         if(idar) MEM_freeN(idar);
2266         allqueue(REDRAWBUTSLOGIC, 0);
2267 }
2268
2269 static uiBlock *controller_menu(void *arg_unused)
2270 {
2271         uiBlock *block;
2272         int yco=0;
2273         
2274         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2275         uiBlockSetButmFunc(block, do_controller_menu, NULL);
2276         
2277         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2278         uiDefBut(block, BUTM, 1, "Hide Objects",        0,(short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2279         uiDefBut(block, SEPR, 0, "",                                    0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2280         uiDefBut(block, BUTM, 1, "Show Controllers",    0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 2, 2, "");
2281         uiDefBut(block, BUTM, 1, "Hide Controllers",    0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 3, 3, "");
2282
2283         uiBlockSetDirection(block, UI_TOP);
2284         
2285         return block;
2286 }
2287
2288 static void do_actuator_menu(void *arg, int event)
2289 {       
2290         ID **idar;
2291         Object *ob;
2292         bActuator *act;
2293         short count, a;
2294         
2295         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2296         
2297         for(a=0; a<count; a++) {
2298                 ob= (Object *)idar[a];
2299                 if(event==0 || event==2) ob->scaflag |= OB_SHOWACT;
2300                 else if(event==1) ob->scaflag &= ~OB_SHOWACT;
2301         }
2302
2303         for(a=0; a<count; a++) {
2304                 ob= (Object *)idar[a];
2305                 act= ob->actuators.first;
2306                 while(act) {
2307                         if(event==2) act->flag |= ACT_SHOW;
2308                         else if(event==3) act->flag &= ~ACT_SHOW;
2309                         act= act->next;
2310                 }
2311         }
2312
2313         if(idar) MEM_freeN(idar);
2314         allqueue(REDRAWBUTSLOGIC, 0);
2315 }
2316
2317 static uiBlock *actuator_menu(void *arg_unused)
2318 {
2319         uiBlock *block;
2320         int xco=0;
2321         
2322         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2323         uiBlockSetButmFunc(block, do_actuator_menu, NULL);
2324         
2325         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2326         uiDefBut(block, BUTM, 1, "Hide Objects",        0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2327         uiDefBut(block, SEPR, 0, "",    0, (short)(xco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2328         uiDefBut(block, BUTM, 1, "Show Actuators",      0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
2329         uiDefBut(block, BUTM, 1, "Hide Actuators",      0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
2330
2331         uiBlockSetDirection(block, UI_TOP);
2332         
2333         return block;
2334 }
2335
2336
2337 void buttons_enji(uiBlock *block, Object *ob)
2338 {
2339         uiDefButBitI(block, TOG, OB_SECTOR, B_SETSECTOR, "Sector",
2340                          10,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2341                          "All game elements should be in the Sector boundbox");
2342         uiDefButBitI(block, TOG, OB_PROP, B_SETPROP, "Prop",
2343                          75,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2344                          "An Object fixed within a sector");
2345         uiBlockSetCol(block, BUTPURPLE);
2346         uiDefButBitI(block, TOG, OB_ACTOR, B_SETACTOR, "Actor",
2347                          140,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2348                          "Objects that are evaluated by the engine ");
2349         if(ob->gameflag & OB_ACTOR) {   
2350                 uiDefButBitI(block, TOG, OB_DYNAMIC, B_SETDYNA, "Dynamic",
2351                                  205,205,75,19, &ob->gameflag, 0, 0, 0, 0, 
2352                                  "Motion defined by laws of physics");
2353                 uiDefButBitI(block, TOG, OB_MAINACTOR, B_SETMAINACTOR, "MainActor",
2354                                  280,205,70,19, &ob->gameflag, 0, 0, 0, 0, "");
2355                 
2356                 if(ob->gameflag & OB_DYNAMIC) {
2357                         uiDefButBitI(block, TOG, OB_DO_FH, B_DIFF, "Do Fh",
2358                                          10,185,50,19, &ob->gameflag, 0, 0, 0, 0, 
2359                                          "Use Fh settings in Materials");
2360                         uiDefButBitI(block, TOG, OB_ROT_FH, B_DIFF, "Rot Fh",
2361                                          60,185,50,19, &ob->gameflag, 0, 0, 0, 0, 
2362                                          "Use face normal to rotate Object");
2363                 
2364                         uiBlockSetCol(block, BUTGREY);
2365                         uiDefButF(block, NUM, B_DIFF, "Mass:",
2366                                          110, 185, 120, 19, &ob->mass, 0.01, 100.0, 10, 0, 
2367                                          "The mass of the Object");
2368                         uiDefButF(block, NUM, REDRAWVIEW3D, "Size:",
2369                                          230, 185, 120, 19, &ob->inertia, 0.01, 10.0, 10, 0, 
2370                                          "Bounding sphere size");
2371                         uiDefButF(block, NUM, B_DIFF, "Damp:",
2372                                          10, 165, 100, 19, &ob->damping, 0.0, 1.0, 10, 0, 
2373                                          "General movement damping");
2374                         uiDefButF(block, NUM, B_DIFF, "RotDamp:",
2375                                          110, 165, 120, 19, &ob->rdamping, 0.0, 1.0, 10, 0, 
2376                                          "General rotation damping");
2377                 }
2378         }
2379
2380 }
2381
2382 void buttons_ketsji(uiBlock *block, Object *ob)
2383 {
2384         uiDefButBitI(block, TOG, OB_ACTOR, B_REDR, "Actor",
2385                           10,205,75,19, &ob->gameflag, 0, 0, 0, 0,
2386                           "Objects that are evaluated by the engine ");
2387         if(ob->gameflag & OB_ACTOR) {   
2388                 uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 85,205,65,19, 
2389                                   &ob->gameflag, 0, 0, 0, 0, 
2390                                   "Objects that don't restitute collisions (like a ghost)");
2391                 uiDefButBitI(block, TOG, OB_DYNAMIC, B_REDR, "Dynamic", 150,205,65,19, 
2392                                   &ob->gameflag, 0, 0, 0, 0, 
2393                                   "Motion defined by laws of physics");
2394         
2395                 if(ob->gameflag & OB_DYNAMIC) {
2396                         uiDefButBitI(block, TOG, OB_RIGID_BODY, B_REDR, "Rigid Body", 215,205,135,19, 
2397                                           &ob->gameflag, 0, 0, 0, 0, 
2398                                           "Enable rolling physics");
2399                         uiDefButBitI(block, TOG, OB_DO_FH, B_DIFF, "Do Fh", 10,185,50,19, 
2400                                           &ob->gameflag, 0, 0, 0, 0, 
2401                                           "Use Fh settings in Materials");
2402                         uiDefButBitI(block, TOG, OB_ROT_FH, B_DIFF, "Rot Fh", 60,185,50,19, 
2403                                           &ob->gameflag, 0, 0, 0, 0, 
2404                                           "Use face normal to rotate Object");
2405                         uiDefButF(block, NUM, B_DIFF, "Mass:", 110, 185, 80, 19, 
2406                                           &ob->mass, 0.01, 10000.0, 10, 0, 
2407                                           "The mass of the Object");
2408                         uiDefButF(block, NUM, REDRAWVIEW3D, "Size:", 190, 185, 80, 19, 
2409                                           &ob->inertia, 0.01, 10.0, 10, 0, 
2410                                           "Bounding sphere size");
2411                         uiDefButF(block, NUM, B_DIFF, "Form:", 270, 185, 80, 19, 
2412                                           &ob->formfactor, 0.01, 100.0, 10, 0, 
2413                                           "Form factor");
2414
2415                         uiDefButF(block, NUM, B_DIFF, "Damp:", 10, 165, 100, 19, 
2416                                           &ob->damping, 0.0, 1.0, 10, 0, 
2417                                           "General movement damping");
2418                         uiDefButF(block, NUM, B_DIFF, "RotDamp:", 110, 165, 120, 19, 
2419                                           &ob->rdamping, 0.0, 1.0, 10, 0, 
2420                                           "General rotation damping");
2421                         uiDefButBitI(block, TOG, OB_ANISOTROPIC_FRICTION, B_REDR, "Anisotropic", 
2422                                           230, 165, 120, 19,
2423                                           &ob->gameflag, 0.0, 1.0, 10, 0,
2424                                           "Enable anisotropic friction");                       
2425                 }
2426
2427                 if (ob->gameflag & OB_ANISOTROPIC_FRICTION) {
2428                         uiDefButF(block, NUM, B_DIFF, "x friction:", 10, 145, 114, 19,
2429                                           &ob->anisotropicFriction[0], 0.0, 1.0, 10, 0,
2430                                           "Relative friction coefficient in the x-direction.");
2431                         uiDefButF(block, NUM, B_DIFF, "y friction:", 124, 145, 113, 19,
2432                                           &ob->anisotropicFriction[1], 0.0, 1.0, 10, 0,
2433                                           "Relative friction coefficient in the y-direction.");
2434                         uiDefButF(block, NUM, B_DIFF, "z friction:", 237, 145, 113, 19,
2435                                           &ob->anisotropicFriction[2], 0.0, 1.0, 10, 0,
2436                                           "Relative friction coefficient in the z-direction.");
2437                 }
2438         }
2439
2440         if (!(ob->gameflag & OB_GHOST)) {
2441                 uiDefButBitI(block, TOG, OB_BOUNDS, B_REDR, "Bounds", 10, 125, 75, 19,
2442                                 &ob->gameflag, 0, 0,0, 0,
2443                                 "Specify a bounds object for physics");
2444                 if (ob->gameflag & OB_BOUNDS) {
2445                         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder%x4|Polytope%x5",
2446                                 85, 125, 100, 19, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
2447                 }
2448         }
2449 }
2450
2451 /* never used, see CVS 1.134 for the code */
2452 /*  static FreeCamera *new_freecamera(void) */
2453
2454 /* never used, see CVS 1.120 for the code */
2455 /*  static uiBlock *freecamera_menu(void) */
2456
2457
2458 void logic_buts(void)
2459 {
2460         ID **idar;
2461         Object *ob;
2462         bProperty *prop;
2463         bSensor *sens;
2464         bController *cont;
2465         bActuator *act;
2466         uiBlock *block;
2467         uiBut *but;
2468         World *wrld;
2469         int a;
2470         short xco, yco, count, width, ycoo;
2471         char *pupstr, name[32];
2472         int butreturn = 0;
2473
2474         wrld= G.scene->world;
2475
2476         ob= OBACT;
2477
2478         if(ob==0) return;
2479         uiSetButLock(ob->id.lib!=0, "Can't edit library data");
2480
2481         sprintf(name, "buttonswin %d", curarea->win);
2482         block= uiNewBlock(&curarea->uiblocks, name, UI_EMBOSS, UI_HELV, curarea->win);
2483         
2484         uiBlockSetCol(block, TH_BUT_SETTING2);
2485
2486         if(wrld) {
2487                 if 
2488                         (wrld->physicsEngine == 1) buttons_enji(block, ob);
2489                 else
2490                         buttons_ketsji(block, ob);
2491         }
2492         else buttons_ketsji(block, ob);
2493         
2494         uiBlockSetCol(block, TH_AUTO);
2495         uiDefBut(block, BUT, B_ADD_PROP, "ADD property",                10, 90, 340, 24,
2496                          NULL, 0.0, 100.0, 100, 0,
2497                          "");
2498         
2499         pupstr= "Types %t|Bool %x0|Int %x1|Float %x2|String %x3|Timer %x5";
2500         
2501         a= 0;
2502         prop= ob->prop.first;
2503         while(prop) {
2504                 
2505                 but= uiDefBut(block, BUT, 1, "Del",             10, (short)(70-20*a), 40, 19, NULL, 0.0, 0.0, 1, (float)a, "");
2506                 uiButSetFunc(but, del_property, prop, NULL);
2507                 uiDefButS(block, MENU, B_CHANGE_PROP, pupstr,           50, (short)(70-20*a), 60, 19, &prop->type, 0, 0, 0, 0, "");
2508                 but= uiDefBut(block, TEX, 1, "Name:",                                   110, (short)(70-20*a), 105, 19, prop->name, 0, 31, 0, 0, "");
2509                 uiButSetFunc(but, make_unique_prop_names_cb, prop->name, (void*) 1);
2510                 
2511                 if (strcmp(prop->name, "Text") == 0) {
2512                         butreturn = REDRAWVIEW3D;
2513                 } else {
2514                         butreturn = 0;
2515                 }
2516
2517                 if(prop->type==PROP_BOOL) {
2518                         uiDefButBitI(block, TOG, PROP_BOOL, B_REDR, "True",             215, (short)(70-20*a), 55, 19, &prop->data, 0, 0, 0, 0, "");
2519                         uiDefButBitI(block, TOGN, PROP_BOOL, B_REDR, "False",   270, (short)(70-20*a), 55, 19, &prop->data, 0, 0, 0, 0, "");
2520                 }
2521                 else if(prop->type==PROP_INT) 
2522                         uiDefButI(block, NUM, butreturn, "",                    215, (short)(70-20*a), 110, 19, &prop->data, -10000, 10000, 0, 0, "");
2523                 else if(prop->type==PROP_FLOAT) 
2524                         uiDefButF(block, NUM, butreturn, "",                    215, (short)(70-20*a), 110, 19, (float*) &prop->data, -10000, 10000, 100, 3, "");
2525                 else if(prop->type==PROP_STRING) 
2526                         uiDefBut(block, TEX, butreturn, "",                             215, (short)(70-20*a), 110, 19, prop->poin, 0, 127, 0, 0, "");
2527                 else if(prop->type==PROP_TIME) 
2528                         uiDefButF(block, NUM, butreturn, "",                    215, (short)(70-20*a), 110, 19, (float*) &prop->data, -10000, 10000, 0, 0, "");
2529                 
2530                 uiDefButBitS(block, TOG, PROP_DEBUG, 0, "D",            325, (short)(70-20*a), 20, 19, &prop->flag, 0, 0, 0, 0, "Print Debug info");
2531                 
2532                 a++;
2533                 prop= prop->next;
2534         }
2535         
2536         uiClearButLock();
2537
2538         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2539         
2540         /* ******************************* */
2541         xco= 375; yco= 170; width= 230;
2542
2543         uiBlockSetEmboss(block, UI_EMBOSSP);
2544         uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco+35, 80, 19, "");
2545         uiBlockSetEmboss(block, UI_EMBOSS);
2546         uiDefButBitS(block, TOG, BUTS_SENS_SEL, B_REDR, "Sel", xco+110, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show all selected Objects");
2547         uiDefButBitS(block, TOG, BUTS_SENS_ACT, B_REDR, "Act", xco+110+(width-100)/3, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show active Object");
2548         uiDefButBitS(block, TOG, BUTS_SENS_LINK, B_REDR, "Link", xco+110+2*(width-100)/3, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show linked Objects to Controller");
2549         
2550         for(a=0; a<count; a++) {
2551                 ob= (Object *)idar[a];
2552                 uiClearButLock();
2553                 uiSetButLock(ob->id.lib!=0, "Can't edit library data");
2554                 
2555                 if( (ob->scavisflag & OB_VIS_SENS) == 0) continue;
2556                 
2557                 /* presume it is only objects for now */
2558                 uiBlockSetEmboss(block, UI_EMBOSS);
2559                 if(ob->sensors.first) uiSetCurFont(block, UI_HELVB);
2560                 uiDefButBitS(block, TOG, OB_SHOWSENS, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), 19, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide sensors");
2561                 if(ob->sensors.first) uiSetCurFont(block, UI_HELV);
2562                 uiDefButBitS(block, TOG, OB_ADDSENS, B_ADD_SENS, "Add",(short)(xco+width-40), yco, 50, 19, &ob->scaflag, 0, 0, 0, 0, "Add a new Sensor");
2563                 yco-=20;
2564                 
2565                 if(ob->scaflag & OB_SHOWSENS) {
2566                         
2567                         sens= ob->sensors.first;
2568                         while(sens) {
2569                                 uiBlockSetEmboss(block, UI_EMBOSSM);
2570                                 uiDefIconButBitS(block, TOG, SENS_DEL, B_DEL_SENS, ICON_X,      xco, yco, 22, 19, &sens->flag, 0, 0, 0, 0, "Delete Sensor");
2571                                 uiDefIconButBitS(block, ICONTOG, SENS_SHOW, B_REDR, ICON_RIGHTARROW, (short)(xco+width-22), yco, 22, 19, &sens->flag, 0, 0, 0, 0, "Sensor settings");
2572
2573                                 ycoo= yco;
2574                                 if(sens->flag & SENS_SHOW)
2575                                 {
2576                                         uiDefButS(block, MENU, B_CHANGE_SENS, sensor_pup(),     (short)(xco+22), yco, 100, 19, &sens->type, 0, 0, 0, 0, "Sensor type");
2577                                         but= uiDefBut(block, TEX, 1, "", (short)(xco+122), yco, (short)(width-144), 19, sens->name, 0, 31, 0, 0, "Sensor name");
2578                                         uiButSetFunc(but, make_unique_prop_names_cb, sens->name, (void*) 0);
2579
2580                                         sens->otype= sens->type;
2581                                         yco= draw_sensorbuttons(sens, block, xco, yco, width,ob->id.name);
2582                                         if(yco-6 < ycoo) ycoo= (yco+ycoo-20)/2;
2583                                 }
2584                                 else {
2585                                         set_col_sensor(sens->type, 1);
2586                                         glRecti(xco+22, yco, xco+width-22,yco+19);
2587                                         but= uiDefBut(block, LABEL, 0, sensor_name(sens->type), (short)(xco+22), yco, 100, 19, sens, 0, 0, 0, 0, "");
2588                                         uiButSetFunc(but, sca_move_sensor, sens, NULL);
2589                                         but= uiDefBut(block, LABEL, 0, sens->name, (short)(xco+122), yco, (short)(width-144), 19, sens, 0, 31, 0, 0, "");
2590                                         uiButSetFunc(but, sca_move_sensor, sens, NULL);
2591                                 }
2592
2593                                 but= uiDefIconBut(block, LINK, 0, ICON_LINK,    (short)(xco+width), ycoo, 19, 19, NULL, 0, 0, 0, 0, "");
2594                                 uiSetButLink(but, NULL, (void ***)&(sens->links), &sens->totlinks, LINK_SENSOR, LINK_CONTROLLER);
2595
2596                                 yco-=20;
2597
2598                                 sens= sens->next;
2599                         }
2600                         yco-= 6;
2601                 }
2602         }
2603
2604         /* ******************************* */
2605         xco= 675; yco= 170; width= 230;
2606
2607         uiBlockSetEmboss(block, UI_EMBOSSP);
2608         uiDefBlockBut(block, controller_menu, NULL, "Controllers", xco-10, yco+35, 100, 19, "");
2609         uiBlockSetEmboss(block, UI_EMBOSS);
2610         uiDefButBitS(block, TOG, BUTS_CONT_SEL,  B_REDR, "Sel", xco+110, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show all selected Objects");
2611         uiDefButBitS(block, TOG, BUTS_CONT_ACT, B_REDR, "Act", xco+110+(width-100)/3, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show active Object");
2612         uiDefButBitS(block, TOG, BUTS_CONT_LINK, B_REDR, "Link", xco+110+2*(width-100)/3, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show linked Objects to Sensor/Actuator");
2613         
2614         ob= OBACT;
2615         
2616         for(a=0; a<count; a++) {
2617                 ob= (Object *)idar[a];
2618                 uiClearButLock();
2619                 uiSetButLock(ob->id.lib!=0, "Can't edit library data");
2620                 if( (ob->scavisflag & OB_VIS_CONT) == 0) continue;
2621
2622                 /* presume it is only objects for now */
2623                 uiBlockSetEmboss(block, UI_EMBOSS);
2624                 uiDefButBitS(block, TOG, OB_ADDCONT, B_ADD_CONT, "Add",(short)(xco+width-40), yco, 50, 19, &ob->scaflag, 0, 0, 0, 0, "Add a new Controller");
2625                 if(ob->controllers.first) uiSetCurFont(block, UI_HELVB);
2626                 uiDefButBitS(block, TOG, OB_SHOWCONT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), 19, &ob->scaflag, 0, 0, 0, 0, "Active Object name");
2627                 if(ob->controllers.first) uiSetCurFont(block, UI_HELV);
2628                 yco-=20;
2629                 
2630                 if(ob->scaflag & OB_SHOWCONT) {
2631                 
2632                         cont= ob->controllers.first;
2633                         while(cont) {
2634                                 uiBlockSetEmboss(block, UI_EMBOSSM);
2635                                 uiDefIconButBitS(block, TOG, CONT_DEL, B_DEL_CONT, ICON_X,      xco, yco, 22, 19, &cont->flag, 0, 0, 0, 0, "Delete Controller");
2636                                 uiDefIconButBitS(block, ICONTOG, CONT_SHOW, B_REDR, ICON_RIGHTARROW, (short)(xco+width-22), yco, 22, 19, &cont->flag, 0, 0, 0, 0, "Controller settings");
2637                 
2638                                 if(cont->flag & CONT_SHOW) {
2639                                         cont->otype= cont->type;
2640                                         uiDefButS(block, MENU, B_CHANGE_CONT, controller_pup(),(short)(xco+22), yco, 100, 19, &cont->type, 0, 0, 0, 0, "Controller type");
2641                                         but= uiDefBut(block, TEX, 1, "", (short)(xco+122), yco, (short)(width-144), 19, cont->name, 0, 31, 0, 0, "Controller name");
2642                                         uiButSetFunc(but, make_unique_prop_names_cb, cont->name, (void*) 0);
2643                 
2644                                         ycoo= yco;
2645                                         yco= draw_controllerbuttons(cont, block, xco, yco, width);
2646                                         if(yco-6 < ycoo) ycoo= (yco+ycoo-20)/2;
2647                                 }
2648                                 else {
2649                                         cpack(0x999999);
2650                                         glRecti(xco+22, yco, xco+width-22,yco+19);
2651                                         but= uiDefBut(block, LABEL, 0, controller_name(cont->type), (short)(xco+22), yco, 100, 19, cont, 0, 0, 0, 0, "Controller type");
2652                                         uiButSetFunc(but, sca_move_controller, cont, NULL);
2653                                         but= uiDefBut(block, LABEL, 0, cont->name,(short)(xco+122), yco,(short)(width-144), 19, cont, 0, 0, 0, 0, "Controller name");
2654                                         uiButSetFunc(but, sca_move_controller, cont, NULL);
2655                                         ycoo= yco;
2656                                 }
2657                 
2658                                 but= uiDefIconBut(block, LINK, 0, ICON_LINK,    (short)(xco+width), ycoo, 19, 19, NULL, 0, 0, 0, 0, "");
2659                                 uiSetButLink(but, NULL, (void ***)&(cont->links), &cont->totlinks, LINK_CONTROLLER, LINK_ACTUATOR);
2660                 
2661                                 uiDefIconBut(block, INLINK, 0, ICON_INLINK,(short)(xco-19), ycoo, 19, 19, cont, LINK_CONTROLLER, 0, 0, 0, "");
2662                 
2663                                 yco-=20;
2664                                 
2665                                 cont= cont->next;
2666                         }
2667                         yco-= 6;
2668                 }
2669         }
2670         
2671         /* ******************************* */
2672         xco= 985; yco= 170; width= 280;
2673         
2674         uiBlockSetEmboss(block, UI_EMBOSSP);
2675         uiDefBlockBut(block, actuator_menu, NULL, "Actuators", xco-10, yco+35, 100, 19, "");
2676         uiBlockSetEmboss(block, UI_EMBOSS);
2677         uiDefButBitS(block, TOG, BUTS_ACT_SEL, B_REDR, "Sel", xco+110, yco+35, (width-110)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show all selected Objects");
2678         uiDefButBitS(block, TOG, BUTS_ACT_ACT, B_REDR, "Act", xco+110+(width-110)/3, yco+35, (width-110)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show active Object");
2679         uiDefButBitS(block, TOG, BUTS_ACT_LINK, B_REDR, "Link", xco+110+2*(width-110)/3, yco+35, (width-110)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show linked Objects to Controller");
2680         
2681         for(a=0; a<count; a++) {
2682                 ob= (Object *)idar[a];
2683                 uiClearButLock();
2684                 uiSetButLock(ob->id.lib!=0, "Can't edit library data");
2685                 if( (ob->scavisflag & OB_VIS_ACT) == 0) continue;
2686
2687                 /* presume it is only objects for now */
2688                 uiBlockSetEmboss(block, UI_EMBOSS);
2689                 if(ob->actuators.first) uiSetCurFont(block, UI_HELVB);
2690                 uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2,(short)(xco-10), yco,(short)(width-30), 19, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators");
2691                 if(ob->actuators.first) uiSetCurFont(block, UI_HELV);
2692                 uiDefButBitS(block, TOG, OB_ADDACT, B_ADD_ACT, "Add",(short)(xco+width-40), yco, 50, 19, &ob->scaflag, 0, 0, 0, 0, "Add a new Actuator");
2693                 yco-=20;
2694                 
2695                 if(ob->scaflag & OB_SHOWACT) {
2696                         
2697                         act= ob->actuators.first;
2698                         while(act) {
2699                                 uiBlockSetEmboss(block, UI_EMBOSSM);
2700                                 uiDefIconButBitS(block, TOG, ACT_DEL, B_DEL_ACT, ICON_X,        xco, yco, 22, 19, &act->flag, 0, 0, 0, 0, "Delete Actuator");
2701                                 uiDefIconButBitS(block, ICONTOG, ACT_SHOW, B_REDR, ICON_RIGHTARROW, (short)(xco+width-22), yco, 22, 19, &act->flag, 0, 0, 0, 0, "Actuator settings");
2702
2703                                 if(act->flag & ACT_SHOW) {
2704                                         act->otype= act->type;
2705                                         uiDefButS(block, MENU, B_CHANGE_ACT, actuator_pup(ob),  (short)(xco+22), yco, 100, 19, &act->type, 0, 0, 0, 0, "Actuator type");
2706                                         but= uiDefBut(block, TEX, 1, "", (short)(xco+122), yco, (short)(width-144), 19, act->name, 0, 31, 0, 0, "Actuator name");
2707                                         uiButSetFunc(but, make_unique_prop_names_cb, act->name, (void*) 0);
2708
2709                                         ycoo= yco;
2710                                         yco= draw_actuatorbuttons(act, block, xco, yco, width);
2711                                         if(yco-6 < ycoo) ycoo= (yco+ycoo-20)/2;
2712                                 }
2713                                 else {
2714                                         set_col_actuator(act->type, 1);
2715                                         glRecti((short)(xco+22), yco, (short)(xco+width-22),(short)(yco+19));
2716                                         but= uiDefBut(block, LABEL, 0, actuator_name(act->type), (short)(xco+22), yco, 100, 19, act, 0, 0, 0, 0, "Actuator type");
2717                                         uiButSetFunc(but, sca_move_actuator, act, NULL);
2718                                         but= uiDefBut(block, LABEL, 0, act->name, (short)(xco+122), yco, (short)(width-144), 19, act, 0, 0, 0, 0, "Actuator name");
2719                                         uiButSetFunc(but, sca_move_actuator, act, NULL);
2720                                         ycoo= yco;
2721                                 }
2722
2723                                 uiDefIconBut(block, INLINK, 0, ICON_INLINK,(short)(xco-19), ycoo, 19, 19, act, LINK_ACTUATOR, 0, 0, 0, "");
2724
2725                                 yco-=20;
2726
2727                                 act= act->next;
2728                         }
2729                         yco-= 6;
2730                 }
2731         }
2732
2733         uiComposeLinks(block);
2734         uiDrawBlock(block);
2735
2736         if(idar) MEM_freeN(idar);
2737 }
2738