Canvas: Fix handling drag events and some cleanup.

This commit is contained in:
Thomas Geymayer 2012-12-07 18:34:43 +01:00
parent fc49be1e05
commit 4dfe36cdc1
2 changed files with 57 additions and 11 deletions

View File

@ -28,6 +28,38 @@ namespace canvas
const unsigned int drag_threshold = 8; const unsigned int drag_threshold = 8;
const double multi_click_timeout = 0.4; const double multi_click_timeout = 0.4;
//----------------------------------------------------------------------------
EventManager::StampedPropagationPath::StampedPropagationPath():
time(0)
{
}
//----------------------------------------------------------------------------
EventManager::StampedPropagationPath::StampedPropagationPath(
const EventPropagationPath& path,
double time
):
path(path),
time(time)
{
}
//----------------------------------------------------------------------------
void EventManager::StampedPropagationPath::clear()
{
path.clear();
time = 0;
}
//----------------------------------------------------------------------------
bool EventManager::StampedPropagationPath::valid() const
{
return !path.empty() && time > 0;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
EventManager::EventManager(): EventManager::EventManager():
_current_click_count(0) _current_click_count(0)
@ -39,7 +71,6 @@ namespace canvas
bool EventManager::handleEvent( const MouseEventPtr& event, bool EventManager::handleEvent( const MouseEventPtr& event,
const EventPropagationPath& path ) const EventPropagationPath& path )
{ {
propagateEvent(event, path);
switch( event->type ) switch( event->type )
{ {
case Event::MOUSE_DOWN: case Event::MOUSE_DOWN:
@ -51,16 +82,30 @@ namespace canvas
// Ignore mouse up without any previous mouse down // Ignore mouse up without any previous mouse down
return false; return false;
// normal mouseup
propagateEvent(event, path);
// now handle click/dblclick
if( checkClickDistance(path, _last_mouse_down.path) ) if( checkClickDistance(path, _last_mouse_down.path) )
handleClick(event, getCommonAncestor(_last_mouse_down.path, path)); handleClick(event, getCommonAncestor(_last_mouse_down.path, path));
break; _last_mouse_down.clear();
return true;
} }
case Event::DRAG:
if( !_last_mouse_down.valid() )
return false;
else
return propagateEvent(event, _last_mouse_down.path);
case Event::WHEEL:
case Event::MOUSE_MOVE:
break;
default: default:
return false; return false;
} }
return true; return propagateEvent(event, path);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -135,8 +180,12 @@ namespace canvas
// (eg. removed by another event handler) // (eg. removed by another event handler)
continue; continue;
if( mouse_event ) if( mouse_event && event->type != Event::DRAG )
{ {
// TODO transform pos and delta for drag events. Maybe we should just
// store the global coordinates and convert to local coordinates
// on demand.
// Position and delta are specified in local coordinate system of // Position and delta are specified in local coordinate system of
// current element // current element
mouse_event->pos = it->local_pos; mouse_event->pos = it->local_pos;

View File

@ -46,14 +46,11 @@ namespace canvas
protected: protected:
struct StampedPropagationPath struct StampedPropagationPath
{ {
StampedPropagationPath(): StampedPropagationPath();
time(0) StampedPropagationPath(const EventPropagationPath& path, double time);
{}
StampedPropagationPath(const EventPropagationPath& path, double time): void clear();
path(path), bool valid() const;
time(time)
{}
EventPropagationPath path; EventPropagationPath path;
double time; double time;