1 ///@file
2 /// Visitor for traversing a canvas element hierarchy similar to the traversal
3 /// of the DOM Level 3 Event Model
4 //
5 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
20 
21 #ifndef CANVAS_EVENT_VISITOR_HXX_
22 #define CANVAS_EVENT_VISITOR_HXX_
23 
24 #include "canvas_fwd.hxx"
25 #include "CanvasEventManager.hxx"
26 
27 namespace simgear
28 {
29 namespace canvas
30 {
31 
32   class EventVisitor
33   {
34     public:
35 
36       enum TraverseMode
37       {
38         TRAVERSE_UP,
39         TRAVERSE_DOWN
40       };
41 
42       /**
43        *
44        * @param mode
45        * @param pos     Mouse position
46        * @param root    Element to dispatch events to if no element is hit
47        */
48       EventVisitor( TraverseMode mode,
49                     const osg::Vec2f& pos,
50                     const ElementPtr& root = ElementPtr() );
51       virtual ~EventVisitor();
52       virtual bool traverse(Element& el);
53       virtual bool apply(Element& el);
54 
55       const EventPropagationPath& getPropagationPath() const;
56 
57     protected:
58 
59       TraverseMode          _traverse_mode;
60       EventPropagationPath  _target_path;
61       ElementPtr            _root;
62 
63   };
64 
65 } // namespace canvas
66 } // namespace simgear
67 
68 
69 #endif /* CANVAS_EVENTVISITOR_HXX_ */
70