2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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>
33 // Forward declarations.
36 class DefineButtonTag
;
45 class Button
: public InteractiveObject
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
;
60 OVER_DOWN
= FLAG_OVER
| FLAG_DOWN
,
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
);
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
);
98 /// Return the topmost entity that the given point covers.
101 /// I.e. check against ourself.
103 virtual InteractiveObject
* topmostMouseEntity(boost::int32_t x
,
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;
119 /// Properly destroy contained DisplayObjects
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);
132 // Override to append button DisplayObjects info, see dox in DisplayObject.h
133 virtual InfoTree::iterator
getMovieInfo(InfoTree
& tr
,
134 InfoTree::iterator it
);
139 /// Properly unload contained DisplayObjects
140 virtual bool unloadChildren();
142 /// Mark reachable resources (for the GC)
145 /// - this char's definition (_def)
146 /// - the vector of state DisplayObjects (_stateCharacters)
147 /// - the vector of hit DisplayObjects (_hitCharacters)
149 void markOwnResources() const;
153 /// Returns all DisplayObjects that are active based on the current state.
155 /// The "_visible" property does not matter here.
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
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
177 /// The set to push active DisplayObjects record number into
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
214 // indent-tabs-mode: t