Text3DBatch.h 4.1 KB

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