Gnash  0.8.11dev
DefineButtonTag.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 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 #ifndef GNASH_SWF_DEFINEBUTTONTAG_H
21 #define GNASH_SWF_DEFINEBUTTONTAG_H
22 
23 #include <vector>
24 #include <boost/ptr_container/ptr_vector.hpp>
25 #include <memory>
26 #include <cstdint>
27 #include <memory>
28 
29 #include "DefinitionTag.h"
30 #include "SWFMatrix.h"
31 #include "SWFCxForm.h"
32 #include "action_buffer.h"
33 #include "filter_factory.h"
34 #include "Filters.h"
35 #include "TypesParser.h"
36 #include "DefineButtonSoundTag.h"
37 #include "SWF.h"
38 #include "Button.h"
39 
40 // Forward declarations
41 namespace gnash {
42  class movie_definition;
43  class event_id;
44  class SWFStream;
45  class DisplayObject;
46 }
47 
48 namespace gnash {
49 namespace SWF {
50 
51 
54 {
55 
56 public:
57 
59  :
60  _blendMode(0),
61  _hitTest(false),
62  _down(false),
63  _over(false),
64  _up(false),
65  _definitionTag(nullptr),
66  _buttonLayer(0)
67  {
68  }
69 
70  ButtonRecord(ButtonRecord&&) = default;
71 
73  //
78  DisplayObject* instantiate(Button* button, bool name = true) const;
79 
81  //
85  bool hasState(Button::MouseState st) const;
86 
88  //
92  _cxform = readCxFormRGB(in);
93  }
94 
96  //
103  unsigned long endPos);
104 
106  //
109  bool valid() const {
110  return _definitionTag.get();
111  }
112 
113 private:
114 
117  //
119  Filters _filters;
120 
123  //
125  std::uint8_t _blendMode;
126 
127  bool _hitTest;
128  bool _down;
129  bool _over;
130  bool _up;
131 
132  // This is a ref-counted resource, so not owned by anyone.
133  boost::intrusive_ptr<const DefinitionTag> _definitionTag;
134 
135  int _buttonLayer;
136 
137  SWFMatrix _matrix;
138 
139  SWFCxForm _cxform;
140 
141 };
142 
145 {
146 public:
147 
148  // TODO: define ownership of list elements !!
150 
158  ButtonAction(SWFStream& in, TagType t, unsigned long endPos,
159  movie_definition& mdef);
160 
162  bool triggeredBy(const event_id& ev) const;
163 
165  bool triggeredByKeyPress() const {
166  return (_conditions & KEYPRESS);
167  }
168 
170  //
172  int getKeyCode() const {
173  return (_conditions & KEYPRESS) >> 9;
174  }
175 
176 private:
177 
178  enum Condition
179  {
180  IDLE_TO_OVER_UP = 1 << 0,
181  OVER_UP_TO_IDLE = 1 << 1,
182  OVER_UP_TO_OVER_DOWN = 1 << 2,
183  OVER_DOWN_TO_OVER_UP = 1 << 3,
184  OVER_DOWN_TO_OUT_DOWN = 1 << 4,
185  OUT_DOWN_TO_OVER_DOWN = 1 << 5,
186  OUT_DOWN_TO_IDLE = 1 << 6,
187  IDLE_TO_OVER_DOWN = 1 << 7,
188  OVER_DOWN_TO_IDLE = 1 << 8,
189  KEYPRESS = 0xFE00 // highest 7 bits
190  };
191 
192  std::uint16_t _conditions;
193 
194 };
195 
198 {
199 public:
200 
202  static void loader(SWFStream& in, TagType tag, movie_definition& m,
203  const RunResources& r);
204 
205  typedef std::vector<ButtonRecord> ButtonRecords;
206  typedef boost::ptr_vector<ButtonAction> ButtonActions;
207 
208  virtual ~DefineButtonTag();
209 
211  DisplayObject* createDisplayObject(Global_as& gl, DisplayObject* parent)
212  const;
213 
216  ButtonRecords& buttonRecords() { return _buttonRecords; }
217 
219  const ButtonRecords& buttonRecords() const { return _buttonRecords; }
220 
222  bool hasSound() const { return (_soundTag.get()); }
223 
226  void addSoundTag(std::unique_ptr<SWF::DefineButtonSoundTag> soundTag) {
227  // Do not replace a sound tag.
228  assert(!_soundTag.get());
229  _soundTag.reset(soundTag.release());
230  }
231 
233  //
236  const DefineButtonSoundTag::ButtonSound& buttonSound(size_t index) const {
237  assert(_soundTag.get());
238  return _soundTag->getSound(index);
239  }
240 
242  int getSWFVersion() const;
243 
245  bool trackAsMenu() const {
246  return _trackAsMenu;
247  }
248 
249  bool hasKeyPressHandler() const;
250 
252  //
255  template <class E>
256  void forEachTrigger(const event_id& ev, E& f) const {
257  for (size_t i = 0, e = _buttonActions.size(); i < e; ++i) {
258  const ButtonAction& ba = _buttonActions[i];
259  if (ba.triggeredBy(ev)) f(ba._actions);
260  }
261  }
262 
264  //
267  template<class E>
268  void visitKeyCodes(E& f) const {
269  std::for_each(_buttonActions.begin(), _buttonActions.end(),
270  std::bind(f, std::bind(
272  }
273 
274 private:
275 
277  friend class DefineButton2Tag;
278 
280  //
283  std::uint16_t id);
284 
286  void readDefineButtonTag(SWFStream& in, movie_definition& m);
287 
289  void readDefineButton2Tag(SWFStream& in, movie_definition& m);
290 
291  std::unique_ptr<SWF::DefineButtonSoundTag> _soundTag;
292 
293  ButtonRecords _buttonRecords;
294 
295  ButtonActions _buttonActions;
296 
298  bool _trackAsMenu;
299 
301  movie_definition& _movieDef;
302 };
303 
305 //
309 {
310 public:
312  static void loader(SWFStream& in, TagType tag, movie_definition& m,
313  const RunResources& r);
314 };
315 
316 }
317 } // end namespace gnash
318 
319 
320 #endif // GNASH_BUTTON_CHARACTER_DEF_H
321 
322 
323 // Local Variables:
324 // mode: C++
325 // c-basic-offset: 8
326 // tab-width: 8
327 // indent-tabs-mode: t
328 // End:
const DefineButtonSoundTag::ButtonSound & buttonSound(size_t index) const
Return one of the four sounds associated with this Button.
Definition: DefineButtonTag.h:236
bool triggeredByKeyPress() const
Return true if this action is triggered by a keypress.
Definition: DefineButtonTag.h:165
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
std::vector< ButtonRecord > ButtonRecords
Definition: DefineButtonTag.h:205
Definition: GnashKey.h:117
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
int getKeyCode() const
Return the keycode triggering this action.
Definition: DefineButtonTag.h:172
ButtonRecord()
Definition: DefineButtonTag.h:58
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:30
action_buffer _actions
Definition: DefineButtonTag.h:149
Definition: SWFMatrix.h:53
bool hasSound() const
Does this button have an associated DefineButtonSoundTag?
Definition: DefineButtonTag.h:222
void addSoundTag(std::unique_ptr< SWF::DefineButtonSoundTag > soundTag)
Definition: DefineButtonTag.h:226
A class for parsing an ActionRecord.
Definition: DefineButtonTag.h:144
std::vector< std::unique_ptr< BitmapFilter > > Filters
Definition: filter_factory.h:32
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
MouseState
Definition: Button.h:66
Immutable data representing the definition of a movie display element.
Definition: DefinitionTag.h:47
void readRGBTransform(SWFStream &in)
Read an RGB SWFCxForm for this record.
Definition: DefineButtonTag.h:91
bool valid() const
Return true if the ButtonRecord is valid.
Definition: DefineButtonTag.h:109
Definition: GnashKey.h:152
A class for parsing DefineButton and DefineButton2 tags.
Definition: DefineButtonTag.h:197
Color transformation record.
Definition: SWFCxForm.h:34
A class for parsing ButtonRecord, used by DefineButton and DefineButton2.
Definition: DefineButtonTag.h:53
ButtonRecords & buttonRecords()
Definition: DefineButtonTag.h:216
Definition: GnashKey.h:164
Definition: GnashKey.h:166
DisplayObject * instantiate(Button *button, bool name=true) const
Create a DisplayObject from a ButtonRecord.
Definition: DefineButtonTag.cpp:319
void forEachTrigger(const event_id &ev, E &f) const
Invoke a functor for each action triggered by given event.
Definition: DefineButtonTag.h:256
Definition: DefineButtonSoundTag.h:44
void visitKeyCodes(E &f) const
Invoke a functor for each key code that should trigger an action.
Definition: DefineButtonTag.h:268
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:53
SWFCxForm readCxFormRGB(SWFStream &in)
Read a RGB CxForm from the input stream.
Definition: TypesParser.cpp:322
bool read(SWFStream &in, TagType t, movie_definition &m, unsigned long endPos)
Read a ButtonRecord from the SWF stream.
Definition: DefineButtonTag.cpp:351
Button implements Flash buttons.
Definition: Button.h:44
bool hasState(Button::MouseState st) const
Check if this ButtonRecord has a DisplayObject for a particular state.
Definition: DefineButtonTag.cpp:338
int getSWFVersion(const as_environment &env)
Definition: as_environment.cpp:657
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:49
const ButtonRecords & buttonRecords() const
Read-only access to the ButtonRecords directly.
Definition: DefineButtonTag.h:219
Definition: GnashKey.h:155
Definition: GnashKey.h:151
Definition: GnashKey.h:159
A class to identify &#39;static&#39; SWF events (system events).
Definition: event_id.h:52
Definition: GnashKey.h:95
boost::ptr_vector< ButtonAction > ButtonActions
Definition: DefineButtonTag.h:206
A code segment.
Definition: action_buffer.h:49
bool trackAsMenu() const
Whether to track this button as a menu.
Definition: DefineButtonTag.h:245
bool triggeredBy(const event_id &ev) const
Return true if this action should be triggered by the given event.
Definition: DefineButtonTag.cpp:294
std::string name
Definition: LocalConnection_as.cpp:149
Definition: GnashKey.h:331
SWF stream wrapper class.
Definition: SWFStream.h:58
A class for parsing a DefineButton2 tag.
Definition: DefineButtonTag.h:308