Gnash  0.8.11dev
Button.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
20 // SWF buttons. Mouse-sensitive update/display, actions, etc.
21 
22 
23 #ifndef GNASH_BUTTON_H
24 #define GNASH_BUTTON_H
25 
26 #include <boost/intrusive_ptr.hpp>
27 #include <vector>
28 #include <set>
29 
30 #include "InteractiveObject.h"
31 #include "GnashKey.h"
32 #include "dsodefs.h"
33 
34 // Forward declarations.
35 namespace gnash {
36  namespace SWF {
37  class DefineButtonTag;
38  }
39 }
40 
41 namespace gnash {
42 
45 {
46 public:
47 
48  typedef std::vector<DisplayObject*> DisplayObjects;
49  typedef std::vector<const DisplayObject*> ConstDisplayObjects;
50 
52  typedef std::set<int> ActiveRecords;
53 
55  {
56  FLAG_IDLE = 0,
57  FLAG_OVER = 1,
58  FLAG_DOWN = 2,
59  OVER_DOWN = FLAG_OVER | FLAG_DOWN,
60 
61  // aliases
62  OVER_UP = FLAG_OVER,
63  OUT_DOWN = FLAG_DOWN
64  };
65 
67  {
68  MOUSESTATE_UP = 0,
71  MOUSESTATE_HIT
72  };
73 
75  //
77  Button(as_object* object, const SWF::DefineButtonTag* def,
78  DisplayObject* parent);
79 
80  ~Button();
81 
82  bool mouseEnabled() const { return true; }
83 
84  virtual bool trackAsMenu();
85 
87  void keyPress(key::code c);
88 
90  virtual void display(Renderer& renderer, const Transform& xform);
91 
92  void set_current_state(MouseState new_state);
93 
95  //
97  virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
98  boost::int32_t y);
99 
101  virtual void mouseEvent(const event_id& event);
102 
104  virtual bool handleFocus();
105 
106  void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
107 
108  virtual SWFRect getBounds() const;
109 
110  // See dox in DisplayObject.h
111  bool pointInShape(boost::int32_t x, boost::int32_t y) const;
112 
113  bool isEnabled();
114 
116  void destroy();
117 
119  //
121  //
124  virtual void construct(as_object* init = 0);
125 
126 #ifdef USE_SWFTREE
127  // Override to append button DisplayObjects info, see dox in DisplayObject.h
128  virtual InfoTree::iterator getMovieInfo(InfoTree& tr,
129  InfoTree::iterator it);
130 #endif
131 
132 protected:
133 
135  virtual bool unloadChildren();
136 
138  //
144  void markOwnResources() const;
145 
146 private:
147 
149  //
155  void getActiveCharacters(DisplayObjects& list, bool includeUnloaded=false);
156 
158  //
163  void getActiveCharacters(ConstDisplayObjects& list) const;
164 
167  //
174  void get_active_records(ActiveRecords& list, MouseState state);
175 
177  virtual int getDefinitionVersion() const;
178 
179  MouseState _mouseState;
180 
181  const boost::intrusive_ptr<const SWF::DefineButtonTag> _def;
182 
183  DisplayObjects _stateCharacters;
184 
185  DisplayObjects _hitCharacters;
186 
187 };
188 
189 std::ostream& operator<<(std::ostream& o, const Button::MouseState& st);
190 
192 void button_class_init(as_object& global, const ObjectURI& uri);
193 
194 void registerButtonNative(as_object& global);
195 
196 } // namespace gnash
197 
198 
199 #endif // GNASH_BUTTON_H
200 
201 
202 // Local Variables:
203 // mode: C++
204 // c-basic-offset: 8
205 // tab-width: 8
206 // indent-tabs-mode: t
207 // End: