mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 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.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkDrawable.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 11 | #include "SkPath.h" |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 12 | |
| 13 | struct MyDrawable : public SkDrawable { |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 14 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 15 | |
| 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 | |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Test calling drawables w/ translate and matrices |
| 33 | */ |
| 34 | DEF_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); |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 47 | } |