1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsPrerequisites.h" |
6 | #include "GUI/BsGUIElement.h" |
7 | #include "Math/BsMath.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @addtogroup GUI |
12 | * @{ |
13 | */ |
14 | |
15 | /** Displays a Camera view in the form of a GUI element. */ |
16 | class BS_EXPORT GUIViewport : public GUIElement |
17 | { |
18 | public: |
19 | /** Returns type name of the GUI element used for finding GUI element styles. */ |
20 | static const String& getGUITypeName(); |
21 | |
22 | /** |
23 | * Creates a new GUI viewport element. |
24 | * |
25 | * @param[in] camera Camera whos view to display in the element. Element will update the camera as it |
26 | * resizes. |
27 | * @param[in] aspectRatio Initial aspect of the camera. Determines how is FOV adjusted as the element resizes. |
28 | * @param[in] fieldOfView Initial FOV of the camera. Determines how is FOV adjusted as the element resizes. |
29 | * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the |
30 | * GUIWidget the element is used on. If not specified default style is used. |
31 | * |
32 | * @note Render target used by the GUIWidget and Camera must be the same. |
33 | */ |
34 | static GUIViewport* create(const HCamera& camera, float aspectRatio, Degree fieldOfView, const String& styleName = StringUtil::BLANK); |
35 | |
36 | /** |
37 | * Creates a new GUI viewport element. |
38 | * |
39 | * @param[in] camera Camera whos view to display in the element. Element will update the camera as it |
40 | * resizes. |
41 | * @param[in] aspectRatio Initial aspect of the camera. Determines how is FOV adjusted as the element resizes. |
42 | * @param[in] fieldOfView Initial FOV of the camera. Determines how is FOV adjusted as the element resizes. |
43 | * @param[in] options Options that allow you to control how is the element positioned and sized. This will |
44 | * override any similar options set by style. |
45 | * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the |
46 | * GUIWidget the element is used on. If not specified default style is used. |
47 | * |
48 | * @note Render target used by the GUIWidget and Camera must be the same. |
49 | */ |
50 | static GUIViewport* create(const GUIOptions& options, const HCamera& camera, |
51 | float aspectRatio, Degree fieldOfView, const String& styleName = StringUtil::BLANK); |
52 | |
53 | public: // ***** INTERNAL ****** |
54 | /** @name Internal |
55 | * @{ |
56 | */ |
57 | |
58 | /** @copydoc GUIElement::_getOptimalSize */ |
59 | Vector2I _getOptimalSize() const override; |
60 | |
61 | /** @} */ |
62 | |
63 | protected: |
64 | ~GUIViewport() = default; |
65 | |
66 | /** @copydoc GUIElement::_getNumRenderElements */ |
67 | UINT32 _getNumRenderElements() const override; |
68 | |
69 | /** @copydoc GUIElement::_getMaterial */ |
70 | const SpriteMaterialInfo& _getMaterial(UINT32 renderElementIdx, SpriteMaterial** material) const override; |
71 | |
72 | /** @copydoc GUIElement::_getMeshInfo() */ |
73 | void _getMeshInfo(UINT32 renderElementIdx, UINT32& numVertices, UINT32& numIndices, GUIMeshType& type) const override; |
74 | |
75 | /** @copydoc GUIElement::_fillBuffer */ |
76 | void _fillBuffer(UINT8* vertices, UINT32* indices, UINT32 vertexOffset, UINT32 indexOffset, |
77 | UINT32 maxNumVerts, UINT32 maxNumIndices, UINT32 renderElementIdx) const override; |
78 | |
79 | /** @copydoc GUIElement::updateClippedBounds */ |
80 | void updateClippedBounds() override; |
81 | |
82 | /** @copydoc GUIElement::updateRenderElementsInternal */ |
83 | void updateRenderElementsInternal() override; |
84 | |
85 | private: |
86 | GUIViewport(const String& styleName, const HCamera& camera, float aspectRatio, Degree fieldOfView, const GUIDimensions& dimensions); |
87 | |
88 | /** @copydoc GUIElement::_changeParentWidget */ |
89 | void _changeParentWidget(GUIWidget* widget) override; |
90 | |
91 | HCamera mCamera; |
92 | float mAspectRatio; |
93 | Degree mFieldOfView; |
94 | Radian mVerticalFOV; |
95 | }; |
96 | |
97 | /** @} */ |
98 | } |