gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10240: Transfer all button parsing


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10240: Transfer all button parsing to libcore/swf.
Date: Fri, 07 Nov 2008 18:32:12 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10240
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2008-11-07 18:32:12 +0100
message:
  Transfer all button parsing to libcore/swf.
added:
  libcore/swf/DefineButtonCxformTag.cpp
renamed:
  libcore/parser/button_character_def.cpp => libcore/swf/DefineButtonTag.cpp
  libcore/parser/button_character_def.h => libcore/swf/DefineButtonTag.h
modified:
  libcore/Button.cpp
  libcore/Button.h
  libcore/Makefile.am
  libcore/impl.cpp
  libcore/parser/Makefile.am
  libcore/swf/DefineButtonCxformTag.h
  libcore/swf/DefineButtonSoundTag.cpp
  libcore/swf/DefineButtonSoundTag.h
  libcore/swf/tag_loaders.cpp
  libcore/swf/tag_loaders.h
  libcore/swf/DefineButtonTag.cpp
  libcore/swf/DefineButtonTag.h
    ------------------------------------------------------------
    revno: 10239.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 15:50:12 +0100
    message:
      Move parsing of DefineButtonCxform tag outside of 
button_character_definition
      (though it still needs direct access to the button records). Rename stuff,
      make more things private, and provide accessors where necessary.
    added:
      libcore/swf/DefineButtonCxformTag.cpp
    modified:
      libcore/Button.cpp
      libcore/Makefile.am
      libcore/parser/button_character_def.cpp
      libcore/parser/button_character_def.h
      libcore/swf/DefineButtonCxformTag.h
    ------------------------------------------------------------
    revno: 10239.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 15:51:21 +0100
    message:
      Fix include.
    modified:
      libcore/swf/DefineButtonCxformTag.cpp
    ------------------------------------------------------------
    revno: 10239.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 16:05:25 +0100
    message:
      Rename button_action to ButtonAction.
    modified:
      libcore/parser/button_character_def.cpp
      libcore/parser/button_character_def.h
    ------------------------------------------------------------
    revno: 10239.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 17:05:23 +0100
    message:
      Movie button_character_def to swf/DefineButtonTag. Clean up.
    renamed:
      libcore/parser/button_character_def.cpp => libcore/swf/DefineButtonTag.cpp
      libcore/parser/button_character_def.h => libcore/swf/DefineButtonTag.h
    modified:
      libcore/Button.cpp
      libcore/Button.h
      libcore/Makefile.am
      libcore/impl.cpp
      libcore/parser/Makefile.am
      libcore/swf/DefineButtonCxformTag.cpp
      libcore/swf/DefineButtonSoundTag.cpp
      libcore/swf/DefineButtonSoundTag.h
      libcore/swf/tag_loaders.cpp
      libcore/swf/tag_loaders.h
      libcore/swf/DefineButtonTag.cpp
      libcore/swf/DefineButtonTag.h
    ------------------------------------------------------------
    revno: 10239.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2008-11-07 17:14:21 +0100
    message:
      Minor cleanup.
    modified:
      libcore/swf/DefineButtonTag.cpp
      libcore/swf/DefineButtonTag.h
=== modified file 'libcore/Button.cpp'
--- a/libcore/Button.cpp        2008-11-07 12:19:16 +0000
+++ b/libcore/Button.cpp        2008-11-07 16:05:23 +0000
@@ -23,7 +23,7 @@
 
 #include "smart_ptr.h" // GNASH_USE_GC
 #include "Button.h"
-#include "button_character_def.h"
+#include "DefineButtonTag.h"
 #include "as_value.h"
 
 #include "ActionExec.h"
@@ -290,9 +290,7 @@
 
 }
 
-Button::Button(
-               button_character_definition& def,
-               character* parent, int id)
+Button::Button(SWF::DefineButtonTag& def, character* parent, int id)
        :
        character(parent, id),
        m_last_mouse_flags(IDLE),
@@ -542,7 +540,8 @@
                        }
                        if (bi >= 0)
                        {
-                               const SWF::DefineButtonSoundTag::ButtonSound& 
bs = _def.buttonSound(bi);
+                               const SWF::DefineButtonSoundTag::ButtonSound& 
bs = 
+                    _def.buttonSound(bi);
                                // character zero is considered as null 
character
                                if (bs.soundID > 0)
                                {
@@ -591,7 +590,8 @@
        //else log_debug(_("No statically-defined handler for event: %s"), 
event);
 
        // Call conventional attached method.
-       boost::intrusive_ptr<as_function> method = 
getUserDefinedEventHandler(event.get_function_key());
+       boost::intrusive_ptr<as_function> method =
+        getUserDefinedEventHandler(event.get_function_key());
        if ( method )
        {
                //log_debug(_("Got user-defined handler for event: %s"), event);
@@ -637,20 +637,21 @@
 {
        list.clear();
        
-       size_t nrecs = _def.m_button_records.size();
+    using namespace SWF;
+    const DefineButtonTag::ButtonRecords& br = _def.buttonRecords();
+    size_t index = 0;
 
-       //log_debug("%s.get_active_records(%s) - def has %d records", 
getTarget(), mouseStateName(state), _def.m_button_records.size());
-       for (size_t i=0; i<nrecs; ++i)
+       for (DefineButtonTag::ButtonRecords::const_iterator i = br.begin(),
+            e = br.end(); i != e; ++i, ++index)
        {
-               button_record& rec = _def.m_button_records[i];
-               //log_debug(" rec %d has hit:%d down:%d over:%d up:%d", i, 
rec.m_hit_test, rec.m_down, rec.m_over, rec.m_up);
+               const ButtonRecord& rec =*i;
 
                if ((state == UP && rec.m_up)
                    || (state == DOWN && rec.m_down)
                    || (state == OVER && rec.m_over)
                    || (state == HIT && rec.m_hit_test))
                {
-                       list.insert(i);
+                       list.insert(index);
                }
        }
 }
