Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / source / blender / editors / space_logic / logic_window.c
index 55e2156..dc8b111 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <string.h>
 #include <stdio.h>
+#include <float.h>
 
 #include "DNA_actuator_types.h"
 #include "DNA_controller_types.h"
@@ -38,6 +39,9 @@
 #include "DNA_screen_types.h"
 #include "DNA_sensor_types.h"
 #include "DNA_sound_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_action_types.h"
 #include "DNA_windowmanager_types.h"
 
 #include "MEM_guardedalloc.h"
 #include "logic_intern.h"
 
 
-
-/* XXX */
-static int pupmenu() {return 1;}
-/* XXX */
-
 #define MAX_RENDER_PASS   100
 #define B_REDR         1
 #define B_IDNAME       2
 
-#define B_ADD_PROP             2701
-#define B_CHANGE_PROP          2702
-
 #define B_ADD_SENS             2703
 #define B_CHANGE_SENS          2704
 #define B_DEL_SENS             2705
@@ -204,7 +200,7 @@ static void make_unique_prop_names_cb(bContext *C, void *strv, void *redraw_view
 }
 
 
-static void sca_move_sensor(bContext *C, void *datav, void *data2_unused)
+static void sca_move_sensor(bContext *C, void *datav, void *move_up)
 {
        Scene *scene= CTX_data_scene(C);
        bSensor *sens_to_delete= datav;
@@ -212,7 +208,8 @@ static void sca_move_sensor(bContext *C, void *datav, void *data2_unused)
        Base *base;
        bSensor *sens, *tmp;
        
-       val= pupmenu("Move up%x1|Move down %x2");
+       // val= pupmenu("Move up%x1|Move down %x2");
+       val = move_up ? 1:2;
        
        if(val>0) {
                /* now find out which object has this ... */
@@ -255,7 +252,7 @@ static void sca_move_sensor(bContext *C, void *datav, void *data2_unused)
        }
 }
 
-static void sca_move_controller(bContext *C, void *datav, void *data2_unused)
+static void sca_move_controller(bContext *C, void *datav, void *move_up)
 {
        Scene *scene= CTX_data_scene(C);
        bController *controller_to_del= datav;
@@ -263,7 +260,8 @@ static void sca_move_controller(bContext *C, void *datav, void *data2_unused)
        Base *base;
        bController *cont, *tmp;
        
-       val= pupmenu("Move up%x1|Move down %x2");
+       //val= pupmenu("Move up%x1|Move down %x2");
+       val = move_up ? 1:2;
        
        if(val>0) {
                /* now find out which object has this ... */
@@ -309,7 +307,7 @@ static void sca_move_controller(bContext *C, void *datav, void *data2_unused)
        }
 }
 
-static void sca_move_actuator(bContext *C, void *datav, void *data2_unused)
+static void sca_move_actuator(bContext *C, void *datav, void *move_up)
 {
        Scene *scene= CTX_data_scene(C);
        bActuator *actuator_to_move= datav;
@@ -317,7 +315,8 @@ static void sca_move_actuator(bContext *C, void *datav, void *data2_unused)
        Base *base;
        bActuator *act, *tmp;
        
-       val= pupmenu("Move up%x1|Move down %x2");
+       //val= pupmenu("Move up%x1|Move down %x2");
+       val = move_up ? 1:2;
        
        if(val>0) {
                /* now find out which object has this ... */
@@ -363,7 +362,6 @@ static void sca_move_actuator(bContext *C, void *datav, void *data2_unused)
 
 void do_logic_buts(bContext *C, void *arg, int event)
 {
-       bProperty *prop;
        bSensor *sens;
        bController *cont;
        bActuator *act;
@@ -385,24 +383,6 @@ void do_logic_buts(bContext *C, void *arg, int event)
        case B_SETMAINACTOR:
                ob->gameflag &= ~(OB_SECTOR|OB_PROP);
                break;
-
-
-       case B_ADD_PROP:
-               prop= new_property(PROP_FLOAT);
-               make_unique_prop_names(C, prop->name);
-               BLI_addtail(&ob->prop, prop);
-               ED_undo_push(C, "Add property");
-               break;
-       
-       case B_CHANGE_PROP:
-               prop= ob->prop.first;
-               while(prop) {
-                       if(prop->type!=prop->otype) {
-                               init_property(prop);
-                       }
-                       prop= prop->next;
-               }
-               break;
        
        case B_ADD_SENS:
                for(ob=G.main->object.first; ob; ob=ob->id.next) {
@@ -631,6 +611,8 @@ static char *sensor_name(int type)
                return "Keyboard";
        case SENS_PROPERTY:
                return "Property";
+       case SENS_ARMATURE:
+               return "Armature";
        case SENS_ACTUATOR:
                return "Actuator";
        case SENS_DELAY:
@@ -658,7 +640,7 @@ static char *sensor_pup(void)
        /* the number needs to match defines in game.h */
        return "Sensors %t|Always %x0|Delay %x13|Keyboard %x3|Mouse %x5|"
                "Touch %x1|Collision %x6|Near %x2|Radar %x7|"
-               "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11|Actuator %x12";
+               "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11|Actuator %x12|Armature %x14";
 }
 
 static char *controller_name(int type)
@@ -708,8 +690,6 @@ static char *actuator_name(int type)
                return "Material";
        case ACT_SOUND:
                return "Sound";
-       case ACT_CD:
-               return "CD";
        case ACT_PROPERTY:
                return "Property";
        case ACT_EDIT_OBJECT:
@@ -734,6 +714,8 @@ static char *actuator_name(int type)
                return "Parent";
        case ACT_STATE:
                return "State";
+       case ACT_ARMATURE:
+               return "Armature";
        }
        return "unknown";
 }
@@ -746,23 +728,23 @@ static char *actuator_pup(Object *owner)
        switch (owner->type)
        {
        case OB_ARMATURE:
-               return "Actuators  %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
+               return "Actuators  %t|Action %x15|Armature %x23|Motion %x0|Constraint %x9|Ipo %x1"
                        "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
-                       "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
+                        "|Scene %x11|Random %x13|Message %x14|Game %x17"
                        "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
                break;
 
        case OB_MESH:
                return "Actuators  %t|Shape Action %x21|Motion %x0|Constraint %x9|Ipo %x1"
                        "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
-                       "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
+                        "|Scene %x11|Random %x13|Message %x14|Game %x17"
                        "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
                break;
 
        default:
                return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
                        "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
-                       "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
+                        "|Scene %x11|Random %x13|Message %x14|Game %x17"
                        "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
        }
 }
