michael@0:
michael@0: /*
michael@0: * Copyright 2006 The Android Open Source Project
michael@0: *
michael@0: * Use of this source code is governed by a BSD-style license that can be
michael@0: * found in the LICENSE file.
michael@0: */
michael@0:
michael@0:
michael@0: #include "SkMatrixParts.h"
michael@0: #include "SkAnimateMaker.h"
michael@0: #include "SkDrawMatrix.h"
michael@0: #include "SkDrawRectangle.h"
michael@0: #include "SkDrawPath.h"
michael@0:
michael@0: SkMatrixPart::SkMatrixPart() : fMatrix(NULL) {
michael@0: }
michael@0:
michael@0: void SkMatrixPart::dirty() {
michael@0: fMatrix->dirty();
michael@0: }
michael@0:
michael@0: SkDisplayable* SkMatrixPart::getParent() const {
michael@0: return fMatrix;
michael@0: }
michael@0:
michael@0: bool SkMatrixPart::setParent(SkDisplayable* parent) {
michael@0: SkASSERT(parent != NULL);
michael@0: if (parent->isMatrix() == false)
michael@0: return true;
michael@0: fMatrix = (SkDrawMatrix*) parent;
michael@0: return false;
michael@0: }
michael@0:
michael@0:
michael@0: #if SK_USE_CONDENSED_INFO == 0
michael@0:
michael@0: const SkMemberInfo SkRotate::fInfo[] = {
michael@0: SK_MEMBER(center, Point),
michael@0: SK_MEMBER(degrees, Float)
michael@0: };
michael@0:
michael@0: #endif
michael@0:
michael@0: DEFINE_GET_MEMBER(SkRotate);
michael@0:
michael@0: SkRotate::SkRotate() : degrees(0) {
michael@0: center.fX = center.fY = 0;
michael@0: }
michael@0:
michael@0: bool SkRotate::add() {
michael@0: fMatrix->rotate(degrees, center);
michael@0: return false;
michael@0: }
michael@0:
michael@0:
michael@0: #if SK_USE_CONDENSED_INFO == 0
michael@0:
michael@0: const SkMemberInfo SkScale::fInfo[] = {
michael@0: SK_MEMBER(center, Point),
michael@0: SK_MEMBER(x, Float),
michael@0: SK_MEMBER(y, Float)
michael@0: };
michael@0:
michael@0: #endif
michael@0:
michael@0: DEFINE_GET_MEMBER(SkScale);
michael@0:
michael@0: SkScale::SkScale() : x(SK_Scalar1), y(SK_Scalar1) {
michael@0: center.fX = center.fY = 0;
michael@0: }
michael@0:
michael@0: bool SkScale::add() {
michael@0: fMatrix->scale(x, y, center);
michael@0: return false;
michael@0: }
michael@0:
michael@0:
michael@0: #if SK_USE_CONDENSED_INFO == 0
michael@0:
michael@0: const SkMemberInfo SkSkew::fInfo[] = {
michael@0: SK_MEMBER(center, Point),
michael@0: SK_MEMBER(x, Float),
michael@0: SK_MEMBER(y, Float)
michael@0: };
michael@0:
michael@0: #endif
michael@0:
michael@0: DEFINE_GET_MEMBER(SkSkew);
michael@0:
michael@0: SkSkew::SkSkew() : x(0), y(0) {
michael@0: center.fX = center.fY = 0;
michael@0: }
michael@0:
michael@0: bool SkSkew::add() {
michael@0: fMatrix->skew(x, y, center);
michael@0: return false;
michael@0: }
michael@0:
michael@0:
michael@0: #if SK_USE_CONDENSED_INFO == 0
michael@0:
michael@0: const SkMemberInfo SkTranslate::fInfo[] = {
michael@0: SK_MEMBER(x, Float),
michael@0: SK_MEMBER(y, Float)
michael@0: };
michael@0:
michael@0: #endif
michael@0:
michael@0: DEFINE_GET_MEMBER(SkTranslate);
michael@0:
michael@0: SkTranslate::SkTranslate() : x(0), y(0) {
michael@0: }
michael@0:
michael@0: bool SkTranslate::add() {
michael@0: fMatrix->translate(x, y);
michael@0: return false;
michael@0: }
michael@0:
michael@0:
michael@0: #if SK_USE_CONDENSED_INFO == 0
michael@0:
michael@0: const SkMemberInfo SkFromPath::fInfo[] = {
michael@0: SK_MEMBER(mode, FromPathMode),
michael@0: SK_MEMBER(offset, Float),
michael@0: SK_MEMBER(path, Path)
michael@0: };
michael@0:
michael@0: #endif
michael@0:
michael@0: DEFINE_GET_MEMBER(SkFromPath);
michael@0:
michael@0: SkFromPath::SkFromPath() :
michael@0: mode(0), offset(0), path(NULL) {
michael@0: }
michael@0:
michael@0: SkFromPath::~SkFromPath() {
michael@0: }
michael@0:
michael@0: bool SkFromPath::add() {
michael@0: if (path == NULL)
michael@0: return true;
michael@0: static const uint8_t gFlags[] = {
michael@0: SkPathMeasure::kGetPosAndTan_MatrixFlag, // normal
michael@0: SkPathMeasure::kGetTangent_MatrixFlag, // angle
michael@0: SkPathMeasure::kGetPosition_MatrixFlag // position
michael@0: };
michael@0: if ((unsigned)mode >= SK_ARRAY_COUNT(gFlags))
michael@0: return true;
michael@0: SkMatrix result;
michael@0: fPathMeasure.setPath(&path->getPath(), false);
michael@0: if (fPathMeasure.getMatrix(offset, &result, (SkPathMeasure::MatrixFlags)gFlags[mode]))
michael@0: fMatrix->set(result);
michael@0: return false;
michael@0: }
michael@0:
michael@0:
michael@0: #if SK_USE_CONDENSED_INFO == 0
michael@0:
michael@0: const SkMemberInfo SkRectToRect::fInfo[] = {
michael@0: SK_MEMBER(destination, Rect),
michael@0: SK_MEMBER(source, Rect)
michael@0: };
michael@0:
michael@0: #endif
michael@0:
michael@0: DEFINE_GET_MEMBER(SkRectToRect);
michael@0:
michael@0: SkRectToRect::SkRectToRect() :
michael@0: source(NULL), destination(NULL) {
michael@0: }
michael@0:
michael@0: SkRectToRect::~SkRectToRect() {
michael@0: }
michael@0:
michael@0: bool SkRectToRect::add() {
michael@0: if (source == NULL || destination == NULL)
michael@0: return true;
michael@0: SkMatrix temp;
michael@0: temp.setRectToRect(source->fRect, destination->fRect,
michael@0: SkMatrix::kFill_ScaleToFit);
michael@0: fMatrix->set(temp);
michael@0: return false;
michael@0: }
michael@0:
michael@0: #ifdef SK_DUMP_ENABLED
michael@0: void SkRectToRect::dump(SkAnimateMaker* maker) {
michael@0: dumpBase(maker);
michael@0: SkDebugf("/>\n");
michael@0: SkDisplayList::fIndent += 4;
michael@0: if (source) {
michael@0: SkDebugf("%*s\n", SkDisplayList::fIndent, "");
michael@0: SkDisplayList::fIndent += 4;
michael@0: source->dump(maker);
michael@0: SkDisplayList::fIndent -= 4;
michael@0: SkDebugf("%*s\n", SkDisplayList::fIndent, "");
michael@0: }
michael@0: if (destination) {
michael@0: SkDebugf("%*s\n", SkDisplayList::fIndent, "");
michael@0: SkDisplayList::fIndent += 4;
michael@0: destination->dump(maker);
michael@0: SkDisplayList::fIndent -= 4;
michael@0: SkDebugf("%*s\n", SkDisplayList::fIndent, "");
michael@0: }
michael@0: SkDisplayList::fIndent -= 4;
michael@0: dumpEnd(maker);
michael@0: }
michael@0: #endif
michael@0:
michael@0: const SkMemberInfo* SkRectToRect::preferredChild(SkDisplayTypes ) {
michael@0: if (source == NULL)
michael@0: return getMember("source"); // !!! cwap! need to refer to member through enum like kScope instead
michael@0: else {
michael@0: SkASSERT(destination == NULL);
michael@0: return getMember("destination");
michael@0: }
michael@0: }
michael@0:
michael@0:
michael@0: #if SK_USE_CONDENSED_INFO == 0
michael@0:
michael@0: const SkMemberInfo SkPolyToPoly::fInfo[] = {
michael@0: SK_MEMBER(destination, Polygon),
michael@0: SK_MEMBER(source, Polygon)
michael@0: };
michael@0:
michael@0: #endif
michael@0:
michael@0: DEFINE_GET_MEMBER(SkPolyToPoly);
michael@0:
michael@0: SkPolyToPoly::SkPolyToPoly() : source(NULL), destination(NULL) {
michael@0: }
michael@0:
michael@0: SkPolyToPoly::~SkPolyToPoly() {
michael@0: }
michael@0:
michael@0: bool SkPolyToPoly::add() {
michael@0: SkASSERT(source);
michael@0: SkASSERT(destination);
michael@0: SkPoint src[4];
michael@0: SkPoint dst[4];
michael@0: SkPath& sourcePath = source->getPath();
michael@0: int srcPts = sourcePath.getPoints(src, 4);
michael@0: SkPath& destPath = destination->getPath();
michael@0: int dstPts = destPath.getPoints(dst, 4);
michael@0: if (srcPts != dstPts)
michael@0: return true;
michael@0: SkMatrix temp;
michael@0: temp.setPolyToPoly(src, dst, srcPts);
michael@0: fMatrix->set(temp);
michael@0: return false;
michael@0: }
michael@0:
michael@0: #ifdef SK_DUMP_ENABLED
michael@0: void SkPolyToPoly::dump(SkAnimateMaker* maker) {
michael@0: dumpBase(maker);
michael@0: SkDebugf("/>\n");
michael@0: SkDisplayList::fIndent += 4;
michael@0: if (source) {
michael@0: SkDebugf("%*s\n", SkDisplayList::fIndent, "");
michael@0: SkDisplayList::fIndent += 4;
michael@0: source->dump(maker);
michael@0: SkDisplayList::fIndent -= 4;
michael@0: SkDebugf("%*s\n", SkDisplayList::fIndent, "");
michael@0: }
michael@0: if (destination) {
michael@0: SkDebugf("%*s\n", SkDisplayList::fIndent, "");
michael@0: SkDisplayList::fIndent += 4;
michael@0: destination->dump(maker);
michael@0: SkDisplayList::fIndent -= 4;
michael@0: SkDebugf("%*s\n", SkDisplayList::fIndent, "");
michael@0: }
michael@0: SkDisplayList::fIndent -= 4;
michael@0: dumpEnd(maker);
michael@0: }
michael@0: #endif
michael@0:
michael@0: void SkPolyToPoly::onEndElement(SkAnimateMaker& ) {
michael@0: SkASSERT(source);
michael@0: SkASSERT(destination);
michael@0: if (source->childHasID() || destination->childHasID())
michael@0: fMatrix->setChildHasID();
michael@0: }
michael@0:
michael@0: const SkMemberInfo* SkPolyToPoly::preferredChild(SkDisplayTypes ) {
michael@0: if (source == NULL)
michael@0: return getMember("source"); // !!! cwap! need to refer to member through enum like kScope instead
michael@0: else {
michael@0: SkASSERT(destination == NULL);
michael@0: return getMember("destination");
michael@0: }
michael@0: }