Canvas: create mouseover/mouseout events
This commit is contained in:
@@ -98,8 +98,14 @@ namespace canvas
|
|||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return propagateEvent(event, _last_mouse_down.path);
|
return propagateEvent(event, _last_mouse_down.path);
|
||||||
case Event::WHEEL:
|
|
||||||
case Event::MOUSE_MOVE:
|
case Event::MOUSE_MOVE:
|
||||||
|
handleMove(event, path);
|
||||||
|
break;
|
||||||
|
case Event::MOUSE_LEAVE:
|
||||||
|
// Mouse leaves window and therefore also current mouseover element
|
||||||
|
handleMove(event, EventPropagationPath());
|
||||||
|
return true;
|
||||||
|
case Event::WHEEL:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@@ -147,6 +153,30 @@ namespace canvas
|
|||||||
_last_click = StampedPropagationPath(path, event->getTime());
|
_last_click = StampedPropagationPath(path, event->getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void EventManager::handleMove( const MouseEventPtr& event,
|
||||||
|
const EventPropagationPath& path )
|
||||||
|
{
|
||||||
|
if( _last_mouse_over.path == path )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( !_last_mouse_over.path.empty() )
|
||||||
|
{
|
||||||
|
MouseEventPtr mouseout(new MouseEvent(*event));
|
||||||
|
mouseout->type = Event::MOUSE_OUT;
|
||||||
|
propagateEvent(mouseout, _last_mouse_over.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !path.empty() )
|
||||||
|
{
|
||||||
|
MouseEventPtr mouseover(new MouseEvent(*event));
|
||||||
|
mouseover->type = Event::MOUSE_OVER;
|
||||||
|
propagateEvent(mouseover, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
_last_mouse_over.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
bool EventManager::propagateEvent( const EventPtr& event,
|
bool EventManager::propagateEvent( const EventPtr& event,
|
||||||
const EventPropagationPath& path )
|
const EventPropagationPath& path )
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ namespace canvas
|
|||||||
local_delta;
|
local_delta;
|
||||||
};
|
};
|
||||||
typedef std::deque<EventTarget> EventPropagationPath;
|
typedef std::deque<EventTarget> EventPropagationPath;
|
||||||
|
inline bool operator==(const EventTarget& t1, const EventTarget& t2)
|
||||||
|
{
|
||||||
|
return t1.element.lock() == t2.element.lock();
|
||||||
|
}
|
||||||
|
|
||||||
class EventManager
|
class EventManager
|
||||||
{
|
{
|
||||||
@@ -59,7 +63,8 @@ namespace canvas
|
|||||||
// TODO if we really need the paths modify to not copy around the paths
|
// TODO if we really need the paths modify to not copy around the paths
|
||||||
// that much.
|
// that much.
|
||||||
StampedPropagationPath _last_mouse_down,
|
StampedPropagationPath _last_mouse_down,
|
||||||
_last_click;
|
_last_click,
|
||||||
|
_last_mouse_over;
|
||||||
size_t _current_click_count;
|
size_t _current_click_count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,6 +73,12 @@ namespace canvas
|
|||||||
void handleClick( const MouseEventPtr& event,
|
void handleClick( const MouseEventPtr& event,
|
||||||
const EventPropagationPath& path );
|
const EventPropagationPath& path );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle mouseover/enter/out/leave
|
||||||
|
*/
|
||||||
|
void handleMove( const MouseEventPtr& event,
|
||||||
|
const EventPropagationPath& path );
|
||||||
|
|
||||||
bool propagateEvent( const EventPtr& event,
|
bool propagateEvent( const EventPtr& event,
|
||||||
const EventPropagationPath& path );
|
const EventPropagationPath& path );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user