gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9797: Working but *not sufficiently


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9797: Working but *not sufficiently tested* implementation of MovieClip.transform
Date: Sat, 20 Sep 2008 11:25:29 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9797
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sat 2008-09-20 11:25:29 +0200
message:
  Working but *not sufficiently tested* implementation of MovieClip.transform
  and flash.geom.Transform.matrix getter. This is for testing of the internal
  matrix.
  
  Implementing the setter should be very easy.
modified:
  libcore/asobj/flash/display/BitmapData_as.cpp
  libcore/asobj/flash/geom/Transform_as.cpp
  libcore/sprite_instance.cpp
    ------------------------------------------------------------
    revno: 9795.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Sat 2008-09-20 11:19:09 +0200
    message:
      Return undefined on invalid ctor. Should probably implement a throw so
      that the object isn't constructed.
    modified:
      libcore/asobj/flash/display/BitmapData_as.cpp
    ------------------------------------------------------------
    revno: 9795.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Sat 2008-09-20 11:20:31 +0200
    message:
      Construct a flash.geom.Transform with 'this' as argument for
      MovieClip.transform.
    modified:
      libcore/sprite_instance.cpp
    ------------------------------------------------------------
    revno: 9795.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Sat 2008-09-20 11:21:17 +0200
    message:
      Hold reference to MovieClip (sprite_instance), use to construct properties
      on demand.
    modified:
      libcore/asobj/flash/geom/Transform_as.cpp
=== modified file 'libcore/asobj/flash/display/BitmapData_as.cpp'
--- a/libcore/asobj/flash/display/BitmapData_as.cpp     2008-07-25 13:09:58 
+0000
+++ b/libcore/asobj/flash/display/BitmapData_as.cpp     2008-09-20 09:19:09 
+0000
@@ -581,8 +581,7 @@
        if ( fn.nargs < 2)
        {
            // TODO: should fail if not enough arguments are passed.
-               boost::intrusive_ptr<as_object> obj = new as_object;
-        return as_value(obj.get());
+        return as_value();
        }
 
     size_t width, height;

=== modified file 'libcore/asobj/flash/geom/Transform_as.cpp'
--- a/libcore/asobj/flash/geom/Transform_as.cpp 2008-05-07 09:38:06 +0000
+++ b/libcore/asobj/flash/geom/Transform_as.cpp 2008-09-20 09:21:17 +0000
@@ -30,6 +30,7 @@
 #include "GnashException.h" // for ActionException
 #include "Object.h" // for AS inheritance
 #include "VM.h" // for addStatics
+#include "sprite_instance.h" // For MovieClip
 
 #include <sstream>
 
@@ -47,11 +48,21 @@
 static void
 attachTransformInterface(as_object& o)
 {
-    o.init_property("colorTransform", Transform_colorTransform_getset, 
Transform_colorTransform_getset);
-    o.init_property("concatenatedColorTransform", 
Transform_concatenatedColorTransform_getset, 
Transform_concatenatedColorTransform_getset);
-    o.init_property("concatenatedMatrix", Transform_concatenatedMatrix_getset, 
Transform_concatenatedMatrix_getset);
-    o.init_property("matrix", Transform_matrix_getset, 
Transform_matrix_getset);
-    o.init_property("pixelBounds", Transform_pixelBounds_getset, 
Transform_pixelBounds_getset);
+    o.init_property("colorTransform",
+            Transform_colorTransform_getset,
+            Transform_colorTransform_getset);
+    o.init_property("concatenatedColorTransform",
+            Transform_concatenatedColorTransform_getset,
+            Transform_concatenatedColorTransform_getset);
+    o.init_property("concatenatedMatrix",
+            Transform_concatenatedMatrix_getset,
+            Transform_concatenatedMatrix_getset);
+    o.init_property("matrix",
+            Transform_matrix_getset,
+            Transform_matrix_getset);
+    o.init_property("pixelBounds",
+            Transform_pixelBounds_getset,
+            Transform_pixelBounds_getset);
 }
 
 static void
@@ -84,16 +95,19 @@
 
 public:
 
-       Transform_as()
+       Transform_as(sprite_instance& movieClip)
                :
-               as_object(getTransformInterface())
+               as_object(getTransformInterface()),
+               _movieClip(movieClip)
        {}
 
