UIOffscreenView.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Graphics/Camera.h"
  24. #include "../Graphics/Material.h"
  25. #include "../Graphics/Technique.h"
  26. #include "../Graphics/Texture2D.h"
  27. #include "../Graphics/Octree.h"
  28. #include "../Graphics/VertexBuffer.h"
  29. #include "../Resource/ResourceCache.h"
  30. #include "UIWidget.h"
  31. namespace Atomic
  32. {
  33. /// a root widget that renders offscreen
  34. class UIOffscreenView : public UIWidget
  35. {
  36. friend UI;
  37. ATOMIC_OBJECT(UIOffscreenView, UIWidget)
  38. public:
  39. /// Construct
  40. UIOffscreenView(Context* context);
  41. /// Destruct
  42. virtual ~UIOffscreenView();
  43. /// Get the current width of the texture.
  44. int GetWidth() const { return GetTexture2D()->GetWidth(); }
  45. /// Get the current height of the texture.
  46. int GetHeight() const { return GetTexture2D()->GetHeight(); }
  47. /// Set the dimensions of the texture.
  48. void SetSize(int width, int height);
  49. /// Get the Texture2D to which this view is rendering.
  50. Texture2D* GetTexture2D() const { return texture_; }
  51. /// Return render surface.
  52. RenderSurface* GetRenderSurface() const { return GetTexture2D()->GetRenderSurface(); }
  53. /// Get a material for this view (for convenience only/doesn't have to be used).
  54. Material* GetMaterial();
  55. /// Register instances nessisary to process input events automatically.
  56. void RegisterInput(Camera* camera, Octree* octree, Drawable* drawable, const IntRect& rect = IntRect::ZERO);
  57. /// Unregister instances to return to manual input.
  58. void UnregisterInput();
  59. /// Get wether to clear the render target each frame.
  60. bool GetClearRenderTargetEachFrame() const { return clearRenderTargetEachFrame_; }
  61. /// Set wether to clear the render target each frame.
  62. void SetClearRenderTargetEachFrame(bool clear) { clearRenderTargetEachFrame_ = clear; }
  63. /// Save PNG to a serializer.
  64. bool SavePNGTo(Serializer& dest) const;
  65. /// Save PNG to a file.
  66. bool SavePNG(const String& fileName) const;
  67. void InvokeRightPointerDown(int x, int y, int click_count, int qualifiers, bool super = false);
  68. void InvokeRightPointerUp(int x, int y, int qualifiers, bool super = false);
  69. void InvokePointerDown(int x, int y, int click_count, int qualifiers, bool touch, int touchId, bool super = false);
  70. void InvokePointerUp(int x, int y, int qualifiers, bool touch, int touchId, bool super = false);
  71. void InvokePointerMove(int x, int y, int qualifiers, bool touch, int touchId, bool super = false);
  72. void InvokeWheel(int x, int y, int delta_x, int delta_y, int qualifiers, bool super = false);
  73. bool InvokeKey(int key, int keycode, bool down, int qualifiers, bool super = false);
  74. protected:
  75. SharedPtr<Texture2D> texture_;
  76. SharedPtr<Material> material_;
  77. PODVector<UIBatch> batches_;
  78. PODVector<float> vertexData_;
  79. SharedPtr<VertexBuffer> vertexBuffer_;
  80. SharedPtr<Camera> inputCamera_;
  81. SharedPtr<Octree> inputOctree_;
  82. SharedPtr<Drawable> inputDrawable_;
  83. IntRect inputRect_;
  84. bool clearRenderTargetEachFrame_;
  85. private:
  86. };
  87. }