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