Option for MouseFocus sensor. only used when 'Mouse over any' type is set.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 23 Aug 2009 06:17:59 +0000 (06:17 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 23 Aug 2009 06:17:59 +0000 (06:17 +0000)
Previously the only way to detect if the mouse moved over a different object was to enable true-level-triggering and have a python script detect the change.

When the Pulse option is set, focusing on a different object pulses true.
Python attribute is focusSensor.usePulseFocus.

This is similar to the collision sensors pulse option where changes in the set of collision objects generates an event too.

Found this functionality missing when trying to make a logic demo that used mouse-over with overlapping objects.

source/blender/makesdna/DNA_sensor_types.h
source/blender/src/buttons_logic.c
source/gameengine/Converter/KX_ConvertSensors.cpp
source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
source/gameengine/Ketsji/KX_MouseFocusSensor.h
source/gameengine/PyDoc/GameTypes.py

index 8b29ce1338dd3a1a83bbca906c9a2fd27673ee88..cc998de7eecf18118e365db62171bb6375688273 100644 (file)
@@ -178,6 +178,9 @@ typedef struct bJoystickSensor {
 
 /* bMouseSensor->type: uses blender event defines */
 
+/* bMouseSensor->flag: only pulse for now */
+#define SENS_MOUSE_FOCUS_PULSE 1
+
 /* propertysensor->type */
 #define SENS_PROP_EQUAL                0
 #define SENS_PROP_NEQUAL       1
index a57bcf5d7dfe2c2ac59d43b9886229448ab184df..0412aa72b37f5391b6dc82a636eb0a94e57eb576 100644 (file)
@@ -1367,10 +1367,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;
                }
index 31a3cfbd1acde1cfce14dc6489d3a53e5e2ed815..a628881058a3cc9b0cfe6c390da2c24addf478cb 100644 (file)
@@ -522,6 +522,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                                        starty,
                                                        keytype,
                                                        trackfocus,
+                                                       (bmouse->flag & SENS_MOUSE_FOCUS_PULSE) ? true:false,
                                                        kxscene,
                                                        kxengine,
                                                        gameobj); 
index fde10a493db073e79a0f73d2dc35fc9091782593..1880fcfb6f0aba104bdc12e43d4e0950bcb88c80 100644 (file)
@@ -61,12 +61,14 @@ KX_MouseFocusSensor::KX_MouseFocusSensor(SCA_MouseManager* eventmgr,
                                                                                 int starty,
                                                                                 short int mousemode,
                                                                                 int focusmode,
+                                                                                bool bTouchPulse,
                                                                                 KX_Scene* kxscene,
                                                                                 KX_KetsjiEngine *kxengine,
                                                                                 SCA_IObject* gameobj, 
                                                                                 PyTypeObject* T)
     : SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj, T),
          m_focusmode(focusmode),
+         m_bTouchPulse(bTouchPulse),
          m_kxscene(kxscene),
          m_kxengine(kxengine)
 {
@@ -78,6 +80,7 @@ void KX_MouseFocusSensor::Init()
        m_mouse_over_in_previous_frame = (m_invert)?true:false;
        m_positive_event = false;
        m_hitObject = 0;
+       m_hitObject_Last = NULL;
        m_reset = true;
        
        m_hitPosition.setValue(0,0,0);
@@ -108,7 +111,10 @@ bool KX_MouseFocusSensor::Evaluate()
                        m_positive_event = true;
                        if (!m_mouse_over_in_previous_frame) {
                                result = true;
-                       } 
+                       }
+                       else if(m_bTouchPulse && (m_hitObject != m_hitObject_Last)) {
+                               result = true;
+                       }
                } 
                if (reset) {
                        // force an event 
@@ -124,7 +130,8 @@ bool KX_MouseFocusSensor::Evaluate()
        }
 
        m_mouse_over_in_previous_frame = obHasFocus;
-
+       m_hitObject_Last = (void *)m_hitObject;
+                                          
        return result;
 }
 
@@ -390,6 +397,7 @@ PyAttributeDef KX_MouseFocusSensor::Attributes[] = {
        KX_PYATTRIBUTE_RO_FUNCTION("hitObject",         KX_MouseFocusSensor, pyattr_get_hit_object),
        KX_PYATTRIBUTE_RO_FUNCTION("hitPosition",       KX_MouseFocusSensor, pyattr_get_hit_position),
        KX_PYATTRIBUTE_RO_FUNCTION("hitNormal",         KX_MouseFocusSensor, pyattr_get_hit_normal),
+       KX_PYATTRIBUTE_BOOL_RW("usePulseFocus", KX_MouseFocusSensor,m_bTouchPulse),
        { NULL }        //Sentinel
 };
 
index 29d674eb30527875f5186d9fc516390c6335f1af..e1f8d9246e318bf2448b027c6c78949cd148b3b7 100644 (file)
@@ -49,11 +49,12 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
        
  public:
        
-       KX_MouseFocusSensor(class SCA_MouseManager* keybdmgr,
+       KX_MouseFocusSensor(class SCA_MouseManager* eventmgr,
                                                int startx,
                                                int starty,
                                                short int mousemode,
                                                int focusmode,
+                                               bool bTouchPulse,
                                                KX_Scene* kxscene,
                                                KX_KetsjiEngine* kxengine,
                                                SCA_IObject* gameobj,
@@ -110,6 +111,7 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
                
        /* --------------------------------------------------------------------- */
        SCA_IObject*    m_hitObject;
+       void*                   m_hitObject_Last; /* only use for comparison, never access */
 
  private:
        /**
@@ -122,6 +124,11 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
         */
        bool m_mouse_over_in_previous_frame;
 
+       /**
+        * Flags whether changes in hit object should trigger a pulse
+        */
+       bool m_bTouchPulse;
+       
        /**
         * Flags whether the previous test evaluated positive.
         */
index b1d1ce711732dd96972050e3c4601841d1fadb87..71a0c8c1a47e3be0cc66222ce7fe76e24331d31a 100644 (file)
@@ -2472,6 +2472,8 @@ class KX_MouseFocusSensor(SCA_MouseSensor):
        @type hitPosition: list (vector of 3 floats)
        @ivar hitNormal: the worldspace normal from the face at point of intersection.
        @type hitNormal: list (normalized vector of 3 floats)
+       @ivar usePulseFocus: When enabled, moving the mouse over a different object generates a pulse. (only used when the 'Mouse Over Any' sensor option is set)
+       @type usePulseFocus: bool
        """
 #{ Deprecated
        def getHitNormal():
@@ -2533,7 +2535,7 @@ class KX_TouchSensor(SCA_ISensor):
        @ivar useMaterial: Determines if the sensor is looking for a property or material.
                                                KX_True = Find material; KX_False = Find property
        @type useMaterial: boolean
-       @ivar usePulseCollision: The last collided object.
+       @ivar usePulseCollision: When enabled, changes to the set of colliding objects generate a pulse.
        @type usePulseCollision: bool
        @ivar hitObject: The last collided object. (read-only)
        @type hitObject: L{KX_GameObject} or None