@@ -961,6 +943,7 @@ static int get_col_sensor(int type)
        case SENS_NEAR:                 return TH_PANEL; 
        case SENS_KEYBOARD:             return TH_PANEL;
        case SENS_PROPERTY:             return TH_PANEL;
+       case SENS_ARMATURE:             return TH_PANEL;
        case SENS_ACTUATOR:             return TH_PANEL;
        case SENS_MOUSE:                return TH_PANEL;
        case SENS_RADAR:                return TH_PANEL;
@@ -990,6 +973,120 @@ static void verify_logicbutton_func(bContext *C, void *data1, void *data2)
        }
 }
 
+static void test_scriptpoin_but(struct bContext *C, char *name, ID **idpp)
+{
+       ID *id;
+       
+       id= CTX_data_main(C)->text.first;
+       while(id) {
+               if( strcmp(name, id->name+2)==0 ) {
+                       *idpp= id;
+                       return;
+               }
+               id= id->next;
+       }
+       *idpp= NULL;
+}
+
+static void test_actionpoin_but(struct bContext *C, char *name, ID **idpp)
+{
+       ID *id;
+       
+       id= CTX_data_main(C)->action.first;
+       while(id) {
+               if( strcmp(name, id->name+2)==0 ) {
+                       id_us_plus(id);
+                       *idpp= id;
+                       return;
+               }
+               id= id->next;
+       }
+       *idpp= NULL;
+}
+
+
+static void test_obpoin_but(struct bContext *C, char *name, ID **idpp)
+{
+       ID *id;
+       
+       id= CTX_data_main(C)->object.first;
+       while(id) {
+               if( strcmp(name, id->name+2)==0 ) {
+                       *idpp= id;
+                       id_lib_extern(id);      /* checks lib data, sets correct flag for saving then */
+                       return;
+               }
+               id= id->next;
+       }
+       *idpp= NULL;
+}
+
+static void test_meshpoin_but(struct bContext *C, char *name, ID **idpp)
+{
+       ID *id;
+
+       if( *idpp ) (*idpp)->us--;
+       
+       id= CTX_data_main(C)->mesh.first;
+       while(id) {
+               if( strcmp(name, id->name+2)==0 ) {
+                       *idpp= id;
+                       id_us_plus(id);
+                       return;
+               }
+               id= id->next;
+       }
+       *idpp= NULL;
+}
+
+static void test_matpoin_but(struct bContext *C, char *name, ID **idpp)
+{
+       ID *id;
+
+       if( *idpp ) (*idpp)->us--;
+       
+       id= CTX_data_main(C)->mat.first;
+       while(id) {
+               if( strcmp(name, id->name+2)==0 ) {
+                       *idpp= id;
+                       id_us_plus(id);
+                       return;
+               }
+               id= id->next;
+       }
+       *idpp= NULL;
+}
+
+static void test_scenepoin_but(struct bContext *C, char *name, ID **idpp)
+{
+       ID *id;
+       
+       if( *idpp ) (*idpp)->us--;
+       
+       id= CTX_data_main(C)->scene.first;
+       while(id) {
+               if( strcmp(name, id->name+2)==0 ) {
+                       *idpp= id;
+                       id_us_plus(id);
+                       return;
+               }
+               id= id->next;
+       }
+       *idpp= NULL;
+}
+
+
+static void test_keyboard_event(struct bContext *C, void *arg_ks, void *arg_unused)
+{
+       bKeyboardSensor *ks= (bKeyboardSensor*)arg_ks;
+       
+       if(!ISKEYBOARD(ks->key))
+               ks->key= 0;
+       if(!ISKEYBOARD(ks->qual))
+               ks->qual= 0;
+       if(!ISKEYBOARD(ks->qual2))
+               ks->qual2= 0;
+}
 
 /**
  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
@@ -1004,6 +1101,7 @@ static void draw_default_sensor_header(bSensor *sens,
        uiBut *but;
        
        /* Pulsing and frequency */
+       uiBlockBeginAlign(block);
        uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP,
                         (short)(x + 10 + 0. * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19,
                         &sens->pulse, 0.0, 0.0, 0, 0,
@@ -1017,8 +1115,10 @@ static void draw_default_sensor_header(bSensor *sens,
                         (short)(x + 10 + 0.2 * (w-20)), (short)(y - 21), (short)(0.275 * (w-20)), 19,
                         &sens->freq, 0.0, 10000.0, 0, 0,
                         "Delay between repeated pulses (in logic tics, 0 = no delay)");
+       uiBlockEndAlign(block);
        
        /* value or shift? */
+       uiBlockBeginAlign(block);
        but= uiDefButS(block, TOG, 1, "Level",
                         (short)(x + 10 + 0.5 * (w-20)), (short)(y - 21), (short)(0.20 * (w-20)), 19,
                         &sens->level, 0.0, 0.0, 0, 0,
@@ -1029,6 +1129,7 @@ static void draw_default_sensor_header(bSensor *sens,
                         &sens->tap, 0.0, 0.0, 0, 0,
                         "Trigger controllers only for an instant, even while the sensor remains true");
        uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->tap));
+       uiBlockEndAlign(block);
        
        uiDefButS(block, TOG, 1, "Inv",
                         (short)(x + 10 + 0.85 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
@@ -1036,12 +1137,51 @@ static void draw_default_sensor_header(bSensor *sens,
                         "Invert the level (output) of this sensor");
 }
 
-static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
+static void check_armature_bone_constraint(Object *ob, char *posechannel, char *constraint)
+{
+       /* check that bone exist in the active object */
+       if (ob->type == OB_ARMATURE && ob->pose) {
+               bPoseChannel *pchan;
+               bPose *pose = ob->pose;
+               for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) {
+                       if (!strcmp(pchan->name, posechannel)) {
+                               /* found it, now look for constraint channel */
+                               bConstraint *con;
+                               for (con=pchan->constraints.first; con; con=con->next) {
+                                       if (!strcmp(con->name, constraint)) {
+                                               /* found it, all ok */
+                                               return;                                         
+                                       }
+                               }
+                               /* didn't find constraint, make empty */
+                               constraint[0] = 0;
+                               return;
+                       }
+               }
+       }
+       /* didn't find any */
+       posechannel[0] = 0;
+       constraint[0] = 0;
+}
+
+static void check_armature_sensor(bContext *C, void *arg1_but, void *arg2_sens)
+{
+       bArmatureSensor *sens = arg2_sens;
+       uiBut *but = arg1_but;
+       Object *ob= CTX_data_active_object(C);
+
+       /* check that bone exist in the active object */
+       but->retval = B_REDR;
+       check_armature_bone_constraint(ob, sens->posechannel, sens->constraint);
+}
+
+static short draw_sensorbuttons(Object *ob, bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
 {
        bNearSensor      *ns           = NULL;
        bTouchSensor     *ts           = NULL;
        bKeyboardSensor  *ks           = NULL;
        bPropertySensor  *ps           = NULL;
+       bArmatureSensor  *arm          = NULL;
        bMouseSensor     *ms           = NULL;
        bCollisionSensor *cs           = NULL;
        bRadarSensor     *rs           = NULL;
@@ -1051,6 +1191,7 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
        bJoystickSensor  *joy              = NULL;
        bActuatorSensor  *as           = NULL;
        bDelaySensor     *ds               = NULL;
+       uiBut *but;
        short ysize;
        char *str;
        
@@ -1199,12 +1340,15 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
                        
                        if ((ks->type&1)==0) { /* is All Keys option off? */
                                /* line 2: hotkey and allkeys toggle */
-                               uiDefKeyevtButS(block, 0, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
+                               but= uiDefKeyevtButS(block, 0, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
+                               uiButSetFunc(but, test_keyboard_event, ks, NULL);
                                
                                /* line 3: two key modifyers (qual1, qual2) */
                                uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
-                               uiDefKeyevtButS(block, 0, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
-                               uiDefKeyevtButS(block, 0, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
+                               but= uiDefKeyevtButS(block, 0, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
+                               uiButSetFunc(but, test_keyboard_event, ks, NULL);
+                               but= uiDefKeyevtButS(block, 0, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
+                               uiButSetFunc(but, test_keyboard_event, ks, NULL);
                        }
                        
                        /* line 4: toggle property for string logging mode */
@@ -1260,6 +1404,45 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
                                        ps->value, 0, 31, 0, 0, "check for value");
                        }
                        
+                       yco-= ysize;
+                       break;
+               }
+       case SENS_ARMATURE:
+               {
+                       ysize= 70;
+                       
+                       glRects(xco, yco-ysize, xco+width, yco);
+                       uiEmboss((float)xco, (float)yco-ysize,
+                               (float)xco+width, (float)yco, 1);
+                       
+                       draw_default_sensor_header(sens, block, xco, yco, width);
+                       arm= sens->data;
+
+                       if (ob->type == OB_ARMATURE) {
+                               uiBlockBeginAlign(block);
+                               but = uiDefBut(block, TEX, 1, "Bone: ",
+                                               (xco+10), (yco-44), (width-20)/2, 19,
+                                               arm->posechannel, 0, 31, 0, 0,
+                                               "Bone on which you want to check a constraint");
+                               uiButSetFunc(but, check_armature_sensor, but, arm);
+                               but = uiDefBut(block, TEX, 1, "Cons: ",
+                                               (xco+10)+(width-20)/2, (yco-44), (width-20)/2, 19,
+                                               arm->constraint, 0, 31, 0, 0,
+                                               "Name of the constraint you want to control");
+                               uiButSetFunc(but, check_armature_sensor, but, arm);
+                               uiBlockEndAlign(block);
+
+                               str= "Type %t|State changed %x0|Lin error below %x1|Lin error above %x2|Rot error below %x3|Rot error above %x4"; 
+
+                               uiDefButI(block, MENU, B_REDR, str,                     xco+10,yco-66,0.4*(width-20), 19,
+                                       &arm->type, 0, 31, 0, 0, "Type");
+                       
+                               if (arm->type != SENS_ARM_STATE_CHANGED)
+                               {
+                                       uiDefButF(block, NUM, 1, "Value: ",             xco+10+0.4*(width-20),yco-66,0.6*(width-20), 19,
+                                       &arm->value, -10000.0, 10000.0, 100, 0, "Test the error against this value");
+                               }
+                       }
                        yco-= ysize;
                        break;
                }
@@ -1316,10 +1499,16 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
                        * proper compatibility with older .blend files. */
                        str= "Type %t|Left button %x1|Middle button %x2|"
                                "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16|Mouse over any%x32"; 
-                       uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, width-20, 19,
+                       uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, (width*0.8f)-20, 19,
                                &ms->type, 0, 31, 0, 0,
                                "Specify the type of event this mouse sensor should trigger on");
                        
+                       if(ms->type==32) {
+                               uiDefButBitS(block, TOG, SENS_MOUSE_FOCUS_PULSE, B_REDR, "Pulse",(short)(xco + 10) + (width*0.8f)-20,(short)(yco - 44),
+                                       (short)(0.20 * (width-20)), 19, &ms->flag, 0.0, 0.0, 0, 0,
+                                       "Moving the mouse over a different object generates a pulse");  
+                       }
+                       
                        yco-= ysize;
                        break;
                }
@@ -1549,7 +1738,7 @@ static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco
                uiBlockBeginAlign(block);
                uiDefButI(block, MENU, B_REDR, "Execution Method%t|Script%x0|Module%x1", xco+4,yco-23, 66, 19, &pc->mode, 0, 0, 0, 0, "Python script type (textblock or module - faster)");
                if(pc->mode==0)
-                       uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "", xco+70,yco-23,width-74, 19, &pc->text, "Blender textblock to run as a script");
+                       uiDefIDPoinBut(block, test_scriptpoin_but, ID_TXT, 1, "", xco+70,yco-23,width-74, 19, &pc->text, "Blender textblock to run as a script");
                else {
                        uiDefBut(block, TEX, 1, "", xco+70,yco-23,(width-70)-25, 19, pc->module, 0, 63, 0, 0, "Module name and function to run e.g. \"someModule.main\". Internal texts and external python files can be used");
                        uiDefButBitI(block, TOG, CONT_PY_DEBUG, B_REDR, "D", (xco+width)-25, yco-23, 19, 19, &pc->flag, 0, 0, 0, 0, "Continuously reload the module from disk for editing external modules without restarting");
@@ -1581,7 +1770,6 @@ static int get_col_actuator(int type)
        case ACT_IPO:                   return TH_PANEL;
        case ACT_PROPERTY:              return TH_PANEL;
        case ACT_SOUND:                 return TH_PANEL;
-       case ACT_CD:                    return TH_PANEL;
        case ACT_CAMERA:                return TH_PANEL;
        case ACT_EDIT_OBJECT:           return TH_PANEL;
        case ACT_GROUP:                 return TH_PANEL;
@@ -1592,6 +1780,7 @@ static int get_col_actuator(int type)
        case ACT_VISIBILITY:            return TH_PANEL;
        case ACT_CONSTRAINT:            return TH_PANEL;
        case ACT_STATE:                 return TH_PANEL;
+       case ACT_ARMATURE:                      return TH_PANEL;
        default:                                return TH_PANEL;
        }
 }
@@ -1662,7 +1851,8 @@ char *get_state_name(Object *ob, short bit)
 
 static void check_state_mask(bContext *C, void *arg1_but, void *arg2_mask)
 {
-       int shift= 0; // XXX
+       wmWindow *win= CTX_wm_window(C);
+       int shift= win->eventstate->shift;
        unsigned int *cont_mask = arg2_mask;
        uiBut *but = arg1_but;
 
@@ -1671,10 +1861,21 @@ static void check_state_mask(bContext *C, void *arg1_but, void *arg2_mask)
        but->retval = B_REDR;
 }
 
+static void check_armature_actuator(bContext *C, void *arg1_but, void *arg2_act)
+{
+       bArmatureActuator *act = arg2_act;
+       uiBut *but = arg1_but;
+       Object *ob= CTX_data_active_object(C);
+
+       /* check that bone exist in the active object */
+       but->retval = B_REDR;
+       check_armature_bone_constraint(ob, act->posechannel, act->constraint);
+}
+
+
 static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
 {
        bSoundActuator      *sa      = NULL;
-       bCDActuator                     *cda     = NULL;
        bObjectActuator     *oa      = NULL;
        bIpoActuator        *ia      = NULL;
        bPropertyActuator   *pa      = NULL;
@@ -1691,6 +1892,7 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
        bTwoDFilterActuator     *tdfa    = NULL;
        bParentActuator     *parAct  = NULL;
        bStateActuator          *staAct  = NULL;
+       bArmatureActuator   *armAct  = NULL;
        
        float *fp;
        short ysize = 0, wval;
@@ -1984,11 +2186,14 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
                }
     case ACT_SOUND:
                {
-                       ysize = 70;
-                       
                        sa = act->data;
                        sa->sndnr = 0;
                        
+                       if(sa->flag & ACT_SND_3D_SOUND)
+                               ysize = 180;
+                       else
+                               ysize = 92;
+
                        wval = (width-20)/2;
                        glRects(xco, yco-ysize, xco+width, yco);
                        uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
@@ -1998,57 +2203,35 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
                                /* reset this value, it is for handling the event */
                                sa->sndnr = 0;
                                uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
+                               uiDefButO(block, BUT, "sound.open", 0, "Load Sound", xco+wval+10, yco-22, wval, 19, "Load a sound file. Remember to set caching on for small sounds that are played often.");
 
                                if(sa->sound) {
                                        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";
-                                       uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
+                                       uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,wval-20,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
                                        uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
-                                       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");
-                                       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");
+                                       uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->volume, 0.0,  1.0, 0, 0, "Sets the volume of this sound");
+                                       uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound");
+                                       uiDefButS(block, TOG | BIT, 0, "3D Sound", xco+10, yco-88, width-20, 19, &sa->flag, 0.0, 1.0, 0.0, 0.0, "Plays the sound positioned in 3D space.");
+                                       if(sa->flag & ACT_SND_3D_SOUND)
+                                       {
+                                               uiDefButF(block, NUM, 0, "Minimum Gain: ", xco+10, yco-110, wval, 19, &sa->sound3D.min_gain, 0.0, 1.0, 0.0, 0.0, "The minimum gain of the sound, no matter how far it is away.");
+                                               uiDefButF(block, NUM, 0, "Maximum Gain: ", xco+10, yco-132, wval, 19, &sa->sound3D.max_gain, 0.0, 1.0, 0.0, 0.0, "The maximum gain of the sound, no matter how near it is..");
+                                               uiDefButF(block, NUM, 0, "Reference Distance: ", xco+10, yco-154, wval, 19, &sa->sound3D.reference_distance, 0.0, FLT_MAX, 0.0, 0.0, "The reference distance is the distance where the sound has a gain of 1.0.");
+                                               uiDefButF(block, NUM, 0, "Maximum Distance: ", xco+10, yco-176, wval, 19, &sa->sound3D.max_distance, 0.0, FLT_MAX, 0.0, 0.0, "The maximum distance at which you can hear the sound.");
+                                               uiDefButF(block, NUM, 0, "Rolloff: ", xco+wval+10, yco-110, wval, 19, &sa->sound3D.rolloff_factor, 0.0, 5.0, 0.0, 0.0, "The rolloff factor defines the influence factor on volume depending on distance.");
+                                               uiDefButF(block, NUM, 0, "Cone Outer Gain: ", xco+wval+10, yco-132, wval, 19, &sa->sound3D.cone_outer_gain, 0.0, 1.0, 0.0, 0.0, "The gain outside the outer cone. The gain in the outer cone will be interpolated between this value und the normal gain in the inner cone.");
+                                               uiDefButF(block, NUM, 0, "Cone Outer Angle: ", xco+wval+10, yco-154, wval, 19, &sa->sound3D.cone_outer_angle, 0.0, 360.0, 0.0, 0.0, "The angle of the outer cone.");
+                                               uiDefButF(block, NUM, 0, "Cone Inner Angle: ", xco+wval+10, yco-176, wval, 19, &sa->sound3D.cone_inner_angle, 0.0, 360.0, 0.0, 0.0, "The angle of the inner cone.");
+                                       }
                                }
                                MEM_freeN(str);
                        } 
                        else {
-                               uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
+                               uiDefButO(block, BUT, "sound.open", 0, "Load Sound", xco+10, yco-22, width-20, 19, "Load a sound file.");
                        }
                                        
                        yco-= ysize;
                        
