Drawable2D.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  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 "Drawable.h"
  24. #include "GraphicsDefs.h"
  25. namespace Urho3D
  26. {
  27. class Renderer2D;
  28. class Texture2D;
  29. class VertexBuffer;
  30. /// 2D vertex.
  31. struct Vertex2D
  32. {
  33. /// Position.
  34. Vector3 position_;
  35. /// Color.
  36. unsigned color_;
  37. /// UV.
  38. Vector2 uv_;
  39. };
  40. static const unsigned MASK_VERTEX2D = MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1;
  41. /// Pixel size (equal 0.01f).
  42. extern URHO3D_API const float PIXEL_SIZE;
  43. /// Base class for 2D visible components.
  44. class URHO3D_API Drawable2D : public Drawable
  45. {
  46. OBJECT(Drawable2D);
  47. public:
  48. /// Construct.
  49. Drawable2D(Context* context);
  50. /// Destruct.
  51. ~Drawable2D();
  52. /// Register object factory. Drawable must be registered first.
  53. static void RegisterObject(Context* context);
  54. /// Set layer.
  55. void SetLayer(int layer);
  56. /// Set order in layer.
  57. void SetOrderInLayer(int orderInLayer);
  58. /// Set texture.
  59. void SetTexture(Texture2D* texture);
  60. /// Set blend mode.
  61. void SetBlendMode(BlendMode mode);
  62. /// Set custom material.
  63. void SetCustomMaterial(Material* customMaterial);
  64. /// Return layer.
  65. int GetLayer() const { return layer_; }
  66. /// Return order in layer.
  67. int GetOrderInLayer() const { return orderInLayer_; }
  68. /// Return texture.
  69. Texture2D* GetTexture() const;
  70. /// Return blend mode.
  71. BlendMode GetBlendMode() const { return blendMode_; }
  72. /// Return custom material.
  73. Material* GetCustomMaterial() const;
  74. /// Set material (called by Renderer2D).
  75. void SetMaterial(Material* material);
  76. /// Return custom material or material (called by Renderer2D).
  77. Material* GetMaterial() const;
  78. /// Set visibility (called by Renderer2D).
  79. void SetVisibility(bool visibility) { visibility_ = visibility; }
  80. /// Return visibility (called by Renderer2D).
  81. bool GetVisibility() const { return visibility_; }
  82. /// Return all vertices (called by Renderer2D).
  83. const Vector<Vertex2D>& GetVertices();
  84. protected:
  85. /// Handle node being assigned.
  86. virtual void OnNodeSet(Node* node);
  87. /// Handle node transform being dirtied.
  88. virtual void OnMarkedDirty(Node* node);
  89. /// Update vertices.
  90. virtual void UpdateVertices() = 0;
  91. /// Layer.
  92. int layer_;
  93. /// Order in layer.
  94. int orderInLayer_;
  95. /// Texture.
  96. SharedPtr<Texture2D> texture_;
  97. /// Blend mode.
  98. BlendMode blendMode_;
  99. /// Custom material.
  100. SharedPtr<Material> customMaterial_;
  101. /// Vertices.
  102. Vector<Vertex2D> vertices_;
  103. /// Vertices dirty flag.
  104. bool verticesDirty_;
  105. /// Material.
  106. SharedPtr<Material> material_;
  107. /// Test visible.
  108. bool visibility_;
  109. };
  110. }