Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
SlideDir::FocusController Class Referencefinal
Inheritance diagram for SlideDir::FocusController:
SlideDir::Animator SkRefCnt SkRefCntBase

Public Member Functions

 FocusController (const SlideDir *dir, const SkRect &focusRect)
 
bool hasFocus () const
 
void startFocus (const Rec *target)
 
void startUnfocus ()
 
bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
bool onChar (SkUnichar c)
 
- Public Member Functions inherited from SlideDir::Animator
 Animator (const Animator &)=delete
 
Animatoroperator= (const Animator &)=delete
 
void tick (float t)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

void onTick (float t) override
 
- Protected Member Functions inherited from SlideDir::Animator
 Animator ()=default
 
virtual void onTick (float t)=0
 

Detailed Description

Definition at line 136 of file SlideDir.cpp.

Constructor & Destructor Documentation

◆ FocusController()

SlideDir::FocusController::FocusController ( const SlideDir dir,
const SkRect focusRect 
)
inline

Definition at line 138 of file SlideDir.cpp.

139 : fDir(dir)
140 , fRect(focusRect)
141 , fTarget(nullptr)
142 , fMap(kFocusCtrl1, kFocusCtrl0)
143 , fState(State::kIdle) {
144 fShadePaint = sksg::Color::Make(kFocusShade);
145 fShade = sksg::Draw::Make(sksg::Plane::Make(), fShadePaint);
146 }
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
static sk_sp< Plane > Make()
Definition: SkSGPlane.h:29
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145

Member Function Documentation

◆ hasFocus()

bool SlideDir::FocusController::hasFocus ( ) const
inline

Definition at line 148 of file SlideDir.cpp.

148{ return fState == State::kFocused; }

◆ onChar()

bool SlideDir::FocusController::onChar ( SkUnichar  c)
inline

Definition at line 201 of file SlideDir.cpp.

201 {
202 SkASSERT(fTarget);
203
204 return fTarget->fSlide->onChar(c);
205 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual bool onChar(SkUnichar c)
Definition: Slide.h:44
sk_sp< Slide > fSlide
Definition: SlideDir.cpp:130

◆ onMouse()

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

Definition at line 185 of file SlideDir.cpp.

185 {
186 SkASSERT(fTarget);
187
188 if (!fRect.contains(x, y)) {
189 this->startUnfocus();
190 return true;
191 }
192
193 // Map coords to slide space.
194 const auto xform = SkMatrix::RectToRect(fRect, SkRect::MakeSize(fDir->fWinSize),
196 const auto pt = xform.mapXY(x, y);
197
198 return fTarget->fSlide->onMouse(pt.x(), pt.y(), state, modifiers);
199 }
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
@ kCenter_ScaleToFit
scales and aligns to center
Definition: SkMatrix.h:139
virtual bool onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
Definition: Slide.h:45
AtkStateType state
double y
double x
bool contains(SkScalar x, SkScalar y) const
Definition: extension.cpp:19
static constexpr SkRect MakeSize(const SkSize &size)
Definition: SkRect.h:633

◆ onTick()

void SlideDir::FocusController::onTick ( float  t)
inlineoverrideprotectedvirtual

Implements SlideDir::Animator.

Definition at line 208 of file SlideDir.cpp.

208 {
209 if (!this->isAnimating())
210 return;
211
212 if (!fTimeBase) {
213 fTimeBase = t;
214 }
215
216 const auto rel_t = (t - fTimeBase) / kFocusDuration,
217 map_t = SkTPin(fMap.computeYFromX(rel_t), 0.0f, 1.0f);
218
219 SkMatrix m;
220 for (int i = 0; i < 9; ++i) {
221 m[i] = fM0[i] + map_t * (fM1[i] - fM0[i]);
222 }
223
224 SkASSERT(fTarget);
225 fTarget->fMatrix->setMatrix(m);
226
227 const auto shadeOpacity = fOpacity0 + map_t * (fOpacity1 - fOpacity0);
228 fShadePaint->setOpacity(shadeOpacity);
229
230 if (rel_t < 1)
231 return;
232
233 switch (fState) {
234 case State::kFocusing:
235 fState = State::kFocused;
236 break;
237 case State::kUnfocusing:
238 fState = State::kIdle;
239 fDir->fRoot->removeChild(fShade);
240 break;
241
242 case State::kIdle:
243 case State::kFocused:
244 SkASSERT(false);
245 break;
246 }
247 }
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
float computeYFromX(float x) const
Definition: SkCubicMap.cpp:61
void removeChild(const sk_sp< RenderNode > &)
Definition: SkSGGroup.cpp:59
sk_sp< sksg::Matrix< SkMatrix > > fMatrix
Definition: SlideDir.cpp:132

◆ startFocus()

void SlideDir::FocusController::startFocus ( const Rec target)
inline

Definition at line 150 of file SlideDir.cpp.

150 {
151 if (fState != State::kIdle)
152 return;
153
154 fTarget = target;
155
156 // Move the shade & slide to front.
157 fDir->fRoot->removeChild(fTarget->fSlideRoot);
158 fDir->fRoot->addChild(fShade);
159 fDir->fRoot->addChild(fTarget->fSlideRoot);
160
161 fM0 = SlideMatrix(fTarget->fSlide, fTarget->fRect);
162 fM1 = SlideMatrix(fTarget->fSlide, fRect);
163
164 fOpacity0 = 0;
165 fOpacity1 = 1;
166
167 fTimeBase = 0;
168 fState = State::kFocusing;
169
170 // Push initial state to the scene graph.
171 this->onTick(fTimeBase);
172 }
void onTick(float t) override
Definition: SlideDir.cpp:208
void addChild(sk_sp< RenderNode >)
Definition: SkSGGroup.cpp:45
uint32_t * target
sk_sp< sksg::RenderNode > fSlideRoot
Definition: SlideDir.cpp:131
SkRect fRect
Definition: SlideDir.cpp:133

◆ startUnfocus()

void SlideDir::FocusController::startUnfocus ( )
inline

Definition at line 174 of file SlideDir.cpp.

174 {
175 SkASSERT(fTarget);
176
177 using std::swap;
178 swap(fM0, fM1);
179 swap(fOpacity0, fOpacity1);
180
181 fTimeBase = 0;
182 fState = State::kUnfocusing;
183 }
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341

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