This commit is contained in:
Campbell Barton 2009-08-23 07:46:34 +00:00
commit 01d4748e5f
6 changed files with 32 additions and 5 deletions

@ -1314,10 +1314,16 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
* proper compatibility with older .blend files. */ * proper compatibility with older .blend files. */
str= "Type %t|Left button %x1|Middle button %x2|" 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"; "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, &ms->type, 0, 31, 0, 0,
"Specify the type of event this mouse sensor should trigger on"); "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; yco-= ysize;
break; break;
} }

@ -178,6 +178,9 @@ typedef struct bJoystickSensor {
/* bMouseSensor->type: uses blender event defines */ /* bMouseSensor->type: uses blender event defines */
/* bMouseSensor->flag: only pulse for now */
#define SENS_MOUSE_FOCUS_PULSE 1
/* propertysensor->type */ /* propertysensor->type */
#define SENS_PROP_EQUAL 0 #define SENS_PROP_EQUAL 0
#define SENS_PROP_NEQUAL 1 #define SENS_PROP_NEQUAL 1

@ -536,6 +536,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
starty, starty,
keytype, keytype,
trackfocus, trackfocus,
(bmouse->flag & SENS_MOUSE_FOCUS_PULSE) ? true:false,
kxscene, kxscene,
kxengine, kxengine,
gameobj); gameobj);

@ -61,11 +61,13 @@ KX_MouseFocusSensor::KX_MouseFocusSensor(SCA_MouseManager* eventmgr,
int starty, int starty,
short int mousemode, short int mousemode,
int focusmode, int focusmode,
bool bTouchPulse,
KX_Scene* kxscene, KX_Scene* kxscene,
KX_KetsjiEngine *kxengine, KX_KetsjiEngine *kxengine,
SCA_IObject* gameobj) SCA_IObject* gameobj)
: SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj), : SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj),
m_focusmode(focusmode), m_focusmode(focusmode),
m_bTouchPulse(bTouchPulse),
m_kxscene(kxscene), m_kxscene(kxscene),
m_kxengine(kxengine) m_kxengine(kxengine)
{ {
@ -77,6 +79,7 @@ void KX_MouseFocusSensor::Init()
m_mouse_over_in_previous_frame = (m_invert)?true:false; m_mouse_over_in_previous_frame = (m_invert)?true:false;
m_positive_event = false; m_positive_event = false;
m_hitObject = 0; m_hitObject = 0;
m_hitObject_Last = NULL;
m_reset = true; m_reset = true;
m_hitPosition.setValue(0,0,0); m_hitPosition.setValue(0,0,0);
@ -107,7 +110,10 @@ bool KX_MouseFocusSensor::Evaluate()
m_positive_event = true; m_positive_event = true;
if (!m_mouse_over_in_previous_frame) { if (!m_mouse_over_in_previous_frame) {
result = true; result = true;
} }
else if(m_bTouchPulse && (m_hitObject != m_hitObject_Last)) {
result = true;
}
} }
if (reset) { if (reset) {
// force an event // force an event
@ -123,7 +129,8 @@ bool KX_MouseFocusSensor::Evaluate()
} }
m_mouse_over_in_previous_frame = obHasFocus; m_mouse_over_in_previous_frame = obHasFocus;
m_hitObject_Last = (void *)m_hitObject;
return result; return result;
} }
@ -378,6 +385,7 @@ PyAttributeDef KX_MouseFocusSensor::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_MouseFocusSensor, pyattr_get_hit_object), 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("hitPosition", KX_MouseFocusSensor, pyattr_get_hit_position),
KX_PYATTRIBUTE_RO_FUNCTION("hitNormal", KX_MouseFocusSensor, pyattr_get_hit_normal), KX_PYATTRIBUTE_RO_FUNCTION("hitNormal", KX_MouseFocusSensor, pyattr_get_hit_normal),
KX_PYATTRIBUTE_BOOL_RW("usePulseFocus", KX_MouseFocusSensor,m_bTouchPulse),
{ NULL } //Sentinel { NULL } //Sentinel
}; };

@ -49,11 +49,12 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
public: public:
KX_MouseFocusSensor(class SCA_MouseManager* keybdmgr, KX_MouseFocusSensor(class SCA_MouseManager* eventmgr,
int startx, int startx,
int starty, int starty,
short int mousemode, short int mousemode,
int focusmode, int focusmode,
bool bTouchPulse,
KX_Scene* kxscene, KX_Scene* kxscene,
KX_KetsjiEngine* kxengine, KX_KetsjiEngine* kxengine,
SCA_IObject* gameobj); SCA_IObject* gameobj);
@ -107,6 +108,7 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
SCA_IObject* m_hitObject; SCA_IObject* m_hitObject;
void* m_hitObject_Last; /* only use for comparison, never access */
private: private:
/** /**
@ -119,6 +121,11 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
*/ */
bool m_mouse_over_in_previous_frame; 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. * Flags whether the previous test evaluated positive.
*/ */

@ -2419,6 +2419,8 @@ class KX_MouseFocusSensor(SCA_MouseSensor):
@type hitPosition: list (vector of 3 floats) @type hitPosition: list (vector of 3 floats)
@ivar hitNormal: the worldspace normal from the face at point of intersection. @ivar hitNormal: the worldspace normal from the face at point of intersection.
@type hitNormal: list (normalized vector of 3 floats) @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 #{ Deprecated
def getHitNormal(): def getHitNormal():
@ -2480,7 +2482,7 @@ class KX_TouchSensor(SCA_ISensor):
@ivar useMaterial: Determines if the sensor is looking for a property or material. @ivar useMaterial: Determines if the sensor is looking for a property or material.
KX_True = Find material; KX_False = Find property KX_True = Find material; KX_False = Find property
@type useMaterial: boolean @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 @type usePulseCollision: bool
@ivar hitObject: The last collided object. (read-only) @ivar hitObject: The last collided object. (read-only)
@type hitObject: L{KX_GameObject} or None @type hitObject: L{KX_GameObject} or None