Flutter Engine
The Flutter Engine
Colors.cpp
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(Colors, 128, 256, false, 0) {
5void draw(SkCanvas* canvas) {
6 const struct { SkColor4f fColor; const char* fName; } kColors[] = {
7 {SkColors::kBlack, "SkColors::kBlack"},
8 {SkColors::kDkGray, "SkColors::kDkGray"},
9 {SkColors::kGray, "SkColors::kGray"},
10 {SkColors::kLtGray, "SkColors::kLtGray"},
11 {SkColors::kWhite, "SkColors::kWhite"},
12 {SkColors::kRed, "SkColors::kRed"},
13 {SkColors::kGreen, "SkColors::kGreen"},
14 {SkColors::kBlue, "SkColors::kBlue"},
15 {SkColors::kYellow, "SkColors::kYellow"},
16 {SkColors::kCyan, "SkColors::kCyan"},
17 {SkColors::kMagenta, "SkColors::kMagenta"},
18 };
19 float y = 0;
20 constexpr float kSize = 256.0f / (sizeof(kColors) / sizeof(kColors[0]));
21 const SkColor4f kBrown{0.5f, 0.25f, 0, 1};
22 SkFont defaultFont = SkFont(fontMgr->matchFamilyStyle(nullptr, {}));
23 for (const auto& c : kColors) {
24 canvas->drawRect(SkRect{0, y, 128, y + kSize}, SkPaint(c.fColor));
25 canvas->drawString(c.fName, 4, y + kSize * 0.7f, defaultFont, SkPaint(kBrown));
26 y += kSize;
27 }
28}
29} // END FIDDLE
REG_FIDDLE(Colors, 128, 256, false, 0)
Definition: Colors.cpp:4
const char * fName
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
constexpr int kSize
double y
constexpr SkColor4f kLtGray
Definition: SkColor.h:438
constexpr SkColor4f kMagenta
Definition: SkColor.h:445
constexpr SkColor4f kGreen
Definition: SkColor.h:441
constexpr SkColor4f kRed
Definition: SkColor.h:440
constexpr SkColor4f kWhite
Definition: SkColor.h:439
constexpr SkColor4f kCyan
Definition: SkColor.h:444
constexpr SkColor4f kBlack
Definition: SkColor.h:435
constexpr SkColor4f kGray
Definition: SkColor.h:437
constexpr SkColor4f kBlue
Definition: SkColor.h:442
constexpr SkColor4f kYellow
Definition: SkColor.h:443
constexpr SkColor4f kDkGray
Definition: SkColor.h:436
const DlColor kColors[]