Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GNASH_SWF_DEFINEBUTTONTAG_H
00022 #define GNASH_SWF_DEFINEBUTTONTAG_H
00023
00024 #include "DefinitionTag.h"
00025 #include "SWFMatrix.h"
00026 #include "cxform.h"
00027 #include "action_buffer.h"
00028 #include "filter_factory.h"
00029 #include "DefineButtonSoundTag.h"
00030 #include "SWF.h"
00031 #include "Button.h"
00032
00033 #include <vector>
00034 #include <boost/scoped_ptr.hpp>
00035 #include <boost/cstdint.hpp>
00036 #include <memory>
00037
00038
00039 namespace gnash {
00040 class movie_definition;
00041 class event_id;
00042 class SWFStream;
00043 class DisplayObject;
00044 }
00045
00046 namespace gnash {
00047 namespace SWF {
00048
00049
00051 class ButtonRecord
00052 {
00053
00054 public:
00055
00056 ButtonRecord()
00057 :
00058 _definitionTag(0)
00059 {
00060 }
00061
00063
00068 DisplayObject* instantiate(Button* button, bool name = true) const;
00069
00071
00075 bool hasState(Button::MouseState st) const;
00076
00078
00081 void readRGBTransform(SWFStream& in) {
00082 _cxform.read_rgb(in);
00083 }
00084
00086
00092 bool read(SWFStream& in, TagType t, movie_definition& m,
00093 unsigned long endPos);
00094
00096
00099 bool valid() const {
00100 return (_definitionTag);
00101 }
00102
00103 private:
00104
00107
00109 Filters _filters;
00110
00113
00115 boost::uint8_t _blendMode;
00116
00117 bool _hitTest;
00118 bool _down;
00119 bool _over;
00120 bool _up;
00121 int _id;
00122
00123
00124 const DefinitionTag* _definitionTag;
00125
00126 int _buttonLayer;
00127
00128 SWFMatrix _matrix;
00129
00130 cxform _cxform;
00131
00132 };
00133
00135 class ButtonAction
00136 {
00137 public:
00138
00139
00140 action_buffer _actions;
00141
00149 ButtonAction(SWFStream& in, TagType t, unsigned long endPos,
00150 movie_definition& mdef);
00151
00153 bool triggeredBy(const event_id& ev) const;
00154
00156 bool triggeredByKeyPress() const
00157 {
00158 return (_conditions & KEYPRESS);
00159 }
00160
00161 private:
00162
00164
00167 int getKeyCode() const
00168 {
00169 return (_conditions & KEYPRESS) >> 9;
00170 }
00171
00172 enum condition
00173 {
00174 IDLE_TO_OVER_UP = 1 << 0,
00175 OVER_UP_TO_IDLE = 1 << 1,
00176 OVER_UP_TO_OVER_DOWN = 1 << 2,
00177 OVER_DOWN_TO_OVER_UP = 1 << 3,
00178 OVER_DOWN_TO_OUT_DOWN = 1 << 4,
00179 OUT_DOWN_TO_OVER_DOWN = 1 << 5,
00180 OUT_DOWN_TO_IDLE = 1 << 6,
00181 IDLE_TO_OVER_DOWN = 1 << 7,
00182 OVER_DOWN_TO_IDLE = 1 << 8,
00183 KEYPRESS = 0xFE00
00184 };
00185 int _conditions;
00186
00187 };
00188
00190 class DefineButtonTag : public DefinitionTag
00191 {
00192 public:
00193
00195 static void loader(SWFStream& in, TagType tag, movie_definition& m,
00196 const RunResources& r);
00197
00198 typedef std::vector<ButtonRecord> ButtonRecords;
00199 typedef std::vector<ButtonAction*> ButtonActions;
00200
00201 virtual ~DefineButtonTag();
00202
00204 DisplayObject* createDisplayObject(Global_as& gl, DisplayObject* parent)
00205 const;
00206
00209 ButtonRecords& buttonRecords() { return _buttonRecords; }
00210
00212 const ButtonRecords& buttonRecords() const { return _buttonRecords; }
00213
00215 bool hasSound() const { return (_soundTag.get()); }
00216
00219 void addSoundTag(std::auto_ptr<SWF::DefineButtonSoundTag> soundTag) {
00220
00221 assert(!_soundTag.get());
00222 _soundTag.reset(soundTag.release());
00223 }
00224
00226
00229 const DefineButtonSoundTag::ButtonSound& buttonSound(size_t index) const {
00230 assert(_soundTag.get());
00231 return _soundTag->getSound(index);
00232 }
00233
00235 int getSWFVersion() const;
00236
00238 bool trackAsMenu() const {
00239 return _trackAsMenu;
00240 }
00241
00242 bool hasKeyPressHandler() const;
00243
00245
00249 template <class E>
00250 void forEachTrigger(const event_id& ev, E& f) const
00251 {
00252 for (size_t i = 0, e = _buttonActions.size(); i < e; ++i)
00253 {
00254 const ButtonAction& ba = *(_buttonActions[i]);
00255 if ( ba.triggeredBy(ev) ) f(ba._actions);
00256 }
00257 }
00258
00259 private:
00260
00262 friend class DefineButton2Tag;
00263
00265
00267 DefineButtonTag(SWFStream& in, movie_definition& m, TagType tag,
00268 boost::uint16_t id);
00269
00271 void readDefineButtonTag(SWFStream& in, movie_definition& m);
00272
00274 void readDefineButton2Tag(SWFStream& in, movie_definition& m);
00275
00276 boost::scoped_ptr<SWF::DefineButtonSoundTag> _soundTag;
00277
00278 ButtonRecords _buttonRecords;
00279 ButtonActions _buttonActions;
00280
00282 bool _trackAsMenu;
00283
00285 movie_definition& _movieDef;
00286 };
00287
00289
00292 class DefineButton2Tag
00293 {
00294 public:
00296 static void loader(SWFStream& in, TagType tag, movie_definition& m,
00297 const RunResources& r);
00298 };
00299
00300 }
00301 }
00302
00303
00304 #endif // GNASH_BUTTON_CHARACTER_DEF_H
00305
00306
00307
00308
00309
00310
00311
00312