@@ -743,14 +744,16 @@
                        if ( ! oldch )
                        {
                                // Not there, instantiate
-                               button_record& bdef = _def.m_button_records[i];
+                SWF::ButtonRecord& bdef = _def.buttonRecords()[i];
 
-                               const SWFMatrix&        mat = 
bdef.m_button_matrix;
-                               const cxform&   cx = bdef.m_button_cxform;
-                               int ch_depth = 
bdef.m_button_layer+character::staticDepthOffset+1;
+                               const SWFMatrix& mat = bdef.m_button_matrix;
+                               const cxform& cx = bdef.m_button_cxform;
+                               int ch_depth = bdef.m_button_layer + 
+                    character::staticDepthOffset + 1;
                                int ch_id = bdef.m_character_id;
 
-                               character* ch = 
bdef.m_character_def->create_character_instance(this, ch_id);
+                               character* ch = 
bdef.m_character_def->create_character_instance(
+                        this, ch_id);
                                ch->setMatrix(mat, true); // update caches
                                ch->set_cxform(cx); 
                                ch->set_depth(ch_depth); 
@@ -896,7 +899,7 @@
        get_active_records(hitChars, HIT);
        for (RecSet::iterator i=hitChars.begin(),e=hitChars.end(); i!=e; ++i)
        {
-               button_record& bdef = _def.m_button_records[*i];
+        SWF::ButtonRecord& bdef = _def.buttonRecords()[*i];
 
                const SWFMatrix& mat = bdef.m_button_matrix;
                const cxform& cx = bdef.m_button_cxform;
@@ -918,7 +921,7 @@
        // Some slots will probably be never used (consider HIT-only records)
        // but for now this direct corrispondence between record number
        // and active character will be handy.
-       _stateCharacters.resize(_def.m_button_records.size());
+       _stateCharacters.resize(_def.buttonRecords().size());
 
        // Instantiate the default state characters 
        RecSet upChars;
@@ -927,14 +930,15 @@
        for (RecSet::iterator i=upChars.begin(),e=upChars.end(); i!=e; ++i)
        {
                int rno = *i;
-               button_record& bdef = _def.m_button_records[rno];
+        SWF::ButtonRecord& bdef = _def.buttonRecords()[rno];
 
-               const SWFMatrix&        mat = bdef.m_button_matrix;
-               const cxform&   cx = bdef.m_button_cxform;
+               const SWFMatrix& mat = bdef.m_button_matrix;
+               const cxform& cx = bdef.m_button_cxform;
                int ch_depth = 
bdef.m_button_layer+character::staticDepthOffset+1;
                int ch_id = bdef.m_character_id;
 
-               character* ch = 
bdef.m_character_def->create_character_instance(this, ch_id);
+               character* ch = bdef.m_character_def->create_character_instance(
+                this, ch_id);
                ch->setMatrix(mat, true);  // update caches
                ch->set_cxform(cx); 
                ch->set_depth(ch_depth); 

=== modified file 'libcore/Button.h'
--- a/libcore/Button.h  2008-10-25 10:38:32 +0000
+++ b/libcore/Button.h  2008-11-07 16:05:23 +0000
@@ -28,16 +28,15 @@
 #include <vector>
 #include <set>
 
+// Forward declarations.
 namespace gnash {
-
-// Forward declarations
        class MovieClip;
-       class button_character_definition;
-
-//
-// button characters
-//
-
+    namespace SWF {
+        class DefineButtonTag;
+    }
+}
+
+namespace gnash {
 //
 // Button
 //
@@ -74,8 +73,7 @@
 
        MouseState m_mouse_state;
 
-       Button(button_character_definition& def,
-                       character* parent, int id);
+       Button(SWF::DefineButtonTag& def, character* parent, int id);
 
        ~Button();
 
@@ -163,7 +161,7 @@
 
 private:
 
-       button_character_definition& _def;
+    SWF::DefineButtonTag& _def;
 
        CharsVect _stateCharacters;
 

=== modified file 'libcore/Makefile.am'
--- a/libcore/Makefile.am       2008-11-07 11:35:40 +0000
+++ b/libcore/Makefile.am       2008-11-07 16:05:23 +0000
@@ -84,6 +84,8 @@
        swf/TagLoadersTable.cpp \
        swf/DefineVideoStreamTag.cpp \
        swf/DefineButtonSoundTag.cpp \
+       swf/DefineButtonCxformTag.cpp \
+       swf/DefineButtonTag.cpp \
        swf/VideoFrameTag.cpp \
        swf/SoundInfoRecord.cpp \
        swf/tag_loaders.cpp \
@@ -186,6 +188,7 @@
        swf/CSMTextSettingsTag.h \
        swf/SoundInfoRecord.h \
        swf/DefineButtonSoundTag.h \
+       swf/DefineButtonTag.h \
        swf/DefineEditTextTag.h \
        swf/DefineButtonCxformTag.h \
        swf/PlaceObject2Tag.h \

=== modified file 'libcore/impl.cpp'
--- a/libcore/impl.cpp  2008-11-07 12:47:31 +0000
+++ b/libcore/impl.cpp  2008-11-07 16:05:23 +0000
@@ -39,6 +39,7 @@
 #include "DefineFontAlignZonesTag.h"
 #include "DefineButtonCxformTag.h"
 #include "CSMTextSettingsTag.h"
+#include "DefineButtonTag.h"
 #include "PlaceObject2Tag.h"
 #include "RemoveObjectTag.h"
 #include "DoActionTag.h"
@@ -100,19 +101,21 @@
     register_tag_loader(SWF::PLACEOBJECT, PlaceObject2Tag::loader);
     register_tag_loader(SWF::REMOVEOBJECT,  RemoveObjectTag::loader); // 05
     register_tag_loader(SWF::DEFINEBITS,  define_bits_jpeg_loader);
-    register_tag_loader(SWF::DEFINEBUTTON,  button_character_loader);
-    register_tag_loader(SWF::JPEGTABLES,  jpeg_tables_loader);
+    register_tag_loader(SWF::DEFINEBUTTON, DefineButtonTag::loader);
+    register_tag_loader(SWF::JPEGTABLES, jpeg_tables_loader);
     register_tag_loader(SWF::SETBACKGROUNDCOLOR, 
SetBackgroundColorTag::loader);
     register_tag_loader(SWF::DEFINEFONT,  define_font_loader);
     register_tag_loader(SWF::DEFINETEXT,  define_text_loader);
     register_tag_loader(SWF::DOACTION,  DoActionTag::doActionLoader);
     register_tag_loader(SWF::DEFINEFONTINFO, define_font_info_loader);
-    register_tag_loader(SWF::DEFINEFONTINFO2, define_font_info_loader); // 62
+    // 62
+    register_tag_loader(SWF::DEFINEFONTINFO2, define_font_info_loader);
     register_tag_loader(SWF::DEFINESOUND, define_sound_loader);
     register_tag_loader(SWF::STARTSOUND, StartSoundTag::loader);
+    // 89
     register_tag_loader(SWF::STARTSOUND2, StartSound2Tag::loader);
 
-    register_tag_loader(SWF::STOPSOUND,     fixme_loader); // 16 
+    register_tag_loader(SWF::STOPSOUND, fixme_loader); // 16 
 
     // 17
     register_tag_loader(SWF::DEFINEBUTTONSOUND, DefineButtonSoundTag::loader);
@@ -136,7 +139,8 @@
     register_tag_loader(SWF::FREEALL, fixme_loader); // 31
     register_tag_loader(SWF::DEFINESHAPE3,  define_shape_loader);
     register_tag_loader(SWF::DEFINETEXT2, define_text_loader);
-    register_tag_loader(SWF::DEFINEBUTTON2, button_character_loader);
+    // 37
+    register_tag_loader(SWF::DEFINEBUTTON2, DefineButton2Tag::loader);
     register_tag_loader(SWF::DEFINEBITSJPEG3, define_bits_jpeg3_loader);
     register_tag_loader(SWF::DEFINELOSSLESS2, define_bits_lossless_2_loader);
     register_tag_loader(SWF::DEFINEEDITTEXT, DefineEditTextTag::loader);

=== modified file 'libcore/parser/Makefile.am'
--- a/libcore/parser/Makefile.am        2008-11-06 22:57:43 +0000
+++ b/libcore/parser/Makefile.am        2008-11-07 16:05:23 +0000
@@ -50,7 +50,6 @@
        action_buffer.cpp \
        bitmap_character_def.cpp \
        BitmapMovieDefinition.cpp \
-       button_character_def.cpp \
        character_def.cpp \
        text_character_def.cpp \
        SWFMovieDefinition.cpp \
@@ -62,7 +61,6 @@
 noinst_HEADERS = \
        abc_block.h \
        action_buffer.h \
-       button_character_def.h \
        character_def.h \
        bitmap_character_def.h \
        BitmapMovieDefinition.h \

=== added file 'libcore/swf/DefineButtonCxformTag.cpp'
--- a/libcore/swf/DefineButtonCxformTag.cpp     1970-01-01 00:00:00 +0000
+++ b/libcore/swf/DefineButtonCxformTag.cpp     2008-11-07 16:05:23 +0000
@@ -0,0 +1,81 @@
+// DefineButtonCxformTag.cpp: parse SWF2 DefineButtonCxform tag.
+// 
+//   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#include "swf.h" // for tag_type definition
+#include "SWFStream.h" // for inlines
+#include "movie_definition.h"
+#include "DefineButtonTag.h"
+#include "DefineButtonCxformTag.h"
+
+namespace gnash {
+namespace SWF {
+
+void
+DefineButtonCxformTag::loader(SWFStream& in, tag_type tag, movie_definition& m,
+        const RunInfo& /*r*/)
+{
+
+    assert(tag == SWF::DEFINEBUTTONCXFORM);
+
+    in.ensureBytes(2);
+    const boost::uint16_t buttonID = in.read_u16();
+
+    IF_VERBOSE_PARSE (
+        log_debug("DefineButtonCxformTag: ButtonId=%d", buttonID);
+    );
+    
+    character_def* chdef = m.get_character_def(buttonID);
+    if (!chdef)
+    {
+        IF_VERBOSE_MALFORMED_SWF(
+        log_swferror(_("DefineButtonCxform refers to an unknown "
+                "character %d"), buttonID);
+        );
+        return;
+    }
+
+    DefineButtonTag* ch = 
+        dynamic_cast<DefineButtonTag*> (chdef);
+    if (!ch)
+    {
+        IF_VERBOSE_MALFORMED_SWF(
+        log_swferror(_("DefineButtonCxform refers to character ID %d (%s)."
+                  " Expected a button definition"),
+                  buttonID, typeName(*chdef));
+        );
+        return;
+    }
+    
+    DefineButtonTag::ButtonRecords& br = ch->buttonRecords();
+    for (DefineButtonTag::ButtonRecords::iterator i = br.begin(),
+            e = br.end(); i != e; ++i)
+    {
+        // This will throw a parser exception if not enough bytes are
+        // left.
+        (*i).m_button_cxform.read_rgb(in);
+        IF_VERBOSE_PARSE(
+            log_parse("Read DefineButtonCxform: %s", (*i).m_button_cxform);
+        );
+    }
+}
+
+
+} // namespace gnash::SWF
+} // namespace gnash
+
+

=== modified file 'libcore/swf/DefineButtonCxformTag.h'
--- a/libcore/swf/DefineButtonCxformTag.h       2008-10-29 09:45:23 +0000
+++ b/libcore/swf/DefineButtonCxformTag.h       2008-11-07 14:50:12 +0000
@@ -20,59 +20,27 @@
 #define GNASH_SWF_DEFINEBUTTONCXFORMTAG_H
 
 #include "swf.h" // for tag_type definition
-#include "SWFStream.h" // for inlines
-#include "movie_definition.h"
-#include "button_character_def.h"
+
+namespace gnash {
+    class SWFStream;
+    class movie_definition;
+}
 
 namespace gnash {
 namespace SWF {
-
-/// \brief Sets the desired limits for recursion and timeout for AS scripts
+    
+/// A simple rgb cxform for SWF2 buttons, superseded by DefineButton2.
 //
-/// A loaded movie containing a ScriptLimits tag should change the *global*
-/// scriptlimits setting, so this is kept in movie_root rather than the
-/// immutable movie_definition. Whenever this tag is parsed, the value in
-/// movie_root is overridden.
+/// The loader directly modifies a previous DefineButton tag.
+/// TODO: should it also modify a DefineButton2 tag? Probably, but not
+/// tested.
 class DefineButtonCxformTag
 {
 public:
+
     static void loader(SWFStream& in, tag_type tag, movie_definition& m,
-            const RunInfo& /*r*/)
-    {
-
-        assert(tag == SWF::DEFINEBUTTONCXFORM);
-
-        in.ensureBytes(2);
-        const boost::uint16_t buttonID = in.read_u16();
-
-        IF_VERBOSE_PARSE (
-            log_debug("DefineButtonCxformTag: ButtonId=%d", buttonID);
-        );
-        
-        character_def* chdef = m.get_character_def(buttonID);
-        if ( ! chdef )
-        {
-            IF_VERBOSE_MALFORMED_SWF(
-            log_swferror(_("DefineButtonCxform refers to an unknown "
-                    "character %d"), buttonID);
-            );
-            return;
-        }
-
-        button_character_definition* ch = 
-            dynamic_cast<button_character_definition*> (chdef);
-        if ( ! ch )
-        {
-            IF_VERBOSE_MALFORMED_SWF(
-            log_swferror(_("DefineButtonCxform refers to character ID %d (%s)."
-                      " Expected a button definition"),
-                      buttonID, typeName(*chdef));
-            );
-            return;
-        }
-
-    ch->readDefineButtonCxform(in, m);
-    }
+            const RunInfo& /*r*/);
+
 };
 
 } // namespace gnash::SWF

=== modified file 'libcore/swf/DefineButtonSoundTag.cpp'
--- a/libcore/swf/DefineButtonSoundTag.cpp      2008-11-07 11:35:40 +0000
+++ b/libcore/swf/DefineButtonSoundTag.cpp      2008-11-07 16:05:23 +0000
@@ -22,7 +22,7 @@
 #include "movie_definition.h"
 #include "SoundInfoRecord.h"
 #include "SWFStream.h"
-#include "button_character_def.h"
+#include "DefineButtonTag.h"
 
 namespace gnash {
 namespace SWF {
@@ -52,8 +52,7 @@
         return;
     }
 
-    button_character_definition* button = 
-        dynamic_cast<button_character_definition*> (chdef);
+    DefineButtonTag* button = dynamic_cast<DefineButtonTag*> (chdef);
 
     if (!button)
     {

=== modified file 'libcore/swf/DefineButtonSoundTag.h'
--- a/libcore/swf/DefineButtonSoundTag.h        2008-11-07 11:35:40 +0000
+++ b/libcore/swf/DefineButtonSoundTag.h        2008-11-07 16:05:23 +0000
@@ -83,7 +83,7 @@
     /// Mark all reachable resources (for GC)
     //
     /// Reachable resources are:
-    ///  - button sound infos (m_button_sounds)
+    ///  - button sound infos (_sounds)
     ///
     void markReachableResources() const
     {

=== renamed file 'libcore/parser/button_character_def.cpp' => 
'libcore/swf/DefineButtonTag.cpp'
--- a/libcore/parser/button_character_def.cpp   2008-11-07 10:57:43 +0000
+++ b/libcore/swf/DefineButtonTag.cpp   2008-11-07 16:14:21 +0000
@@ -1,4 +1,4 @@
-// button_character_def.cpp:  Mouse-sensitive SWF buttons, for Gnash.
+// DefineButtonTag.cpp:  Mouse-sensitive SWF buttons, for Gnash.
 //
 //   Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
 //
@@ -21,8 +21,9 @@
 // Based on the public domain work of Thatcher Ulrich <address@hidden> 2003
 
 #include "smart_ptr.h" // GNASH_USE_GC
-#include "button_character_def.h"
+#include "DefineButtonTag.h"
 #include "Button.h" // for create_character_instance()
+#include "DefineButtonCxformTag.h"
 
 #include "SWFStream.h" // for read()
 #include "movie_definition.h"
@@ -31,13 +32,14 @@
 #include "GnashKey.h" // for gnash::key::codeMap
 
 namespace gnash {
-
-//
-// button_action
-//
-
-
-button_action::button_action(SWFStream& in, int tag_type, unsigned long 
endPos, movie_definition& mdef)
+namespace SWF {
+//
+// ButtonAction
+//
+
+
+ButtonAction::ButtonAction(SWFStream& in, int tag_type, unsigned long endPos,
+        movie_definition& mdef)
        :
        m_actions(mdef)
 {
@@ -53,7 +55,8 @@
                if ( in.tell()+2 > endPos ) 
                {
                        IF_VERBOSE_MALFORMED_SWF(
-                       log_swferror(_("Premature end of button action input: 
can't read conditions"));
+                       log_swferror(_("Premature end of button action input: "
+                    "can't read conditions"));
                        );
                        return;
                }
@@ -62,7 +65,8 @@
        }
 
        IF_VERBOSE_PARSE (
-       log_parse(_("   button actions for conditions 0x%x"), m_conditions); // 
@@ need more info about which actions
+           log_parse(_("   button actions for conditions 0x%x"),
+            m_conditions); // @@ need more info about which actions
        );
 
        // Read actions.
@@ -70,7 +74,7 @@
 }
 
 bool
-button_action::triggeredBy(const event_id& ev) const
+ButtonAction::triggeredBy(const event_id& ev) const
 {
        switch ( ev.id() )
        {
@@ -92,11 +96,11 @@
 }
 
 //
-// button_record
+// ButtonRecord
 //
 
 bool
-button_record::is_valid()
+ButtonRecord::is_valid()
 {
        return (m_character_def != NULL);
 }
@@ -113,14 +117,15 @@
 }
 
 bool
-button_record::read(SWFStream& in, int tag_type,
+ButtonRecord::read(SWFStream& in, int tag_type,
                movie_definition& m, unsigned long endPos)
 {
        // caller should check this
        if (in.tell()+1 > endPos)
        {
                IF_VERBOSE_MALFORMED_SWF(
-               log_swferror(_("   premature end of button record input stream, 
can't read flags"));
+               log_swferror(_("   premature end of button record input stream, 
"
+                "can't read flags"));
                );
                return false;
        }
@@ -157,7 +162,7 @@
 
        // If no character with given ID is found in the movie
        // definition, we print an error, but keep parsing.
-       if ( ! m_character_def )
+       if (!m_character_def)
        {
                IF_VERBOSE_MALFORMED_SWF(
                log_swferror(_("   button record for states [%s] refer to "
@@ -169,8 +174,8 @@
        {
                IF_VERBOSE_PARSE(
                log_parse(_("   button record for states [%s] contain "
-                       "character %d (%s)"), computeButtonStatesString(flags), 
m_character_id,
-                       typeName(*m_character_def));
+                       "character %d (%s)"), computeButtonStatesString(flags),
+            m_character_id, typeName(*m_character_def));
                );
        }
 
@@ -201,7 +206,7 @@
                );
        }
 
-       if ( buttonHasBlendMode )
+       if (buttonHasBlendMode)
        {
                in.ensureBytes(1);
         _blendMode = in.read_u8();
@@ -213,24 +218,68 @@
        return true;
 }
 
-
-//
-// button_character_definition
-//
-
-button_character_definition::button_character_definition(movie_definition& m)
+void
+DefineButtonTag::loader(SWFStream& in, tag_type tag, movie_definition& m, 
+            const RunInfo& /*r*/)
+{
+    assert(tag == DEFINEBUTTON);
+    in.ensureBytes(2);
+    int id = in.read_u16();
+
+    IF_VERBOSE_PARSE(
+        log_parse(_("  DefineButton loader: chararacter id = %d"), id);
+    );
+
+    std::auto_ptr<DefineButtonTag> bt(new DefineButtonTag(in, m, tag));
+
+    m.add_character(id, bt.release());
+}
+
+void
+DefineButton2Tag::loader(SWFStream& in, tag_type tag, movie_definition& m, 
+            const RunInfo& /*r*/)
+{
+    assert(tag == DEFINEBUTTON2);
+    in.ensureBytes(2);
+    int id = in.read_u16();
+
+    IF_VERBOSE_PARSE(
+        log_parse(_("  DefineButton2 loader: chararacter id = %d"), id);
+    );
+
+    std::auto_ptr<DefineButtonTag> bt(new DefineButtonTag(in, m, tag));
+
+    m.add_character(id, bt.release());
+}
+
+//
+// DefineButtonTag
+//
+
+DefineButtonTag::DefineButtonTag(SWFStream& in, movie_definition& m,
+        tag_type tag)
        :
        _soundTag(0),
        _movieDef(m)
-
-// Constructor.
 {
+    switch (tag)
+    {
+        default:
+            std::abort();
+            break;
+        case DEFINEBUTTON:
+            readDefineButtonTag(in, m);
+            break;
+        case DEFINEBUTTON2:
+            readDefineButton2Tag(in, m);
+            break;
+    }
 }
 
-button_character_definition::~button_character_definition()
+DefineButtonTag::~DefineButtonTag()
 {
-       for (ButtonActVect::iterator i=m_button_actions.begin(),
-                       ie=m_button_actions.end();
+       for (ButtonActions::iterator i = _buttonActions.begin(),
+                       ie = _buttonActions.end();
                        i != ie; ++i )
        {
                delete *i;
@@ -239,7 +288,7 @@
 
 
 void
-button_character_definition::readDefineButton(SWFStream& in, movie_definition& 
m)
+DefineButtonTag::readDefineButtonTag(SWFStream& in, movie_definition& m)
 {
 
        // Character ID has been read already
@@ -251,7 +300,7 @@
        // Read button character records.
        for (;;)
        {
-               button_record r;
+               ButtonRecord r;
                if (r.read(in, SWF::DEFINEBUTTON, m, endTagPos) == false)
                {
                        // Null record; marks the end of button records.
@@ -259,10 +308,10 @@
                }
 
                // SAFETY CHECK:
-               // if the button_record is corrupted, discard it
+               // if the ButtonRecord is corrupted, discard it
                if ( r.is_valid() )
                {
-                       m_button_records.push_back(r);
+                       _buttonRecords.push_back(r);
                }
        }
 
@@ -275,26 +324,12 @@
        }
 
        // Read actions.
-       m_button_actions.push_back(new button_action(in, SWF::DEFINEBUTTON, 
endTagPos, m));
-
-}
-
-void
-button_character_definition::readDefineButtonCxform(SWFStream& in, 
movie_definition& /*m*/)
-{
-    // A simple rgb cxform for SWF2 buttons, superseded by DefineButton2.
-    for (ButtonRecVect::iterator i = m_button_records.begin(), e = 
m_button_records.end();
-            i != e; ++i)
-    {
-        (*i).m_button_cxform.read_rgb(in);
-        IF_VERBOSE_PARSE(
-            log_parse("Read DefineButtonCxform: %s", (*i).m_button_cxform);
-        );
-    }
-}
-
-void
-button_character_definition::readDefineButton2(SWFStream& in, 
movie_definition& m)
+       _buttonActions.push_back(new ButtonAction(in, SWF::DEFINEBUTTON, 
endTagPos, m));
+
+}
+
+void
+DefineButtonTag::readDefineButton2Tag(SWFStream& in, movie_definition& m)
 {
        // Character ID has been read already
 
@@ -328,7 +363,7 @@
        // we don't attempt to parse at all unless we have at least 1 byte left
        while ( in.tell() < endOfButtonRecords )
        {
-               button_record   r;
+               ButtonRecord r;
                if (r.read(in, SWF::DEFINEBUTTON2, m, endOfButtonRecords) == 
false)
                {
                        // Null record; marks the end of button records.
@@ -336,10 +371,10 @@
                }
 
                // SAFETY CHECK:
-               // if the button_record is corrupted, discard it
+               // if the ButtonRecord is corrupted, discard it
                if ( r.is_valid() )
                {
-                       m_button_records.push_back(r);
+                       _buttonRecords.push_back(r);
                }
        }
 
@@ -368,7 +403,7 @@
 
                        unsigned long endActionPos = next_action_offset ? 
next_action_pos : tagEndPosition;
 
-                       m_button_actions.push_back(new button_action(in, 
SWF::DEFINEBUTTON2, endActionPos, m));
+                       _buttonActions.push_back(new ButtonAction(in, 
SWF::DEFINEBUTTON2, endActionPos, m));
 
                        if (next_action_offset == 0 )
                        {
@@ -383,51 +418,31 @@
 }
 
 
-
-void
-button_character_definition::read(SWFStream& in, int tag_type, 
movie_definition& m)
-{
-       // Character ID has been read already
-
-       switch (tag_type)
-       {
-               case SWF::DEFINEBUTTON:
-                       readDefineButton(in, m);
-                       break;
-               case SWF::DEFINEBUTTON2:
-                       readDefineButton2(in, m);
-                       break;
-               default:
-                       abort();
-       }
-}
-
-
 character*
-button_character_definition::create_character_instance(
-               character* parent, int id)
+DefineButtonTag::create_character_instance(character* parent, int id)
 {
        character* ch = new Button(*this, parent, id);
        return ch;
 }
 
 int
-button_character_definition::getSWFVersion() const
+DefineButtonTag::getSWFVersion() const
 {
        return _movieDef.get_version();
 }
 
 bool
-button_character_definition::hasKeyPressHandler() const
+DefineButtonTag::hasKeyPressHandler() const
 {
-       for (size_t i = 0, e = m_button_actions.size(); i < e; ++i)
+       for (size_t i = 0, e = _buttonActions.size(); i < e; ++i)
        {
-               const button_action& ba = *(m_button_actions[i]);
+               const ButtonAction& ba = *(_buttonActions[i]);
                if ( ba.triggeredByKeyPress() ) return true;
        }
        return false;
 }
 
+} // namespace SWF
 } // namespace gnash
 
 // Local Variables:

=== renamed file 'libcore/parser/button_character_def.h' => 
'libcore/swf/DefineButtonTag.h'
--- a/libcore/parser/button_character_def.h     2008-11-07 10:57:43 +0000
+++ b/libcore/swf/DefineButtonTag.h     2008-11-07 16:14:21 +0000
@@ -17,9 +17,8 @@
 //
 
 
-
-#ifndef GNASH_BUTTON_CHARACTER_DEF_H
-#define GNASH_BUTTON_CHARACTER_DEF_H
+#ifndef GNASH_SWF_DEFINEBUTTONTAG_H
+#define GNASH_SWF_DEFINEBUTTONTAG_H
 
 #include "smart_ptr.h" // GNASH_USE_GC
 #include "character_def.h"
@@ -27,7 +26,7 @@
 #include "rect.h" // for get_bound
 #include "SWFMatrix.h" // for composition
 #include "cxform.h" // for composition
-#include "action_buffer.h" // for composition of button_action
+#include "action_buffer.h" // for composition of ButtonAction
 #include "filter_factory.h" // for Filters (composition of button_record)
 #include "sound_handler.h" // for sound_handler::sound_envelope in a vector..
 #include "DefineButtonSoundTag.h"
@@ -45,8 +44,11 @@
 }
 
 namespace gnash {
-
-class button_record
+namespace SWF {
+
+
+/// A class for parsing ButtonRecord, used by DefineButton and DefineButton2
+class ButtonRecord
 {
 
 private:
@@ -84,7 +86,7 @@
 
 public:
 
-       button_record()
+       ButtonRecord()
                :
                m_character_def(0)
        {
@@ -120,7 +122,8 @@
 
 };
        
-class button_action
+/// A class for parsing an ActionRecord.
+class ButtonAction
 {
 public:
 
@@ -134,7 +137,7 @@
        ///     The movie_definition this button action was read from
        ///
        ///
-       button_action(SWFStream& in, int tag_type, unsigned long endPos,
+       ButtonAction(SWFStream& in, int tag_type, unsigned long endPos,
             movie_definition& mdef);
 
        /// Return true if this action should be triggered by the given event.
@@ -143,7 +146,7 @@
        /// Return true if this action is triggered by a keypress
        bool triggeredByKeyPress() const
        {
-               return m_conditions&KEYPRESS;
+               return (m_conditions & KEYPRESS);
        }
 
 private:
@@ -154,7 +157,7 @@
        ///
        int getKeyCode() const
        {
-               return (m_conditions&KEYPRESS) >> 9;
+               return (m_conditions & KEYPRESS) >> 9;
        }
 
        enum condition
@@ -174,52 +177,51 @@
 
 };
 
-
-class button_character_definition : public character_def
+/// A class for parsing DefineButton and DefineButton2 tags.
+class DefineButtonTag : public character_def
 {
 public:
 
-
-       /// \brief
-       /// Construct a character definition as read from
-       /// the given movie_definition (SWF)
-       button_character_definition(movie_definition& m);
-
-       virtual ~button_character_definition();
+    /// Load a DefineButtonTag.
+    static void loader(SWFStream& in, tag_type tag, movie_definition& m, 
+            const RunInfo& r);
+
+       typedef std::vector<ButtonRecord> ButtonRecords; 
+       typedef std::vector<ButtonAction*> ButtonActions;
+
+       /// Construct a DefineButtonTag (DefinitionTag) (SWF)
+       DefineButtonTag(SWFStream& in, movie_definition& m, tag_type tag);
+
+       virtual ~DefineButtonTag();
 
        /// Create a mutable instance of our definition.
        character* create_character_instance(character* parent, int id);
 
-       /// Read a SWF::DEFINEBUTTON, SWF::DEFINEBUTTONSOUND or 
SWF::DEFINEBUTTON2
-       void    read(SWFStream& in, int tag_type, movie_definition& m);
-
-       /// Read a SWF::DEFINEBUTTON tag
-       void    readDefineButton(SWFStream& in, movie_definition& m);
-
-       /// Read a SWF::DEFINEBUTTON2 tag
-       void    readDefineButton2(SWFStream& in, movie_definition& m);
-
-       /// Read a SWF::DEFINEBUTTONCXFORM tag
-       void readDefineButtonCxform(SWFStream& in, movie_definition& m);
-       
        const rect&     get_bound() const {
-               // It is required that get_bound() is implemented in character 
definition
-               // classes. However, button character definitions do not have 
shape 
-               // definitions themselves. Instead, they hold a list of 
shape_character_def.
-               // get_bound() is currently only used by generic_character 
which normally
-               // is used only shape character definitions. See 
character_def.h to learn
-               // why it is virtual anyway.
+               // It is required that get_bound() is implemented in character
+        // definition classes. However, button character definitions do
+        // not have shape definitions themselves. Instead, they hold a list
+        // of shape_character_def. get_bound() is currently only used
+        // by generic_character which normally is used only shape character
+        // definitions. See character_def.h to learn why it is virtual anyway.
                // get_button_bound() is used for buttons.
                abort(); // should not be called  
                static rect unused;
                return unused;
        }
   
+    /// Access the ButtonRecords directly. Used for modifying the
+    /// Cxform by a DefineButtonCxform tag.
+    ButtonRecords& buttonRecords() { return _buttonRecords; }
 
     /// Does this button have an associated DefineButtonSoundTag?
     bool hasSound() const { return (_soundTag.get()); }
 
+    /// Add a DefineButtonSoundTag to the button. This should not be
+    /// done twice, so check hasSound() first.
     void addSoundTag(std::auto_ptr<SWF::DefineButtonSoundTag> soundTag) {
+        // Do not replace a sound tag.
+        assert(!_soundTag.get());
         _soundTag.reset(soundTag.release());
     }
 
@@ -227,7 +229,7 @@
     //
     /// @param index    The sound index (0-3) to get.
     /// Do not call this function without checking hasSound() first.
-    const SWF::DefineButtonSoundTag::ButtonSound& buttonSound(size_t index) 
const {
+    const DefineButtonSoundTag::ButtonSound& buttonSound(size_t index) const {
         assert(_soundTag.get());
         return _soundTag->getSound(index);
     }
@@ -247,9 +249,9 @@
        template <class E>
        void forEachTrigger(const event_id& ev, E& f) const
        {
-               for (size_t i = 0, e = m_button_actions.size(); i < e; ++i)
+               for (size_t i = 0, e = _buttonActions.size(); i < e; ++i)
                {
-                       const button_action& ba = *(m_button_actions[i]);
+                       const ButtonAction& ba = *(_buttonActions[i]);
                        if ( ba.triggeredBy(ev) ) f(ba.m_actions);
                }
        }
@@ -266,8 +268,8 @@
        void markReachableResources() const
        {
                assert(isReachable());
-               for (ButtonRecVect::const_iterator i=m_button_records.begin(),
-                e=m_button_records.end(); i!=e; ++i)
+               for (ButtonRecords::const_iterator i = _buttonRecords.begin(),
+                e = _buttonRecords.end(); i!=e; ++i)
                {
                        i->markReachableResources();
                }
@@ -276,17 +278,19 @@
        }
 #endif // GNASH_USE_GC
 
-public: // TODO: make private
-
-       typedef std::vector<button_record> ButtonRecVect; 
-       ButtonRecVect m_button_records;
-
-       boost::scoped_ptr<SWF::DefineButtonSoundTag> _soundTag;
 
 private:
 
-       typedef std::vector<button_action*> ButtonActVect;
-       ButtonActVect m_button_actions;
+       /// Read a DEFINEBUTTON tag
+       void readDefineButtonTag(SWFStream& in, movie_definition& m);
+
+       /// Read a DEFINEBUTTON2 tag
+       void readDefineButton2Tag(SWFStream& in, movie_definition& m);
+
+    boost::scoped_ptr<SWF::DefineButtonSoundTag> _soundTag;
+
+       ButtonRecords _buttonRecords;
+       ButtonActions _buttonActions;
 
        /// Currently set but unused (and also unaccessible)
        bool m_menu;
@@ -295,6 +299,19 @@
        movie_definition& _movieDef;
 };
 
+/// A class for parsing a DefineButton2 tag.
+//
+/// This only contains a loader because a DefineButton2Tag uses the same
+/// code as DefineButtonTag with minor modifications. 
+class DefineButton2Tag
+{
+public:
+    /// Load a DefineButton2 tag.
+    static void loader(SWFStream& in, tag_type tag, movie_definition& m, 
+            const RunInfo& r);
+};
+
+}
 }      // end namespace gnash
 
 

=== modified file 'libcore/swf/tag_loaders.cpp'
--- a/libcore/swf/tag_loaders.cpp       2008-11-07 10:57:43 +0000
+++ b/libcore/swf/tag_loaders.cpp       2008-11-07 16:05:23 +0000
@@ -30,7 +30,6 @@
 #include "utility.h"
 #include "action.h"
 #include "action_buffer.h"
-#include "button_character_def.h"
 #include "font.h"
 #include "fontlib.h"
 #include "log.h"
@@ -59,6 +58,7 @@
 #include "gnash.h" // FileType enum
 #include "MediaHandler.h"
 #include "SimpleBuffer.h"
+#include "sound_handler.h"
 
 #ifdef HAVE_ZLIB_H
 #include <zlib.h>
@@ -945,26 +945,6 @@
 // end_tag doesn't actually need to exist.
 
 
-void button_character_loader(SWFStream& in, tag_type tag, movie_definition& m,
-               const RunInfo& /*r*/)
-{
-    // 7 || 34
-    assert(tag == SWF::DEFINEBUTTON || tag == SWF::DEFINEBUTTON2);
-
-    in.ensureBytes(2);
-    int    character_id = in.read_u16();
-
-    IF_VERBOSE_PARSE(
-        log_parse(_("  button character loader: char_id = %d"), character_id);
-    );
-
-    button_character_definition* ch = new button_character_definition(m);
-    ch->read(in, tag, m);
-
-    m.add_character(character_id, ch);
-}
-
-
 //
 // export
 //

=== modified file 'libcore/swf/tag_loaders.h'
--- a/libcore/swf/tag_loaders.h 2008-11-07 10:57:43 +0000
+++ b/libcore/swf/tag_loaders.h 2008-11-07 16:05:23 +0000
@@ -124,9 +124,6 @@
 
 void do_action_loader(SWFStream&, tag_type, movie_definition&, const RunInfo&);
 
-void button_character_loader(SWFStream&, tag_type, movie_definition&,
-               const RunInfo&);
-
 /// Label the current frame  (SWF::FRAMELABEL)
 void frame_label_loader(SWFStream&, tag_type, movie_definition&,
                const RunInfo&);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]