Gnash  0.8.11dev
Button.h
Go to the documentation of this file.
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
18 //
19 
20 // SWF buttons. Mouse-sensitive update/display, actions, etc.
21 
22 
23 #ifndef GNASH_BUTTON_H
24 #define GNASH_BUTTON_H
25 
26 #include <boost/intrusive_ptr.hpp>
27 #include <vector>
28 #include <set>
29 
30 #include "InteractiveObject.h"
31 #include "GnashKey.h"
32 #include "dsodefs.h"
33 
34 // Forward declarations.
35 namespace gnash {
36  namespace SWF {
37  class DefineButtonTag;
38  }
39 }
40 
41 namespace gnash {
42 
45 {
46 public:
47 
48  typedef std::vector<DisplayObject*> DisplayObjects;
49  typedef std::vector<const DisplayObject*> ConstDisplayObjects;
50 
52  typedef std::set<int> ActiveRecords;
53 
55  {
56  FLAG_IDLE = 0,
57  FLAG_OVER = 1,
58  FLAG_DOWN = 2,
59  OVER_DOWN = FLAG_OVER | FLAG_DOWN,
60 
61  // aliases
62  OVER_UP = FLAG_OVER,
63  OUT_DOWN = FLAG_DOWN
64  };
65 
67  {
68  MOUSESTATE_UP = 0,
71  MOUSESTATE_HIT
72  };
73 
75  //
77  Button(as_object* object, const SWF::DefineButtonTag* def,
78  DisplayObject* parent);
79 
80  ~Button();
81 
82  bool mouseEnabled() const { return true; }
83 
84  virtual bool trackAsMenu();
85 
87  void keyPress(key::code c);
88 
90  virtual void display(Renderer& renderer, const Transform& xform);
91 
92  void set_current_state(MouseState new_state);
93 
95  //
97  virtual InteractiveObject* topmostMouseEntity(std::int32_t x,
98  std::int32_t y);
99 
101  virtual void mouseEvent(const event_id& event);
102 
104  virtual bool handleFocus();
105 
106  void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
107 
108  virtual SWFRect getBounds() const;
109 
110  // See dox in DisplayObject.h
111  bool pointInShape(std::int32_t x, std::int32_t y) const;
112 
113  bool isEnabled();
114 
116  void destroy();
117 
119  //
121  //
124  virtual void construct(as_object* init = nullptr);
125 
126 #ifdef USE_SWFTREE
127  // Override to append button DisplayObjects info, see dox in DisplayObject.h
128  virtual InfoTree::iterator getMovieInfo(InfoTree& tr,
129  InfoTree::iterator it);
130 #endif
131 
132 protected:
133 
135  virtual bool unloadChildren();
136 
138  //
144  void markOwnResources() const;
145 
146 private:
147 
149  //
155  void getActiveCharacters(DisplayObjects& list, bool includeUnloaded=false);
156 
158  //
163  void getActiveCharacters(ConstDisplayObjects& list) const;
164 
167  //
174  void get_active_records(ActiveRecords& list, MouseState state);
175 
177  virtual int getDefinitionVersion() const;
178 
179  MouseState _mouseState;
180 
181  const boost::intrusive_ptr<const SWF::DefineButtonTag> _def;
182 
183  DisplayObjects _stateCharacters;
184 
185  DisplayObjects _hitCharacters;
186 
187 };
188 
189 std::ostream& operator<<(std::ostream& o, const Button::MouseState& st);
190 
192 void button_class_init(as_object& global, const ObjectURI& uri);
193 
194 void registerButtonNative(as_object& global);
195 
196 } // namespace gnash
197 
198 
199 #endif // GNASH_BUTTON_H
200 
201 
202 // Local Variables:
203 // mode: C++
204 // c-basic-offset: 8
205 // tab-width: 8
206 // indent-tabs-mode: t
207 // End:
gnash::geometry::SnappingRanges2d< std::int32_t >
sound_handler.h
gnash::SWF::SoundInfoRecord::loopCount
int loopCount
Number of loops started by an execution of this tag.
Definition: SoundInfoRecord.h:66
gnash::DisplayObject::set_depth
void set_depth(int d)
Definition: DisplayObject.h:270
movie_root.h
name
std::string name
Definition: LocalConnection_as.cpp:149
ExecutableCode.h
gnash::toBool
bool toBool(const as_value &v, const VM &vm)
Convert an as_value to boolean type.
Definition: VM.cpp:445
gnash::key::d
@ d
Definition: GnashKey.h:150
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::Button::topmostMouseEntity
virtual InteractiveObject * topmostMouseEntity(std::int32_t x, std::int32_t y)
Return the topmost entity that the given point covers. NULL if none.
Definition: Button.cpp:383
gnash::DisplayObject::get_event_handler
std::unique_ptr< ExecutableCode > get_event_handler(const event_id &id) const
Get the built-in function handlers code for the given event.
Definition: DisplayObject.cpp:434
gnash::DisplayObject::MaskRenderer
Render a dynamic mask for a specified DisplayObject.
Definition: DisplayObject.h:969
gnash::Button::unloadChildren
virtual bool unloadChildren()
Properly unload contained DisplayObjects.
Definition: Button.cpp:859
gnash::DisplayObject::staticDepthOffset
static const int staticDepthOffset
Definition: DisplayObject.h:205
dsodefs.h
Button.h
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::event_id::MOUSE_UP
@ MOUSE_UP
Definition: event_id.h:77
y
std::int32_t y
Definition: BitmapData_as.cpp:435
gnash::key::i
@ i
Definition: GnashKey.h:155
LOG_ONCE
#define LOG_ONCE(x)
Definition: log.h:49
SoundInfoRecord.h
gnash::SWF::DefineButtonSoundTag::ButtonSound::soundID
std::uint16_t soundID
Definition: DefineButtonSoundTag.h:46
gnash::Button::MOUSESTATE_HIT
@ MOUSESTATE_HIT
Definition: Button.h:71
_
#define _(String)
Definition: log.h:44
gnash::event_id::functionURI
const ObjectURI & functionURI() const
Definition: event_id.cpp:68
gnash::DisplayObject::isDestroyed
bool isDestroyed() const
Return true if this DisplayObject was destroyed.
Definition: DisplayObject.h:807
gnash::event_id
A class to identify 'static' SWF events (system events).
Definition: event_id.h:53
gnash::as_object::init_member
void init_member(const std::string &name, const as_value &val, int flags=DefaultFlags)
Initialize a member value by string.
Definition: as_object.cpp:669
gnash::VM
The AVM1 virtual machine.
Definition: VM.h:72
Transform.h
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
ActionExec.h
gnash::SWF::SoundInfoRecord::inPoint
unsigned int inPoint
In point, 44100 for one second.
Definition: SoundInfoRecord.h:79
gnash::event_id::id
EventCode id() const
Return the identifier for this event type.
Definition: event_id.h:141
gnash::Button::set_current_state
void set_current_state(MouseState new_state)
Definition: Button.cpp:636
gnash::event_id::ROLL_OVER
@ ROLL_OVER
Definition: event_id.h:65
_env
const as_environment & _env
Definition: Array_as.cpp:682
gnash::getWorldMatrix
SWFMatrix getWorldMatrix(const DisplayObject &d, bool includeRoot=true)
Get concatenated SWFMatrix (all ancestor transforms and our SWFMatrix)
Definition: DisplayObject.h:1131
gnash::DisplayObject::get_environment
virtual as_environment & get_environment()
Return a reference to the variable scope of this DisplayObject.
Definition: DisplayObject.h:233
gnash::movie_root::PRIORITY_DOACTION
@ PRIORITY_DOACTION
Frame actions, load handlers, unload handlers.
Definition: movie_root.h:539
gnash::DisplayObject::DisplayObject
DisplayObject(movie_root &mr, as_object *object, DisplayObject *parent)
Construct a DisplayObject.
Definition: DisplayObject.cpp:86
gnash::movie_root::registerButton
void registerButton(Button *listener)
Push a new DisplayObject listener for key events.
Definition: movie_root.cpp:1992
gnash::Renderer
Base class for render handlers.
Definition: Renderer.h:189
GnashKey.h
gnash::key::m
@ m
Definition: GnashKey.h:159
gnash::DisplayObject::m_old_invalidated_ranges
InvalidatedRanges m_old_invalidated_ranges
Bounds of this DisplayObject instance before first invalidation since last call to clear_invalidated(...
Definition: DisplayObject.h:1029
gnash::key::s
@ s
Definition: GnashKey.h:165
as_value.h
gnash::Button::destroy
void destroy()
Properly destroy contained DisplayObjects.
Definition: Button.cpp:883
gnash::DisplayObject::saveOriginalTarget
void saveOriginalTarget()
Definition: DisplayObject.h:991
NativeFunction.h
Global_as.h
gnash::DisplayObject::transform
const Transform & transform() const
Definition: DisplayObject.h:292
gnash::SWF::DefineButtonTag
A class for parsing DefineButton and DefineButton2 tags.
Definition: DefineButtonTag.h:198
gnash::Button::display
virtual void display(Renderer &renderer, const Transform &xform)
Render this Button.
Definition: Button.cpp:360
gnash::getGlobal
Global_as & getGlobal(const as_environment &env)
Definition: as_environment.cpp:651
gnash::movie_root::pushAction
void pushAction(std::unique_ptr< ExecutableCode > code, size_t lvl)
Push an executable code to the ActionQueue.
Definition: movie_root.cpp:1496
gnash::registerButtonNative
void registerButtonNative(as_object &global)
Definition: Button.cpp:923
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
UNUSED
#define UNUSED(x)
Definition: utility.h:113
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::DisplayObject::construct
virtual void construct(as_object *=nullptr)
Callback invoked whenever a DisplayObject is placed on stage.
Definition: DisplayObject.h:763
gnash::createObject
as_object * createObject(const Global_as &gl)
Definition: Global_as.cpp:303
gnash::Button::MOUSESTATE_OVER
@ MOUSESTATE_OVER
Definition: Button.h:70
gnash::InteractiveObject
The base class for interactive objects.
Definition: InteractiveObject.h:45
gnash::SWFRect
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:45
gnash::Button::mouseEnabled
bool mouseEnabled() const
Whether the DisplayObject can handle a mouse event.
Definition: Button.h:82
gnash::as_object::DefaultFlags
static const int DefaultFlags
The most common flags for built-in properties.
Definition: as_object.h:192
gnash::SWF::SoundInfoRecord
Definition: SoundInfoRecord.h:36
gnash::event_id::DRAG_OVER
@ DRAG_OVER
Definition: event_id.h:67
gnash::event_id::ROLL_OUT
@ ROLL_OUT
Definition: event_id.h:66
gnash::Button::construct
virtual void construct(as_object *init=nullptr)
Do ActionScript construction of the Button.
Definition: Button.cpp:782
gnash::SWF::DefineButtonSoundTag::ButtonSound
Definition: DefineButtonSoundTag.h:45
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
DefineButtonTag.h
gnash::event_id::RELEASE
@ RELEASE
Definition: event_id.h:63
gnash::geometry::Point2d::x
std::int32_t x
The x coordinate.
Definition: Point2d.h:43
gnash::DisplayObject::get_depth
int get_depth() const
Definition: DisplayObject.h:268
gnash::Global_as::createClass
as_object * createClass(Global_as::ASFunction ctor, as_object *prototype)
Create an ActionScript class.
Definition: Global_as.cpp:180
gnash::getRunResources
const RunResources & getRunResources(const as_object &o)
Get the RunResources from an as_object.
Definition: as_object.cpp:1142
gnash::movie_root::removeButton
void removeButton(Button *listener)
Remove a DisplayObject listener for key events.
Definition: movie_root.cpp:1986
StringPredicates.h
gnash::Button::DisplayObjects
std::vector< DisplayObject * > DisplayObjects
Definition: Button.h:48
IF_VERBOSE_ASCODING_ERRORS
#define IF_VERBOSE_ASCODING_ERRORS(x)
Definition: log.h:397
gnash::key::code
code
Definition: GnashKey.h:44
gnash::SWFMatrix::transform
void transform(geometry::Point2d &p) const
Transform a given point by our SWFMatrix.
Definition: SWFMatrix.cpp:99
gnash::NSV::PROP_ENABLED
@ PROP_ENABLED
Definition: namedStrings.h:74
gnash::Button::mouse_flags
mouse_flags
Definition: Button.h:55
gnash::emptyFunction
as_value emptyFunction(const fn_call &)
Definition: Global_as.h:256
gnash::Button::trackAsMenu
virtual bool trackAsMenu()
ActionScript property of Buttons and MovieClips altering mouse handling.
Definition: Button.cpp:307
gnash::as_object::get_member
virtual bool get_member(const ObjectURI &uri, as_value *val)
Get a property by name if it exists.
Definition: as_object.cpp:378
gnash::VM::registerNative
void registerNative(as_c_function_ptr fun, unsigned int x, unsigned int y)
Definition: VM.cpp:268
MovieClip.h
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::Button::keyPress
void keyPress(key::code c)
Handle a key press associated with a button event.
Definition: Button.cpp:339
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::DisplayObject::set_invalidated
void set_invalidated()
This function marks the DisplayObject as being modified in aspect and keeps track of current invalida...
Definition: DisplayObject.cpp:183
gnash::sound_sample::m_sound_handler_id
int m_sound_handler_id
Definition: sound_definition.h:65
gnash::event_id::PRESS
@ PRESS
Definition: event_id.h:62
gnash::SWFMatrix
Definition: SWFMatrix.h:54
gnash::PropFlags::onlySWF8Up
@ onlySWF8Up
Only visible by VM initialized for version 8 or higher.
Definition: PropFlags.h:54
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
gnash::geometry::Point2d
2D Point class
Definition: Point2d.h:39
gnash::Button::getBounds
virtual SWFRect getBounds() const
Returns local, untransformed bounds of this DisplayObject in TWIPS.
Definition: Button.cpp:747
gnash::DisplayObject::unloaded
bool unloaded() const
Return true if this DisplayObject was unloaded from the stage.
Definition: DisplayObject.h:785
VM.h
gnash::SWF::SoundInfoRecord::outPoint
unsigned int outPoint
Out point, 44100 for one second.
Definition: SoundInfoRecord.h:87
gnash::Button::MouseState
MouseState
Definition: Button.h:67
gnash::SWF::SoundInfoRecord::envelopes
sound::SoundEnvelopes envelopes
Sound effects (envelopes) for this start of the sound.
Definition: SoundInfoRecord.h:93
gnash::Button
Button implements Flash buttons.
Definition: Button.h:45
gnash::log_aserror
void log_aserror(StringType msg, Args... args)
Definition: log.h:331
gnash::DisplayObject::clear_invalidated
void clear_invalidated()
Definition: DisplayObject.h:720
gnash::DisplayObject::parent
DisplayObject * parent() const
Return the parent of this DisplayObject, or NULL if the DisplayObject has no parent.
Definition: DisplayObject.h:252
gnash::geometry::SnappingRanges2d::add
void add(const RangeType &range)
Add a Range to the set, merging when possible and appropriate.
Definition: snappingrange.h:250
gnash::Button::ActiveRecords
std::set< int > ActiveRecords
A container for holding the id of active button records.
Definition: Button.h:52
gnash::Button::MOUSESTATE_DOWN
@ MOUSESTATE_DOWN
Definition: Button.h:69
gnash::SWF::DefineButtonSoundTag::ButtonSound::sample
sound_sample * sample
Definition: DefineButtonSoundTag.h:47
fn_call.h
gnash::event_id::MOUSE_DOWN
@ MOUSE_DOWN
Definition: event_id.h:76
gnash::as_object::delProperty
DSOTEXPORT std::pair< bool, bool > delProperty(const ObjectURI &uri)
Delete a property of this object, unless protected from deletion.
Definition: as_object.cpp:313
gnash::sound::sound_handler
Sound mixer.
Definition: sound_handler.h:88
gnash::button_class_init
void button_class_init(as_object &global, const ObjectURI &uri)
Initialize the global Button class.
Definition: Button.cpp:910
sound_definition.h
gnash::getObject
as_object * getObject(const DisplayObject *d)
Return the as_object associated with a DisplayObject if it exists.
Definition: DisplayObject.h:1160
gnashconfig.h
gnash::Button::pointInShape
bool pointInShape(std::int32_t x, std::int32_t y) const
Return true if the given point falls in this DisplayObject's shape.
Definition: Button.cpp:768
gnash::movie_root
This class represents the 'Stage' and top-level movie.
Definition: movie_root.h:151
DSOTEXPORT
#define DSOTEXPORT
Definition: dsodefs.h:63
namedStrings.h
gnash::Button::Button
Button(as_object *object, const SWF::DefineButtonTag *def, DisplayObject *parent)
Construct a Button.
Definition: Button.cpp:292
gnash::Global_as
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:50
gnash::DisplayObject::add_invalidated_bounds
virtual void add_invalidated_bounds(InvalidatedRanges &ranges, bool force)
Add the DisplayObject's invalidated bounds to the given ranges list.
Definition: DisplayObject.cpp:226
RunResources.h
test.uri
uri
Definition: test.py:12
gnash::sound::SoundEnvelopes
std::vector< SoundEnvelope > SoundEnvelopes
A vector of SoundEnvelope objects.
Definition: SoundEnvelope.h:60
gnash::Button::isEnabled
bool isEnabled()
Definition: Button.cpp:326
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::SWF::SoundInfoRecord::stopPlayback
bool stopPlayback
If true this tag actually stops the sound rather then playing it.
Definition: SoundInfoRecord.h:73
gnash::Button::add_invalidated_bounds
void add_invalidated_bounds(InvalidatedRanges &ranges, bool force)
Add the DisplayObject's invalidated bounds to the given ranges list.
Definition: Button.cpp:730
gnash::SWF::SoundInfoRecord::noMultiple
bool noMultiple
Definition: SoundInfoRecord.h:53
gnash::DisplayObject::removedDepthOffset
static const int removedDepthOffset
Definition: DisplayObject.h:222
gnash::Button::markOwnResources
void markOwnResources() const
Mark reachable resources (for the GC)
Definition: Button.cpp:843
gnash::DisplayObject::getBounds
virtual SWFRect getBounds() const =0
gnash::DisplayObject::pointInShape
virtual bool pointInShape(std::int32_t x, std::int32_t y) const =0
Return true if the given point falls in this DisplayObject's shape.
gnash::getURI
ObjectURI getURI(const VM &vm, const std::string &str, bool lowerCaseHint=false)
Definition: VM.h:290
gnash::Button::ConstDisplayObjects
std::vector< const DisplayObject * > ConstDisplayObjects
Definition: Button.h:49
gnash::geometry::Point2d::y
std::int32_t y
The y coordinate.
Definition: Point2d.h:46
gnash::Button::mouseEvent
virtual void mouseEvent(const event_id &event)
Called whenever a mouse event affects this Button.
Definition: Button.cpp:445
gnash::RunResources::soundHandler
sound::sound_handler * soundHandler() const
Get a pointer to a sound::sound_handler set by a hosting application.
Definition: RunResources.h:96
gnash::DisplayObject
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
gnash::SWF::ButtonRecord
A class for parsing ButtonRecord, used by DefineButton and DefineButton2.
Definition: DefineButtonTag.h:54
gnash::DisplayObject::destroy
virtual void destroy()
Mark this DisplayObject as destroyed.
Definition: DisplayObject.cpp:677
gnash::DisplayObject::unload
bool unload()
Unload this instance from the stage.
Definition: DisplayObject.cpp:448
gnash::sendEvent
void sendEvent(as_object &o, const as_environment &env, const ObjectURI &name)
Send a system event.
Definition: as_object.cpp:1099
gnash::event_id::RELEASE_OUTSIDE
@ RELEASE_OUTSIDE
Definition: event_id.h:64
gnash::Transform
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:34
gnash::DisplayObject::topmostMouseEntity
virtual InteractiveObject * topmostMouseEntity(std::int32_t, std::int32_t)
DisplayObjects are not a mouse entity by default.
Definition: DisplayObject.h:637
gnash::key::o
@ o
Definition: GnashKey.h:161
gnash::getMatrix
const SWFMatrix & getMatrix(const DisplayObject &o)
Get local transform SWFMatrix for this DisplayObject.
Definition: DisplayObject.h:1119
gnash::key::SWF
@ SWF
Definition: GnashKey.h:331
gnash::log_unimpl
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
gnash::Button::~Button
~Button()
Definition: Button.cpp:302
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::DisplayObject::invalidated
bool invalidated() const
Return whether this DisplayObject has been invalidated or not.
Definition: DisplayObject.h:657
x
std::int32_t x
Definition: BitmapData_as.cpp:434
gnash::key::b
@ b
Definition: GnashKey.h:148
gnash::SWFRect::expand_to_transformed_rect
DSOEXPORT void expand_to_transformed_rect(const SWFMatrix &m, const SWFRect &r)
Definition: SWFRect.cpp:74
InteractiveObject.h
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::SWF::ButtonRecord::instantiate
DisplayObject * instantiate(Button *button, bool name=true) const
Create a DisplayObject from a ButtonRecord.
Definition: DefineButtonTag.cpp:319
gnash::event_id::KEY_PRESS
@ KEY_PRESS
Definition: event_id.h:69
gnash::DisplayObject::stage
movie_root & stage() const
Get the movie_root to which this DisplayObject belongs.
Definition: DisplayObject.h:981
gnash::Button::MOUSESTATE_UP
@ MOUSESTATE_UP
Definition: Button.h:68
gnash::Button::handleFocus
virtual bool handleFocus()
Called when the Button is in focus.
Definition: Button.cpp:352
gnash::DisplayObject::visible
bool visible() const
Definition: DisplayObject.h:623
gnash::event_id::DRAG_OUT
@ DRAG_OUT
Definition: event_id.h:68
gnash::SWF::DefineButtonSoundTag::ButtonSound::soundInfo
SoundInfoRecord soundInfo
Definition: DefineButtonSoundTag.h:48
gnash::operator<<
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:447
gnash::GcResource::setReachable
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92