Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | List of all members
SlideDir Class Referencefinal

#include <SlideDir.h>

Inheritance diagram for SlideDir:
Slide SkRefCnt SkRefCntBase

Classes

class  Animator
 
class  FocusController
 
struct  Rec
 

Public Member Functions

 SlideDir (const SkString &name, skia_private::TArray< sk_sp< Slide > > &&, int columns=kDefaultColumnCount)
 
- 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 winWidth, SkScalar winHeight) override
 
void unload () override
 
SkISize getDimensions () const override
 
void draw (SkCanvas *) override
 
bool animate (double) override
 
bool onChar (SkUnichar) override
 
bool onMouse (SkScalar x, SkScalar y, skui::InputState, skui::ModifierKey modifiers) override
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 32 of file SlideDir.h.

Constructor & Destructor Documentation

◆ SlideDir()

SlideDir::SlideDir ( const SkString name,
skia_private::TArray< sk_sp< Slide > > &&  slides,
int  columns = kDefaultColumnCount 
)

Definition at line 275 of file SlideDir.cpp.

276 : fSlides(std::move(slides))
277 , fColumns(columns) {
278 fName = name;
279}
SkString fName
Definition: Slide.h:54
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

Member Function Documentation

◆ animate()

bool SlideDir::animate ( double  nanos)
overrideprotectedvirtual

Reimplemented from Slide.

Definition at line 376 of file SlideDir.cpp.

376 {
377 SkMSec msec = TimeUtils::NanosToMSec(nanos);
378 if (fTimeBase == 0) {
379 // Reset the animation time.
380 fTimeBase = msec;
381 }
382
383 const auto t = msec - fTimeBase;
384 for (const auto& anim : fSceneAnimators) {
385 anim->tick(t);
386 }
387 fFocusController->tick(t);
388
389 return true;
390}
uint32_t SkMSec
Definition: SkTypes.h:184
static SkMSec NanosToMSec(double nanos)
Definition: TimeUtils.h:16

◆ draw()

void SlideDir::draw ( SkCanvas canvas)
overrideprotectedvirtual

Implements Slide.

Definition at line 372 of file SlideDir.cpp.

372 {
373 fScene->render(canvas);
374}

◆ getDimensions()

SkISize SlideDir::getDimensions ( ) const
overrideprotectedvirtual

A slide may have a content dimensions that is independent of the current window size. An empty size indicates that the Slide's dimensions are equal to the window's dimensions.

Reimplemented from Slide.

Definition at line 367 of file SlideDir.cpp.

367 {
368 return SkSize::Make(fWinSize.width(),
369 fCellSize.height() * (1 + (fSlides.size() - 1) / fColumns)).toCeil();
370}
int size() const
Definition: SkTArray.h:421
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56
SkISize toCeil() const
Definition: SkSize.h:83
SkScalar width() const
Definition: SkSize.h:76
SkScalar height() const
Definition: SkSize.h:77

◆ load()

void SlideDir::load ( SkScalar  winWidth,
SkScalar  winHeight 
)
overrideprotectedvirtual

Reimplemented from Slide.

Definition at line 294 of file SlideDir.cpp.