-       // override from as_object ?
-       //std::string get_text_value() const { return "Transform"; }
-
-       // override from as_object ?
-       //double get_numeric_value() const { return 0; }
+    const matrix& getMatrix() const { return _movieClip.get_matrix(); }
+    const cxform& getColorTransform() const { return _movieClip.get_cxform(); }
+
+private:
+
+    sprite_instance& _movieClip;
+
 };
 
 
@@ -127,10 +141,91 @@
 static as_value
 Transform_matrix_getset(const fn_call& fn)
 {
+
+    // TODO: What happens if you do: "mat = mc.transform.matrix; mat.a = 6;"
+    // (where mc is a MovieClip)? Nothing (probable), or does it change mc (how
+    // would that work?)?
+    // This should work by passing a new matrix, in which case we should just
+    // set our _movieClip's matrix from the AS matrix.
        boost::intrusive_ptr<Transform_as> ptr = 
ensureType<Transform_as>(fn.this_ptr);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
-       return as_value();
+
+    VM& vm = ptr->getVM();
+    string_table& st = vm.getStringTable();
+
+    if (!fn.nargs)
+    {
+
+        // This is silly. Should be easier to do, even if it's necessary
+        // somewhere in the chain to go through all the objects.
+
+        // Getter
+        as_value flash;
+        if (!vm.getGlobal()->get_member(st.find("flash"), &flash))
+        {
+            log_error("No flash object found!");
+            return as_value();
+        }
+        boost::intrusive_ptr<as_object> flashObj = flash.to_object();
+
+        if (!flashObj)
+        {
+            log_error("flash isn't an object!");
+            return as_value();
+        }
+        
+        as_value geom;
+        if (!flashObj->get_member(st.find("geom"), &geom))
+        {
+            log_error("No flash.geom object found!");
+            return as_value();
+        }
+        boost::intrusive_ptr<as_object> geomObj = geom.to_object();
+
+        if (!geomObj)
+        {
+            log_error("flash.geom isn't an object!");
+            return as_value();
+        }
+       
+        as_value matrixVal1;
+        if (!geomObj->get_member(st.find("Matrix"), &matrixVal1))
+        {
+            log_error("No flash.geom.Matrix object found!");
+            return as_value();
+        }
+
+        boost::intrusive_ptr<as_function> matrixCtor = 
matrixVal1.to_as_function();
+        if (!matrixCtor)
+        {
+            log_error("flash.geom.Matrix isn't a function!");
+            return as_value();
+        }
+
+        std::auto_ptr<std::vector<as_value> > args(new std::vector<as_value>);
+        const matrix& m = ptr->getMatrix();
+
+        log_debug("Sprite matrix: %d, %d, %d, %d, %d, %d", m.sx, m.shx
+            , m.sy, m.shy, m.tx, m.ty);
+
+        const double factor = 65536.0;
+
+        args->push_back(m.sx / factor);
+        args->push_back(m.shx / factor);
+        args->push_back(m.shy / factor);
+        args->push_back(m.sy / factor);
+        args->push_back(TWIPS_TO_PIXELS(m.tx));
+        args->push_back(TWIPS_TO_PIXELS(m.ty));                                
+
+        boost::intrusive_ptr<as_object> matrixObj =
+            matrixCtor->constructInstance(fn.env(), args);
+
+        return as_value(matrixObj.get());
+    }
+
+    // Setter
+       LOG_ONCE(log_unimpl("flash.geom.Transform.matrix setter"));
+    return as_value();
+
 }
 
 static as_value
@@ -147,18 +242,54 @@
 as_value
 Transform_ctor(const fn_call& fn)
 {
-       boost::intrusive_ptr<as_object> obj = new Transform_as;
-
-       if ( fn.nargs )
+
+    if (!fn.nargs)
+    {
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Transform constructor: needs one argument", ss.str());
+        );
+        return as_value();
+    }
+
+    // TODO: what about more than one argument? 
+       if (fn.nargs > 1)
        {
                std::stringstream ss;
                fn.dump_args(ss);
                LOG_ONCE( log_unimpl("Transform(%s): %s", ss.str(), 
_("arguments discarded")) );
        }
 