-                       break;
-               }
-       case ACT_CD:
-               {
-                       char cd_type_str[] = "Sound mode %t|Play all tracks %x0|Play one track %x1|"
-                               "Volume %x3|Stop %x4|Pause %x5|Resume %x6";
-                       cda = act->data;
-
-                       if (cda) {
-                               if (cda->track == 0) {
-                                       cda->track = 1;
-                                       cda->volume = 1;
-                                       cda->type = ACT_CD_PLAY_ALL;
-                               }
-                               
-                               if (cda->type == ACT_CD_PLAY_TRACK || cda->type == ACT_CD_LOOP_TRACK) {
-                                       ysize = 48;
-                                       glRects(xco, yco-ysize, xco+width, yco);
-                                       uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
-                                       uiDefButS(block, NUM, 0, "Track:", xco+10,yco-44,width-20, 19, &cda->track, 1, 99, 0, 0, "Select the track to be played");
-                               }
-                               else if (cda->type == ACT_CD_VOLUME) {
-                                       ysize = 48;
-                                       glRects(xco, yco-ysize, xco+width, yco);
-                                       uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
-                                       uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-44,width-20, 19, &cda->volume, 0, 1, 0, 0, "Set the volume for CD playback");
-                               }
-                               else {
-                                       ysize = 28;
-                                       glRects(xco, yco-ysize, xco+width, yco);
-                                       uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
-                               }
-                               uiDefButS(block, MENU, B_REDR, cd_type_str,xco+10,yco-22,width-20, 19, &cda->type, 0.0, 0.0, 0, 0, "");
-                       }
-                       yco-= ysize;
                        break;
                }
        case ACT_CAMERA:
