michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsTransform2D_h___ michael@0: #define nsTransform2D_h___ michael@0: michael@0: #include "gfxCore.h" michael@0: #include "nsCoord.h" michael@0: michael@0: class NS_GFX nsTransform2D michael@0: { michael@0: private: michael@0: /** michael@0: * This represents the following matrix (note that the order of row/column michael@0: * indices is opposite to usual notation) michael@0: * michael@0: * / m00 0 m20 \ michael@0: * M = | 0 m11 m21 | michael@0: * \ 0 0 1 / michael@0: * michael@0: * Transformation of a coordinate (x, y) is obtained by setting michael@0: * v = (x, y, 1)^T and evaluating M . v michael@0: **/ michael@0: michael@0: float m00, m11, m20, m21; michael@0: michael@0: public: michael@0: nsTransform2D(void) { m20 = m21 = 0.0f; m00 = m11 = 1.0f; } michael@0: nsTransform2D(nsTransform2D *aTransform2D) { michael@0: m00 = aTransform2D->m00; michael@0: m11 = aTransform2D->m11; michael@0: m20 = aTransform2D->m20; michael@0: m21 = aTransform2D->m21; michael@0: } michael@0: michael@0: ~nsTransform2D(void) { } michael@0: michael@0: /** michael@0: * set this transform to a translation michael@0: * michael@0: * @param tx, x translation michael@0: * @param ty, y translation michael@0: **/ michael@0: michael@0: void SetToTranslate(float tx, float ty) { m00 = m11 = 1.0f; m20 = tx; m21 = ty; } michael@0: michael@0: /** michael@0: * get the translation portion of this transform michael@0: * michael@0: * @param pt, Point to return translation values in michael@0: **/ michael@0: michael@0: void GetTranslationCoord(nscoord *ptX, nscoord *ptY) const { *ptX = NSToCoordRound(m20); *ptY = NSToCoordRound(m21); } michael@0: michael@0: /** michael@0: * apply matrix to vector michael@0: * michael@0: * @param pt Point to transform michael@0: **/ michael@0: michael@0: void TransformCoord(nscoord *ptX, nscoord *ptY) const; michael@0: michael@0: /** michael@0: * apply matrix to rect michael@0: * michael@0: * @param rect Rect to transform michael@0: **/ michael@0: michael@0: void TransformCoord(nscoord *aX, nscoord *aY, nscoord *aWidth, nscoord *aHeight) const; michael@0: michael@0: /** michael@0: * add a scale to a Transform via x, y pair michael@0: * michael@0: * @param ptX x value to add as x scale michael@0: * @param ptY y value to add as y scale michael@0: **/ michael@0: michael@0: void AddScale(float ptX, float ptY) { m00 *= ptX; m11 *= ptY; } michael@0: michael@0: /** michael@0: * Set the scale (overriding any previous calls to AddScale, but leaving michael@0: * any existing translation). michael@0: * michael@0: * @param ptX x value to add as x scale michael@0: * @param ptY y value to add as y scale michael@0: **/ michael@0: michael@0: void SetScale(float ptX, float ptY) { m00 = ptX; m11 = ptY; } michael@0: }; michael@0: michael@0: #endif