2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
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 <boost/intrusive_ptr.hpp>
30 #include "InteractiveObject.h"
33 // Forward declarations.
36 class DefineButtonTag
;
42 /// Button implements Flash buttons.
43 class Button
: public InteractiveObject
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
;
58 OVER_DOWN
= FLAG_OVER
| FLAG_DOWN
,
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
);
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
,
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;
114 /// Properly destroy contained DisplayObjects
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);
126 // Override to append button DisplayObjects info, see dox in DisplayObject.h
127 virtual InfoTree::iterator
getMovieInfo(InfoTree
& tr
,
128 InfoTree::iterator it
);
133 /// Properly unload contained DisplayObjects
134 virtual bool unloadChildren();
136 /// Mark reachable resources (for the GC)
139 /// - this char's definition (_def)
140 /// - the vector of state DisplayObjects (_stateCharacters)
141 /// - the vector of hit DisplayObjects (_hitCharacters)
143 void markOwnResources() const;
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
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
168 /// The set to push active DisplayObjects record number into
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
);
198 #endif // GNASH_BUTTON_H
205 // indent-tabs-mode: t