@@ -2134,7 +2317,10 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
                        glRects(xco, yco-ysize, xco+width, yco);
                        uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
         
-                       uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, 1, "ME:",               xco+40, yco-44, (width-80), 19, &(eoa->me), "replace the existing mesh with this one");
+                       uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, 1, "ME:",               xco+40, yco-44, (width-80)/2, 19, &(eoa->me), "replace the existing, when left blank 'Phys' will remake the existing physics mesh");
+                       
+                       uiDefButBitS(block, TOGN, ACT_EDOB_REPLACE_MESH_NOGFX, 0, "Gfx",        xco+40 + (width-80)/2, yco-44, (width-80)/4, 19, &eoa->flag, 0, 0, 0, 0, "Replace the display mesh");
+                       uiDefButBitS(block, TOG, ACT_EDOB_REPLACE_MESH_PHYS, 0, "Phys", xco+40 + (width-80)/2 +(width-80)/4, yco-44, (width-80)/4, 19, &eoa->flag, 0, 0, 0, 0, "Replace the physics mesh (triangle bounds only. compound shapes not supported)");
                }
                else if(eoa->type==ACT_EDOB_TRACK_TO) {
                        ysize= 48;
@@ -2734,6 +2920,48 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
 
                yco-= ysize; 
                break; 
+       case ACT_ARMATURE:
+               armAct = act->data; 
+
+               if (ob->type == OB_ARMATURE) {
+                       str= "Constraint %t|Run armature %x0|Enable %x1|Disable %x2|Set target %x3|Set weight %x4";
+                       uiDefButI(block, MENU, B_REDR, str,             xco+5, yco-24, (width-10)*0.35, 19, &armAct->type, 0.0, 0.0, 0, 0, ""); 
+
+                       switch (armAct->type) {
+                       case ACT_ARM_RUN:
+                               ysize = 28;
+                               break;
+                       default:
+                               uiBlockBeginAlign(block);
+                               but = uiDefBut(block, TEX, 1, "Bone: ",
+                                               (xco+5), (yco-44), (width-10)/2, 19,
+                                               armAct->posechannel, 0, 31, 0, 0,
+                                               "Bone on which the constraint is defined");
+                               uiButSetFunc(but, check_armature_actuator, but, armAct);
+                               but = uiDefBut(block, TEX, 1, "Cons: ",
+                                               (xco+5)+(width-10)/2, (yco-44), (width-10)/2, 19,
+                                               armAct->constraint, 0, 31, 0, 0,
+                                               "Name of the constraint you want to controle");
+                               uiButSetFunc(but, check_armature_actuator, but, armAct);
+                               uiBlockEndAlign(block);
+                               ysize = 48;
+                               switch (armAct->type) {
+                               case ACT_ARM_SETTARGET:
+                                       uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "Target: ",            xco+5, yco-64, (width-10), 19, &(armAct->target), "Set this object as the target of the constraint"); 
+                                       uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "Secondary Target: ",          xco+5, yco-84, (width-10), 19, &(armAct->subtarget), "Set this object as the secondary target of the constraint (only IK polar target at the moment)"); 
+                                       ysize += 40;
+                                       break;
+                               case ACT_ARM_SETWEIGHT:
+                                       uiDefButF(block, NUM, B_REDR, "Weight:", xco+5+(width-10)*0.35,yco-24,(width-10)*0.65,19,&armAct->weight,0.0,1.0,0.0,0.0,"Set weight of this constraint");
+                                       break;
+                               }
+                       }
+               }
+               glRects(xco, yco-ysize, xco+width, yco); 
+               uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
+               yco-= ysize; 
+               break; 
+
        default:
                ysize= 4;
 
