• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

DefineButtonTag.h

Go to the documentation of this file.
00001 //
00002 //   Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 //
00019 
00020 
00021 #ifndef GNASH_SWF_DEFINEBUTTONTAG_H
00022 #define GNASH_SWF_DEFINEBUTTONTAG_H
00023 
00024 #include "DefinitionTag.h"
00025 #include "SWFMatrix.h" // for composition
00026 #include "cxform.h" // for composition
00027 #include "action_buffer.h" // for composition of ButtonAction
00028 #include "filter_factory.h" // for Filters (composition of button_record)
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 // Forward declarations
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     // This is a GC resource, so not owned by anyone.
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     // TODO: define ownership of list elements !!
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  // highest 7 bits
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         // Do not replace a sound tag.
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 }    // end namespace gnash
00302 
00303 
00304 #endif // GNASH_BUTTON_CHARACTER_DEF_H
00305 
00306 
00307 // Local Variables:
00308 // mode: C++
00309 // c-basic-offset: 8 
00310 // tab-width: 8
00311 // indent-tabs-mode: t
00312 // End:

Generated on Thu Sep 30 2010 14:34:57 for Gnash by  doxygen 1.7.1