diff options
author | jmarshallnz <jmarshallnz@svn> | 2010-01-09 09:05:41 +0000 |
---|---|---|
committer | jmarshallnz <jmarshallnz@svn> | 2010-01-09 09:05:41 +0000 |
commit | 8bd9964d8a756ac92149efe980e2616f8f2e5c4a (patch) | |
tree | 3e09129bec0c4c533d7d5fd1592faceca358dbb8 /guilib/GUIControlGroupList.cpp | |
parent | f2508d4a464540428c7c0f293b356b5a5d1003b4 (diff) |
changed: Improved mouse event handling - we now pass events down through the control structure, giving better context for the performed event. Allows groups to react if their children don't.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@26577 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'guilib/GUIControlGroupList.cpp')
-rw-r--r-- | guilib/GUIControlGroupList.cpp | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/guilib/GUIControlGroupList.cpp b/guilib/GUIControlGroupList.cpp index 4670af2afc..ce5bd2f651 100644 --- a/guilib/GUIControlGroupList.cpp +++ b/guilib/GUIControlGroupList.cpp @@ -311,31 +311,39 @@ void CGUIControlGroupList::ScrollTo(float offset) m_scrollSpeed = (m_scrollOffset - m_offset) / m_scrollTime; } -void CGUIControlGroupList::GetControlsFromPoint(const CPoint &point, std::vector< std::pair<CGUIControl *, CPoint> > &controls) const +bool CGUIControlGroupList::SendMouseEvent(const CPoint &point, const CMouseEvent &event) { - if (!CGUIControl::CanFocus()) return; - float pos = 0; - CPoint controlCoords(point); - m_transform.InverseTransformPosition(controlCoords.x, controlCoords.y); - float alignOffset = GetAlignOffset(); - for (ciControls it = m_children.begin(); it != m_children.end(); ++it) + // transform our position into child coordinates + CPoint childPoint(point); + m_transform.InverseTransformPosition(childPoint.x, childPoint.y); + if (CanFocus()) { - CGUIControl *child = *it; - if (child->IsVisible()) + // run through our controls in reverse order (so that last rendered is checked first) + float pos = 0; + float alignOffset = GetAlignOffset(); + for (ciControls i = m_children.begin(); i != m_children.end(); ++i) { - if (pos + Size(child) > m_offset && pos < m_offset + Size()) - { // we're on screen - float offsetX = m_orientation == VERTICAL ? m_posX : m_posX + alignOffset + pos - m_offset; - float offsetY = m_orientation == VERTICAL ? m_posY + alignOffset + pos - m_offset : m_posY; - CPoint childCoords; - if (child->IsGroup()) - ((CGUIControlGroup *)child)->GetControlsFromPoint(controlCoords - CPoint(offsetX, offsetY), controls); - else if (child->CanFocusFromPoint(controlCoords - CPoint(offsetX, offsetY), childCoords)) - controls.push_back(std::make_pair(child, childCoords)); + CGUIControl *child = *i; + if (child->IsVisible()) + { + if (pos + Size(child) > m_offset && pos < m_offset + Size()) + { // we're on screen + float offsetX = m_orientation == VERTICAL ? m_posX : m_posX + alignOffset + pos - m_offset; + float offsetY = m_orientation == VERTICAL ? m_posY + alignOffset + pos - m_offset : m_posY; + if (child->SendMouseEvent(childPoint - CPoint(offsetX, offsetY), event)) + { // we've handled the action, and/or have focused an item + return true; + } + } + pos += Size(child) + m_itemGap; } - pos += Size(child) + m_itemGap; } } + // if we get here we none of our children want the event, but we may want it. + if (HitTest(point) && OnMouseEvent(point, event)) + return true; + m_focusedControl = 0; + return false; } void CGUIControlGroupList::UnfocusFromPoint(const CPoint &point) |