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