Flutter Engine
The Flutter Engine
MixerSlide.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 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
11#include "include/core/SkPath.h"
15#include "src/base/SkUtils.h"
16#include "tools/DecodeUtils.h"
17#include "tools/Resources.h"
19
20const float gMat[] = {
21 .3f, .6f, .1f, 0, 0,
22 .3f, .6f, .1f, 0, 0,
23 .3f, .6f, .1f, 0, 0,
24 0, 0, 0, 1, 0,
25};
26
28 sk_sp<SkImage> fImg;
31
32 float fWeight = 0;
33 float fDW = 0.02f;
34
35public:
36 MixerSlide() { fName = "Mixer"; }
37
38 void draw(SkCanvas* canvas) override {
39 if (!fImg) {
40 fImg = ToolUtils::GetResourceAsImage("images/mandrill_256.png");
43 }
44
45 float gap = fImg->width() * 3;
46
47 canvas->translate(10, 10);
48 dodraw(canvas, nullptr, fCF1, gap);
49 canvas->translate(0, fImg->height() + 10);
50 dodraw(canvas, fCF0, nullptr, gap);
51 canvas->translate(0, fImg->height() + 10);
52 dodraw(canvas, fCF0, fCF1, gap);
53
54 fWeight += fDW;
55 if (fWeight > 1 || fWeight < 0) {
56 fDW = -fDW;
57 }
58 }
59
60protected:
62 return fRect.contains(SkScalarRoundToInt(x),
63 SkScalarRoundToInt(y)) ? new Click() : nullptr;
64 }
65
66 bool onClick(Click* click) override {
67 fRect.offset(click->fCurr.fX - click->fPrev.fX,
68 click->fCurr.fY - click->fPrev.fY);
69 return true;
70 }
71
72private:
73 void dodraw(SkCanvas* canvas, sk_sp<SkColorFilter> cf0, sk_sp<SkColorFilter> cf1, float gap) {
75 paint.setColorFilter(cf0);
76 canvas->drawImage(fImg, 0, 0, SkSamplingOptions(), &paint);
77
78 paint.setColorFilter(SkColorFilters::Lerp(fWeight, cf0, cf1));
79 canvas->drawImage(fImg, fImg->width() + gap * fWeight, 0,
81
82 paint.setColorFilter(cf1);
83 canvas->drawImage(fImg, 2*fImg->width() + gap, 0, SkSamplingOptions(), &paint);
84 }
85
86 SkIRect fRect;
87
88};
89DEF_SLIDE( return new MixerSlide; )
const float gMat[]
Definition: MixerSlide.cpp:20
@ kScreen
r = s + d - s*d
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
#define DEF_SLIDE(code)
Definition: Slide.h:25
void draw(SkCanvas *canvas) override
Definition: MixerSlide.cpp:38
bool onClick(Click *click) override
Definition: MixerSlide.cpp:66
Click * onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override
Definition: MixerSlide.cpp:61
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
static sk_sp< SkColorFilter > Lerp(float t, sk_sp< SkColorFilter > dst, sk_sp< SkColorFilter > src)
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
SkString fName
Definition: Slide.h:54
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
SkSamplingOptions(SkFilterMode::kLinear))
ModifierKey
Definition: ModifierKey.h:9
Definition: SkRect.h:32
void offset(int32_t dx, int32_t dy)
Definition: SkRect.h:367
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165