Merge branch 'master' of git.sv.gnu.org:/srv/git/gnash
[gnash.git] / libcore / Button.h
blobf0155e201a70dcd065508ea4a75af9de9a5f9554
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" // GNASH_USE_GC
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 #ifdef GNASH_USE_GC
143 /// Mark reachabe resources (for the GC)
145 /// These are:
146 /// - this char's definition (_def)
147 /// - the vector of state DisplayObjects (_stateCharacters)
148 /// - the vector of hit DisplayObjects (_hitCharacters)
150 void markOwnResources() const;
151 #endif // GNASH_USE_GC
153 private:
155 /// Returns all DisplayObjects that are active based on the current state.
157 /// The "_visible" property does not matter here.
159 /// @param list
160 /// The container to push active DisplayObjects into
162 /// @param includeUnloaded
163 /// If true, include unloaded but still reachable chars in the records slot.
165 void getActiveCharacters(DisplayObjects& list, bool includeUnloaded=false);
167 /// Returns all DisplayObjects that are active based on the current state.
169 /// This is a const method because the returned DisplayObjects cannot be
170 /// modified.
172 /// @param list The container to push unmodifiable DisplayObjects into.
173 void getActiveCharacters(ConstDisplayObjects& list) const;
175 /// Returns all DisplayObjects (record nums) that should be active on
176 /// the given state.
178 /// @param list
179 /// The set to push active DisplayObjects record number into
181 /// @param state
182 /// The state we're interested in
184 void get_active_records(ActiveRecords& list, MouseState state);
186 /// Return version of the SWF containing the button definition.
187 virtual int getDefinitionVersion() const;
189 MouseState _mouseState;
191 const boost::intrusive_ptr<const SWF::DefineButtonTag> _def;
193 DisplayObjects _stateCharacters;
195 DisplayObjects _hitCharacters;
201 /// Initialize the global Button class
202 void button_class_init(as_object& global, const ObjectURI& uri);
204 void registerButtonNative(as_object& global);
206 } // end namespace gnash
209 #endif // GNASH_BUTTON_H
212 // Local Variables:
213 // mode: C++
214 // c-basic-offset: 8
215 // tab-width: 8
216 // indent-tabs-mode: t
217 // End: