Made to Order Software Corporation Logo

libsswf: sswf::Matrix Class Reference

The position matrix. More...

#include <libsswf.h>

List of all members.


Public Member Functions

bool IsNull (void) const
 Check whether the matrix has an effect.
 Matrix (void)
 Initialize a matrix to a "no effect" matrix.
bool operator!= (const Matrix &matrix) const
 Compare two matrices for inequality.
bool operator== (const Matrix &matrix) const
 Compare two matrices for equality.
ErrorManager::error_code_t Parse (const Data &data)
 Save a matrix to a data buffer.
void Reset (void)
 Reset a matrix to a "no effect" matrix.
void Save (Data &data)
 Save a matrix to a data buffer.
void SetRotate (double rotate)
 Change the rotation.
void SetScale (double scale)
 Define the scale of the object.
void SetScale (double x, double y)
 Define the horizontal and vertical scaling factors.
void SetSkew (double skew0, double skew1)
 Set a skew (sliding off).
void SetTranslate (long x, long y)
 Define the matrix translation.

Private Member Functions

void ComputeMatrix (signed_matrix_t &m) const
 Internal function used to compute the matrix.
void UncomputeMatrix (const signed_matrix_t &m)
 Internal function used to "uncompute" the matrix.

Private Attributes

double f_rotate
double f_scale_x
double f_scale_y
double f_skew_0
double f_skew_1
long f_translate_x
long f_translate_y

Classes

struct  signed_matrix_t
 Matrix of longs; used to compute the matrix to be saved in the movie. More...

Detailed Description

This class is used to position shapes. The matrix supports rotations, skews, offsets and scaling.

The matrix is a 2D matrix and thus is only a 3x3.

The default is the identity matrix:

  | 1 0 0 |
  | 0 1 0 |
  | 0 0 1 |

However, the matrix is not managed as a matrix. Instead, you define the scaling, skewing, rotation and translation parameters. The library takes care of generating the matrix when it is saved in the SWF movie.

Notice that the translation is defined in twips and not floating point values.

See also:
SWF Alexis' Reference—swf_matrix

Constructor & Destructor Documentation

Matrix::Matrix ( void   ) 

The constructor creates and initializes a matrix with no effect. (i.e. the identity matrix.)

See also:
sswf::Matrix::Reset(void)

References Reset().


Member Function Documentation

void Matrix::ComputeMatrix ( signed_matrix_t m  )  const [private]

This function computes the matrix of signed values. The matrix is saved as 4x 16.16 fixed point values. This function computes the 4 fixed point values using the current definition of the matrix (i.e. rotation, skew and scaling.) The translation is not added in this matrix since this matrix is a 2x2 matrix.

Parameters:
[out] m When the computed matrix is saved
See also:
sswf::Matrix::IsNull(void) const

Matrix::Save(Data& data)

Matrix::operator == (const Matrix& matrix) const

Matrix::operator != (const Matrix& matrix) const

References sswf::TagBase::Double2Signed(), f_rotate, f_scale_x, f_scale_y, f_skew_0, f_skew_1, and sswf::Matrix::signed_matrix_t::m.

Referenced by IsNull(), operator==(), and Save().

bool Matrix::IsNull ( void   )  const

This function checks whether the different parameters define a null matrix. If so, then the function returns true.

The test is performed with the floating point values transformed in 16.16 fixed points as when they are saved in the final matrix. To ensures that the normal rounding is applied and thus it catches more matrices as null matrices.

Returns:
true if the matrix is the identity matrix.
See also:
sswf::TagBase::Double2Signed(double value)

References ComputeMatrix(), f_translate_x, f_translate_y, and sswf::Matrix::signed_matrix_t::m.

bool Matrix::operator!= ( const Matrix matrix  )  const

This operator compares two matrices to know whether they are inequal.

Note that the doubles are first transformed into 16.16 fixed point values and these are compared for inequality. This means less matrices may look inequal than what their exact definitions with doubles would imply.

See also:
sswf::Matrix::operator != (const Matrix& matrix) const

References operator==().

bool Matrix::operator== ( const Matrix matrix  )  const

This operator compares two matrices to know whether they are equal or not.

Note that the doubles are first transformed into 16.16 fixed point values and these are compared for equality. This means more matrices may look equal than what their exact definitions with doubles would imply.

See also:
sswf::Matrix::operator != (const Matrix& matrix) const

References ComputeMatrix(), f_translate_x, f_translate_y, and sswf::Matrix::signed_matrix_t::m.

Referenced by operator!=().

ErrorManager::error_code_t Matrix::Parse ( const Data data  ) 

The Save() function computes the matrix and then saves it in the specified data buffer.

It is valid to save an identity matrix.

Parameters:
[in] data The buffer where the matrix is to be saved
See also:
sswf::Matrix::IsNull(void) const

References sswf::ErrorManager::ERROR_CODE_NONE, f_translate_x, f_translate_y, sswf::Data::GetBits(), sswf::Matrix::signed_matrix_t::m, sswf::Data::ReadAlign(), and UncomputeMatrix().

Referenced by sswf::State::Parse().

void Matrix::Reset ( void   ) 

The Reset() function sets all the parameters to no effect. (i.e. the identity matrix.)

References f_rotate, f_scale_x, f_scale_y, f_skew_0, f_skew_1, f_translate_x, and f_translate_y.

Referenced by Matrix(), sswf::State::Reset(), and sswf::Style::Reset().

void Matrix::Save ( Data data  ) 

The Save() function computes the matrix and then saves it in the specified data buffer.

It is valid to save an identity matrix.

Parameters:
[in] data The buffer where the matrix is to be saved
See also:
sswf::Matrix::IsNull(void) const

References sswf::Data::Align(), ComputeMatrix(), f_translate_x, f_translate_y, sswf::Matrix::signed_matrix_t::m, sswf::TagBase::SIBitSize(), and sswf::Data::WriteBits().

Referenced by sswf::TagText::Save(), sswf::TagPlace::Save(), sswf::State::Save(), and sswf::Style::Save().

void Matrix::SetRotate ( double  rotate  ) 

Set the rotation in radian. The SetRotate() function takes a radian angle and saves it as the current rotation angle. This function is not cumulative. Instead the new angle overwrites any other angle previously defined with SetRotate().

Parameters:
[in] rotate The rotation angle
See also:
sswf::Matrix::SetScale(double x, double y)

sswf::Matrix::SetScale(double scale)

sswf::Matrix::SetSkew(double skew0, double skew1)

sswf::Matrix::SetTranslate(long x, long y)

References f_rotate, and M_PI.

sswf::Matrix::SetScale ( double  scale  )  [inline]

This function changes the matrix scaling. This function can be used to change the scaling uniformly in both directions. This is often used when you need to enlarge or reduce an object without losing its aspect ratio.

A call to this function is not cumulative. Each call sets the new scale to the specified value by overwriting the previous value.

It is equivalent to call SetScale() with the same value in x and y:

  // both calls are equivalent
  SetScale(scale);
  SetScale(scale, scale);

Parameters:
[in] scale Defines the new horizontal and vertical scaling
See also:
sswf::Matrix::SetScale(double x, double y)

sswf::Matrix::SetRotate(double rotate)

sswf::Matrix::SetSkew(double skew0, double skew1)

sswf::Matrix::SetTranslate(long x, long y)

References f_scale_x, and f_scale_y.

sswf::Matrix::SetScale ( double  x,
double  y 
) [inline]

This function changes the matrix scaling. This function can be used to change the horizontal and vertical scaling with different values. This let's you scale objects exactly the way you want.

A call to this function is not cumulative. Each call sets the new scaling values to the specified (x, y) scaling by overwriting the previous values.

Parameters:
[in] x Defines the new horizontal scaling
[in] y Defines the new vertical scaling
See also:
sswf::Matrix::SetScale(double scale)

sswf::Matrix::SetRotate(double rotate)

sswf::Matrix::SetSkew(double skew0, double skew1)

sswf::Matrix::SetTranslate(long x, long y)

References f_scale_x, and f_scale_y.

sswf::Matrix::SetSkew ( double  skew0,
double  skew1 
) [inline]

This function is used to change the skew parameters. The skew makes the top and bottom (or left and right) edges move horizontally (vertically) away from each others.

The skew defined by this function is not cumulative. Instead it replaces the current value with the new values.

The unit of the skew is the twips times the scaling factors.

Parameters:
[in] skew0 The horizontal skew
[in] skew1 The vertical skew
See also:
sswf::Matrix::SetScale(double x, double y)

sswf::Matrix::SetScale(double scale)

sswf::Matrix::SetRotate(double rotate)

sswf::Matrix::SetTranslate(long x, long y)

References f_skew_0, and f_skew_1.

sswf::Matrix::SetTranslate ( long  x,
long  y 
) [inline]

Set the translation to (x, y). Previous translations are replaced by each new call to this function.

The translation is defined in twips and taken as long values. (i.e. 20 represents 1 pixel on the screen.)

Parameters:
[in] x The horizontal translation
[in] y The vertical translation
See also:
sswf::Matrix::SetScale(double x, double y)

sswf::Matrix::SetScale(double scale)

sswf::Matrix::SetRotate(double rotate)

sswf::Matrix::SetSkew(double skew0, double skew1)

References f_translate_x, and f_translate_y.

void Matrix::UncomputeMatrix ( const signed_matrix_t m  )  [private]

This function is used when we read a matrix from a Data buffer. We attempt to determine the scaling, rotation, and skewing.

Parameters:
[in] m The computed matrix to restore in this matrix
See also:
sswf::Matrix::IsNull(void) const

Matrix::Load(const Data& data)

References f_rotate, f_scale_x, f_scale_y, f_skew_0, f_skew_1, sswf::Matrix::signed_matrix_t::m, and sswf::TagBase::Signed2Double().

Referenced by Parse().


Member Data Documentation


The documentation for this class was generated from the following files:


Generated on Wed Mar 18 15:13:58 2009 for libsswf by  doxygen 1.5.5