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

Public Member Functions

 AudioSlide ()
 
void load (SkScalar w, SkScalar h) override
 
void draw (SkCanvas *canvas) override
 
bool onChar (SkUnichar c) override
 
ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey) override
 
bool onClick (ClickHandlerSlide::Click *) override
 
bool animate (double) override
 
- 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
 

Additional Inherited Members

virtual ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi)=0
 
virtual bool onClick (Click *)=0
 
- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 15 of file AudioSlide.cpp.

Constructor & Destructor Documentation

◆ AudioSlide()

AudioSlide::AudioSlide ( )
inline

Definition at line 20 of file AudioSlide.cpp.

20{ fName = "Audio"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ animate()

bool AudioSlide::animate ( double  )
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 87 of file AudioSlide.cpp.

87 {
88 return true;
89 }

◆ draw()

void AudioSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 36 of file AudioSlide.cpp.

36 {
37 if (!fPlayer) {
38 return;
39 }
40
41 SkPaint p;
42 p.setColor(0xFFCCCCCC);
43 canvas->drawRect(fBar, p);
44
45 p.setColor(fPlayer->isPlaying() ? SK_ColorBLUE : 0xFF8888FF);
46 SkRect r = fBar;
47 r.fRight = r.fLeft + (float)fPlayer->normalizedTime() * r.width();
48 canvas->drawRect(r, p);
49 }
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
constexpr float width() const
Definition: SkRect.h:762

◆ load()

void AudioSlide::load ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 22 of file AudioSlide.cpp.

22 {
23 auto data = SkData::MakeFromFileName("/Users/reed/skia/mp3/scott-joplin-peacherine-rag.mp3");
24 if (data) {
25 fPlayer = SkAudioPlayer::Make(data);
26
27 SkDebugf("make: dur:%g time%g state:%d",
28 fPlayer->duration(),
29 fPlayer->time(),
30 (int)fPlayer->state());
31 }
32
33 fBar = { 10, 10, 510, 30 };
34 }
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static std::unique_ptr< SkAudioPlayer > Make(sk_sp< SkData >)
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition: SkData.cpp:148
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ onChar()

bool AudioSlide::onChar ( SkUnichar  c)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 51 of file AudioSlide.cpp.

51 {
52 if (c == ' ') {
53 switch (fPlayer->state()) {
54 case SkAudioPlayer::State::kPlaying: fPlayer->pause(); break;
55 case SkAudioPlayer::State::kPaused: fPlayer->play(); break;
56 case SkAudioPlayer::State::kStopped: fPlayer->play(); break;
57 }
58 return true;
59 }
60 return this->ClickHandlerSlide::onChar(c);
61 }
virtual bool onChar(SkUnichar c)
Definition: Slide.h:44

◆ onClick()

bool AudioSlide::onClick ( ClickHandlerSlide::Click )
inlineoverridevirtual

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

Implements ClickHandlerSlide.

Definition at line 85 of file AudioSlide.cpp.

85{ return false; }

◆ onFindClickHandler()

Click * AudioSlide::onFindClickHandler ( SkScalar  x,
SkScalar  y,
skui::ModifierKey  modi 
)
inlineoverridevirtual

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 63 of file AudioSlide.cpp.

63 {
64 if (fPlayer && fBar.contains(x, y)) {
65 bool wasPlaying = fPlayer->isPlaying();
66 if (wasPlaying) {
67 fPlayer->pause();
68 }
69 return new Click([this, wasPlaying](Click* click) {
70 if (fBar.contains(click->fCurr.fX, click->fCurr.fY)) {
71 fPlayer->setNormalizedTime((click->fCurr.fX - fBar.fLeft) / fBar.width());
72 }
73
74 if (click->fState == skui::InputState::kUp) {
75 if (wasPlaying) {
76 fPlayer->play();
77 }
78 }
79 return true;
80 });
81 }
82 return nullptr;
83 }
if(end==-1)
double y
double x
bool contains(SkScalar x, SkScalar y) const
Definition: extension.cpp:19

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