| 1 |
/* |
| 2 |
* Copyright 2015 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "gm/gm.h" |
| 9 |
#include "include/core/SkCanvas.h" |
| 10 |
#include "include/core/SkColor.h" |
| 11 |
#include "include/core/SkDrawable.h" |
| 12 |
#include "include/core/SkMatrix.h" |
| 13 |
#include "include/core/SkPaint.h" |
| 14 |
#include "include/core/SkPathBuilder.h" |
| 15 |
#include "include/core/SkRect.h" |
| 16 |
#include "include/core/SkRefCnt.h" |
| 17 |
|
| 18 |
struct MyDrawable : public SkDrawable { |
| 19 |
SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 20 |
|
| 21 |
void onDraw(SkCanvas* canvas) override { |
| 22 |
SkPath path = SkPathBuilder().moveTo(10, 10) |
| 23 |
.conicTo(10, 90, 50, 90, 0.9f) |
| 24 |
.detach(); |
| 25 |
|
| 26 |
SkPaint paint; |
| 27 |
paint.setColor(SK_ColorBLUE); |
| 28 |
canvas->drawRect(path.getBounds(), paint); |
| 29 |
|
| 30 |
paint.setAntiAlias(true); |
| 31 |
paint.setColor(SK_ColorWHITE); |
| 32 |
canvas->drawPath(path, paint); |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
/* |
| 37 |
* Test calling drawables w/ translate and matrices |
| 38 |
*/ |
| 39 |
DEF_SIMPLE_GM(drawable, canvas, 180, 275) { |
| 40 |
sk_sp<SkDrawable> drawable(new MyDrawable); |
| 41 |
|
| 42 |
canvas->translate(10, 10); |
| 43 |
canvas->drawDrawable(drawable.get()); |
| 44 |
canvas->drawDrawable(drawable.get(), 0, 150); |
| 45 |
|
| 46 |
SkMatrix m = SkMatrix::Scale(1.5f, 0.8f); |
| 47 |
m.postTranslate(70, 0); |
| 48 |
canvas->drawDrawable(drawable.get(), &m); |
| 49 |
|
| 50 |
m.postTranslate(0, 150); |
| 51 |
canvas->drawDrawable(drawable.get(), &m); |
| 52 |
} |