blob: c97bf72680663d82d3d9d18031353bcb88151ee4 [file] [log] [blame]
reed@android.com86d40082010-02-12 17:17:10 +00001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkLayer_DEFINED
18#define SkLayer_DEFINED
19
20#include "SkRefCnt.h"
21#include "SkTDArray.h"
22#include "SkColor.h"
reed@android.com81dc3312010-02-18 19:32:03 +000023#include "SkMatrix.h"
reed@android.com86d40082010-02-12 17:17:10 +000024#include "SkPoint.h"
25#include "SkRect.h"
26#include "SkSize.h"
27
28class SkCanvas;
reed@android.com86d40082010-02-12 17:17:10 +000029
30class SkLayer : public SkRefCnt {
31
32public:
33 SkLayer();
34 SkLayer(const SkLayer&);
35 virtual ~SkLayer();
36
reed@android.com81dc3312010-02-18 19:32:03 +000037 SkScalar getOpacity() const { return m_opacity; }
reed@android.comda6fb322010-02-19 21:41:30 +000038 const SkSize& getSize() const { return m_size; }
reed@android.com81dc3312010-02-18 19:32:03 +000039 const SkPoint& getPosition() const { return m_position; }
reed@android.com81dc3312010-02-18 19:32:03 +000040 const SkPoint& getAnchorPoint() const { return m_anchorPoint; }
reed@android.com81dc3312010-02-18 19:32:03 +000041 const SkMatrix& getMatrix() const { return fMatrix; }
reed@android.com81dc3312010-02-18 19:32:03 +000042 const SkMatrix& getChildrenMatrix() const { return fChildrenMatrix; }
reed@android.comda6fb322010-02-19 21:41:30 +000043
44 SkScalar getWidth() const { return m_size.width(); }
45 SkScalar getHeight() const { return m_size.height(); }
46
47 void setOpacity(SkScalar opacity) { m_opacity = opacity; }
48 void setSize(SkScalar w, SkScalar h) { m_size.set(w, h); }
49 void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); }
50 void setAnchorPoint(SkScalar x, SkScalar y) { m_anchorPoint.set(x, y); }
51 void setMatrix(const SkMatrix&);
reed@android.com81dc3312010-02-18 19:32:03 +000052 void setChildrenMatrix(const SkMatrix&);
reed@android.com86d40082010-02-12 17:17:10 +000053
54 // children
55
56 int countChildren() const;
57 SkLayer* getChild(int index) const;
58 SkLayer* addChild(SkLayer* child);
59 void removeChildren();
60
61 // paint method
62
reed@android.comda6fb322010-02-19 21:41:30 +000063 void draw(SkCanvas*, SkScalar opacity);
64 void draw(SkCanvas* canvas) {
65 this->draw(canvas, SK_Scalar1);
66 }
reed@android.com81dc3312010-02-18 19:32:03 +000067
68protected:
reed@android.comda6fb322010-02-19 21:41:30 +000069 virtual void onDraw(SkCanvas*, SkScalar opacity);
reed@android.com81dc3312010-02-18 19:32:03 +000070
71private:
reed@android.comda6fb322010-02-19 21:41:30 +000072 SkScalar m_opacity;
73 SkSize m_size;
74 SkPoint m_position;
75 SkPoint m_anchorPoint;
reed@android.com81dc3312010-02-18 19:32:03 +000076 SkMatrix fMatrix;
77 SkMatrix fChildrenMatrix;
reed@android.com86d40082010-02-12 17:17:10 +000078
reed@android.com86d40082010-02-12 17:17:10 +000079 SkTDArray<SkLayer*> m_children;
80};
81
82#endif