UIComponent.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Scene/Component.h"
  5. #include "../UI/UIElement.h"
  6. namespace Urho3D
  7. {
  8. class Material;
  9. class Texture2D;
  10. class StaticModel;
  11. class Viewport;
  12. class UIElement;
  13. class UIBatch;
  14. class VertexBuffer;
  15. class UIElement3D;
  16. class URHO3D_API UIComponent : public Component
  17. {
  18. URHO3D_OBJECT(UIComponent, Component);
  19. public:
  20. /// Construct.
  21. explicit UIComponent(Context* context);
  22. /// Destruct.
  23. ~UIComponent() override;
  24. /// Register object factory.
  25. /// @nobind
  26. static void RegisterObject(Context* context);
  27. /// Return UIElement.
  28. /// @property
  29. UIElement* GetRoot() const;
  30. /// Return material which will be used for rendering UI texture.
  31. /// @property
  32. Material* GetMaterial() const;
  33. /// Return texture which will be used for rendering UI to.
  34. /// @property
  35. Texture2D* GetTexture() const;
  36. /// Set index of viewport to be used for screen coordinate translation.
  37. void SetViewportIndex(unsigned index);
  38. protected:
  39. /// Handle component being added to Node or removed from it.
  40. void OnNodeSet(Node* node) override;
  41. /// Handle resizing of element. Setting size of element will automatically resize texture. UIElement size matches size of texture.
  42. void OnElementResized(StringHash eventType, VariantMap& args);
  43. /// Material that is set to the model.
  44. SharedPtr<Material> material_;
  45. /// Texture that UIElement will be rendered into.
  46. SharedPtr<Texture2D> texture_;
  47. /// Model created by this component. If node already has StaticModel then this will be null.
  48. SharedPtr<StaticModel> model_;
  49. /// UIElement to be rendered into texture. It also handles screen to UI coordinate translation.
  50. SharedPtr<UIElement3D> rootElement_;
  51. /// Viewport index to be set when component is added to a node.
  52. unsigned viewportIndex_;
  53. };
  54. }