1 // Manage event handling inside a Canvas similar to the DOM Level 3 Event Model
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef CANVAS_EVENT_MANAGER_HXX_
20 #define CANVAS_EVENT_MANAGER_HXX_
22 #include "canvas_fwd.hxx"
32 ElementWeakPtr element;
34 // Used as storage by EventManager during event propagation
35 mutable osg::Vec2f local_pos;
37 typedef std::deque<EventTarget> EventPropagationPath;
38 inline bool operator==(const EventTarget& t1, const EventTarget& t2)
40 return t1.element.lock() == t2.element.lock();
48 bool handleEvent( const MouseEventPtr& event,
49 const EventPropagationPath& path );
52 struct StampedPropagationPath
54 StampedPropagationPath();
55 StampedPropagationPath(const EventPropagationPath& path, double time);
60 EventPropagationPath path;
64 // TODO if we really need the paths modify to not copy around the paths
66 StampedPropagationPath _last_mouse_over;
67 size_t _current_click_count;
69 struct MouseEventInfo:
70 public StampedPropagationPath
75 void set( const MouseEventPtr& event,
76 const EventPropagationPath& path );
81 * Propagate click event and handle multi-click (eg. create dblclick)
83 bool handleClick( const MouseEventPtr& event,
84 const EventPropagationPath& path );
87 * Handle mouseover/enter/out/leave
89 bool handleMove( const MouseEventPtr& event,
90 const EventPropagationPath& path );
92 bool propagateEvent( const EventPtr& event,
93 const EventPropagationPath& path );
96 * Check if two click events (either mousedown/up or two consecutive
97 * clicks) are inside a maximum distance to still create a click or
98 * dblclick event respectively.
100 bool checkClickDistance( const osg::Vec2f& pos1,
101 const osg::Vec2f& pos2 ) const;
103 getCommonAncestor( const EventPropagationPath& path1,
104 const EventPropagationPath& path2 ) const;
107 } // namespace canvas
108 } // namespace simgear
110 #endif /* CANVAS_EVENT_MANAGER_HXX_ */