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