use the VERSION instead of master in the revno.h generated from a src tarball
[gnash.git] / libcore / Button.h
blob6f835827702c88e5697cb72cf8393902c47ba56b
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // 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
20 // SWF buttons. Mouse-sensitive update/display, actions, etc.
23 #ifndef GNASH_BUTTON_H
24 #define GNASH_BUTTON_H
26 #include "smart_ptr.h"
27 #include "InteractiveObject.h" // for inheritance
29 #include <boost/intrusive_ptr.hpp>
30 #include <vector>
31 #include <set>
33 // Forward declarations.
34 namespace gnash {
35 namespace SWF {
36 class DefineButtonTag;
40 namespace gnash {
42 // Button
45 class Button : public InteractiveObject
47 public:
49 typedef std::vector<DisplayObject*> DisplayObjects;
50 typedef std::vector<const DisplayObject*> ConstDisplayObjects;
52 /// A container for holding the id of active button records.
53 typedef std::set<int> ActiveRecords;
55 enum mouse_flags
57 FLAG_IDLE = 0,
58 FLAG_OVER = 1,
59 FLAG_DOWN = 2,
60 OVER_DOWN = FLAG_OVER | FLAG_DOWN,
62 // aliases
63 OVER_UP = FLAG_OVER,
64 OUT_DOWN = FLAG_DOWN
67 enum MouseState
69 MOUSESTATE_UP = 0,
70 MOUSESTATE_DOWN,
71 MOUSESTATE_OVER,
72 MOUSESTATE_HIT
75 /// Construct a Button
77 /// A button should always have an associated object.
78 Button(as_object* object, const SWF::DefineButtonTag* def,
79 DisplayObject* parent);
81 ~Button();
83 static const char* mouseStateName(MouseState s);
85 bool mouseEnabled() const { return true; }
87 virtual bool trackAsMenu();
89 // called from keypress listener only
90 void notifyEvent(const event_id& id);
92 /// Render this Button.
93 virtual void display(Renderer& renderer, const Transform& xform);
95 void set_current_state(MouseState new_state);
97 /// \brief
98 /// Return the topmost entity that the given point covers.
99 /// NULL if none.
101 /// I.e. check against ourself.
103 virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
104 boost::int32_t y);
106 virtual void mouseEvent(const event_id& event);
108 virtual bool handleFocus();
110 void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
112 virtual SWFRect getBounds() const;
114 // See dox in DisplayObject.h
115 bool pointInShape(boost::int32_t x, boost::int32_t y) const;
117 bool isEnabled();
119 /// Properly destroy contained DisplayObjects
120 void destroy();
122 /// Do ActionScript construction of the Button.
124 /// (1) Register this button instance as a live DisplayObject
125 /// (2) Construct all button state DisplayObjects.
127 /// @param init An init object, which can be passed when constructing
128 /// Buttons with attachMovie, but is never used.
129 virtual void construct(as_object* init = 0);
131 #ifdef USE_SWFTREE
132 // Override to append button DisplayObjects info, see dox in DisplayObject.h
133 virtual InfoTree::iterator getMovieInfo(InfoTree& tr,
134 InfoTree::iterator it);
135 #endif
137 protected:
139 /// Properly unload contained DisplayObjects
140 virtual bool unloadChildren();
142 /// Mark reachable resources (for the GC)
144 /// These are:
145 /// - this char's definition (_def)
146 /// - the vector of state DisplayObjects (_stateCharacters)
147 /// - the vector of hit DisplayObjects (_hitCharacters)
149 void markOwnResources() const;
151 private:
153 /// Returns all DisplayObjects that are active based on the current state.
155 /// The "_visible" property does not matter here.
157 /// @param list
158 /// The container to push active DisplayObjects into
160 /// @param includeUnloaded
161 /// If true, include unloaded but still reachable chars in the records slot.
163 void getActiveCharacters(DisplayObjects& list, bool includeUnloaded=false);
165 /// Returns all DisplayObjects that are active based on the current state.
167 /// This is a const method because the returned DisplayObjects cannot be
168 /// modified.
170 /// @param list The container to push unmodifiable DisplayObjects into.
171 void getActiveCharacters(ConstDisplayObjects& list) const;
173 /// Returns all DisplayObjects (record nums) that should be active on
174 /// the given state.
176 /// @param list
177 /// The set to push active DisplayObjects record number into
179 /// @param state
180 /// The state we're interested in
182 void get_active_records(ActiveRecords& list, MouseState state);
184 /// Return version of the SWF containing the button definition.
185 virtual int getDefinitionVersion() const;
187 MouseState _mouseState;
189 const boost::intrusive_ptr<const SWF::DefineButtonTag> _def;
191 DisplayObjects _stateCharacters;
193 DisplayObjects _hitCharacters;
199 /// Initialize the global Button class
200 void button_class_init(as_object& global, const ObjectURI& uri);
202 void registerButtonNative(as_object& global);
204 } // end namespace gnash
207 #endif // GNASH_BUTTON_H
210 // Local Variables:
211 // mode: C++
212 // c-basic-offset: 8
213 // tab-width: 8
214 // indent-tabs-mode: t
215 // End: