gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/movie_root.cpp server/mo...


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog server/movie_root.cpp server/mo...
Date: Tue, 29 Apr 2008 08:53:37 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/04/29 08:53:37

Modified files:
        .              : ChangeLog 
        server         : movie_root.cpp movie_root.h 
        gui            : gui.cpp 
        server/asobj   : Stage.cpp Stage.h 
        testsuite/actionscript.all: ASnative.as 

Log message:
                * server/asobj/Stage.{cpp,h}: drop methods from Stage class,
                  implement in movie_root instead. Fixes using ASnative before
                  Stage has been initialised on demand.
                * server/movie_root.{cpp,h}: implement displayState, alignMode
                  here.
                * testsuite/actionscript.all/ASnative.as: test Stage ASnative
                  methods, new tests pass with this commit.
                * gui/gui.cpp: movie_root function name change (getScaleMode ->
                  getStageScaleMode).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6437&r2=1.6438
http://cvs.savannah.gnu.org/viewcvs/gnash/server/movie_root.cpp?cvsroot=gnash&r1=1.188&r2=1.189
http://cvs.savannah.gnu.org/viewcvs/gnash/server/movie_root.h?cvsroot=gnash&r1=1.127&r2=1.128
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gui.cpp?cvsroot=gnash&r1=1.164&r2=1.165
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Stage.cpp?cvsroot=gnash&r1=1.44&r2=1.45
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Stage.h?cvsroot=gnash&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/ASnative.as?cvsroot=gnash&r1=1.6&r2=1.7

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6437
retrieving revision 1.6438
diff -u -b -r1.6437 -r1.6438
--- ChangeLog   29 Apr 2008 06:10:01 -0000      1.6437
+++ ChangeLog   29 Apr 2008 08:53:35 -0000      1.6438
@@ -1,3 +1,15 @@
+2008-04-29 Benjamin Wolsey <address@hidden>
+
+       * server/asobj/Stage.{cpp,h}: drop methods from Stage class,
+         implement in movie_root instead. Fixes using ASnative before
+         Stage has been initialised on demand.
+       * server/movie_root.{cpp,h}: implement displayState, alignMode
+         here.
+       * testsuite/actionscript.all/ASnative.as: test Stage ASnative
+         methods, new tests pass with this commit.
+       * gui/gui.cpp: movie_root function name change (getScaleMode ->
+         getStageScaleMode).
+
 2008-04-29 Sandro Santilli <address@hidden>
 
        * testsuite/actionscript.all/MovieClip.as: test influence

Index: server/movie_root.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/movie_root.cpp,v
retrieving revision 1.188
retrieving revision 1.189
diff -u -b -r1.188 -r1.189
--- server/movie_root.cpp       24 Apr 2008 08:02:38 -0000      1.188
+++ server/movie_root.cpp       29 Apr 2008 08:53:36 -0000      1.189
@@ -93,9 +93,9 @@
        _disableScripts(false),
        _processingActionLevel(movie_root::apSIZE),
        _hostfd(-1),
-       _valign(STAGE_V_ALIGN_C),
-       _halign(STAGE_H_ALIGN_C),
-       _scaleMode(showAll)
+       _alignMode(0),
+       _scaleMode(showAll),
+       _displayState(normal)
 {
 }
 
@@ -962,27 +962,6 @@
        dragChar->set_matrix(local);
 }
 
-/// Get current viewport width, in pixels
-unsigned int
-movie_root::getStageWidth() const
-{
-    if (_scaleMode == noScale)
-    {
-        return m_viewport_width;    
-    }
-    return static_cast<unsigned 
int>(get_movie_definition()->get_width_pixels());
-}
-
-/// Get current viewport height, in pixels
-unsigned int
-movie_root::getStageHeight() const
-{
-    if (_scaleMode == noScale)
-    {
-        return m_viewport_height;    
-    }
-    return static_cast<unsigned 
int>(get_movie_definition()->get_height_pixels());
-}
 
 unsigned int
 movie_root::add_interval_timer(std::auto_ptr<Timer> timer, bool internal)
@@ -1304,29 +1283,78 @@
        return true;
 }
 
