Fission FSN
Loading...
Searching...
No Matches
fsNAxmolRenderView.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: fsNAxmolRenderView.h
4*
5* Purpose: Shared Axmol RenderView helpers.
6*
7*********************************************************************/
8
9#ifndef fsNAxmolRenderViewhdr
10#define fsNAxmolRenderViewhdr
11
12#ifdef AXMOL_V3
13 #include <platform/RenderViewCore.h>
14#else
15 #include <platform/RenderView.h>
16#endif
17
18#include <fsCore/fsBaseTypes.h>
19
21{
22#ifdef AXMOL_V3
23using fsTRenderView = ax::RenderViewCore;
24#else
25using fsTRenderView = ax::RenderView;
26#endif
27
29{
30 fsF32 x = 0.0f;
31 fsF32 y = 0.0f;
32 fsF32 w = 0.0f;
33 fsF32 h = 0.0f;
34};
35
36// Fit a target aspect ratio inside a container, centred (letterbox/pillarbox).
37inline fsSAspectFitRect aspectFitRectGet(const fsF32 pTargetAspect, const fsF32 pContainerW, const fsF32 pContainerH)
38{
40 rect.w = pContainerW;
41 rect.h = pContainerH;
42 if (pContainerW <= 0.0f || pContainerH <= 0.0f || pTargetAspect <= 0.0f)
43 {
44 return rect;
45 }
46
47 const fsF32 containerAspect = pContainerW / pContainerH;
48 if (containerAspect < pTargetAspect)
49 {
50 rect.h = pContainerW / pTargetAspect;
51 rect.y = (pContainerH - rect.h) / 2.0f;
52 }
53 else if (containerAspect > pTargetAspect)
54 {
55 rect.w = pContainerH * pTargetAspect;
56 rect.x = (pContainerW - rect.w) / 2.0f;
57 }
58 return rect;
59}
60
61inline const ax::Rect& viewportRectGet(fsTRenderView* const pRenderView)
62{
63#ifdef AXMOL_V3
64 return pRenderView->getViewportRect();
65#else
66 return pRenderView->getViewPortRect();
67#endif
68}
69
70inline void pixelScaleGet(fsTRenderView* const pRenderView, fsF32& pScaleX, fsF32& pScaleY)
71{
72 pScaleX = 1.0f;
73 pScaleY = 1.0f;
74 if (!pRenderView)
75 {
76 return;
77 }
78
79#ifndef AXMOL_V3
80 // Desktop Axmol v2 reports frame/visible sizes in points, so their ratio
81 // can remain 1 even when the backing framebuffer is Retina-scaled.
82 const fsF32 retinaScale = static_cast<fsF32>(pRenderView->getRetinaFactor());
83 if (retinaScale > 0.0f)
84 {
85 pScaleX = retinaScale;
86 pScaleY = retinaScale;
87 }
88#endif
89
90 const auto visibleSize = pRenderView->getVisibleSize();
91#ifdef AXMOL_V3
92 const auto frameSize = pRenderView->getWindowSize();
93#else
94 const auto frameSize = pRenderView->getFrameSize();
95#endif
96 if (visibleSize.width > 0.0f && frameSize.width > 0.0f)
97 {
98 const fsF32 frameScaleX = static_cast<fsF32>(frameSize.width / visibleSize.width);
99 if (frameScaleX > pScaleX)
100 {
101 pScaleX = frameScaleX;
102 }
103 }
104 if (visibleSize.height > 0.0f && frameSize.height > 0.0f)
105 {
106 const fsF32 frameScaleY = static_cast<fsF32>(frameSize.height / visibleSize.height);
107 if (frameScaleY > pScaleY)
108 {
109 pScaleY = frameScaleY;
110 }
111 }
112
113#ifdef AXMOL_V3
114 if (pRenderView->getRenderScale() > 0.0f)
115 {
116 pScaleX = pRenderView->getRenderScale();
117 pScaleY = pRenderView->getRenderScale();
118 }
119#endif
120}
121}
122
123#endif
float fsF32
Definition fsBaseTypes.h:28
Definition fsNAxmolRenderView.h:21
void pixelScaleGet(fsTRenderView *const pRenderView, fsF32 &pScaleX, fsF32 &pScaleY)
Definition fsNAxmolRenderView.h:70
ax::RenderView fsTRenderView
Definition fsNAxmolRenderView.h:25
const ax::Rect & viewportRectGet(fsTRenderView *const pRenderView)
Definition fsNAxmolRenderView.h:61
fsSAspectFitRect aspectFitRectGet(const fsF32 pTargetAspect, const fsF32 pContainerW, const fsF32 pContainerH)
Definition fsNAxmolRenderView.h:37
Definition fsNAxmolRenderView.h:29
fsF32 w
Definition fsNAxmolRenderView.h:32
fsF32 y
Definition fsNAxmolRenderView.h:31
fsF32 h
Definition fsNAxmolRenderView.h:33
fsF32 x
Definition fsNAxmolRenderView.h:30