From ccab1cc6f4586b75e85766750dfc7a928887ca31 Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Fri, 3 May 2019 14:07:22 -0400 Subject: [PATCH] docs/examples/Colors Change-Id: I61a295daacaf8a4b0350ae7fc7641059a990552a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212020 Commit-Queue: Hal Canary Commit-Queue: Brian Osman Auto-Submit: Hal Canary Reviewed-by: Brian Osman --- docs/examples/Colors.cpp | 28 ++++++++++++++++++++++++++++ tools/fiddle/all_examples.cpp | 1 + 2 files changed, 29 insertions(+) create mode 100644 docs/examples/Colors.cpp diff --git a/docs/examples/Colors.cpp b/docs/examples/Colors.cpp new file mode 100644 index 0000000000..e76a90f6ba --- /dev/null +++ b/docs/examples/Colors.cpp @@ -0,0 +1,28 @@ +// Copyright 2019 Google LLC. +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +#include "tools/fiddle/examples.h" +REG_FIDDLE(Colors, 128, 256, false, 0) { +void draw(SkCanvas* canvas) { + const struct { SkColor4f fColor; const char* fName; } kColors[] = { + {SkColors::kBlack, "SkColors::kBlack"}, + {SkColors::kDkGray, "SkColors::kDkGray"}, + {SkColors::kGray, "SkColors::kGray"}, + {SkColors::kLtGray, "SkColors::kLtGray"}, + {SkColors::kWhite, "SkColors::kWhite"}, + {SkColors::kRed, "SkColors::kRed"}, + {SkColors::kGreen, "SkColors::kGreen"}, + {SkColors::kBlue, "SkColors::kBlue"}, + {SkColors::kYellow, "SkColors::kYellow"}, + {SkColors::kCyan, "SkColors::kCyan"}, + {SkColors::kMagenta, "SkColors::kMagenta"}, + }; + float y = 0; + constexpr float kSize = 256.0f / (sizeof(kColors) / sizeof(kColors[0])); + const SkColor4f kBrown{0.5f, 0.25f, 0, 1}; + for (const auto& c : kColors) { + canvas->drawRect(SkRect{0, y, 128, y + kSize}, SkPaint(c.fColor)); + canvas->drawString(c.fName, 4, y + kSize * 0.7f, SkFont(), SkPaint(kBrown)); + y += kSize; + } +} +} // END FIDDLE diff --git a/tools/fiddle/all_examples.cpp b/tools/fiddle/all_examples.cpp index e3966e8c5c..b14f23cecd 100644 --- a/tools/fiddle/all_examples.cpp +++ b/tools/fiddle/all_examples.cpp @@ -247,6 +247,7 @@ #include "../../docs/examples/Color_Type_RGB_101010.cpp" #include "../../docs/examples/Color_Type_RGB_565.cpp" #include "../../docs/examples/Color_Type_RGB_888.cpp" +#include "../../docs/examples/Colors.cpp" #include "../../docs/examples/Conic_Weight_a.cpp" #include "../../docs/examples/Conic_Weight_b.cpp" #include "../../docs/examples/Conic_Weight_c.cpp"