+/// Get actionscript width of stage, in pixels. The width
+/// returned depends on the scale mode.
+unsigned int
+movie_root::getStageWidth() const
+{
+    if (_scaleMode == noScale)
+    {
+        return m_viewport_width;    
+    }
 
-void
-movie_root::setStageAlignment(StageHorizontalAlign h, StageVerticalAlign v)
+    // If scaling is allowed, always return the original movie size.
+    return static_cast<unsigned 
int>(get_movie_definition()->get_width_pixels());
+}
+
+/// Get actionscript height of stage, in pixels. The height
+/// returned depends on the scale mode.
+unsigned int
+movie_root::getStageHeight() const
 {
-    if ( _valign == v && _halign == h ) return; // nothing to do
+    if (_scaleMode == noScale)
+    {
+        return m_viewport_height;    
+    }
 
-    _valign = v;
-    _halign = h;
-    //log_debug("valign: %d, halign: %d", _valign, _halign);
+    // If scaling is allowed, always return the original movie size.
+    return static_cast<unsigned 
int>(get_movie_definition()->get_height_pixels());
+}
     
+/// Takes a short int bitfield: the four bits correspond
+/// to the AlignMode enum 
+void
+movie_root::setStageAlignment(short s)
+{
+    _alignMode = s;
     if (interfaceHandle) (*interfaceHandle)("Stage.align", "");
 }
 
-
+/// Returns a pair of enum values giving the actual alignment
+/// of the stage after align mode flags are evaluated.
 movie_root::StageAlign
 movie_root::getStageAlignment() const
 {
-    return std::make_pair(_halign, _valign);
+
+    /// L takes precedence over R. Default is centred.
+    StageHorizontalAlign ha = STAGE_H_ALIGN_C;
+    if (_alignMode.test(STAGE_ALIGN_L)) ha = STAGE_H_ALIGN_L;
+    else if (_alignMode.test(STAGE_ALIGN_R)) ha = STAGE_H_ALIGN_R;
+
+    /// T takes precedence over B. Default is centred.
+    StageVerticalAlign va = STAGE_V_ALIGN_C;
+    if (_alignMode.test(STAGE_ALIGN_T)) va = STAGE_V_ALIGN_T;
+    else if (_alignMode.test(STAGE_ALIGN_B)) va = STAGE_V_ALIGN_B;
+
+    return std::make_pair(ha, va);
 }
 
+/// Returns the string representation of the current align mode,
+/// which must always be in the order: LTRB
+std::string
+movie_root::getStageAlignMode() const
+{
+    std::string align;
+    if (_alignMode.test(STAGE_ALIGN_L)) align.push_back('L');
+    if (_alignMode.test(STAGE_ALIGN_T)) align.push_back('T');
+    if (_alignMode.test(STAGE_ALIGN_R)) align.push_back('R');
+    if (_alignMode.test(STAGE_ALIGN_B)) align.push_back('B');
+    
+    return align;
+}
 
 void
-movie_root::setScaleMode(ScaleMode sm)
+movie_root::setStageScaleMode(ScaleMode sm)
 {
     if ( _scaleMode == sm ) return; // nothing to do
 
@@ -1357,6 +1385,22 @@
     }
 }
 
+void
+movie_root::setStageDisplayState(const DisplayState ds)
+{
+    _displayState = ds;
+
+       if (!movie_root::interfaceHandle) return; // No registered callback
+       
+       if (_displayState == fullScreen)
+       {
+           (*movie_root::interfaceHandle)("Stage.displayState", "fullScreen");
+       }
+       else if (_displayState == normal)
+       {
+           (*movie_root::interfaceHandle)("Stage.displayState", "normal");
+       }   
+}
 
 void
 movie_root::add_invalidated_bounds(InvalidatedRanges& ranges, bool force)

Index: server/movie_root.h
===================================================================
RCS file: /sources/gnash/gnash/server/movie_root.h,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -b -r1.127 -r1.128
--- server/movie_root.h 24 Apr 2008 08:02:38 -0000      1.127
+++ server/movie_root.h 29 Apr 2008 08:53:36 -0000      1.128
@@ -94,6 +94,7 @@
 #include <vector>
 #include <list>
 #include <set>
