Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
drawable.cpp
Go to the documentation of this file.
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/gm.h"
15#include "include/core/SkRect.h"
17
18struct MyDrawable : public SkDrawable {
19 SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
20
21 void onDraw(SkCanvas* canvas) override {
22 SkPath path = SkPathBuilder().moveTo(10, 10)
23 .conicTo(10, 90, 50, 90, 0.9f)
24 .detach();
25
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
36/*
37 * Test calling drawables w/ translate and matrices
38 */
39DEF_SIMPLE_GM(drawable, canvas, 180, 275) {
40 sk_sp<SkDrawable> drawable(new MyDrawable);
41
42 canvas->translate(10, 10);
43 canvas->drawDrawable(drawable.get());
44 canvas->drawDrawable(drawable.get(), 0, 150);
45
46 SkMatrix m = SkMatrix::Scale(1.5f, 0.8f);
47 m.postTranslate(70, 0);
48 canvas->drawDrawable(drawable.get(), &m);
49
50 m.postTranslate(0, 150);
51 canvas->drawDrawable(drawable.get(), &m);
52}
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawPath(const SkPath &path, const SkPaint &paint)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
SkPathBuilder & conicTo(SkPoint pt1, SkPoint pt2, SkScalar w)
SkPathBuilder & moveTo(SkPoint pt)
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
void onDraw(SkCanvas *canvas) override
Definition drawable.cpp:21
SkRect onGetBounds() override
Definition drawable.cpp:19
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609