diff options
author | jmarshallnz <jmarshallnz@svn> | 2010-03-25 02:10:38 +0000 |
---|---|---|
committer | jmarshallnz <jmarshallnz@svn> | 2010-03-25 02:10:38 +0000 |
commit | 16c2e44f08ff8d28be65033aaf84ce31f3bfe659 (patch) | |
tree | 967a38edcc51661f7f4a691f9d724c9b940c7ba9 /guilib | |
parent | 44a3d70de84e60ed25c6c15258d01324cfe3377d (diff) |
added: initial gesture support to guilib.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@28797 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'guilib')
-rw-r--r-- | guilib/GUIBaseContainer.cpp | 35 | ||||
-rw-r--r-- | guilib/GUIControl.h | 6 | ||||
-rw-r--r-- | guilib/GUIMessage.h | 5 | ||||
-rw-r--r-- | guilib/GUIWindow.cpp | 9 | ||||
-rw-r--r-- | guilib/Key.h | 9 |
5 files changed, 62 insertions, 2 deletions
diff --git a/guilib/GUIBaseContainer.cpp b/guilib/GUIBaseContainer.cpp index 6d36c77c89..475a9d6589 100644 --- a/guilib/GUIBaseContainer.cpp +++ b/guilib/GUIBaseContainer.cpp @@ -31,6 +31,7 @@ #include "StringUtils.h" #include "GUIStaticItem.h" #include "Key.h" +#include "MathUtils.h" using namespace std; @@ -562,6 +563,40 @@ EVENT_RESULT CGUIBaseContainer::OnMouseEvent(const CPoint &point, const CMouseEv Scroll(1); return EVENT_RESULT_HANDLED; } + else if (event.m_id == ACTION_GESTURE_NOTIFY) + { + return (m_orientation == HORIZONTAL) ? EVENT_RESULT_PAN_HORIZONTAL : EVENT_RESULT_PAN_VERTICAL; + } + else if (event.m_id == ACTION_GESTURE_BEGIN) + { // grab exclusive access + CGUIMessage msg(GUI_MSG_EXCLUSIVE_MOUSE, GetID(), GetParentID()); + SendWindowMessage(msg); + return EVENT_RESULT_HANDLED; + } + else if (event.m_id == ACTION_GESTURE_PAN) + { // do the drag and validate our offset (corrects for end of scroll) + m_scrollOffset -= (m_orientation == HORIZONTAL) ? event.m_offsetX : event.m_offsetY; + float size = (m_layout) ? m_layout->Size(m_orientation) : 10.0f; + int offset = (int)MathUtils::round_int(m_scrollOffset / size); + m_offset = offset; + ValidateOffset(); + return EVENT_RESULT_HANDLED; + } + else if (event.m_id == ACTION_GESTURE_END) + { // release exclusive access + CGUIMessage msg(GUI_MSG_EXCLUSIVE_MOUSE, 0, GetParentID()); + SendWindowMessage(msg); + // and compute the nearest offset from this and scroll there + float size = (m_layout) ? m_layout->Size(m_orientation) : 10.0f; + float offset = m_scrollOffset / size; + int toOffset = (int)MathUtils::round_int(offset); + if (toOffset < offset) + m_offset = toOffset+1; + else + m_offset = toOffset-1; + ScrollToOffset(toOffset); + return EVENT_RESULT_HANDLED; + } return EVENT_RESULT_UNHANDLED; } diff --git a/guilib/GUIControl.h b/guilib/GUIControl.h index ea4be50318..ad80a04c4e 100644 --- a/guilib/GUIControl.h +++ b/guilib/GUIControl.h @@ -57,7 +57,11 @@ public: Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was handled. */ enum EVENT_RESULT { EVENT_RESULT_UNHANDLED = 0, - EVENT_RESULT_HANDLED }; + EVENT_RESULT_HANDLED, + EVENT_RESULT_PAN_HORIZONTAL, + EVENT_RESULT_PAN_VERTICAL, + EVENT_RESULT_ROTATE, + EVENT_RESULT_ZOOM }; /*! \ingroup controls diff --git a/guilib/GUIMessage.h b/guilib/GUIMessage.h index 395f868584..0a76f33a58 100644 --- a/guilib/GUIMessage.h +++ b/guilib/GUIMessage.h @@ -112,6 +112,11 @@ */ #define GUI_MSG_EXCLUSIVE_MOUSE 37 +/*! + \brief A request for supported gestures is made + */ +#define GUI_MSG_GESTURE_NOTIFY 38 + #define GUI_MSG_USER 1000 /*! diff --git a/guilib/GUIWindow.cpp b/guilib/GUIWindow.cpp index 2fc36b3105..1c98d5563d 100644 --- a/guilib/GUIWindow.cpp +++ b/guilib/GUIWindow.cpp @@ -335,7 +335,7 @@ void CGUIWindow::Close(bool forceClose) bool CGUIWindow::OnAction(const CAction &action) { - if (action.IsMouse()) + if (action.IsMouse() || action.IsGesture()) return EVENT_RESULT_UNHANDLED != OnMouseAction(action); CGUIControl *focusedControl = GetFocusedControl(); @@ -554,6 +554,13 @@ bool CGUIWindow::OnMessage(CGUIMessage& message) return true; } break; + case GUI_MSG_GESTURE_NOTIFY: + { + CAction action(ACTION_GESTURE_NOTIFY, 0, (float)message.GetParam1(), (float)message.GetParam2(), 0, 0); + EVENT_RESULT result = OnMouseAction(action); + message.SetParam1(result); + return result != EVENT_RESULT_UNHANDLED; + } case GUI_MSG_NOTIFY_ALL: { // only process those notifications that come from this window, or those intended for every window diff --git a/guilib/Key.h b/guilib/Key.h index 965dd5eb19..c81a072bca 100644 --- a/guilib/Key.h +++ b/guilib/Key.h @@ -279,6 +279,13 @@ #define ACTION_INCREASE_PAR 219 #define ACTION_DECREASE_PAR 220 +#define ACTION_GESTURE_NOTIFY 221 +#define ACTION_GESTURE_BEGIN 222 +#define ACTION_GESTURE_ZOOM 223 +#define ACTION_GESTURE_ROTATE 224 +#define ACTION_GESTURE_PAN 225 +#define ACTION_GESTURE_END 226 + // Window ID defines to make the code a bit more readable #define WINDOW_INVALID 9999 #define WINDOW_HOME 10000 @@ -421,6 +428,8 @@ public: */ bool IsMouse() const { return (m_id >= ACTION_MOUSE_START && m_id <= ACTION_MOUSE_END); }; + bool IsGesture() const { return (m_id >= ACTION_GESTURE_NOTIFY && m_id <= ACTION_GESTURE_END); }; + /*! \brief Human-readable name of the action \return name of the action */ |