Flutter Engine
The Flutter Engine
Functions
Color_Wheel.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (Color_Wheel, 256, 256, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( Color_Wheel  ,
256  ,
256  ,
false  ,
 
)

Definition at line 4 of file Color_Wheel.cpp.

4 {
5void draw_color_wheel(SkCanvas* canvas, float scale) {
6 const float stroke = scale * 3 / 64;
7 const float size = scale * 9 / 32;
8 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
9 canvas->translate(0.5f * scale, 0.5f * scale);
10 canvas->clear(0);
11 canvas->drawCircle({0, 0}, (scale - stroke) * 0.5f, SkPaint(SkColors::kWhite));
12 {
13 SkPaint sweep;
14 const SkMatrix rotate = SkMatrix::MakeAll(0, -1, 0, 1, 0, 0, 0, 0, 1);
15 constexpr unsigned kColorCount = 7;
16 static const SkColor4f kColors[kColorCount] = {
19 sweep.setShader(SkGradientShader::MakeSweep(0, 0, kColors, nullptr, nullptr,
20 kColorCount, 0, &rotate));
23 sweep.setAntiAlias(true);
24 canvas->drawCircle({0, 0}, (scale - stroke) * 0.5f, sweep);
25 }
26
28 const struct { const char* str; float radius; float angle; SkColor4f color;} kLetters[] = {
29 {"K", 0, 0, SkColors::kBlack},
30 {"R", 1, 90, SkColors::kRed},
31 {"Y", 1, 150, SkColors::kYellow},
32 {"G", 1, 210, SkColors::kGreen},
33 {"C", 1, 270, SkColors::kCyan},
34 {"B", 1, 330, SkColors::kBlue},
35 {"M", 1, 30, SkColors::kMagenta},
36 };
37 for (const auto& v : kLetters) {
38 SkRect bnds;
39 font.measureText(v.str, strlen(v.str), SkTextEncoding::kUTF8, &bnds);
40 constexpr double pi_over_180 = 3.141592653589793 / 180;
41 float x = (float)(0.3 * scale * v.radius * cos(pi_over_180 * v.angle) - bnds.centerX());
42 float y = (float)(0.3 * scale * v.radius * sin(pi_over_180 * v.angle) - bnds.centerY());
43 canvas->drawString(v.str, x, y, font, SkPaint(v.color));
44 }
45}
46void draw(SkCanvas* canvas) { draw_color_wheel(canvas, 256); }
47} // END FIDDLE
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static bool rotate(const SkDCubic &cubic, int zero, int index, SkDCubic &rotPath)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
Definition: SkFontMgr.cpp:150
static constexpr SkFontStyle Bold()
Definition: SkFontStyle.h:69
Definition: SkFont.h:35
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition: SkMatrix.h:179
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setShader(sk_sp< SkShader > shader)
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
DlColor color
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
double y
double x
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 kBlue
Definition: SkColor.h:442
constexpr SkColor4f kYellow
Definition: SkColor.h:443
const DlColor kColors[]
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
const Scalar scale
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float centerY() const
Definition: SkRect.h:785