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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkDrawable.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkMatrix.h" |
| 13 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkPath.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 15 | #include "include/core/SkRect.h" |
| 16 | #include "include/core/SkRefCnt.h" |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 17 | |
| 18 | struct MyDrawable : public SkDrawable { |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 19 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 20 | |
| 21 | void onDraw(SkCanvas* canvas) override { |
| 22 | SkPath path; |
| 23 | path.moveTo(10, 10); |
| 24 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 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 | |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 36 | /* |
| 37 | * Test calling drawables w/ translate and matrices |
| 38 | */ |
| 39 | DEF_SIMPLE_GM(drawable, canvas, 180, 275) { |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 40 | sk_sp<SkDrawable> drawable(new MyDrawable); |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 41 | |
| 42 | canvas->translate(10, 10); |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 43 | canvas->drawDrawable(drawable.get()); |
| 44 | canvas->drawDrawable(drawable.get(), 0, 150); |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 45 | |
| 46 | SkMatrix m = SkMatrix::MakeScale(1.5f, 0.8f); |
| 47 | m.postTranslate(70, 0); |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 48 | canvas->drawDrawable(drawable.get(), &m); |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 49 | |
| 50 | m.postTranslate(0, 150); |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 51 | canvas->drawDrawable(drawable.get(), &m); |
mtklein | d2baa90 | 2015-07-07 09:43:28 -0700 | [diff] [blame] | 52 | } |