blob: 9428e32c4db9908506ab7a3948e1b94e3b70c9a7 [file] [log] [blame]
mtkleind2baa902015-07-07 09:43:28 -07001/*
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.h"
9#include "SkCanvas.h"
10#include "SkDrawable.h"
bungemand3ebb482015-08-05 13:57:49 -070011#include "SkPath.h"
mtkleind2baa902015-07-07 09:43:28 -070012
13struct MyDrawable : public SkDrawable {
reeda8db7282015-07-07 10:22:31 -070014 SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
mtkleind2baa902015-07-07 09:43:28 -070015
16 void onDraw(SkCanvas* canvas) override {
17 SkPath path;
18 path.moveTo(10, 10);
19 path.conicTo(10, 90, 50, 90, 0.9f);
20
21 SkPaint paint;
22 paint.setColor(SK_ColorBLUE);
23 canvas->drawRect(path.getBounds(), paint);
24
25 paint.setAntiAlias(true);
26 paint.setColor(SK_ColorWHITE);
27 canvas->drawPath(path, paint);
28 }
29};
30
reeda8db7282015-07-07 10:22:31 -070031/*
32 * Test calling drawables w/ translate and matrices
33 */
34DEF_SIMPLE_GM(drawable, canvas, 180, 275) {
Hal Canarycefc4312016-11-04 16:26:16 -040035 sk_sp<SkDrawable> drawable(new MyDrawable);
reeda8db7282015-07-07 10:22:31 -070036
37 canvas->translate(10, 10);
Hal Canarycefc4312016-11-04 16:26:16 -040038 canvas->drawDrawable(drawable.get());
39 canvas->drawDrawable(drawable.get(), 0, 150);
reeda8db7282015-07-07 10:22:31 -070040
41 SkMatrix m = SkMatrix::MakeScale(1.5f, 0.8f);
42 m.postTranslate(70, 0);
Hal Canarycefc4312016-11-04 16:26:16 -040043 canvas->drawDrawable(drawable.get(), &m);
reeda8db7282015-07-07 10:22:31 -070044
45 m.postTranslate(0, 150);
Hal Canarycefc4312016-11-04 16:26:16 -040046 canvas->drawDrawable(drawable.get(), &m);
mtkleind2baa902015-07-07 09:43:28 -070047}