blob: b61b8e82e75d73b8e047818f4502aeff2da71ecf [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkDrawable.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040012#include "include/core/SkMatrix.h"
13#include "include/core/SkPaint.h"
Mike Reede9d783c2020-08-17 14:14:13 -040014#include "include/core/SkPathBuilder.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040015#include "include/core/SkRect.h"
16#include "include/core/SkRefCnt.h"
mtkleind2baa902015-07-07 09:43:28 -070017
18struct MyDrawable : public SkDrawable {
reeda8db7282015-07-07 10:22:31 -070019 SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
mtkleind2baa902015-07-07 09:43:28 -070020
21 void onDraw(SkCanvas* canvas) override {
Mike Reede9d783c2020-08-17 14:14:13 -040022 SkPath path = SkPathBuilder().moveTo(10, 10)
23 .conicTo(10, 90, 50, 90, 0.9f)
24 .detach();
mtkleind2baa902015-07-07 09:43:28 -070025
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
reeda8db7282015-07-07 10:22:31 -070036/*
37 * Test calling drawables w/ translate and matrices
38 */
39DEF_SIMPLE_GM(drawable, canvas, 180, 275) {
Hal Canarycefc4312016-11-04 16:26:16 -040040 sk_sp<SkDrawable> drawable(new MyDrawable);
reeda8db7282015-07-07 10:22:31 -070041
42 canvas->translate(10, 10);
Hal Canarycefc4312016-11-04 16:26:16 -040043 canvas->drawDrawable(drawable.get());
44 canvas->drawDrawable(drawable.get(), 0, 150);
reeda8db7282015-07-07 10:22:31 -070045
Mike Reed1f607332020-05-21 12:11:27 -040046 SkMatrix m = SkMatrix::Scale(1.5f, 0.8f);
reeda8db7282015-07-07 10:22:31 -070047 m.postTranslate(70, 0);
Hal Canarycefc4312016-11-04 16:26:16 -040048 canvas->drawDrawable(drawable.get(), &m);
reeda8db7282015-07-07 10:22:31 -070049
50 m.postTranslate(0, 150);
Hal Canarycefc4312016-11-04 16:26:16 -040051 canvas->drawDrawable(drawable.get(), &m);
mtkleind2baa902015-07-07 09:43:28 -070052}