+#include <bitset>
 
 // Forward declarations
 namespace gnash {
@@ -492,6 +493,12 @@
 
     bool testInvariant() const;
 
+    /// enum for the values of Stage.displayState
+    enum DisplayState {
+               normal,
+               fullScreen
+       };
+
     /// enum for the values of Stage.scaleMode
     enum ScaleMode {
         showAll,
@@ -514,9 +521,16 @@
         STAGE_V_ALIGN_B
     };
 
+    enum AlignMode {
+        STAGE_ALIGN_L,
+        STAGE_ALIGN_T,
+        STAGE_ALIGN_R,
+        STAGE_ALIGN_B
+    };
+
     /// Sets movie_root's horizontal and vertical alignment to one
     /// of the three possible positions for each dimension.
-    void setStageAlignment(StageHorizontalAlign v, StageVerticalAlign h);
+    void setStageAlignment(short s);
 
     typedef std::pair<StageHorizontalAlign, StageVerticalAlign> StageAlign;
 
@@ -525,10 +539,19 @@
     StageAlign getStageAlignment() const;
 
     /// Sets the Stage object's align mode.
-    void setScaleMode(ScaleMode sm);
+    void setStageScaleMode(ScaleMode sm);
     
     /// Returns the Stage object's align mode.
-    ScaleMode getScaleMode() const { return _scaleMode; }
+    ScaleMode getStageScaleMode() const { return _scaleMode; }
+
+    // The string representation of the current align mode.
+    std::string getStageAlignMode() const;
+
+    /// Returns the Stage object's align mode.
+    DisplayState getStageDisplayState() const { return _displayState; }
+
+    // The string representation of the current align mode.
+    void setStageDisplayState(const DisplayState ds);
 
     /// Action priority levels
     enum ActionPriorityLevel {
@@ -991,10 +1014,11 @@
     ///
     int _hostfd;
     
-    StageVerticalAlign _valign;
-    StageHorizontalAlign _halign;
+    std::bitset<4> _alignMode;
     
     ScaleMode _scaleMode;
+    
+    DisplayState _displayState;
 };
 
 

Index: gui/gui.cpp
===================================================================
RCS file: /sources/gnash/gnash/gui/gui.cpp,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -b -r1.164 -r1.165
--- gui/gui.cpp 27 Apr 2008 15:39:39 -0000      1.164
+++ gui/gui.cpp 29 Apr 2008 08:53:36 -0000      1.165
@@ -237,7 +237,7 @@
        float swfheight = _movieDef->get_height_pixels();
 
        // Fetch scale mode
-       movie_root::ScaleMode scaleMode = _stage->getScaleMode();
+       movie_root::ScaleMode scaleMode = _stage->getStageScaleMode();
        switch (scaleMode)
        {
                case movie_root::noScale:

Index: server/asobj/Stage.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Stage.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- server/asobj/Stage.cpp      25 Apr 2008 15:28:53 -0000      1.44
+++ server/asobj/Stage.cpp      29 Apr 2008 08:53:36 -0000      1.45
@@ -45,7 +45,7 @@
 static as_value stage_height_getset(const fn_call& fn);
 static as_value stage_displaystate_getset(const fn_call& fn);
 static const char* getScaleModeString(movie_root::ScaleMode sm);
-static const char* getDisplayStateString(Stage::DisplayState ds);
+static const char* getDisplayStateString(movie_root::DisplayState ds);
 
 void registerStageNative(as_object& o)
 {
@@ -101,9 +101,7 @@
 
 Stage::Stage()
        :
-       as_object(getObjectInterface()),
-       _alignMode(""),
-       _displayState(normal)
+       as_object(getObjectInterface())
 {
        attachStageInterface(*this);
 
@@ -134,69 +132,8 @@
 }
 
 
-void
-Stage::setDisplayState(DisplayState state)
-{
-       if ( _displayState == state ) return; // nothing to do
-
-       _displayState = state;
-       
-       if (!movie_root::interfaceHandle) return; // No registered callback
-       
-       if (_displayState == Stage::fullScreen)
-       {
-           (*movie_root::interfaceHandle)("Stage.displayState", "fullScreen");
-       }
-       else if (_displayState == Stage::normal)
-       {
-           (*movie_root::interfaceHandle)("Stage.displayState", "normal");
-       }
-
-}
-
-
-void
-Stage::setAlignMode(const std::string& mode)
-{
-    if (_alignMode == mode) return;
-
-    _alignMode = mode;
-    
-    movie_root::StageVerticalAlign v = movie_root::STAGE_V_ALIGN_C;
-    movie_root::StageHorizontalAlign h = movie_root::STAGE_H_ALIGN_C;
-
-    // Order: LTRB. L and T take precedence.
-
-    for (std::string::const_reverse_iterator it = _alignMode.rbegin(),
-         e = _alignMode.rend();
-         it != e;
-         ++it)
-    {
-        switch (*it)
-        {
-            case 'R':
-                h = movie_root::STAGE_H_ALIGN_R;
-                break;
-            case 'L':
-                h = movie_root::STAGE_H_ALIGN_L;
-                break;
-            case 'B':
-                v = movie_root::STAGE_V_ALIGN_B;
-                break;
-            case 'T':
-                v = movie_root::STAGE_V_ALIGN_T;
-                break;
-        }
-    }
-
-    movie_root& m = VM::get().getRoot();
-    m.setStageAlignment(h, v);   
-
-}
-
-
 const char*
-getDisplayStateString(Stage::DisplayState ds)
+getDisplayStateString(movie_root::DisplayState ds)
 {
        static const char* displayStateName[] = {
                "normal",
@@ -226,10 +163,11 @@
 
        if ( fn.nargs == 0 ) // getter
        {
-               return as_value(getScaleModeString(m.getScaleMode()));
+               return as_value(getScaleModeString(m.getStageScaleMode()));
        }
        else // setter
        {
+           // Defaults to showAll if the string is invalid.
                movie_root::ScaleMode mode = movie_root::showAll;
 
                const std::string& str = fn.arg(0).to_string();
@@ -242,9 +180,9 @@
 
         movie_root& m = VM::get().getRoot();
 
-        if ( m.getScaleMode() == mode ) return as_value(); // nothing to do
+        if ( m.getStageScaleMode() == mode ) return as_value(); // nothing to 
do
 
-           m.setScaleMode(mode);
+           m.setStageScaleMode(mode);
                return as_value();
        }
 }
@@ -252,8 +190,6 @@
 as_value
 stage_width_getset(const fn_call& fn)
 {
-       boost::intrusive_ptr<Stage> stage = ensureType<Stage>(fn.this_ptr);
-       UNUSED(stage);
 
        if ( fn.nargs > 0 ) // setter
        {
@@ -271,8 +207,6 @@
 as_value
 stage_height_getset(const fn_call& fn)
 {
-       boost::intrusive_ptr<Stage> stage = ensureType<Stage>(fn.this_ptr);
-       UNUSED(stage);
 
        if ( fn.nargs > 0 ) // setter
        {
@@ -291,39 +225,40 @@
 as_value
 stage_align_getset(const fn_call& fn)
 {
-       boost::intrusive_ptr<Stage> stage = ensureType<Stage>(fn.this_ptr);
+    movie_root& m = VM::get().getRoot();
 
        if ( fn.nargs == 0 ) // getter
        {
-           return as_value (stage->getAlignMode());
+           return as_value (m.getStageAlignMode());
        }
        else // setter
        {
-
                const std::string& str = fn.arg(0).to_string();
-        std::string alignMode;
+        short am = 0;
 
+        // Easy enough to do bitwise - std::bitset is not
+        // really necessary!
         if (str.find_first_of("lL") != std::string::npos)
         {
-            alignMode.push_back('L');
+            am |= 1 << movie_root::STAGE_ALIGN_L;
         } 
 
         if (str.find_first_of("tT") != std::string::npos)
         {
-            alignMode.push_back('T');
+            am |= 1 << movie_root::STAGE_ALIGN_T;
         } 
 
         if (str.find_first_of("rR") != std::string::npos)
         {
-            alignMode.push_back('R');
+            am |= 1 << movie_root::STAGE_ALIGN_R;
         } 
     
         if (str.find_first_of("bB") != std::string::npos)
         {
-            alignMode.push_back('B');
+            am |= 1 << movie_root::STAGE_ALIGN_B;
         }
 
-        stage->setAlignMode(alignMode);
+        m.setStageAlignment(am);
 
                return as_value();
        }
@@ -336,20 +271,12 @@
 
        if ( fn.nargs == 0 ) // getter
        {
-               static bool warned = false;
-               if ( ! warned ) {
-                       log_unimpl("Stage.showMenu getter");
-                       warned=true;
-               }
+               LOG_ONCE(log_unimpl("Stage.showMenu getter"));
                return as_value();
        }
        else // setter
        {
-               static bool warned = false;
-               if ( ! warned ) {
-                       log_unimpl("Stage.showMenu setter");
-                       warned=true;
-               }
+               LOG_ONCE(log_unimpl("Stage.showMenu setter"));
                return as_value();
        }
 }
@@ -357,11 +284,12 @@
 as_value
 stage_displaystate_getset(const fn_call& fn)
 {
-       boost::intrusive_ptr<Stage> stage = ensureType<Stage>(fn.this_ptr);
+
+    movie_root& m = VM::get().getRoot();
 
        if ( fn.nargs == 0 ) // getter
        {
-               return 
as_value(getDisplayStateString(stage->getDisplayState()));
+               return 
as_value(getDisplayStateString(m.getStageDisplayState()));
        }
        else // setter
        {
@@ -371,11 +299,11 @@
                const std::string& str = fn.arg(0).to_string();
                if ( noCaseCompare(str, "normal") )
                {
-                   stage->setDisplayState(Stage::normal);
+                   m.setStageDisplayState(movie_root::normal);
                }
                else if ( noCaseCompare(str, "fullScreen") ) 
                {
-                   stage->setDisplayState(Stage::fullScreen);
+                   m.setStageDisplayState(movie_root::fullScreen);
         }
 
         // If invalid, do nothing.

Index: server/asobj/Stage.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Stage.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- server/asobj/Stage.h        25 Apr 2008 15:28:53 -0000      1.21
+++ server/asobj/Stage.h        29 Apr 2008 08:53:36 -0000      1.22
@@ -35,17 +35,19 @@
 /// - scaleMode
 /// - width
 /// - height
+/// - displayState
+/// - alignMode
+//
+/// Most functions are ASnative, which means they cannot rely on
+/// the existence of a load-on-demand Stage object. Only resize events
+/// appear to need this (not ASnative). The ASnative functions
+/// are available from SWF5
 
 class Stage: public as_object
 {
 
 public:
     
-    enum DisplayState {
-               normal,
-               fullScreen
-       };
-
        Stage();
        
        /// Receive a resize event.
@@ -54,23 +56,6 @@
        /// Notify all listeners about a resize event
        void notifyResize();
 
-    /// Get present align mode
-    const std::string& getAlignMode() const { return _alignMode; }
-
-    /// Set align mode
-    void setAlignMode(const std::string& mode);
-
-       /// Set display state 
-       void setDisplayState(DisplayState state);
-
-       /// Set display state 
-       DisplayState getDisplayState() const { return _displayState; }
-
-private:
-
-       std::string _alignMode;
-       
-       DisplayState _displayState;
 };
 
 /// Register native functions with the VM.

Index: testsuite/actionscript.all/ASnative.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/ASnative.as,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- testsuite/actionscript.all/ASnative.as      20 Apr 2008 17:53:58 -0000      
1.6
+++ testsuite/actionscript.all/ASnative.as      29 Apr 2008 08:53:37 -0000      
1.7
@@ -15,7 +15,7 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-rcsid="$Id: ASnative.as,v 1.6 2008/04/20 17:53:58 bwy Exp $";
+rcsid="$Id: ASnative.as,v 1.7 2008/04/29 08:53:37 bwy Exp $";
 #include "check.as"
 
 a = ASnative (100, 0); // escape
@@ -195,6 +195,34 @@
 func.a = ASnative(102, 1); // SWF5 to lower
 xcheck_equals(func.a(), "gnash must work! öÜäÄ€€");
 
+// Stage
+st = ASnative(666, 2);
+st("exactFit");
+st = ASnative(666, 1);
+check_equals (st(), "exactFit");
+
+st = ASnative(666, 4);
+st("BRL");
+
+st = ASnative(666, 3);
+check_equals (st(), "LRB");
+
+//Stage.width - read only!
+st = ASnative(666, 6);
+st(402);
+st = ASnative(666, 5);
+check_equals (st(), 640);
+
+// Stage.height - read only!
+st = ASnative(666, 8);
+st(402);
+st = ASnative(666, 7);
+check_equals (st(), 480);
+
+// Stage.showMenu
+st = ASnative(666, 10);
+st = ASnative(666, 9);
+
 #if OUTPUT_VERSION > 5
 xcheck_equals (countTS, 4);
 #else
@@ -204,7 +232,7 @@
 xcheck_equals (countVO, 25);
 
 #if OUTPUT_VERSION > 5
-check_totals(70);
+check_totals(74);
 #else
-check_totals(68);
+check_totals(72);
 #endif




reply via email to

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