My Project
Viewport.h
1 #pragma once
2 #include "IAttributeFields.h"
3 #include "2dengine/GUIPosition.h"
4 
5 namespace ParaEngine
6 {
7  class CSceneObject;
8  class CAutoCamera;
9  class CGUIRoot;
10  class CViewportManager;
11  class CRenderTarget;
12 
13  enum STEREO_EYE{
14  STEREO_EYE_NORMAL = 0,
15  STEREO_EYE_LEFT,
16  STEREO_EYE_RIGHT,
17  };
18 
21  class CViewport : public IAttributeFields
22  {
23  public:
24  CViewport(CViewportManager* pViewportManager);
25  virtual ~CViewport(void);
26 
28  virtual int GetAttributeClassID(){ return ATTRIBUTE_CLASSID_ViewPort; }
30  virtual const char* GetAttributeClassName(){ static const char name[] = "CViewport"; return name; }
32  virtual const char* GetAttributeClassDescription(){ static const char desc[] = ""; return desc; }
34  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
35 
36  ATTRIBUTE_METHOD1(CViewport, SetAlignment_s, const char*) { cls->SetAlignment(p1); return S_OK; }
37 
38  ATTRIBUTE_METHOD1(CViewport, SetLeft_s, int) { cls->SetLeft(p1); return S_OK; }
39  ATTRIBUTE_METHOD1(CViewport, GetLeft_s, int*) { *p1 = cls->GetLeft(); return S_OK; }
40 
41  ATTRIBUTE_METHOD1(CViewport, SetTop_s, int) { cls->SetTop(p1); return S_OK; }
42  ATTRIBUTE_METHOD1(CViewport, GetTop_s, int*) { *p1 = cls->GetTop(); return S_OK; }
43 
44  ATTRIBUTE_METHOD1(CViewport, SetWidth_s, int) { cls->SetWidth(p1); return S_OK; }
45  ATTRIBUTE_METHOD1(CViewport, GetWidth_s, int*) { *p1 = cls->GetWidth(); return S_OK; }
46 
47  ATTRIBUTE_METHOD1(CViewport, SetHeight_s, int) { cls->SetHeight(p1); return S_OK; }
48  ATTRIBUTE_METHOD1(CViewport, GetHeight_s, int*) { *p1 = cls->GetHeight(); return S_OK; }
49 
50  ATTRIBUTE_METHOD(CViewport, ApplyViewport_s) { cls->ApplyViewport(); return S_OK; }
51 
52  ATTRIBUTE_METHOD1(CViewport, GetRenderScript_s, const char**) { *p1 = cls->GetRenderScript().c_str(); return S_OK; }
53  ATTRIBUTE_METHOD1(CViewport, SetRenderScript_s, const char*) { cls->SetRenderScript(p1); return S_OK; }
54 
55  ATTRIBUTE_METHOD1(CViewport, GetRenderTargetName_s, const char**) { *p1 = cls->GetRenderTargetName().c_str(); return S_OK; }
56  ATTRIBUTE_METHOD1(CViewport, SetRenderTargetName_s, const char*) { cls->SetRenderTargetName(p1); return S_OK; }
57 
58  ATTRIBUTE_METHOD1(CViewport, GetPipelineOrder_s, int*) { *p1 = cls->GetPipelineOrder(); return S_OK; }
59  ATTRIBUTE_METHOD1(CViewport, SetPipelineOrder_s, int) { cls->SetPipelineOrder(p1); return S_OK; }
60 
61  public:
62 
64  {
65  inline bool operator()(const CViewport* _Left, const CViewport* _Right) const
66  {
67  return (_Left ? _Left->GetZOrder() : 1000) < (_Right ? _Right->GetZOrder() : 1000);
68  };
69  };
70 
76  HRESULT Render(double dTimeDelta, int nPipelineOrder);
77 
78  void ApplyCamera(CAutoCamera* pCamera);
79 
81  void OnParentSizeChanged(int nWidth, int nHeight);
82 
84  void SetActive();
85 
86  public:
87  virtual const std::string& GetIdentifier();
88  virtual void SetIdentifier(const std::string& sID);
89 
90  CSceneObject* GetScene() { return m_pScene; }
91  void SetScene(CSceneObject* val) { m_pScene = val; }
92 
93  CAutoCamera* GetCamera() ;
94  void SetCamera(CAutoCamera* val) { m_pCamera = val; }
95 
96  CGUIRoot* GetGUIRoot() { return m_pGUIRoot; }
97  void SetGUIRoot(CGUIRoot* val) { m_pGUIRoot = val; }
98 
99  /* script to call to render this viewport. default to "" */
100  const std::string& GetRenderScript() const;
101  void SetRenderScript(const std::string&& val);
102 
104  const std::string& GetRenderTargetName() const;
105  void SetRenderTargetName(const std::string& val);
106 
108  int GetPipelineOrder() const;
109  void SetPipelineOrder(int val);
110 
113  void SetPosition(const char* alignment, int left, int top, int width, int height);
114 
115  void SetModified();
116 
120  void GetPointOnViewport(int& x, int& y, int* pWidth, int* pHeight);
121  bool IsPointOnViewport(int x, int y);
122 
123  int GetWidth();
124  int GetHeight();
125  float GetAspectRatio();
126 
127  void SetAlignment(const char* alignment);
128  void SetLeft(int left);
129  int GetLeft();
130  void SetTop(int top);
131  int GetTop();
132  void SetWidth(int width);
133  void SetHeight(int height);
134  ParaEngine::STEREO_EYE GetEyeMode() const;
135  void SetEyeMode(ParaEngine::STEREO_EYE val);
136 
139 
140  ParaViewport SetViewport(DWORD x, DWORD y, DWORD width, DWORD height);
141 
142  void UpdateRect();
143 
145  ParaViewport GetTextureViewport(float fTexWidth, float fTexHeight);
146 
147  int GetZOrder() const;
148  void SetZOrder(int val);
149 
150  bool IsEnabled() const;
151  void SetIsEnabled(bool val);
152 
154  bool DrawQuad();
155 
157  void GetViewportTransform(Vector2* pvScale, Vector2* pvOffset = NULL);
158  protected:
159  float GetStereoEyeSeparation();
160  private:
161  CSceneObject* m_pScene;
162  CAutoCamera* m_pCamera;
163  CGUIRoot* m_pGUIRoot;
164 
165  CGUIPosition m_position;
166  // absolute position
167  RECT m_rect;
168  CViewportManager* m_pViewportManager;
169  float m_fScalingX;
170  float m_fScalingY;
171  float m_fAspectRatio;
172  bool m_bIsModifed;
173  bool m_bIsEnabled;
174 
175  int m_nZOrder;
176  std::string m_sName;
177  std::string m_sRenderTargetName;
178  CRenderTarget* m_pRenderTarget;
179 
180  STEREO_EYE m_nEyeMode;
181 
182  /* script to call to render this viewport. default to "" */
183  std::string m_sRenderScript;
184 
186  int m_nPipelineOrder;
187  };
188 
189 }
190 
void GetViewportTransform(Vector2 *pvScale, Vector2 *pvOffset=NULL)
get viewport transform in terms of scale and offset
Definition: Viewport.cpp:287
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
void OnParentSizeChanged(int nWidth, int nHeight)
called when back buffer size changed.
Definition: Viewport.cpp:196
ParaViewport ApplyViewport()
return last viewport
Definition: Viewport.cpp:281
a render target scene object.
Definition: RenderTarget.h:16
different physics engine has different winding order.
Definition: EventBinding.h:32
Auto Camera is designed to handle smooth transitions between supported camera type, such as first person camera, third person camera, and rotation camera.
Definition: AutoCamera.h:14
Definition: ManagedDef.h:18
void SetActive()
make this viewport the current active one.
Definition: Viewport.cpp:421
ParaViewport GetTextureViewport(float fTexWidth, float fTexHeight)
get the viewport as used for a given render target of given size.
Definition: Viewport.cpp:356
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: Viewport.h:32
Definition: ParaViewport.h:5
HRESULT Render(double dTimeDelta, int nPipelineOrder)
build the render list, and render the entire scene.
Definition: Viewport.cpp:99
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
void GetPointOnViewport(int &x, int &y, int *pWidth, int *pHeight)
Definition: Viewport.cpp:233
const std::string & GetRenderTargetName() const
render target to use.
Definition: Viewport.cpp:81
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: Viewport.h:28
a region of view port to render into.
Definition: Viewport.h:21
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: Viewport.cpp:178
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: Viewport.h:30
The top level scene management class.
Definition: SceneObject.h:58
int GetPipelineOrder() const
-1 or RENDER_PIPELINE_ORDER.
Definition: Viewport.cpp:71
manager multiple viewport
Definition: ViewportManager.h:18
position of the GUI object
Definition: GUIPosition.h:34
bool DrawQuad()
draw post processing quad for this viewport&#39;s area.
Definition: Viewport.cpp:301
void SetPosition(const char *alignment, int left, int top, int width, int height)
reposition the control using the same parameter definition used when control is created.
Definition: Viewport.cpp:244
When rendering scene, root scene and the root GUI are rendered in sequence.
Definition: GUIRoot.h:48