-vv is needed for verbose output, not just -v
[gnash.git] / libcore / Button.h
blob843e2505e5caeb6d6097114275e6d3a83d7b1183
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
20 // SWF buttons. Mouse-sensitive update/display, actions, etc.
23 #ifndef GNASH_BUTTON_H
24 #define GNASH_BUTTON_H
26 #include <boost/intrusive_ptr.hpp>
27 #include <vector>
28 #include <set>
30 #include "InteractiveObject.h"
31 #include "GnashKey.h"
33 // Forward declarations.
34 namespace gnash {
35 namespace SWF {
36 class DefineButtonTag;
40 namespace gnash {
42 /// Button implements Flash buttons.
43 class Button : public InteractiveObject
45 public:
47 typedef std::vector<DisplayObject*> DisplayObjects;
48 typedef std::vector<const DisplayObject*> ConstDisplayObjects;
50 /// A container for holding the id of active button records.
51 typedef std::set<int> ActiveRecords;
53 enum mouse_flags
55 FLAG_IDLE = 0,
56 FLAG_OVER = 1,
57 FLAG_DOWN = 2,
58 OVER_DOWN = FLAG_OVER | FLAG_DOWN,
60 // aliases
61 OVER_UP = FLAG_OVER,
62 OUT_DOWN = FLAG_DOWN
65 enum MouseState
67 MOUSESTATE_UP = 0,
68 MOUSESTATE_DOWN,
69 MOUSESTATE_OVER,
70 MOUSESTATE_HIT
73 /// Construct a Button
75 /// A button should always have an associated object.
76 Button(as_object* object, const SWF::DefineButtonTag* def,
77 DisplayObject* parent);
79 ~Button();
81 bool mouseEnabled() const { return true; }
83 virtual bool trackAsMenu();
85 /// Handle a key press associated with a button event.
86 void keyPress(key::code c);
88 /// Render this Button.
89 virtual void display(Renderer& renderer, const Transform& xform);
91 void set_current_state(MouseState new_state);
93 /// Return the topmost entity that the given point covers. NULL if none.
95 /// I.e. check against ourself.
96 virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
97 boost::int32_t y);
99 /// Called whenever a mouse event affects this Button.
100 virtual void mouseEvent(const event_id& event);
102 /// Called when the Button is in focus.
103 virtual bool handleFocus();
105 void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
107 virtual SWFRect getBounds() const;
109 // See dox in DisplayObject.h
110 bool pointInShape(boost::int32_t x, boost::int32_t y) const;
112 bool isEnabled();
114 /// Properly destroy contained DisplayObjects
115 void destroy();
117 /// Do ActionScript construction of the Button.
119 /// Construct all button state DisplayObjects.
121 /// @param init An init object, which can be passed when constructing
122 /// Buttons with attachMovie, but is never used.
123 virtual void construct(as_object* init = 0);
125 #ifdef USE_SWFTREE
126 // Override to append button DisplayObjects info, see dox in DisplayObject.h
127 virtual InfoTree::iterator getMovieInfo(InfoTree& tr,
128 InfoTree::iterator it);
129 #endif
131 protected:
133 /// Properly unload contained DisplayObjects
134 virtual bool unloadChildren();
136 /// Mark reachable resources (for the GC)
138 /// These are:
139 /// - this char's definition (_def)
140 /// - the vector of state DisplayObjects (_stateCharacters)
141 /// - the vector of hit DisplayObjects (_hitCharacters)
143 void markOwnResources() const;
145 private:
147 /// Returns all DisplayObjects that are active based on the current state.
149 /// The "_visible" property does not matter here.
151 /// @param list The container to push active DisplayObjects into
152 /// @param includeUnloaded If true, include unloaded but still reachable
153 /// chars in the records slot.
154 void getActiveCharacters(DisplayObjects& list, bool includeUnloaded=false);
156 /// Returns all DisplayObjects that are active based on the current state.
158 /// This is a const method because the returned DisplayObjects cannot be
159 /// modified.
161 /// @param list The container to push unmodifiable DisplayObjects into.
162 void getActiveCharacters(ConstDisplayObjects& list) const;
164 /// Returns all DisplayObjects (record nums) that should be active on
165 /// the given state.
167 /// @param list
168 /// The set to push active DisplayObjects record number into
170 /// @param state
171 /// The state we're interested in
173 void get_active_records(ActiveRecords& list, MouseState state);
175 /// Return version of the SWF containing the button definition.
176 virtual int getDefinitionVersion() const;
178 MouseState _mouseState;
180 const boost::intrusive_ptr<const SWF::DefineButtonTag> _def;
182 DisplayObjects _stateCharacters;
184 DisplayObjects _hitCharacters;
188 std::ostream& operator<<(std::ostream& o, const Button::MouseState& st);
190 /// Initialize the global Button class
191 void button_class_init(as_object& global, const ObjectURI& uri);
193 void registerButtonNative(as_object& global);
195 } // namespace gnash
198 #endif // GNASH_BUTTON_H
201 // Local Variables:
202 // mode: C++
203 // c-basic-offset: 8
204 // tab-width: 8
205 // indent-tabs-mode: t
206 // End: