UISceneView.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "UIWidget.h"
  25. #include <Atomic/Graphics/Texture2D.h>
  26. #include <Atomic/Graphics/Viewport.h>
  27. #include <Atomic/Scene/Scene.h>
  28. #include <TurboBadger/tb_widgets.h>
  29. using namespace tb;
  30. namespace Atomic
  31. {
  32. class UISceneView;
  33. class UIRenderer;
  34. class ATOMIC_API SceneViewWidget : public tb::TBWidget
  35. {
  36. friend class UISceneView;
  37. public:
  38. // For safe typecasting
  39. TBOBJECT_SUBCLASS(SceneViewWidget, tb::TBWidget);
  40. SceneViewWidget();
  41. virtual void OnPaint(const PaintProps &paint_props);
  42. private:
  43. WeakPtr<UISceneView> sceneView_;
  44. PODVector<float> vertexData_;
  45. };
  46. class ATOMIC_API UISceneView : public UIWidget
  47. {
  48. friend class SceneViewWidget;
  49. ATOMIC_OBJECT(UISceneView, UIWidget)
  50. public:
  51. UISceneView(Context* context, bool createWidget = true);
  52. virtual ~UISceneView();
  53. /// React to resize.
  54. void OnResize(const IntVector2& newSize);
  55. /// Define the scene and camera to use in rendering. When ownScene is true the View3D will take ownership of them with shared pointers.
  56. void SetView(Scene* scene, Camera* camera);
  57. /// Set render texture pixel format. Default is RGB.
  58. void SetFormat(unsigned format);
  59. /// Set render target auto update mode. Default is true.
  60. void SetAutoUpdate(bool enable);
  61. /// Queue manual update on the render texture.
  62. void QueueUpdate();
  63. /// Return render texture pixel format.
  64. unsigned GetFormat() const { return rttFormat_; }
  65. /// Return whether render target updates automatically.
  66. bool GetAutoUpdate() const { return autoUpdate_; }
  67. /// Return scene.
  68. Scene* GetScene() const;
  69. /// Return camera scene node.
  70. Node* GetCameraNode() const;
  71. /// Return render texture.
  72. Texture2D* GetRenderTexture() const;
  73. /// Return depth stencil texture.
  74. Texture2D* GetDepthTexture() const;
  75. /// Return viewport.
  76. Viewport* GetViewport() const;
  77. void SetResizeRequired() {resizeRequired_ = true;}
  78. const IntVector2& GetSize() const { return size_; }
  79. protected:
  80. void HandleEndFrame(StringHash eventType, VariantMap& eventData);
  81. /// Renderable texture.
  82. SharedPtr<Texture2D> renderTexture_;
  83. /// Depth stencil texture.
  84. SharedPtr<Texture2D> depthTexture_;
  85. /// Viewport.
  86. SharedPtr<Viewport> viewport_;
  87. /// Scene.
  88. SharedPtr<Scene> scene_;
  89. /// Camera scene node.
  90. SharedPtr<Node> cameraNode_;
  91. /// Render texture format.
  92. unsigned rttFormat_;
  93. /// Render texture auto update mode.
  94. bool autoUpdate_;
  95. bool resizeRequired_;
  96. IntVector2 size_;
  97. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  98. private:
  99. UIRenderer* renderer_;
  100. };
  101. }