blob: 77800491f756fc5ec2d67f30ea3648236ea2edcd [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 Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/core/SkPath.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 {
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
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
46 SkMatrix m = SkMatrix::MakeScale(1.5f, 0.8f);
47 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}