blob: c7bc76185b346c9f5b6b329a455e5611a92af9c6 [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) {
35 SkAutoTUnref<SkDrawable> drawable(new MyDrawable);
36
37 canvas->translate(10, 10);
38 canvas->drawDrawable(drawable);
39 canvas->drawDrawable(drawable, 0, 150);
40
41 SkMatrix m = SkMatrix::MakeScale(1.5f, 0.8f);
42 m.postTranslate(70, 0);
43 canvas->drawDrawable(drawable, &m);
44
45 m.postTranslate(0, 150);
46 canvas->drawDrawable(drawable, &m);
mtkleind2baa902015-07-07 09:43:28 -070047}