@@ -2751,7 +2979,7 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
 
 static void do_sensor_menu(bContext *C, void *arg, int event)
 {      
-       SpaceLogic *slogic= (SpaceLogic *)CTX_wm_space_data(C);
+       SpaceLogic *slogic= CTX_wm_space_logic(C);
        ID **idar;
        Object *ob;
        bSensor *sens;
@@ -2800,7 +3028,7 @@ static uiBlock *sensor_menu(bContext *C, ARegion *ar, void *arg_unused)
 
 static void do_controller_menu(bContext *C, void *arg, int event)
 {      
-       SpaceLogic *slogic= (SpaceLogic *)CTX_wm_space_data(C);
+       SpaceLogic *slogic= CTX_wm_space_logic(C);
        ID **idar;
        Object *ob;
        bController *cont;
@@ -2849,7 +3077,7 @@ static uiBlock *controller_menu(bContext *C, ARegion *ar, void *arg_unused)
 
 static void do_actuator_menu(bContext *C, void *arg, int event)
 {      
-       SpaceLogic *slogic= (SpaceLogic *)CTX_wm_space_data(C);
+       SpaceLogic *slogic= CTX_wm_space_logic(C);
        ID **idar;
        Object *ob;
        bActuator *act;
@@ -3011,7 +3239,7 @@ static int is_sensor_linked(uiBlock *block, bSensor *sens)
 
 void logic_buttons(bContext *C, ARegion *ar)
 {
-       SpaceLogic *slogic= (SpaceLogic *)CTX_wm_space_data(C);
+       SpaceLogic *slogic= CTX_wm_space_logic(C);
        Object *ob= CTX_data_active_object(C);
        ID **idar;
        bSensor *sens;
@@ -3054,7 +3282,7 @@ void logic_buttons(bContext *C, ARegion *ar)
                
        /* start with the controller because we need to know which one is visible */
        /* ******************************* */
-       xco= 500; yco= 170; width= 300;
+       xco= 400; yco= 170; width= 300;
 
        uiDefBlockBut(block, controller_menu, NULL, "Controllers", xco-10, yco+35, 100, UI_UNIT_Y, "");
        
@@ -3163,9 +3391,17 @@ void logic_buttons(bContext *C, ARegion *ar)
                                                        cpack(0x999999);
                                                        glRecti(xco+22, yco, xco+width-22,yco+19);
                                                        but= uiDefBut(block, LABEL, 0, controller_name(cont->type), (short)(xco+22), yco, 70, UI_UNIT_Y, cont, 0, 0, 0, 0, "Controller type");
-                                                       uiButSetFunc(but, sca_move_controller, cont, NULL);
+                                                       //uiButSetFunc(but, sca_move_controller, cont, NULL);
                                                        but= uiDefBut(block, LABEL, 0, cont->name,(short)(xco+92), yco,(short)(width-158), UI_UNIT_Y, cont, 0, 0, 0, 0, "Controller name");
-                                                       uiButSetFunc(but, sca_move_controller, cont, NULL);
+                                                       //uiButSetFunc(but, sca_move_controller, cont, NULL);
+
+                                                       uiBlockBeginAlign(block);
+                                                       but= uiDefIconBut(block, BUT, B_REDR, VICON_MOVE_UP, (short)(xco+width-(110+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
+                                                       uiButSetFunc(but, sca_move_controller, cont, (void *)TRUE);
+                                                       but= uiDefIconBut(block, BUT, B_REDR, VICON_MOVE_DOWN, (short)(xco+width-(88+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
+                                                       uiButSetFunc(but, sca_move_controller, cont, (void *)FALSE);
+                                                       uiBlockEndAlign(block);
+
                                                        ycoo= yco;
                                                }
                                
@@ -3186,7 +3422,7 @@ void logic_buttons(bContext *C, ARegion *ar)
        }
        
        /* ******************************* */
-       xco= 10; yco= 170; width= 400;
+       xco= 10; yco= 170; width= 300;
 
        uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco+35, 70, UI_UNIT_Y, "");
        
@@ -3240,16 +3476,23 @@ void logic_buttons(bContext *C, ARegion *ar)
                                                uiButSetFunc(but, make_unique_prop_names_cb, sens->name, (void*) 0);
 
                                                sens->otype= sens->type;
-                                               yco= draw_sensorbuttons(sens, block, xco, yco, width,ob->id.name);
+                                               yco= draw_sensorbuttons(ob, sens, block, xco, yco, width,ob->id.name);
                                                if(yco-6 < ycoo) ycoo= (yco+ycoo-20)/2;
                                        }
                                        else {
                                                set_col_sensor(sens->type, 1);
                                                glRecti(xco+22, yco, xco+width-22,yco+19);
                                                but= uiDefBut(block, LABEL, 0, sensor_name(sens->type), (short)(xco+22), yco, 80, UI_UNIT_Y, sens, 0, 0, 0, 0, "");
-                                               uiButSetFunc(but, sca_move_sensor, sens, NULL);
+                                               //uiButSetFunc(but, sca_move_sensor, sens, NULL);
                                                but= uiDefBut(block, LABEL, 0, sens->name, (short)(xco+102), yco, (short)(width-(pin?146:124)), UI_UNIT_Y, sens, 0, 31, 0, 0, "");
-                                               uiButSetFunc(but, sca_move_sensor, sens, NULL);
+                                               //uiButSetFunc(but, sca_move_sensor, sens, NULL);
+
+                                               uiBlockBeginAlign(block);
+                                               but= uiDefIconBut(block, BUT, B_REDR, VICON_MOVE_UP, (short)(xco+width-(66+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
+                                               uiButSetFunc(but, sca_move_sensor, sens, (void *)TRUE);
+                                               but= uiDefIconBut(block, BUT, B_REDR, VICON_MOVE_DOWN, (short)(xco+width-(44+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
+                                               uiButSetFunc(but, sca_move_sensor, sens, (void *)FALSE);
+                                               uiBlockEndAlign(block);
                                        }
 
                                        but= uiDefIconBut(block, LINK, 0, ICON_LINK,    (short)(xco+width), ycoo, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
@@ -3264,7 +3507,7 @@ void logic_buttons(bContext *C, ARegion *ar)
        }
 
        /* ******************************* */
-       xco= 900; yco= 170; width= 400;
+       xco= 800; yco= 170; width= 300;
        
        uiDefBlockBut(block, actuator_menu, NULL, "Actuators", xco-10, yco+35, 90, UI_UNIT_Y, "");
 
@@ -3320,9 +3563,17 @@ void logic_buttons(bContext *C, ARegion *ar)
                                                set_col_actuator(act->type, 1);
                                                glRecti((short)(xco+22), yco, (short)(xco+width-22),(short)(yco+19));
                                                but= uiDefBut(block, LABEL, 0, actuator_name(act->type), (short)(xco+22), yco, 90, UI_UNIT_Y, act, 0, 0, 0, 0, "Actuator type");
-                                               uiButSetFunc(but, sca_move_actuator, act, NULL);
+                                               // uiButSetFunc(but, sca_move_actuator, act, NULL);
                                                but= uiDefBut(block, LABEL, 0, act->name, (short)(xco+112), yco, (short)(width-(pin?156:134)), UI_UNIT_Y, act, 0, 0, 0, 0, "Actuator name");
-                                               uiButSetFunc(but, sca_move_actuator, act, NULL);
+                                               // uiButSetFunc(but, sca_move_actuator, act, NULL);
+
+                                               uiBlockBeginAlign(block);
+                                               but= uiDefIconBut(block, BUT, B_REDR, VICON_MOVE_UP, (short)(xco+width-(66+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
+                                               uiButSetFunc(but, sca_move_actuator, act, (void *)TRUE);
+                                               but= uiDefIconBut(block, BUT, B_REDR, VICON_MOVE_DOWN, (short)(xco+width-(44+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
+                                               uiButSetFunc(but, sca_move_actuator, act, (void *)FALSE);
+                                               uiBlockEndAlign(block);
+
                                                ycoo= yco;
                                        }