294 {
295 // Build a global scene using transformed animation fragments:
296 //
297 // [Group(root)]
298 // [Transform]
299 // [Group]
300 // [AnimationWrapper]
301 // [Draw]
302 // [Text]
303 // [Color]
304 // [Transform]
305 // [Group]
306 // [AnimationWrapper]
307 // [Draw]
308 // [Text]
309 // [Color]
310 // ...
311 //
312
313 fWinSize = SkSize::Make(winWidth, winHeight);
314 const auto cellWidth = winWidth / fColumns;
315 fCellSize = SkSize::Make(cellWidth, cellWidth / kAspectRatio);
316
317 fRoot = sksg::Group::Make();
318
319 for (int i = 0; i < fSlides.size(); ++i) {
320 const auto& slide = fSlides[i];
321 slide->load(winWidth, winHeight);
322
323 const auto slideSize = slide->getDimensions();
324 const auto cell = SkRect::MakeXYWH(fCellSize.width() * (i % fColumns),
325 fCellSize.height() * (i / fColumns),
326 fCellSize.width(),
327 fCellSize.height()),
328 slideRect = cell.makeInset(kPadding.width(), kPadding.height());
329
330 auto slideMatrix = sksg::Matrix<SkMatrix>::Make(SlideMatrix(slide, slideRect));
331 auto adapter = sk_make_sp<SlideAdapter>(slide);
332 auto slideGrp = sksg::Group::Make();
333 slideGrp->addChild(sksg::Draw::Make(sksg::Rect::Make(SkRect::MakeIWH(slideSize.width(),
334 slideSize.height())),
335 sksg::Color::Make(0xfff0f0f0)));
336 slideGrp->addChild(adapter);
337 slideGrp->addChild(MakeLabel(slide->getName(),
338 SkPoint::Make(slideSize.width() / 2, slideSize.height()),
339 slideMatrix->getMatrix()));
340 auto slideRoot = sksg::TransformEffect::Make(std::move(slideGrp), slideMatrix);
341
342 fSceneAnimators.push_back(adapter->makeForwardingAnimator());
343
344 fRoot->addChild(slideRoot);
345 fRecs.push_back({ slide, slideRoot, slideMatrix, slideRect });
346 }
347
348 fScene = sksg::Scene::Make(fRoot);
349
350 const auto focusRect = SkRect::MakeSize(fWinSize).makeInset(kFocusInset.width(),
351 kFocusInset.height());
352 fFocusController = std::make_unique<FocusController>(this, focusRect);
353}
static sk_sp< sksg::RenderNode > MakeLabel(const SkString &txt, const SkPoint &pos, const SkMatrix &dstXform)
Definition: SlideDir.cpp:281
static sk_sp< Color > Make(SkColor c)
Definition: SkSGPaint.cpp:44
static sk_sp< Draw > Make(sk_sp< GeometryNode > geo, sk_sp< PaintNode > paint)
Definition: SkSGDraw.h:35
void addChild(sk_sp< RenderNode >)
Definition: SkSGGroup.cpp:45
static sk_sp< Group > Make()
Definition: SkSGGroup.h:31
static sk_sp< Matrix > Make(const T &m)
Definition: SkSGTransform.h:70
static sk_sp< Rect > Make()
Definition: SkSGRect.h:36
static std::unique_ptr< Scene > Make(sk_sp< RenderNode > root)
Definition: SkSGScene.cpp:16
static sk_sp< TransformEffect > Make(sk_sp< RenderNode > child, sk_sp< Transform > transform)
Definition: SkSGTransform.h:97
constexpr auto kPadding
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
SkRect makeInset(float dx, float dy) const
Definition: SkRect.h:987
static constexpr SkRect MakeSize(const SkSize &size)
Definition: SkRect.h:633

◆ onChar()

bool SlideDir::onChar ( SkUnichar  c)
overrideprotectedvirtual

Reimplemented from Slide.

Definition at line 392 of file SlideDir.cpp.

392 {
393 if (fFocusController->hasFocus()) {
394 if (c == kUnfocusKey) {
395 fFocusController->startUnfocus();
396 return true;
397 }
398 return fFocusController->onChar(c);
399 }
400
401 return false;
402}

◆ onMouse()

bool SlideDir::onMouse ( SkScalar  x,
SkScalar  y,
skui::InputState  state,
skui::ModifierKey  modifiers 
)
overrideprotectedvirtual

Reimplemented from Slide.

Definition at line 404 of file SlideDir.cpp.

405 {
406 modifiers &= ~skui::ModifierKey::kFirstPress;
407 if (state == skui::InputState::kMove || sknonstd::Any(modifiers))
408 return false;
409
410 if (fFocusController->hasFocus()) {
411 return fFocusController->onMouse(x, y, state, modifiers);
412 }
413
414 const auto* cell = this->findCell(x, y);
415 if (!cell)
416 return false;
417
418 static constexpr SkScalar kClickMoveTolerance = 4;
419
420 switch (state) {
422 fTrackingCell = cell;
423 fTrackingPos = SkPoint::Make(x, y);
424 break;
426 if (cell == fTrackingCell &&
427 SkPoint::Distance(fTrackingPos, SkPoint::Make(x, y)) < kClickMoveTolerance) {
428 fFocusController->startFocus(cell);
429 }
430 break;
431 default:
432 break;
433 }
434
435 return false;
436}
float SkScalar
Definition: extension.cpp:12
AtkStateType state
double y
double x
std::enable_if_t< sknonstd::is_bitmask_enum< E >::value, bool > constexpr Any(E e)
Definition: SkBitmaskEnum.h:16
static float Distance(const SkPoint &a, const SkPoint &b)
Definition: SkPoint_impl.h:508

◆ unload()

void SlideDir::unload ( )
overrideprotectedvirtual

Reimplemented from Slide.

Definition at line 355 of file SlideDir.cpp.

355 {
356 for (const auto& slide : fSlides) {
357 slide->unload();
358 }
359
360 fRecs.clear();
361 fScene.reset();
362 fFocusController.reset();
363 fRoot.reset();
364 fTimeBase = 0;
365}
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310

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