Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
GradientsSlide Class Reference
Inheritance diagram for GradientsSlide:
Slide SkRefCnt SkRefCntBase

Public Member Functions

 GradientsSlide ()
 
void drawUI ()
 
void draw (SkCanvas *canvas) override
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 19 of file GradientsSlide.cpp.

Constructor & Destructor Documentation

◆ GradientsSlide()

GradientsSlide::GradientsSlide ( )
inline

Definition at line 21 of file GradientsSlide.cpp.

21 {
22 fName = "Gradients";
23 fColors.push_back(SkColors::kBlue);
24 fColors.push_back(SkColors::kYellow);
25 }
SkString fName
Definition: Slide.h:54
constexpr SkColor4f kBlue
Definition: SkColor.h:442
constexpr SkColor4f kYellow
Definition: SkColor.h:443

Member Function Documentation

◆ draw()

void GradientsSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 61 of file GradientsSlide.cpp.

61 {
62 canvas->clear(SK_ColorGRAY);
63
64 this->drawUI();
65
66 SkPoint pts[2] = {{0, 0}, {256, 0}};
67 SkRect r = {0, 0, 256, 32};
68 SkPaint labelPaint;
70 paint.setDither(fDither);
71
72 canvas->save();
73 canvas->translate(10, 10);
74
76 struct Config {
77 CS fColorSpace;
78 const char* fLabel;
79 };
80 static const Config kConfigs[] = {
81 { CS::kDestination, "Destination" },
82 { CS::kSRGB, "sRGB" },
83 { CS::kSRGBLinear, "Linear sRGB" },
84 { CS::kLab, "CIELAB" },
85 { CS::kOKLab, "Oklab" },
86 { CS::kOKLabGamutMap, "OklabGamutMap" },
87 { CS::kLCH, "LCH" },
88 { CS::kOKLCH, "Oklch" },
89 { CS::kOKLCHGamutMap, "OklchGamutMap" },
90 { CS::kHSL, "HSL" },
91 { CS::kHWB, "HWB" },
92 };
94
95 for (const Config& config : kConfigs) {
96 fInterpolation.fColorSpace = config.fColorSpace;
97
98 paint.setShader(SkGradientShader::MakeLinear(pts, fColors.data(),
99 SkColorSpace::MakeSRGB(), nullptr,
100 (int)fColors.size(), SkTileMode::kClamp,
101 fInterpolation, nullptr));
102 canvas->drawRect(r, paint);
103 canvas->drawSimpleText(config.fLabel, strlen(config.fLabel), SkTextEncoding::kUTF8,
104 266, 20, font, labelPaint);
105 canvas->translate(0, 42);
106 }
107 canvas->restore();
108 }
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
static sk_sp< SkColorSpace > MakeSRGB()
Definition: SkFont.h:35
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
const Paint & paint
Definition: color_source.cc:38
SkFont DefaultFont()
font
Font Metadata and Metrics.

◆ drawUI()

void GradientsSlide::drawUI ( )
inline

Definition at line 27 of file GradientsSlide.cpp.

27 {
28 ImGui::Begin("Gradient");
29
30 ImGui::Checkbox("Dither", &fDither);
31
32 bool premul = static_cast<bool>(fInterpolation.fInPremul);
33 ImGui::Checkbox("Premul", &premul);
34 fInterpolation.fInPremul = static_cast<SkGradientShader::Interpolation::InPremul>(premul);
35
36 int hm = static_cast<int>(fInterpolation.fHueMethod);
37 ImGui::Combo("Hue Method", &hm, "Shorter\0Longer\0Increasing\0Decreasing\0\0");
38 fInterpolation.fHueMethod = static_cast<SkGradientShader::Interpolation::HueMethod>(hm);
39
40 int removeIdx = -1;
41 for (int i = 0; i < (int)fColors.size(); ++i) {
42 ImGui::PushID(i);
43 if (ImGui::Button("X")) {
44 removeIdx = i;
45 }
46 ImGui::SameLine();
47 ImGui::ColorEdit4("##Color", fColors[i].vec());
48 ImGui::PopID();
49 }
50 if (removeIdx >= 0 && fColors.size() > 2) {
51 fColors.erase(fColors.begin() + removeIdx);
52 }
53
54 if (ImGui::Button("+")) {
55 fColors.push_back(SkColors::kBlack);
56 }
57
58 ImGui::End();
59 }
static uint32_t premul(uint32_t color)
constexpr SkColor4f kBlack
Definition: SkColor.h:435

The documentation for this class was generated from the following file: