michael@0: michael@0: /* michael@0: * Copyright 2010 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: #ifndef SkLayer_DEFINED michael@0: #define SkLayer_DEFINED michael@0: michael@0: #include "SkRefCnt.h" michael@0: #include "SkTDArray.h" michael@0: #include "SkColor.h" michael@0: #include "SkMatrix.h" michael@0: #include "SkPoint.h" michael@0: #include "SkRect.h" michael@0: #include "SkSize.h" michael@0: michael@0: class SkCanvas; michael@0: michael@0: class SkLayer : public SkRefCnt { michael@0: michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkLayer) michael@0: michael@0: SkLayer(); michael@0: SkLayer(const SkLayer&); michael@0: virtual ~SkLayer(); michael@0: michael@0: bool isInheritFromRootTransform() const; michael@0: SkScalar getOpacity() const { return m_opacity; } michael@0: const SkSize& getSize() const { return m_size; } michael@0: const SkPoint& getPosition() const { return m_position; } michael@0: const SkPoint& getAnchorPoint() const { return m_anchorPoint; } michael@0: const SkMatrix& getMatrix() const { return fMatrix; } michael@0: const SkMatrix& getChildrenMatrix() const { return fChildrenMatrix; } michael@0: michael@0: SkScalar getWidth() const { return m_size.width(); } michael@0: SkScalar getHeight() const { return m_size.height(); } michael@0: michael@0: void setInheritFromRootTransform(bool); michael@0: void setOpacity(SkScalar opacity) { m_opacity = opacity; } michael@0: void setSize(SkScalar w, SkScalar h) { m_size.set(w, h); } michael@0: void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); } michael@0: void setAnchorPoint(SkScalar x, SkScalar y) { m_anchorPoint.set(x, y); } michael@0: void setMatrix(const SkMatrix&); michael@0: void setChildrenMatrix(const SkMatrix&); michael@0: michael@0: // children michael@0: michael@0: /** Return the number of layers in our child list. michael@0: */ michael@0: int countChildren() const; michael@0: michael@0: /** Return the child at the specified index (starting at 0). This does not michael@0: affect the reference count of the child. michael@0: */ michael@0: SkLayer* getChild(int index) const; michael@0: michael@0: /** Add this layer to our child list at the end (top-most), and ref() it. michael@0: If it was already in another hierarchy, remove it from that list. michael@0: Return the new child. michael@0: */ michael@0: SkLayer* addChild(SkLayer* child); michael@0: michael@0: /** Remove this layer from its parent's list (or do nothing if it has no michael@0: parent.) If it had a parent, then unref() is called. michael@0: */ michael@0: void detachFromParent(); michael@0: michael@0: /** Remove, and unref(), all of the layers in our child list. michael@0: */ michael@0: void removeChildren(); michael@0: michael@0: /** Return our parent layer, or NULL if we have none. michael@0: */ michael@0: SkLayer* getParent() const { return fParent; } michael@0: michael@0: /** Return the root layer in this hiearchy. If this layer is the root michael@0: (i.e. has no parent), then this returns itself. michael@0: */ michael@0: SkLayer* getRootLayer() const; michael@0: michael@0: // coordinate system transformations michael@0: michael@0: /** Return, in matrix, the matix transfomations that are applied locally michael@0: when this layer draws (i.e. its position and matrix/anchorPoint). michael@0: This does not include the childrenMatrix, since that is only applied michael@0: after this layer draws (but before its children draw). michael@0: */ michael@0: void getLocalTransform(SkMatrix* matrix) const; michael@0: michael@0: /** Return, in matrix, the concatenation of transforms that are applied michael@0: from this layer's root parent to the layer itself. michael@0: This is the matrix that is applied to the layer during drawing. michael@0: */ michael@0: void localToGlobal(SkMatrix* matrix) const; michael@0: michael@0: // paint method michael@0: michael@0: void draw(SkCanvas*, SkScalar opacity); michael@0: void draw(SkCanvas* canvas) { michael@0: this->draw(canvas, SK_Scalar1); michael@0: } michael@0: michael@0: protected: michael@0: virtual void onDraw(SkCanvas*, SkScalar opacity); michael@0: michael@0: private: michael@0: enum Flags { michael@0: kInheritFromRootTransform_Flag = 0x01 michael@0: }; michael@0: michael@0: SkLayer* fParent; michael@0: SkScalar m_opacity; michael@0: SkSize m_size; michael@0: SkPoint m_position; michael@0: SkPoint m_anchorPoint; michael@0: SkMatrix fMatrix; michael@0: SkMatrix fChildrenMatrix; michael@0: uint32_t fFlags; michael@0: michael@0: SkTDArray m_children; michael@0: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: #endif