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