update layers
git-svn-id: http://skia.googlecode.com/svn/trunk@502 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
86d4008e89
commit
81dc331e65
@ -38,13 +38,13 @@ public:
|
|||||||
|
|
||||||
Avoid: In this mode, drawing is allowed only on destination pixels that
|
Avoid: In this mode, drawing is allowed only on destination pixels that
|
||||||
are different from the op-color.
|
are different from the op-color.
|
||||||
Tolerance near 0: avoid anything close to the op-color
|
Tolerance near 0: avoid any colors even remotely similar to the op-color
|
||||||
Tolerance near 255: avoid only colors very close to the op-color
|
Tolerance near 255: avoid only colors nearly identical to the op-color
|
||||||
|
|
||||||
Target: In this mode, drawing only occurs on destination pixels that
|
Target: In this mode, drawing only occurs on destination pixels that
|
||||||
are similar to the op-color
|
are similar to the op-color
|
||||||
Tolerance near 0: draw on colors that are very close to op-color
|
Tolerance near 0: draw only on colors that are nearly identical to the op-color
|
||||||
Tolerance near 255: draw on colors that to the op-color
|
Tolerance near 255: draw on any colors even remotely similar to the op-color
|
||||||
*/
|
*/
|
||||||
SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
|
SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "SkRefCnt.h"
|
#include "SkRefCnt.h"
|
||||||
#include "SkTDArray.h"
|
#include "SkTDArray.h"
|
||||||
#include "SkColor.h"
|
#include "SkColor.h"
|
||||||
|
#include "SkMatrix.h"
|
||||||
#include "SkPoint.h"
|
#include "SkPoint.h"
|
||||||
#include "SkRect.h"
|
#include "SkRect.h"
|
||||||
#include "SkSize.h"
|
#include "SkSize.h"
|
||||||
@ -60,16 +61,36 @@ public:
|
|||||||
SkLayer(const SkLayer&);
|
SkLayer(const SkLayer&);
|
||||||
virtual ~SkLayer();
|
virtual ~SkLayer();
|
||||||
|
|
||||||
// setters
|
// deprecated
|
||||||
|
|
||||||
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 setTranslation(SkScalar x, SkScalar y) { m_translation.set(x, y); }
|
||||||
void setRotation(SkScalar a) { m_angleTransform = a; m_doRotation = true; }
|
void setRotation(SkScalar a) { m_angleTransform = a; m_doRotation = true; }
|
||||||
void setScale(SkScalar x, SkScalar y) { m_scale.set(x, y); }
|
void setScale(SkScalar x, SkScalar y) { m_scale.set(x, y); }
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SkSize& getSize() const { return m_size; }
|
||||||
|
void setSize(SkScalar w, SkScalar h) { m_size.set(w, h); }
|
||||||
|
|
||||||
|
SkScalar getOpacity() const { return m_opacity; }
|
||||||
|
void setOpacity(SkScalar opacity) { m_opacity = opacity; }
|
||||||
|
|
||||||
|
const SkPoint& getPosition() const { return m_position; }
|
||||||
void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); }
|
void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); }
|
||||||
|
|
||||||
|
const SkPoint& getAnchorPoint() const { return m_anchorPoint; }
|
||||||
void setAnchorPoint(SkScalar x, SkScalar y) { m_anchorPoint.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; }
|
virtual void setBackgroundColor(SkColor color) { m_backgroundColor = color; m_backgroundColorSet = true; }
|
||||||
|
|
||||||
void setFixedPosition(SkLength left, SkLength top, SkLength right, SkLength bottom) {
|
void setFixedPosition(SkLength left, SkLength top, SkLength right, SkLength bottom) {
|
||||||
m_fixedLeft = left;
|
m_fixedLeft = left;
|
||||||
m_fixedTop = top;
|
m_fixedTop = top;
|
||||||
@ -78,19 +99,11 @@ public:
|
|||||||
m_isFixed = true;
|
m_isFixed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getters
|
const SkMatrix& getMatrix() const { return fMatrix; }
|
||||||
|
void setMatrix(const SkMatrix&);
|
||||||
|
|
||||||
SkPoint position() const { return m_position; }
|
const SkMatrix& getChildrenMatrix() const { return fChildrenMatrix; }
|
||||||
SkPoint translation() const { return m_translation; }
|
void setChildrenMatrix(const SkMatrix&);
|
||||||
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
|
// children
|
||||||
|
|
||||||
@ -101,7 +114,15 @@ public:
|
|||||||
|
|
||||||
// paint method
|
// paint method
|
||||||
|
|
||||||
virtual void paintOn(SkPoint offset, SkSize size, SkScalar scale, SkCanvas*) = 0;
|
virtual void draw(SkCanvas*, SkScalar opacity, const SkRect* viewPort);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void onSetupCanvas(SkCanvas*, SkScalar opacity, const SkRect*);
|
||||||
|
virtual void onDraw(SkCanvas*, SkScalar opacity, const SkRect* viewPort);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SkMatrix fMatrix;
|
||||||
|
SkMatrix fChildrenMatrix;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "SkLayer.h"
|
#include "SkLayer.h"
|
||||||
|
#include "SkCanvas.h"
|
||||||
|
|
||||||
SkLayer::SkLayer() {
|
SkLayer::SkLayer() {
|
||||||
m_doRotation = false;
|
m_doRotation = false;
|
||||||
@ -15,6 +16,9 @@ SkLayer::SkLayer() {
|
|||||||
m_scale.set(1, 1);
|
m_scale.set(1, 1);
|
||||||
|
|
||||||
m_backgroundColor = 0;
|
m_backgroundColor = 0;
|
||||||
|
|
||||||
|
fMatrix.reset();
|
||||||
|
fChildrenMatrix.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
SkLayer::SkLayer(const SkLayer& src) {
|
SkLayer::SkLayer(const SkLayer& src) {
|
||||||
@ -36,6 +40,9 @@ SkLayer::SkLayer(const SkLayer& src) {
|
|||||||
m_fixedBottom = src.m_fixedBottom;
|
m_fixedBottom = src.m_fixedBottom;
|
||||||
|
|
||||||
m_backgroundColor = src.m_backgroundColor;
|
m_backgroundColor = src.m_backgroundColor;
|
||||||
|
|
||||||
|
fMatrix = src.fMatrix;
|
||||||
|
fChildrenMatrix = src.fChildrenMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkLayer::~SkLayer() {
|
SkLayer::~SkLayer() {
|
||||||
@ -64,4 +71,56 @@ void SkLayer::removeChildren() {
|
|||||||
m_children.reset();
|
m_children.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void SkLayer::setMatrix(const SkMatrix& matrix) {
|
||||||
|
fMatrix = matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkLayer::setChildrenMatrix(const SkMatrix& matrix) {
|
||||||
|
fChildrenMatrix = matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void SkLayer::onSetupCanvas(SkCanvas* canvas, SkScalar, const SkRect*) {
|
||||||
|
SkScalar tx = m_position.fX;
|
||||||
|
SkScalar ty = m_position.fY;
|
||||||
|
canvas->translate(tx, ty);
|
||||||
|
|
||||||
|
// now apply our matrix about the anchorPoint
|
||||||
|
tx = SkScalarMul(m_anchorPoint.fX, m_size.width());
|
||||||
|
ty = SkScalarMul(m_anchorPoint.fY, m_size.height());
|
||||||
|
canvas->translate(tx, ty);
|
||||||
|
canvas->concat(this->getMatrix());
|
||||||
|
canvas->translate(-tx, -ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkLayer::onDraw(SkCanvas*, SkScalar opacity, const SkRect* viewport) {}
|
||||||
|
|
||||||
|
void SkLayer::draw(SkCanvas* canvas, SkScalar opacity, const SkRect* viewport) {
|
||||||
|
#if 0
|
||||||
|
SkDebugf("--- drawlayer %p anchor [%g %g] scale [%g %g]\n", this, m_anchorPoint.fX, m_anchorPoint.fY,
|
||||||
|
m_scale.fX, m_scale.fY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
opacity = SkScalarMul(opacity, this->getOpacity());
|
||||||
|
if (opacity <= 0 || this->getSize().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SkAutoCanvasRestore acr(canvas, false);
|
||||||
|
canvas->save(SkCanvas::kMatrix_SaveFlag);
|
||||||
|
|
||||||
|
this->onSetupCanvas(canvas, opacity, viewport);
|
||||||
|
this->onDraw(canvas, opacity, viewport);
|
||||||
|
|
||||||
|
int count = this->countChildren();
|
||||||
|
if (count > 0) {
|
||||||
|
canvas->concat(this->getChildrenMatrix());
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
this->getChild(i)->draw(canvas, opacity, viewport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user