diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-08-23 10:17:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-08-23 10:17:59 +0400 |
commit | 4a4a3b4989355c699b72a8dc15df09fd47621528 (patch) | |
tree | ab9da790f9950f557862b413065a9a9f95e26f6d /source/gameengine/Ketsji | |
parent | f08a4c9719ac3d745dfcbae3acc3ca48c38777ad (diff) |
Option for MouseFocus sensor. only used when 'Mouse over any' type is set.
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.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 12 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_MouseFocusSensor.h | 9 |
2 files changed, 18 insertions, 3 deletions
diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index fde10a493db..1880fcfb6f0 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -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 }; diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.h b/source/gameengine/Ketsji/KX_MouseFocusSensor.h index 29d674eb305..e1f8d9246e3 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.h +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.h @@ -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: /** @@ -123,6 +125,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. */ bool m_positive_event; |