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