diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-02-12 17:17:10 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-02-12 17:17:10 +0000 |
commit | 86d4008e894f6ce0b1938ac6b45d4074af85d3b7 (patch) | |
tree | cbe4aeefbc34afda182d39780eabb34d457e77b9 | |
parent | dc3381fc8194a6192af39539c6ac9787b20209d3 (diff) |
add layers
git-svn-id: http://skia.googlecode.com/svn/trunk@501 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/utils/SkLayer.h | 133 | ||||
-rw-r--r-- | src/utils/SkLayer.cpp | 67 | ||||
-rw-r--r-- | src/utils/utils_files.mk | 1 |
3 files changed, 201 insertions, 0 deletions
diff --git a/include/utils/SkLayer.h b/include/utils/SkLayer.h new file mode 100644 index 0000000000..c277ddabed --- /dev/null +++ b/include/utils/SkLayer.h @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkLayer_DEFINED +#define SkLayer_DEFINED + +#include "SkRefCnt.h" +#include "SkTDArray.h" +#include "SkColor.h" +#include "SkPoint.h" +#include "SkRect.h" +#include "SkSize.h" + +class SkCanvas; +class SkPicture; + + +struct SkLength { + enum SkLengthType { Undefined, Auto, Relative, Percent, Fixed, Static, Intrinsic, MinIntrinsic }; + SkLengthType type; + SkScalar value; + SkLength() { + type = Undefined; + value = 0; + } + bool defined() const { + if (type == Undefined) + return false; + return true; + } + float calcFloatValue(float max) const { + switch (type) { + case Percent: + return (max * value) / 100.0f; + case Fixed: + return value; + default: + return value; + } + } +}; + +class SkLayer : public SkRefCnt { + +public: + SkLayer(); + SkLayer(const SkLayer&); + virtual ~SkLayer(); + + // setters + + void setSize(SkScalar w, SkScalar h) { m_size.set(w, h); } + void setOpacity(SkScalar opacity) { m_opacity = opacity; } + void setTranslation(SkScalar x, SkScalar y) { m_translation.set(x, y); } + void setRotation(SkScalar a) { m_angleTransform = a; m_doRotation = true; } + void setScale(SkScalar x, SkScalar y) { m_scale.set(x, y); } + void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); } + void setAnchorPoint(SkScalar x, SkScalar y) { m_anchorPoint.set(x, y); } + virtual void setBackgroundColor(SkColor color) { m_backgroundColor = color; m_backgroundColorSet = true; } + void setFixedPosition(SkLength left, SkLength top, SkLength right, SkLength bottom) { + m_fixedLeft = left; + m_fixedTop = top; + m_fixedRight = right; + m_fixedBottom = bottom; + m_isFixed = true; + } + + // getters + + SkPoint position() const { return m_position; } + SkPoint translation() const { return m_translation; } + SkSize size() const { return m_size; } + SkRect bounds() const { + SkRect rect; + rect.set(m_position.fX, m_position.fY, + m_position.fX + m_size.width(), + m_position.fY + m_size.height()); + rect.offset(m_translation.fX, m_translation.fY); + return rect; + } + + // children + + int countChildren() const; + SkLayer* getChild(int index) const; + SkLayer* addChild(SkLayer* child); + void removeChildren(); + + // paint method + + virtual void paintOn(SkPoint offset, SkSize size, SkScalar scale, SkCanvas*) = 0; + +public: + + bool m_doRotation; + bool m_isFixed; + bool m_backgroundColorSet; + + // layers properties + + SkScalar m_angleTransform; + SkScalar m_opacity; + + SkSize m_size; + SkPoint m_position; + SkPoint m_translation; + SkPoint m_anchorPoint; + SkPoint m_scale; + + SkLength m_fixedLeft; + SkLength m_fixedTop; + SkLength m_fixedRight; + SkLength m_fixedBottom; + + SkColor m_backgroundColor; + + SkTDArray<SkLayer*> m_children; +}; + +#endif diff --git a/src/utils/SkLayer.cpp b/src/utils/SkLayer.cpp new file mode 100644 index 0000000000..c5a6d9a20c --- /dev/null +++ b/src/utils/SkLayer.cpp @@ -0,0 +1,67 @@ +#include "SkLayer.h" + +SkLayer::SkLayer() { + m_doRotation = false; + m_isFixed = false; + m_backgroundColorSet = false; + + m_angleTransform = 0; + m_opacity = 1; + + m_size.set(0, 0); + m_position.set(0, 0); + m_translation.set(0, 0); + m_anchorPoint.set(0.5, 0.5); + m_scale.set(1, 1); + + m_backgroundColor = 0; +} + +SkLayer::SkLayer(const SkLayer& src) { + m_doRotation = src.m_doRotation; + m_isFixed = src.m_isFixed; + m_backgroundColorSet = src.m_backgroundColorSet; + + m_angleTransform = src.m_angleTransform; + m_opacity = src.m_opacity; + m_size = src.m_size; + m_position = src.m_position; + m_translation = src.m_translation; + m_anchorPoint = src.m_anchorPoint; + m_scale = src.m_scale; + + m_fixedLeft = src.m_fixedLeft; + m_fixedTop = src.m_fixedTop; + m_fixedRight = src.m_fixedRight; + m_fixedBottom = src.m_fixedBottom; + + m_backgroundColor = src.m_backgroundColor; +} + +SkLayer::~SkLayer() { + this->removeChildren(); +} + +int SkLayer::countChildren() const { + return m_children.count(); +} + +SkLayer* SkLayer::getChild(int index) const { + if ((unsigned)index < (unsigned)m_children.count()) { + return m_children[index]; + } + return NULL; +} + +SkLayer* SkLayer::addChild(SkLayer* child) { + child->ref(); + *m_children.append() = child; + return child; +} + +void SkLayer::removeChildren() { + m_children.unrefAll(); + m_children.reset(); +} + + diff --git a/src/utils/utils_files.mk b/src/utils/utils_files.mk index 0ff23c26cd..68cc587111 100644 --- a/src/utils/utils_files.mk +++ b/src/utils/utils_files.mk @@ -4,6 +4,7 @@ SOURCE := \ SkCullPoints.cpp \ SkDumpCanvas.cpp \ SkInterpolator.cpp \ + SkLayer.cpp \ SkNinePatch.cpp \ SkNWayCanvas.cpp \ SkParse.cpp \ |