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: