You.i Engine
YiApp.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_APP_H_
3 #define _YI_APP_H_
4 
5 #include "event/YiActionEvent.h"
7 #include "framework/YiPredef.h"
8 #include "renderer/YiSurface.h"
10 #include "signal/YiSignal.h"
11 #include "utility/YiRtti.h"
12 
13 class CYIAppPriv;
14 class CYIColor;
15 class CYIDevPanel;
16 class CYIEventHandler;
17 class CYIEvent;
18 class CYIFramework;
19 class CYIHud;
20 class CYIKeyEvent;
21 class CYIRenderSystem;
22 class CYISceneManager;
23 class CYIScreen;
25 class CYIFocusEngine;
26 
45 class CYIApp
46 {
47 public:
48  friend class CYIFPSWidget;
49 
50  enum class MemoryLevel
51  {
52  Moderate,
53  Low,
54  Critical
55  };
56 
57  CYIApp();
58  virtual ~CYIApp();
59 
65  bool Init();
66 
72  bool Init(std::unique_ptr<CYIFocusEngine> pFocusEngine);
73 
78  bool IsInitialized() const;
79 
82 
85 
88 
89  bool SetScreenProperties(int screenSizeX, int screenSizeY, int screenDensityX, int screenDensityY);
90  bool SetScreen(const CYIScreen &screen);
91  bool SetSurface(CYISurface *pSurface);
98  void SurfaceWasResized(int32_t width, int32_t height);
99 
106 
110  virtual void HandleKeyInputs(const CYIKeyEvent &keyEvent);
111 
126  virtual void HandleActionInputs(int32_t x, int32_t y, CYIEvent::Type eventType, uint8_t pointerID = 0, bool hover = false);
127 
131  virtual void HandleActionInputs(int32_t x, int32_t y, int32_t wheelDelta, CYIActionEvent::ButtonType button, CYIEvent::Type eventType, uint8_t pointerID = 0, bool hover = false);
132 
140  void HandleTapGestureInputs(int32_t x, int32_t y, uint32_t numberOfFingers, CYIEvent::Type eventType);
141 
148  void HandleSwipeGestureInputs(uint32_t numberOfFingers, CYISwipeGestureEvent::Direction direction, CYIEvent::Type eventType);
149 
160  void HandleDragGestureInputs(int32_t x, int32_t y, uint32_t numberOfFingers, CYIGestureEvent::State state, CYIEvent::Type eventType);
161 
170  void HandleScrubGestureInputs(uint32_t numberOfFingers, CYIEvent::Type eventType);
171 
175  virtual void HandleLowMemory(MemoryLevel memoryLevel);
176 
181  bool LoadFont(const CYIString &URI, ssize_t *pFontID, bool local = false);
182 
188  bool LoadFont(const uint8_t *pFontData, uint32_t dataSize, ssize_t *pFontID);
189 
194 
199 
204  virtual CYISceneManager *GetSceneManager() const;
205 
210  bool PostEvent(std::unique_ptr<CYIEvent> pEvent, CYIEvent::Priority priority = CYIEvent::Priority::Default, bool bump = false);
211 
215  bool PostEvent(std::unique_ptr<CYIEvent> pEvent, CYIEventHandler *pDestination, CYIEvent::Priority priority = CYIEvent::Priority::Default, bool bump = false);
216 
220  bool SendEvent(std::unique_ptr<CYIEvent> pEvent);
221 
225  bool SendEvent(std::unique_ptr<CYIEvent> pEvent, CYIEventHandler *pDestination);
226 
234  bool Update(bool forceDirty = false, bool updateTime = true);
235 
240  virtual void Draw();
241 
248  virtual void OnPreDraw() {}
249 
256  virtual void OnPostDraw() {}
257 
261  virtual void Swap();
262 
268  void SetHUDVisibility(bool visible);
269 
273  bool IsHUDVisible() const;
274 
278  CYIHud &GetHUD();
279 
283  const CYIHud &GetHUD() const;
284 
290  void SetShowFPS(bool show);
291 
297  bool GetShowFPS() const;
298 
304  CYIDevPanel *GetDevPanel() const;
305 
309  void InitializeDevPanel();
310 
314  void DestroyDevPanel();
315 
319  void SetAssetsPath(const CYIString &assetsPath);
320 
324  const CYIString &GetAssetsPath() const;
325 
329  void SetCachePath(const CYIString &cachePath);
330 
334  const CYIString &GetCachePath() const;
335 
340  void SetDataPath(const CYIString &dataPath);
341 
345  const CYIString &GetDataPath() const;
346 
351  void SetExternalPath(const CYIString &externalPath);
352 
358  const CYIString &GetExternalPath() const;
359 
363  void SetVersion(const CYIString &version);
364 
368  const CYIString &GetVersion() const;
369 
373  void SetMultiTouchEnabled(bool enabled);
374 
378  bool IsMultiTouchEnabled() const;
379 
385  void SetBackgroundColor(const CYIColor &color);
386 
392  const CYIColor &GetBackgroundColor();
393 
401  void SetRenderingThrottling(bool bThrottle);
402 
408  bool IsRenderingThrottled() const;
409 
410  CYISignal<int32_t /* width */, int32_t /* height */> SurfaceSizeChanged;
411 
412 protected:
413  CYIApp(CYIAppPriv *pPriv);
414 
418  virtual bool UserInit() = 0;
419 
424  virtual bool UserStart() = 0;
425 
430  virtual void UserUpdate() {}
431 
444  virtual void OnSurfaceSizeChanged(int32_t width, int32_t height);
445 
446  friend class CYIAppPriv;
448 
449 private:
451 };
452 
455 #endif // _YI_APP_H_
CYIHud & GetHUD()
const CYIString & GetDataPath() const
virtual void HandleLowMemory(MemoryLevel memoryLevel)
#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
void SetDataPath(const CYIString &dataPath)
Class for key events.
Definition: YiKeyEvent.h:15
Allows registering of event filters which can be used to perform processing on an event before and af...
Definition: YiEventHandler.h:25
virtual void HandleActionInputs(int32_t x, int32_t y, CYIEvent::Type eventType, uint8_t pointerID=0, bool hover=false)
Scene trees composed of CYISceneNode objects are registered with the scene manager in order for them ...
Definition: YiSceneManager.h:75
Base class for events.
Definition: YiEvent.h:27
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
Definition: YiScreen.h:12
CYIAppPriv * m_pPriv
Definition: YiApp.h:447
void HandleScrubGestureInputs(uint32_t numberOfFingers, CYIEvent::Type eventType)
bool SendEvent(std::unique_ptr< CYIEvent > pEvent)
const CYIString & GetAssetsPath() const
virtual bool UserStart()=0
void SetRenderingThrottling(bool bThrottle)
Direction
Definition: YiSwipeGestureEvent.h:21
void SetCachePath(const CYIString &cachePath)
void SetHUDVisibility(bool visible)
virtual void Draw()
void HandleSwipeGestureInputs(uint32_t numberOfFingers, CYISwipeGestureEvent::Direction direction, CYIEvent::Type eventType)
void SetDefaultNavigationBarVisibility(CYIScreenProperty::NavigationBar navigationBar)
virtual void OnPreDraw()
Definition: YiApp.h:248
bool SetSurface(CYISurface *pSurface)
State
Definition: YiGestureEvent.h:31
void HandleTapGestureInputs(int32_t x, int32_t y, uint32_t numberOfFingers, CYIEvent::Type eventType)
virtual void Swap()
void SetDefaultOrientation(CYIScreenProperty::Orientation orientation)
void SetShowFPS(bool show)
bool SetScreenProperties(int screenSizeX, int screenSizeY, int screenDensityX, int screenDensityY)
Orientation
Definition: YiScreenProperty.h:15
CYIFrameworkConfiguration is used to specify configuration settings for the CYIFramework class...
Definition: YiFrameworkConfiguration.h:18
const CYIColor & GetBackgroundColor()
virtual void OnSurfaceSizeChanged(int32_t width, int32_t height)
void SetMultiTouchEnabled(bool enabled)
const CYIString & GetExternalPath() const
CYIRenderSystem is a singleton class used to acquire global instances of a number of classes...
Definition: YiRenderSystem.h:27
virtual bool UserInit()=0
NavigationBar
Definition: YiScreenProperty.h:32
void SetBackgroundColor(const CYIColor &color)
void SetDefaultStatusBarVisibility(CYIScreenProperty::StatusBar statusbar)
bool SetScreen(const CYIScreen &screen)
void SetAssetsPath(const CYIString &assetsPath)
bool Update(bool forceDirty=false, bool updateTime=true)
StatusBar
Definition: YiScreenProperty.h:26
ButtonType
Definition: YiActionEvent.h:21
void SetExternalPath(const CYIString &externalPath)
CYIRenderSystem * GetMainRenderSystem()
Definition: YiSurface.h:28
void InitializeDevPanel()
bool IsHUDVisible() const
CYIFramework * GetMainFramework()
MemoryLevel
Definition: YiApp.h:50
CYIScreenProperty::NavigationBar GetDefaultNavigationBarVisibility() const
const CYIString & GetCachePath() const
bool IsMultiTouchEnabled() const
int ssize_t
Definition: YiPredefWin32.h:131
A class used to display information on top of the rendered scenes.
Definition: YiHud.h:24
virtual void HandleKeyInputs(const CYIKeyEvent &keyEvent)
virtual CYISceneManager * GetSceneManager() const
bool PostEvent(std::unique_ptr< CYIEvent > pEvent, CYIEvent::Priority priority=CYIEvent::Priority::Default, bool bump=false)
virtual void OnPostDraw()
Definition: YiApp.h:256
CYIScreenProperty::Orientation GetDefaultOrientation() const
const CYIString & GetVersion() const
friend class CYIAppPriv
Definition: YiApp.h:446
bool IsInitialized() const
void SetVersion(const CYIString &version)
This file contains the classes and macros used to implement RTTI in You.i Engine. ...
void HandleDragGestureInputs(int32_t x, int32_t y, uint32_t numberOfFingers, CYIGestureEvent::State state, CYIEvent::Type eventType)
A class used to represent a color value.
Definition: YiColor.h:31
bool Init()
bool LoadFont(const CYIString &URI, ssize_t *pFontID, bool local=false)
Definition: YiFocusEngine.h:26
Priority
Priority of the event in the event queue.
Definition: YiEvent.h:99
A class used to manipulate developer utilities.
Definition: YiDevPanel.h:60
CYIFramework is a singleton class used to acquire global instances of a number of classes...
Definition: YiFramework.h:30
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:168
bool GetShowFPS() const
virtual ~CYIApp()
bool IsRenderingThrottled() const
virtual CYIFrameworkConfiguration UserConfiguration()
virtual void UserUpdate()
Definition: YiApp.h:430
void SurfaceWasResized(int32_t width, int32_t height)
The base class for all applications.
Definition: YiApp.h:45
CYISignal< int32_t, int32_t > SurfaceSizeChanged
Definition: YiApp.h:410
Type
The event type of the CYIEvent class instance.
Definition: YiEvent.h:33
CYIScreenProperty::StatusBar GetDefaultStatusBarVisibility() const
CYIDevPanel * GetDevPanel() const
void DestroyDevPanel()
friend class CYIFPSWidget
Definition: YiApp.h:48