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 <boost/scoped_ptr.hpp>
26 #include <boost/cstdint.hpp>
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 "TypesParser.h"
35 #include "DefineButtonSoundTag.h"
36 #include "SWF.h"
37 #include "Button.h"
38 
39 // Forward declarations
40 namespace gnash {
41  class movie_definition;
42  class event_id;
43  class SWFStream;
44  class DisplayObject;
45 }
46 
47 namespace gnash {
48 namespace SWF {
49 
50 
53 {
54 
55 public:
56 
58  :
59  _definitionTag(0)
60  {
61  }
62 
64  //
69  DisplayObject* instantiate(Button* button, bool name = true) const;
70 
72  //
76  bool hasState(Button::MouseState st) const;
77 
79  //
83  _cxform = readCxFormRGB(in);
84  }
85 
87  //
94  unsigned long endPos);
95 
97  //
100  bool valid() const {
101  return (_definitionTag);
102  }
103 
104 private:
105 
108  //
110  Filters _filters;
111 
114  //
116  boost::uint8_t _blendMode;
117 
118  bool _hitTest;
119  bool _down;
120  bool _over;
121  bool _up;
122 
123  // This is a ref-counted resource, so not owned by anyone.
124  boost::intrusive_ptr<const DefinitionTag> _definitionTag;
125 
126  int _buttonLayer;
127 
128  SWFMatrix _matrix;
129 
130  SWFCxForm _cxform;
131 
132 };
133 
136 {
137 public:
138 
139  // TODO: define ownership of list elements !!
141 
149  ButtonAction(SWFStream& in, TagType t, unsigned long endPos,
150  movie_definition& mdef);
151 
153  bool triggeredBy(const event_id& ev) const;
154 
156  bool triggeredByKeyPress() const {
157  return (_conditions & KEYPRESS);
158  }
159 
161  //
163  int getKeyCode() const {
164  return (_conditions & KEYPRESS) >> 9;
165  }
166 
167 private:
168 
169  enum Condition
170  {
171  IDLE_TO_OVER_UP = 1 << 0,
172  OVER_UP_TO_IDLE = 1 << 1,
173  OVER_UP_TO_OVER_DOWN = 1 << 2,
174  OVER_DOWN_TO_OVER_UP = 1 << 3,
175  OVER_DOWN_TO_OUT_DOWN = 1 << 4,
176  OUT_DOWN_TO_OVER_DOWN = 1 << 5,
177  OUT_DOWN_TO_IDLE = 1 << 6,
178  IDLE_TO_OVER_DOWN = 1 << 7,
179  OVER_DOWN_TO_IDLE = 1 << 8,
180  KEYPRESS = 0xFE00 // highest 7 bits
181  };
182 
183  boost::uint16_t _conditions;
184 
185 };
186 
189 {
190 public:
191 
193  static void loader(SWFStream& in, TagType tag, movie_definition& m,
194  const RunResources& r);
195 
196  typedef std::vector<ButtonRecord> ButtonRecords;
197  typedef boost::ptr_vector<ButtonAction> ButtonActions;
198 
199  virtual ~DefineButtonTag();
200 
203  const;
204 
207  ButtonRecords& buttonRecords() { return _buttonRecords; }
208 
210  const ButtonRecords& buttonRecords() const { return _buttonRecords; }
211 
213  bool hasSound() const { return (_soundTag.get()); }
214 
217  void addSoundTag(std::auto_ptr<SWF::DefineButtonSoundTag> soundTag) {
218  // Do not replace a sound tag.
219  assert(!_soundTag.get());
220  _soundTag.reset(soundTag.release());
221  }
222 
224  //
227  const DefineButtonSoundTag::ButtonSound& buttonSound(size_t index) const {
228  assert(_soundTag.get());
229  return _soundTag->getSound(index);
230  }
231 
233  int getSWFVersion() const;
234 
236  bool trackAsMenu() const {
237  return _trackAsMenu;
238  }
239 
240  bool hasKeyPressHandler() const;
241 
243  //
246  template <class E>
247  void forEachTrigger(const event_id& ev, E& f) const {
248  for (size_t i = 0, e = _buttonActions.size(); i < e; ++i) {
249  const ButtonAction& ba = _buttonActions[i];
250  if (ba.triggeredBy(ev)) f(ba._actions);
251  }
252  }
253 
255  //
258  template<class E>
259  void visitKeyCodes(E& f) const {
260  std::for_each(_buttonActions.begin(), _buttonActions.end(),
261  boost::bind(f, boost::bind(
262  boost::mem_fn(&ButtonAction::getKeyCode), _1)));
263  }
264 
265 private:
266 
268  friend class DefineButton2Tag;
269 
271  //
274  boost::uint16_t id);
275 
277  void readDefineButtonTag(SWFStream& in, movie_definition& m);
278 
280  void readDefineButton2Tag(SWFStream& in, movie_definition& m);
281 
282  boost::scoped_ptr<SWF::DefineButtonSoundTag> _soundTag;
283 
284  ButtonRecords _buttonRecords;
285 
286  ButtonActions _buttonActions;
287 
289  bool _trackAsMenu;
290 
292  movie_definition& _movieDef;
293 };
294 
296 //
300 {
301 public:
303  static void loader(SWFStream& in, TagType tag, movie_definition& m,
304  const RunResources& r);
305 };
306 
307 }
308 } // end namespace gnash
309 
310 
311 #endif // GNASH_BUTTON_CHARACTER_DEF_H
312 
313 
314 // Local Variables:
315 // mode: C++
316 // c-basic-offset: 8
317 // tab-width: 8
318 // indent-tabs-mode: t
319 // End:
bool valid() const
Return true if the ButtonRecord is valid.
Definition: DefineButtonTag.h:100
Client program'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:692
std::vector< ButtonRecord > ButtonRecords
Definition: DefineButtonTag.h:196
Definition: GnashKey.h:117
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
void forEachTrigger(const event_id &ev, E &f) const
Invoke a functor for each action triggered by given event.
Definition: DefineButtonTag.h:247
ButtonRecord()
Definition: DefineButtonTag.h:57
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:30
action_buffer _actions
Definition: DefineButtonTag.h:140
const ButtonRecords & buttonRecords() const
Read-only access to the ButtonRecords directly.
Definition: DefineButtonTag.h:210
Definition: SWFMatrix.h:53
A class for parsing an ActionRecord.
Definition: DefineButtonTag.h:135
ButtonAction(SWFStream &in, TagType t, unsigned long endPos, movie_definition &mdef)
Definition: DefineButtonTag.cpp:263
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:48
static void loader(SWFStream &in, TagType tag, movie_definition &m, const RunResources &r)
Load a DefineButtonTag.
Definition: DefineButtonTag.cpp:77
void readRGBTransform(SWFStream &in)
Read an RGB SWFCxForm for this record.
Definition: DefineButtonTag.h:82
bool trackAsMenu() const
Whether to track this button as a menu.
Definition: DefineButtonTag.h:236
static void loader(SWFStream &in, TagType tag, movie_definition &m, const RunResources &r)
Load a DefineButton2 tag.
Definition: DefineButtonTag.cpp:94
Definition: GnashKey.h:152
A class for parsing DefineButton and DefineButton2 tags.
Definition: DefineButtonTag.h:188
Color transformation record.
Definition: SWFCxForm.h:35
A class for parsing ButtonRecord, used by DefineButton and DefineButton2.
Definition: DefineButtonTag.h:52
bool hasKeyPressHandler() const
Definition: DefineButtonTag.cpp:252
const DefineButtonSoundTag::ButtonSound & buttonSound(size_t index) const
Return one of the four sounds associated with this Button.
Definition: DefineButtonTag.h:227
ButtonRecords & buttonRecords()
Definition: DefineButtonTag.h:207
Definition: GnashKey.h:164
DisplayObject * createDisplayObject(Global_as &gl, DisplayObject *parent) const
Create a mutable instance of our definition.
Definition: DefineButtonTag.cpp:237
Definition: GnashKey.h:166
int getSWFVersion() const
Return version of the SWF containing this button definition.
Definition: DefineButtonTag.cpp:246
Definition: DefineButtonSoundTag.h:44
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:43
SWFCxForm readCxFormRGB(SWFStream &in)
Read a RGB CxForm from the input stream.
Definition: TypesParser.cpp:315
int getKeyCode() const
Return the keycode triggering this action.
Definition: DefineButtonTag.h:163
std::streampos endPos
Definition: DefineBitsTag.cpp:75
bool read(SWFStream &in, TagType t, movie_definition &m, unsigned long endPos)
Read a ButtonRecord from the SWF stream.
Definition: DefineButtonTag.cpp:355
bool hasSound() const
Does this button have an associated DefineButtonSoundTag?
Definition: DefineButtonTag.h:213
std::vector< boost::shared_ptr< BitmapFilter > > Filters
Definition: filter_factory.h:32
Button implements Flash buttons.
Definition: Button.h:44
bool triggeredBy(const event_id &ev) const
Return true if this action should be triggered by the given event.
Definition: DefineButtonTag.cpp:298
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:55
void addSoundTag(std::auto_ptr< SWF::DefineButtonSoundTag > soundTag)
Definition: DefineButtonTag.h:217
void visitKeyCodes(E &f) const
Invoke a functor for each key code that should trigger an action.
Definition: DefineButtonTag.h:259
Definition: GnashKey.h:155
Definition: GnashKey.h:151
bool hasState(Button::MouseState st) const
Check if this ButtonRecord has a DisplayObject for a particular state.
Definition: DefineButtonTag.cpp:342
Definition: GnashKey.h:159
A class to identify 'static' SWF events (system events).
Definition: event_id.h:52
Definition: GnashKey.h:95
boost::ptr_vector< ButtonAction > ButtonActions
Definition: DefineButtonTag.h:197
A code segment.
Definition: action_buffer.h:49
DisplayObject * instantiate(Button *button, bool name=true) const
Create a DisplayObject from a ButtonRecord.
Definition: DefineButtonTag.cpp:323
virtual ~DefineButtonTag()
Definition: DefineButtonTag.cpp:71
std::string name
Definition: LocalConnection_as.cpp:151
Definition: GnashKey.h:331
SWF stream wrapper class.
Definition: SWFStream.h:58
bool triggeredByKeyPress() const
Return true if this action is triggered by a keypress.
Definition: DefineButtonTag.h:156
A class for parsing a DefineButton2 tag.
Definition: DefineButtonTag.h:299