зеркало из https://github.com/mozilla/moz-skia.git
animate matrixref in sample shapes
git-svn-id: http://skia.googlecode.com/svn/trunk@189 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
aa5a7db64a
Коммит
88c2d8ef15
|
@ -56,6 +56,12 @@ public:
|
|||
SkMatrix& m = *this;
|
||||
m = matrix;
|
||||
}
|
||||
|
||||
SkMatrix& operator=(const SkMatrix& matrix) {
|
||||
SkMatrix& m = *this;
|
||||
m = matrix;
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
class SkGroupShape : public SkShape {
|
||||
|
@ -71,6 +77,14 @@ public:
|
|||
owner count of the index'd shape. If index is out of range, returns NULL
|
||||
*/
|
||||
SkShape* getShape(int index, SkMatrixRef** = NULL) const;
|
||||
|
||||
/** Helper function to return the matrixref of the specified shape.
|
||||
*/
|
||||
SkMatrixRef* getShapeMatrixRef(int index) const {
|
||||
SkMatrixRef* mr = NULL;
|
||||
(void)this->getShape(index, &mr);
|
||||
return mr;
|
||||
}
|
||||
|
||||
/** Ref the specified shape, and insert it into the child list at the
|
||||
specified index. If index == countShapes(), then the shape will be
|
||||
|
|
|
@ -42,6 +42,7 @@ static SkShape* make_shape2() {
|
|||
|
||||
class ShapesView : public SkView {
|
||||
SkGroupShape fGroup;
|
||||
SkMatrixRef* fMatrixRefs[4];
|
||||
public:
|
||||
ShapesView() {
|
||||
SkMatrix m;
|
||||
|
@ -54,6 +55,18 @@ public:
|
|||
fGroup.appendShape(make_shape1(), m)->unref();
|
||||
m.postTranslate(0, SkIntToScalar(120));
|
||||
fGroup.appendShape(make_shape2(), m)->unref();
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
|
||||
SkSafeRef(fMatrixRefs[i] = fGroup.getShapeMatrixRef(i));
|
||||
}
|
||||
|
||||
fAngle = 0;
|
||||
}
|
||||
|
||||
virtual ~ShapesView() {
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
|
||||
SkSafeUnref(fMatrixRefs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -70,14 +83,22 @@ protected:
|
|||
canvas->drawColor(0xFFDDDDDD);
|
||||
}
|
||||
|
||||
int fAngle;
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
this->drawBG(canvas);
|
||||
|
||||
SkMatrix saveM = *fMatrixRefs[3];
|
||||
fAngle = (fAngle + 5) % 360;
|
||||
SkScalar c = SkIntToScalar(50);
|
||||
fMatrixRefs[3]->preRotate(SkIntToScalar(fAngle), c, c);
|
||||
|
||||
SkMatrix matrix;
|
||||
#if 1
|
||||
SkGroupShape gs;
|
||||
gs.appendShape(&fGroup);
|
||||
matrix.setTranslate(0, SkIntToScalar(240));
|
||||
matrix.setScale(-SK_Scalar1, SK_Scalar1);
|
||||
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
|
||||
gs.appendShape(&fGroup, matrix);
|
||||
matrix.setTranslate(SkIntToScalar(240), 0);
|
||||
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
|
||||
|
@ -88,7 +109,10 @@ protected:
|
|||
fGroup.drawXY(canvas, 0, SkIntToScalar(240));
|
||||
fGroup.drawMatrix(canvas, matrix);
|
||||
#endif
|
||||
}
|
||||
|
||||
*fMatrixRefs[3] = saveM;
|
||||
this->inval(NULL);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SkView INHERITED;
|
||||
|
|
Загрузка…
Ссылка в новой задаче