+    boost::intrusive_ptr<sprite_instance> mc = 
ensureType<sprite_instance>(fn.arg(0).to_object());
+
+       boost::intrusive_ptr<as_object> obj = new Transform_as(*mc);
+
+    // We have a movie clip. Do we construct the various properties, or are 
they
+    // constructed on demand?
        return as_value(obj.get()); // will keep alive
 }
 
+as_function* getFlashGeomTransformConstructor()
+{
+    static builtin_function* cl = NULL;
+    if ( ! cl )
+    {
+        cl=new builtin_function(&Transform_ctor, getTransformInterface());
+        VM::get().addStatic(cl);
+        attachTransformStaticProperties(*cl);
+    }
+    return cl;
+}
+
+static as_value
+get_flash_geom_transform_constructor(const fn_call& /*fn*/)
+{
+    log_debug("Loading flash.geom.Transform class");
+
+    return getFlashGeomTransformConstructor();
+}
+
 // extern 
 void Transform_class_init(as_object& where)
 {
@@ -169,7 +300,7 @@
        attachTransformStaticProperties(*cl);
 
        // Register _global.Transform
-       where.init_member("Transform", cl.get());
-}
+    string_table& st = where.getVM().getStringTable();
+    where.init_destructive_property(st.find("Transform"), 
get_flash_geom_transform_constructor);}
 
 } // end of gnash namespace

=== modified file 'libcore/sprite_instance.cpp'
--- a/libcore/sprite_instance.cpp       2008-09-19 13:09:06 +0000
+++ b/libcore/sprite_instance.cpp       2008-09-20 09:20:31 +0000
@@ -57,6 +57,7 @@
 #include "styles.h" // for cap_style_e and join_style_e enums
 #include "PlaceObject2Tag.h" 
 #include "NetStream.h"
+#include "flash/geom/Matrix_as.h"
 
 #ifdef USE_SWFTREE
 # include "tree.hh"
@@ -93,6 +94,8 @@
 static void attachMovieClipInterface(as_object& o);
 static void attachMovieClipProperties(character& o);
 
+static as_value movieClip_transform(const fn_call& fn);
+
 /// Anonymous namespace for module-private definitions
 namespace
 {
@@ -2260,6 +2263,68 @@
     o.init_member("getRect", new builtin_function(sprite_getRect));
     o.init_member("lineGradientStyle", new 
builtin_function(sprite_lineGradientStyle));
 
+    o.init_property("transform", &movieClip_transform, &movieClip_transform); 
// see MovieClip.as testcase
+
+}
+
+as_value
+movieClip_transform(const fn_call& fn)
+{
+    boost::intrusive_ptr<sprite_instance> ptr = 
ensureType<sprite_instance>(fn.this_ptr);
+    
+    VM& vm = ptr->getVM();
+    string_table& st = ptr->getVM().getStringTable();
+
+    as_value flash;
+    if (!vm.getGlobal()->get_member(st.find("flash"), &flash))
+    {
+        log_error("No flash object found!");
+        return as_value();
+    }
+    boost::intrusive_ptr<as_object> flashObj = flash.to_object();
+
+    if (!flashObj)
+    {
+        log_error("flash isn't an object!");
+        return as_value();
+    }
+    
+    as_value geom;
+    if (!flashObj->get_member(st.find("geom"), &geom))
+    {
+        log_error("No flash.geom object found!");
+        return as_value();
+    }
+    boost::intrusive_ptr<as_object> geomObj = geom.to_object();
+
+    if (!geomObj)
+    {
+        log_error("flash.geom isn't an object!");
+        return as_value();
+    }
+    
+    as_value transform;
+    if (!geomObj->get_member(st.find("Transform"), &transform))
+    {
+        log_error("No flash.geom.Transform object found!");
+        return as_value();
+    }    
+
+    boost::intrusive_ptr<as_function> transformCtor = 
transform.to_as_function();
+    if (!transformCtor)
+    {
+        log_error("flash.geom.Transform isn't a function!");
+        return as_value();
+    }
+
+    // Construct a flash.geom.Transform object with "this" as argument.
+    std::auto_ptr< std::vector<as_value> > args (new std::vector<as_value>);
+    args->push_back(ptr.get());
+
+    boost::intrusive_ptr<as_object> transformObj =
+                transformCtor->constructInstance(fn.env(), args);
+
+    return as_value(transformObj.get());
 }
 
 /// Properties (and/or methods) attached to every *instance* of a MovieClip 


reply via email to

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