Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
CubicResamplerSlide Class Reference
Inheritance diagram for CubicResamplerSlide:
ClickHandlerSlide Slide SkRefCnt SkRefCntBase

Public Member Functions

 CubicResamplerSlide ()
 
- Public Member Functions inherited from ClickHandlerSlide
bool onMouse (SkScalar x, SkScalar y, skui::InputState clickState, skui::ModifierKey modifierKeys) final
 
- 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
 

Protected Member Functions

void load (SkScalar, SkScalar) override
 
void draw (SkCanvas *canvas) override
 
ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey) override
 
bool onClick (ClickHandlerSlide::Click *) override
 
virtual ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi)=0
 
virtual bool onClick (Click *)=0
 

Static Protected Member Functions

static float pin_unitize (float min, float max, float value)
 
static SkPoint pin_unitize (const SkRect &r, SkPoint p)
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 206 of file XferSlide.cpp.

Constructor & Destructor Documentation

◆ CubicResamplerSlide()

CubicResamplerSlide::CubicResamplerSlide ( )
inline

Definition at line 208 of file XferSlide.cpp.

208 {
209 fName = "CubicResampler";
210 }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void CubicResamplerSlide::draw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Implements Slide.

Definition at line 225 of file XferSlide.cpp.

225 {
226 for (const auto& rec : fRecs) {
227 rec.draw(canvas, fCubic);
228 }
229
231 paint.setAntiAlias(true);
232 paint.setStroke(true);
233 canvas->drawRect(fDomain, paint);
234
235 paint.setColor(SK_ColorRED);
236 paint.setStroke(false);
237 SkPoint loc = SkMatrix::RectToRect({0,0,1,1}, fDomain).mapXY(fCubic.B, fCubic.C);
238 canvas->drawCircle(loc.fX, loc.fY, 8, paint);
239
240 SkString str;
241 str.printf("B=%4.2f C=%4.2f", fCubic.B, fCubic.C);
243 font.setSize(25);
245 paint.setColor(SK_ColorBLACK);
246 canvas->drawSimpleText(str.c_str(), str.size(), SkTextEncoding::kUTF8,
247 fDomain.fLeft + 10, fDomain.fBottom + 40, font, paint);
248 }
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
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 drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
const Paint & paint
Definition: color_source.cc:38
SkFont DefaultFont()
font
Font Metadata and Metrics.
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14

◆ load()

void CubicResamplerSlide::load ( SkScalar  ,
SkScalar   
)
inlineoverrideprotectedvirtual

Reimplemented from Slide.

Definition at line 213 of file XferSlide.cpp.

213 {
214 SkRect r = {10, 10, 200, 200};
215 for (const char* name : {"images/mandrill_128.png",
216 "images/rle.bmp",
217 "images/example_4.png"}) {
218 fRecs.push_back({ToolUtils::GetResourceAsImage(name), r});
219 r.offset(0, r.height() + 10);
220 }
221 fDomain.setXYWH(r.fLeft + 3 * r.width() + 40, 50, 200, 200);
222 fCubic = {.3f, .5f};
223 }
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
void setXYWH(float x, float y, float width, float height)
Definition: SkRect.h:931
void offset(float dx, float dy)
Definition: SkRect.h:1016
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762

◆ onClick()

bool CubicResamplerSlide::onClick ( ClickHandlerSlide::Click )
inlineoverrideprotectedvirtual

Override to track clicks. Return true as long as you want to track the pen/mouse.

Implements ClickHandlerSlide.

Definition at line 272 of file XferSlide.cpp.

272{ return false; }

◆ onFindClickHandler()

Click * CubicResamplerSlide::onFindClickHandler ( SkScalar  x,
SkScalar  y,
skui::ModifierKey  modi 
)
inlineoverrideprotectedvirtual

Return a Click object to handle the click. onClick will be called repeatedly with the latest mouse state tracked on the Click object until it returns false.

Implements ClickHandlerSlide.

Definition at line 261 of file XferSlide.cpp.

261 {
262 if (fDomain.contains(x, y)) {
263 return new Click([this](Click* click) {
264 auto [B, C] = pin_unitize(fDomain, click->fCurr);
265 fCubic = {B, C};
266 return true;
267 });
268 }
269 return nullptr;
270 }
static float pin_unitize(float min, float max, float value)
Definition: XferSlide.cpp:250
#define C(TEST_CATEGORY)
Definition: colrv1.cpp:248
#define B
double y
double x
bool contains(SkScalar x, SkScalar y) const
Definition: extension.cpp:19

◆ pin_unitize() [1/2]

static SkPoint CubicResamplerSlide::pin_unitize ( const SkRect r,
SkPoint  p 
)
inlinestaticprotected

Definition at line 253 of file XferSlide.cpp.

253 {
254 return {
255 pin_unitize(r.fLeft, r.fRight, p.fX),
256 pin_unitize(r.fTop, r.fBottom, p.fY),
257 };
258 }
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ pin_unitize() [2/2]

static float CubicResamplerSlide::pin_unitize ( float  min,
float  max,
float  value 
)
inlinestaticprotected

Definition at line 250 of file XferSlide.cpp.

250 {
251 return (std::min(std::max(value, min), max) - min) / (max - min);
252 }
uint8_t value
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

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