UIBatch.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // Copyright (c) 2008-2020 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 "../Math/Color.h"
  24. #include "../Math/Rect.h"
  25. #include "../Graphics/GraphicsDefs.h"
  26. #include "../Graphics/Material.h"
  27. namespace Urho3D
  28. {
  29. class PixelShader;
  30. class Graphics;
  31. class Matrix3x4;
  32. class Texture;
  33. class UIElement;
  34. static const unsigned UI_VERTEX_SIZE = 6;
  35. /// %UI rendering draw call.
  36. class URHO3D_API UIBatch
  37. {
  38. public:
  39. /// Construct with defaults.
  40. UIBatch();
  41. /// Construct.
  42. UIBatch(UIElement* element, BlendMode blendMode, const IntRect& scissor, Texture* texture, PODVector<float>* vertexData);
  43. /// Set new color for the batch. Overrides gradient.
  44. void SetColor(const Color& color, bool overrideAlpha = false);
  45. /// Restore UI element's default color.
  46. void SetDefaultColor();
  47. /// Add a quad.
  48. void AddQuad(float x, float y, float width, float height, int texOffsetX, int texOffsetY, int texWidth = 0, int texHeight = 0);
  49. /// Add a quad using a transform matrix.
  50. void AddQuad(const Matrix3x4& transform, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth = 0,
  51. int texHeight = 0);
  52. /// Add a quad with tiled texture.
  53. void AddQuad(int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight, bool tiled);
  54. /// Add a quad with freeform points and UVs. Uses the current color, not gradient. Points should be specified in clockwise order.
  55. void AddQuad(const Matrix3x4& transform, const IntVector2& a, const IntVector2& b, const IntVector2& c, const IntVector2& d,
  56. const IntVector2& texA, const IntVector2& texB, const IntVector2& texC, const IntVector2& texD);
  57. /// Add a quad with freeform points, UVs and colors. Points should be specified in clockwise order.
  58. void AddQuad(const Matrix3x4& transform, const IntVector2& a, const IntVector2& b, const IntVector2& c, const IntVector2& d,
  59. const IntVector2& texA, const IntVector2& texB, const IntVector2& texC, const IntVector2& texD, const Color& colA,
  60. const Color& colB, const Color& colC, const Color& colD);
  61. /// Merge with another batch.
  62. bool Merge(const UIBatch& batch);
  63. /// Return an interpolated color for the UI element.
  64. unsigned GetInterpolatedColor(float x, float y);
  65. /// Add or merge a batch.
  66. static void AddOrMerge(const UIBatch& batch, PODVector<UIBatch>& batches);
  67. /// Element this batch represents.
  68. UIElement* element_{};
  69. /// Blending mode.
  70. BlendMode blendMode_{BLEND_REPLACE};
  71. /// Scissor rectangle.
  72. IntRect scissor_;
  73. /// Texture.
  74. Texture* texture_{};
  75. /// Inverse texture size.
  76. Vector2 invTextureSize_{Vector2::ONE};
  77. /// Vertex data.
  78. PODVector<float>* vertexData_{};
  79. /// Vertex data start index.
  80. unsigned vertexStart_{};
  81. /// Vertex data end index.
  82. unsigned vertexEnd_{};
  83. /// Current color. By default calculated from the element.
  84. unsigned color_{};
  85. /// Gradient flag.
  86. bool useGradient_{};
  87. /// Custom material.
  88. Material* customMaterial_{};
  89. /// Position adjustment vector for pixel-perfect rendering. Initialized by UI.
  90. static Vector3 posAdjust;
  91. };
  92. }