You.i Engine
YiSceneView.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_SCENE_VIEW_H_
3 #define _YI_SCENE_VIEW_H_
4 
6 #include "event/YiEventHandler.h"
7 #include "focus/YiFocus.h"
8 #include "framework/YiPredef.h"
10 #include "scenetree/YiSceneNode.h"
11 
14 class CYIActionEvent;
16 class CYILayout;
19 class CYITimeline;
20 class CYITimelineGroup;
21 enum class EYIAnchorType;
22 
48 {
49  friend class CYISceneViewPriv;
50 
51 public:
63  {
65  glm::vec3 originalScale;
66 
68  : pAnchor(nullptr)
69  {
70  }
71  };
72 
76  typedef struct
77  {
81  enum class Type
82  {
83  RequiresNode,
84  RequiresTimeline
85  };
86 
88  const char *pRequiredName;
90 
92 
96  enum class TimelineGetMode
97  {
98  GetDefault,
99  GetTimeline,
101  GetComponentOfTimelineGroup
102  };
103 
108  {
109  Persistent,
110  ClearOnEntry
111  };
112 
113  CYISceneView();
114  virtual ~CYISceneView();
115 
121  bool BuildFromTemplate(CYISceneManager *pSceneManager, const std::shared_ptr<CYIAssetViewTemplate> &pAssetViewTemplate, CYISceneManager::MissingClassHandlingMode missingHandlingMode = CYISceneManager::MissingClassHandlingMode::Abort);
122 
128  virtual bool Init() override;
129 
133  bool IsInitialized() const;
134 
138  void SetClippingAreaNode(CYISceneNode *pClippingNode);
139 
145  virtual CYIOptional<CYIStringView> GetProperty(CYIStringView propertyName) const override;
146 
152  bool GetProperty(CYIStringView propertyName, CYIString *pValue) const;
153 
157  virtual std::map<CYIString, CYIString> GetProperties() const override;
158 
164  virtual void ForEachProperty(const std::function<void(const CYIString & /* propertyName */, const CYIString & /* propertyValue */)> &action) const override;
165 
171  virtual bool HasProperties() const override;
172 
179  void EnableDefaultHitZone();
180 
189  bool IsResponsiveLayoutEnabled() const;
190 
196  void EnableResponsiveLayout();
197 
204 
208  void AddAnchor(EYIAnchorType anchorType);
209 
213  YI_ANCHOR_DATA GetAnchor(EYIAnchorType anchorType) const;
214 
218  static void RegisterAllViews();
219 
223  virtual const CYISceneView::AssetRequirement *GetAssetRequirements(uint32_t *pRequirementCount);
224 
230 
236 
242 
248 
259  virtual bool HandlesFocusInDescendants() const;
260 
275 
279  bool HasFocus() const;
280 
286  void SetFocusable(bool focusable);
287 
293  bool IsFocusable() const;
294 
298  bool CanBeFocused() const;
299 
313  void SetNextFocus(CYISceneView *pView, CYIFocus::Direction direction);
314 
324 
333 
341 
358 
364  CYISceneView *FindNextFocus(CYIFocus::Direction direction, CYIAABB &screenSpaceFocusRegion, const CYIFocusSearchOptions &options = CYIFocusSearchOptions()) const;
365 
374  virtual CYISceneView *FindNextFocusInDescendants(const CYISceneView *pCurrentFocusView, CYIFocus::Direction direction, CYIAABB &screenSpaceFocusRegion, const CYIFocusSearchOptions &options = CYIFocusSearchOptions()) const;
375 
381  const CYISceneNode *GetFocusRoot() const;
382 
388  CYISceneView *GetFocusHandler() const;
389 
395  virtual void OnFocusGained();
396 
401  virtual void FocusGained();
402 
408  virtual void OnFocusLost();
409 
414  virtual void FocusLost();
415 
416  virtual void FocusGainedInDescendants() override;
417 
418  virtual bool ContainsFocusableDescendant(const CYIFocusSearchOptions &options = CYIFocusSearchOptions()) const override;
419 
427  const std::shared_ptr<CYIAssetViewTemplate> &GetViewTemplate() const;
428 
432  const std::vector<CYIString> &GetChildTemplateNames();
433 
440 
447 
455  std::map<CYIString, CYITimeline *> GetTimelines() const;
456 
464  bool FindTimeline(CYIAbstractTimeline *&pTimeline, CYIStringView markerName, FetchType type, const CYIString &tag = "", TimelineGetMode mode = TimelineGetMode::GetDefault);
465 
480 
493  std::unique_ptr<CYITimelineGroup> BuildTimelineGroup(CYIStringView markerName);
494 
498  void BuildAnchorList();
499 
505  virtual void Reset() {}
506 
512  void SetLayout(std::unique_ptr<CYILayout> pLayout);
513 
517  const CYILayout *GetLayout() const;
518 
522  CYILayout *GetLayout();
523 
524  virtual void Measure(const MeasureSpec &widthSpec, const MeasureSpec &heightSpec, const MeasureSpec &depthSpec) override;
525 
526  virtual void ApplyMeasurements() override;
527 
528  virtual void BuildDrawList(std::vector<IYIRenderer::Command> &children, CYIAbstractCameraSceneNode *pCameraToDrawWith = nullptr) override;
529 
532 
533 protected:
537  void UpdateClipping();
538 
539  virtual void WorldScaleUpdated() override;
540  virtual void WorldBoundingBoxUpdated() override;
541 
545  virtual void OnViewReflowed(const glm::vec3 &worldScale);
546 
551  virtual void ViewReflowed(const glm::vec3 &worldScale);
552 
553  virtual bool HandleEvent(const std::shared_ptr<CYIEventDispatcher> &pDispatcher, CYIEvent *pEvent) override;
554  virtual bool ProcessEvent(const std::shared_ptr<CYIEventDispatcher> &pDispatcher, CYIEvent *pEvent) override;
555 
562 
563  virtual void SizeChanged() override;
564 
565  virtual void ChildNeedsLayout() override;
566 
567  virtual void LayoutDirtied() override;
568 
569  virtual void ChildAdded(CYISceneNode *pChild) override;
570 
571  virtual void ChildRemoved(CYISceneNode *pChild) override;
572 
573  virtual void ChildVisibilityChanged(CYISceneNode *pChild) override;
574 
579 
580  /*
581  \copydoc OnViewIsInAnimatedPosition()
582  */
584 
591  void SetInTimeline(CYIAbstractTimeline *pTimeline);
592 
599  void SetOutTimeline(CYIAbstractTimeline *pTimeline);
600 
604  virtual void OnInit();
605 
615 
623  std::unique_ptr<CYILayout> m_pLayout;
624  std::shared_ptr<CYIAssetViewTemplate> m_pAssetViewTemplate;
625  std::shared_ptr<CYISceneNodeProxy> m_pInitiallyFocusedView;
627 
628  std::multimap<EYIAnchorType, YI_ANCHOR_DATA> m_anchors;
629  std::map<CYIString, std::unique_ptr<CYITimeline>, std::less<>> m_timelines;
630  std::map<CYIString, std::unique_ptr<CYIParallelTimelineGroup>, std::less<>> m_timelineGroups;
631 
632 private:
633  static void RecursivelyAddTimelinesToGroup(CYISceneNode *pNode, CYITimelineGroup *pTimelineGroup, CYIStringView markerName);
634 
635  void SetLayout(std::unique_ptr<CYILayout> pLayout, bool configureFromProperties);
636 
637  void DescendantAdded(CYISceneNode *pDescendant);
638  void DescendantRemoved(CYISceneNode *pDescendant);
639 
640 #ifdef YI_DEBUG
641  CYIPooledViewRecycler *m_pPooledViewRecycler;
642 #endif
643 
644  CYIAbstractTimeline *m_pInTimeline;
645  CYIAbstractTimeline *m_pOutTimeline;
646 
647  std::shared_ptr<CYISceneNodeProxy> m_pNextFocusView[(size_t)CYIFocus::Direction::DirectionsCount];
648  bool m_focusable;
649 
650  bool m_initCalled;
651 
654 };
655 
658 #ifdef YI_FUNCTION_SPECIALIZATION_FULLY_SUPPORTED
659 template<>
660 inline const CYISceneView *YiDynamicCast<CYISceneView>(const CYISceneNode *pObject)
661 {
662  return pObject ? (pObject->CanCastTo<CYISceneView>() ? static_cast<const CYISceneView *>(pObject) : nullptr) : nullptr;
663 }
664 #endif
665 
666 #endif // _YI_SCENE_VIEW_H_
const char * pRequiredName
Definition: YiSceneView.h:88
The base class for the timeline framework.
Definition: YiAbstractTimeline.h:29
bool FindTimeline(CYIAbstractTimeline *&pTimeline, CYIStringView markerName, FetchType type, const CYIString &tag="", TimelineGetMode mode=TimelineGetMode::GetDefault)
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:122
virtual void LayoutDirtied() override
virtual void ForEachProperty(const std::function< void(const CYIString &, const CYIString &)> &action) const override
friend class CYISceneViewPriv
Definition: YiSceneView.h:49
A class containing focus search options.
Definition: YiFocusSearchOptions.h:23
std::map< CYIString, std::unique_ptr< CYITimeline >, std::less<> > m_timelines
Definition: YiSceneView.h:629
Allows registering of event filters which can be used to perform processing on an event before and af...
Definition: YiEventHandler.h:25
Scene trees composed of CYISceneNode objects are registered with the scene manager in order for them ...
Definition: YiSceneManager.h:75
virtual CYIOptional< CYIStringView > GetProperty(CYIStringView propertyName) const override
bool CanBeFocused() const
Automatically picks between the other modes depending on how the given timeline marker is configured...
virtual void Reset()
Definition: YiSceneView.h:505
A timeline which sources its data from a backing store.
Definition: YiTimeline.h:53
Base class for events.
Definition: YiEvent.h:27
The base class for all view types. Views are containers of renderable elements that often define inte...
Definition: YiSceneView.h:47
bool TryRequestFocusOnInitiallyFocusedView()
void EnableDefaultHitZone()
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
ID
Definition: YiMarkerData.h:35
std::unique_ptr< CYITimelineGroup > BuildTimelineGroup(CYIStringView markerName)
The base class for types of timeline groups.
Definition: YiTimelineGroup.h:25
bool BuildFromTemplate(CYISceneManager *pSceneManager, const std::shared_ptr< CYIAssetViewTemplate > &pAssetViewTemplate, CYISceneManager::MissingClassHandlingMode missingHandlingMode=CYISceneManager::MissingClassHandlingMode::Abort)
virtual void OnViewReflowed(const glm::vec3 &worldScale)
CYISceneView * GetInitiallyFocusedView() const
virtual bool HandleEvent(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent) override
Provides a base for the definition of camera objects.
Definition: YiAbstractCameraSceneNode.h:31
void SetClippingAreaNode(CYISceneNode *pClippingNode)
CYIAbstractTimeline * GetInTimeline() const
void SetInitiallyFocusedView(CYISceneView *pView, InitialFocusLifetime initialFocusLifetime=InitialFocusLifetime::Persistent)
void DisableResponsiveLayout()
Type assetRequirementType
Definition: YiSceneView.h:87
CYIMarkerData::ID requiredMarkerID
Definition: YiSceneView.h:89
Direction
Definition: YiFocus.h:44
CYIAbstractTimeline * GetFocusOutTimeline() const
std::map< CYIString, std::unique_ptr< CYIParallelTimelineGroup >, std::less<> > m_timelineGroups
Definition: YiSceneView.h:630
virtual void ViewReflowed(const glm::vec3 &worldScale)
bool m_responsiveLayoutEnabled
Definition: YiSceneView.h:617
virtual void WorldScaleUpdated() override
CYIAbstractTimeline * GetFocusInTimeline() const
CYISceneView * GetFocusHandler() const
Definition: YiSceneView.h:76
CYISceneNode * m_pClippingNode
Definition: YiSceneView.h:620
std::shared_ptr< CYISceneNodeProxy > m_pInitiallyFocusedView
Definition: YiSceneView.h:625
void AddAnchor(EYIAnchorType anchorType)
CYISceneView * GetNextFocus(CYIFocus::Direction direction) const
virtual ~CYISceneView()
const std::vector< CYIString > & GetChildTemplateNames()
bool m_inAnimatedPosition
Definition: YiSceneView.h:619
InitialFocusLifetime
Definition: YiSceneView.h:107
virtual void ChildRemoved(CYISceneNode *pChild) override
const CYILayout * GetLayout() const
void SetLayout(std::unique_ptr< CYILayout > pLayout)
void EnableResponsiveLayout()
void OnViewIsInAnimatedPosition()
void SetFocusable(bool focusable)
static void RegisterAllViews()
CYISignal< CYISceneView * > GainedFocus
Emitted when focus has entered this view.
Definition: YiSceneView.h:530
virtual bool RequestFocus(CYIFocus::Direction direction=CYIFocus::Direction::Forward, CYIFocus::FocusRootRule focusRootRule=CYIFocus::FocusRootRule::DescendantsUpdateContext, const CYIAABB &previousFocusRect=CYIAABB(), const CYIFocusSearchOptions &options=CYIFocusSearchOptions())
CYISceneNode * pAnchor
Definition: YiSceneView.h:64
void SetNextFocus(CYISceneView *pView, CYIFocus::Direction direction)
void SetInTimeline(CYIAbstractTimeline *pTimeline)
virtual void ChildNeedsLayout() override
FetchType
Definition: YiSceneNode.h:358
virtual void ApplyMeasurements() override
virtual bool ContainsFocusableDescendant(const CYIFocusSearchOptions &options=CYIFocusSearchOptions()) const override
InitialFocusLifetime m_initialFocusLifetime
Definition: YiSceneView.h:626
A container class that either contains a value or &#39;nothing&#39;.
Definition: YiOptional.h:58
virtual bool ProcessEvent(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent) override
CYISceneView * FindNextFocus(CYIFocus::Direction direction, const CYIFocusSearchOptions &options=CYIFocusSearchOptions()) const
virtual CYISceneView * FindNextFocusInDescendants(const CYISceneView *pCurrentFocusView, CYIFocus::Direction direction, CYIAABB &screenSpaceFocusRegion, const CYIFocusSearchOptions &options=CYIFocusSearchOptions()) const
MissingClassHandlingMode
Optional fallback rules for missing view types during scene loading.
Definition: YiSceneManager.h:138
virtual void Measure(const MeasureSpec &widthSpec, const MeasureSpec &heightSpec, const MeasureSpec &depthSpec) override
bool m_sceneTreeBuilt
Definition: YiSceneView.h:618
virtual void FocusGainedInDescendants() override
void OnViewIsGoingOutOfAnimatedPosition()
A scene node is the base type for all nodes which are used by the scene manager; it is an integral pa...
Definition: YiSceneNode.h:99
Definition: YiSceneNode.h:373
TimelineGetMode
Definition: YiSceneView.h:96
ViewTemplate asset. Wrapper around a CYIViewTemplate.
Definition: YiAssetViewTemplate.h:21
virtual void ChildAdded(CYISceneNode *pChild) override
Definition: YiPooledViewRecycler.h:24
virtual void ChildVisibilityChanged(CYISceneNode *pChild) override
FocusRootRule
Definition: YiFocus.h:60
bool m_stopEventPropagation
Definition: YiSceneView.h:616
virtual void OnInit()
void UpdateResponsiveLayoutAnchors()
CYIAbstractTimeline * m_pFocusOutTimeline
Definition: YiSceneView.h:622
CYIAbstractTimeline * m_pFocusInTimeline
Definition: YiSceneView.h:621
Anchors are used to apply scaling rules.
Definition: YiSceneView.h:62
std::map< CYIString, CYITimeline * > GetTimelines() const
virtual const CYISceneView::AssetRequirement * GetAssetRequirements(uint32_t *pRequirementCount)
Type
Definition: YiSceneView.h:81
virtual void SizeChanged() override
virtual void OnFocusGained()
CYIAbstractTimeline * GetOutTimeline() const
This class defines a layout that can be applied to a scene view. The layout class determines how obje...
Definition: YiLayout.h:159
const std::shared_ptr< CYIAssetViewTemplate > & GetViewTemplate() const
unsigned long size_t
Definition: YiPredefApple.h:117
virtual CYIAbstractTimeline * GetTimeline(CYIStringView markerName, TimelineGetMode mode=TimelineGetMode::GetDefault)
This class represents an Axis-Aligned Bounding Box.
Definition: YiAABB.h:24
virtual void FocusGained()
glm::vec3 originalScale
Definition: YiSceneView.h:65
virtual void BuildDrawList(std::vector< IYIRenderer::Command > &children, CYIAbstractCameraSceneNode *pCameraToDrawWith=nullptr) override
This kind of timeline group will play its children in parallel, possibly with specified offsets (dela...
Definition: YiParallelTimelineGroup.h:21
virtual void WorldBoundingBoxUpdated() override
bool HasFocus() const
bool IsFocusable() const
#define YI_TYPE_BASES(CLASS, BASES...)
Definition: YiRtti.h:257
bool IsInitialized() const
YI_ANCHOR_DATA()
Definition: YiSceneView.h:67
bool IsResponsiveLayoutEnabled() const
virtual bool Init() override
void BuildAnchorList()
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:168
CYISignal< CYISceneView * > LostFocus
Emitted when focus has left this view.
Definition: YiSceneView.h:531
EYIAnchorType
Definition: YiAnchor.h:7
virtual void OnFocusLost()
std::unique_ptr< CYILayout > m_pLayout
Definition: YiSceneView.h:623
std::multimap< EYIAnchorType, YI_ANCHOR_DATA > m_anchors
Definition: YiSceneView.h:628
YI_ANCHOR_DATA GetAnchor(EYIAnchorType anchorType) const
const CYISceneNode * GetFocusRoot() const
CYITimelineGroup * GetTimelineGroup(CYIStringView markerName)
virtual bool HandlesFocusInDescendants() const
The initally focused view will remain set until the next call to SetInitiallyFocusedView.
virtual bool HasProperties() const override
Stores data related to a user Action event.
Definition: YiActionEvent.h:18
void SetOutTimeline(CYIAbstractTimeline *pTimeline)
virtual void FocusLost()
std::shared_ptr< CYIAssetViewTemplate > m_pAssetViewTemplate
Definition: YiSceneView.h:624
virtual std::map< CYIString, CYIString > GetProperties() const override
A lightweight wrapper around a sequence of Unicode characters.
Definition: YiStringView.h:57
void UpdateClipping()