[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/character.cpp server/cha...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/character.cpp server/cha... |
Date: |
Thu, 12 Apr 2007 16:29:14 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/04/12 16:29:14
Modified files:
. : ChangeLog
server : character.cpp character.h
testsuite/server: MatrixTest.cpp
Log message:
* server/character.{cpp,h}: add set_x_scale and set_y_scale
methods to reduce code messing with matrices. Changed
{x,y}scale_getset and {width,height}_getset to use
these two new functions.
* testsuite/server/MatrixTest.cpp: add a few tests for
set_scale_rotation. I'm not sure the tests are correct
thought, I'd like to hear from Martin about that.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2864&r2=1.2865
http://cvs.savannah.gnu.org/viewcvs/gnash/server/character.cpp?cvsroot=gnash&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/gnash/server/character.h?cvsroot=gnash&r1=1.66&r2=1.67
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/MatrixTest.cpp?cvsroot=gnash&r1=1.4&r2=1.5
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2864
retrieving revision 1.2865
diff -u -b -r1.2864 -r1.2865
--- ChangeLog 12 Apr 2007 11:35:29 -0000 1.2864
+++ ChangeLog 12 Apr 2007 16:29:13 -0000 1.2865
@@ -1,5 +1,15 @@
2007-04-12 Sandro Santilli <address@hidden>
+ * server/character.{cpp,h}: add set_x_scale and set_y_scale
+ methods to reduce code messing with matrices. Changed
+ {x,y}scale_getset and {width,height}_getset to use
+ these two new functions.
+ * testsuite/server/MatrixTest.cpp: add a few tests for
+ set_scale_rotation. I'm not sure the tests are correct
+ thought, I'd like to hear from Martin about that.
+
+2007-04-12 Sandro Santilli <address@hidden>
+
* server/: button_character_instance.{cpp,h},
character.{cpp,h}, edit_text_character.{cpp,h},
generic_character.h, sprite_instance.{cpp,h}:
Index: server/character.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/character.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- server/character.cpp 12 Apr 2007 11:35:30 -0000 1.32
+++ server/character.cpp 12 Apr 2007 16:29:14 -0000 1.33
@@ -18,7 +18,7 @@
//
//
-/* $Id: character.cpp,v 1.32 2007/04/12 11:35:30 strk Exp $ */
+/* $Id: character.cpp,v 1.33 2007/04/12 16:29:14 strk Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -318,15 +318,7 @@
// input is in percent
float scale = (float)scale_percent/100.f;
-
- // Decompose matrix and insert the desired value.
- float x_scale = scale;
- float y_scale = m.get_y_scale();
- float rotation = m.get_rotation();
- m.set_scale_rotation(x_scale, y_scale, rotation);
-
- ptr->set_matrix(m);
- ptr->transformedByScript(); // m_accept_anim_moves = false;
+ ptr->set_x_scale(scale);
}
return rv;
@@ -370,15 +362,7 @@
// input is in percent
float scale = (float)scale_percent/100.f;
-
- // Decompose matrix and insert the desired value.
- float x_scale = m.get_x_scale();
- float y_scale = scale;
- float rotation = m.get_rotation();
- m.set_scale_rotation(x_scale, y_scale, rotation);
-
- ptr->set_matrix(m);
- ptr->transformedByScript(); // m_accept_anim_moves = false;
+ ptr->set_y_scale(scale);
}
return rv;
@@ -486,15 +470,24 @@
}
else // setter
{
- matrix m = ptr->get_matrix();
+ if ( ! bounds.isFinite() )
+ {
+ log_error("FIXME: can't set _width on character with
null or world bounds");
+ return rv;
+ }
- double newwidth = fn.arg(0).to_number(&(fn.env()));
- m.m_[0][0] = infinite_to_fzero(PIXELS_TO_TWIPS(newwidth));
+ double oldwidth = bounds.width();
+ assert(oldwidth>0);
- if ( bounds.isFinite() ) m.m_[0][0] /= bounds.width();
+ double newwidth =
PIXELS_TO_TWIPS(fn.arg(0).to_number(&(fn.env())));
+ if ( newwidth <= 0 )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("Setting _width=%g ?", newwidth/20);
+ );
+ }
- ptr->set_matrix(m);
- ptr->transformedByScript(); // m_accept_anim_moves = false;
+ ptr->set_x_scale(newwidth/oldwidth);
}
return rv;
}
@@ -522,16 +515,26 @@
}
else // setter
{
- matrix m = ptr->get_matrix();
+ if ( ! bounds.isFinite() )
+ {
+ log_error("FIXME: can't set _height on character with
null or world bounds");
+ return rv;
+ }
- double newheight = fn.arg(0).to_number(&(fn.env()));
- m.m_[1][1] = infinite_to_fzero(PIXELS_TO_TWIPS(newheight));
+ double oldheight = bounds.height();
+ assert(oldheight>0);
- if ( bounds.isFinite() ) m.m_[1][1] /= bounds.height();
+ double newheight =
PIXELS_TO_TWIPS(fn.arg(0).to_number(&(fn.env())));
+ if ( newheight <= 0 )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("Setting _height=%g ?", newheight/20);
+ );
+ }
- ptr->set_matrix(m);
- ptr->transformedByScript(); // m_accept_anim_moves = false;
+ ptr->set_y_scale(newheight/oldheight);
}
+
return rv;
}
@@ -710,6 +713,33 @@
return func;
}
+void
+character::set_x_scale(float x_scale)
+{
+ matrix m = get_matrix();
+
+ // Decompose matrix and insert the desired value.
+ float y_scale = m.get_y_scale();
+ float rotation = m.get_rotation();
+ m.set_scale_rotation(x_scale, y_scale, rotation);
+
+ set_matrix(m);
+ transformedByScript(); // m_accept_anim_moves = false;
+}
+
+void
+character::set_y_scale(float y_scale)
+{
+ matrix m = get_matrix();
+
+ // Decompose matrix and insert the desired value.
+ float x_scale = m.get_x_scale();
+ float rotation = m.get_rotation();
+ m.set_scale_rotation(x_scale, y_scale, rotation);
+
+ set_matrix(m);
+ transformedByScript(); // m_accept_anim_moves = false;
+}
} // namespace gnash
Index: server/character.h
===================================================================
RCS file: /sources/gnash/gnash/server/character.h,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -b -r1.66 -r1.67
--- server/character.h 12 Apr 2007 11:35:30 -0000 1.66
+++ server/character.h 12 Apr 2007 16:29:14 -0000 1.67
@@ -18,7 +18,7 @@
//
//
-/* $Id: character.h,v 1.66 2007/04/12 11:35:30 strk Exp $ */
+/* $Id: character.h,v 1.67 2007/04/12 16:29:14 strk Exp $ */
#ifndef GNASH_CHARACTER_H
#define GNASH_CHARACTER_H
@@ -192,28 +192,40 @@
static as_value onmousemove_getset(const fn_call& fn);
#endif
+ /// Getter-setter for _x
static as_value x_getset(const fn_call& fn);
+ /// Getter-setter for _y
static as_value y_getset(const fn_call& fn);
+ /// Getter-setter for _xscale
static as_value xscale_getset(const fn_call& fn);
+ /// Getter-setter for _yscale
static as_value yscale_getset(const fn_call& fn);
+ /// Getter-setter for _xmouse
static as_value xmouse_get(const fn_call& fn);
+ /// Getter-setter for _ymouse
static as_value ymouse_get(const fn_call& fn);
+ /// Getter-setter for _alpha
static as_value alpha_getset(const fn_call& fn);
+ /// Getter-setter for _visible
static as_value visible_getset(const fn_call& fn);
+ /// Getter-setter for _width
static as_value width_getset(const fn_call& fn);
+ /// Getter-setter for _height
static as_value height_getset(const fn_call& fn);
+ /// Getter-setter for _rotation
static as_value rotation_getset(const fn_call& fn);
+ /// Getter-setter for _parent
static as_value parent_getset(const fn_call& fn);
/// @} Common ActionScript getter-setters for characters
@@ -290,6 +302,22 @@
m_matrix = m;
}
}
+
+ /// Set the xscale value of current matrix
+ //
+ /// This is used when setting either _xscale or _width.
+ /// See xscale_getset and width_getset
+ ///
+ void set_x_scale(float factor);
+
+ /// Set the yscale value of current matrix
+ //
+ ///
+ /// This is used when setting either _yscale or _height
+ /// See xscale_getset and width_getset
+ ///
+ void set_y_scale(float factor);
+
const cxform& get_cxform() const { return m_color_transform; }
void set_cxform(const cxform& cx)
{
Index: testsuite/server/MatrixTest.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/server/MatrixTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- testsuite/server/MatrixTest.cpp 15 Mar 2007 22:39:54 -0000 1.4
+++ testsuite/server/MatrixTest.cpp 12 Apr 2007 16:29:14 -0000 1.5
@@ -28,6 +28,32 @@
using namespace std;
using namespace gnash;
+// for double comparison
+struct D {
+ double _d;
+ double _t; // tolerance
+
+ D(double d) : _d(d), _t(1e-6) {}
+
+ // Set tolerance
+ D(double d, double t) : _d(d), _t(t) {}
+
+ // Return true if the difference between the two
+ // doubles is below the minimum tolerance defined for the two
+ bool operator==(const D& d)
+ {
+ double tol = std::min(_t, d._t);
+ double delta = fabs(_d - d._d);
+ bool ret = delta < tol;
+ //cout << "D " << _d << "operator==(const D " << d._d <<")
returning " << ret << " (delta is " << delta << ") " << endl;
+ return ret;
+ }
+};
+std::ostream& operator<<(std::ostream& os, const D& d)
+{
+ return os << d._d << " [tol: " << d._t << "]";
+}
+
int
main(int /*argc*/, char** /*argv*/)
{
@@ -50,5 +76,37 @@
invert.set_inverse(identity);
check_equals(invert, matrix::identity);
+ // Try setting and getting some values
+ matrix m1;
+ m1.set_scale_rotation(1, 3, 0);
+ check_equals(m1.get_x_scale(), 1);
+ check_equals(m1.get_y_scale(), 3);
+ check_equals(m1.get_rotation(), 0);
+ check(!m1.does_flip());
+
+ m1.set_scale_rotation(1.5, 2.5, 0);
+ check_equals(D(m1.get_x_scale()), 1.5);
+ check_equals(D(m1.get_y_scale()), 2.5);
+ check_equals(D(m1.get_rotation()), 0);
+
+ m1.set_scale_rotation(34, 4, 0);
+ check_equals(D(m1.get_x_scale()), 34);
+ check_equals(D(m1.get_y_scale()), 4);
+ check_equals(D(m1.get_rotation()), 0);
+
+ m1.set_scale_rotation(1, 1, 2);
+ check_equals(D(m1.get_x_scale()), 1);
+ check_equals(D(m1.get_y_scale()), 1);
+ check_equals(D(m1.get_rotation()), 2);
+
+ m1.set_scale_rotation(2, 1, 2);
+ xcheck_equals(D(m1.get_x_scale()), 2);
+ xcheck_equals(D(m1.get_y_scale()), 1);
+ check_equals(D(m1.get_rotation()), 2);
+
+ m1.set_scale_rotation(1, 2, 2);
+ xcheck_equals(D(m1.get_x_scale()), 1);
+ xcheck_equals(D(m1.get_y_scale()), 2);
+ check_equals(D(m1.get_rotation()), 2);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog server/character.cpp server/cha...,
Sandro Santilli <=