UIBatch.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "../Math/Color.h"
  25. #include "../Graphics/GraphicsDefs.h"
  26. #include "../Math/Rect.h"
  27. namespace Atomic
  28. {
  29. class PixelShader;
  30. class Graphics;
  31. class Matrix3x4;
  32. class Texture;
  33. static const unsigned UI_VERTEX_SIZE = 6;
  34. /// %UI rendering draw call.
  35. class ATOMIC_API UIBatch
  36. {
  37. public:
  38. /// Construct with defaults.
  39. UIBatch();
  40. /// Construct.
  41. UIBatch(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, bool overrideAlpha = false);
  44. /// Restore UI element's default color.
  45. void SetDefaultColor();
  46. /// Add a quad.
  47. void AddQuad(int x, int y, int width, int 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, int texHeight = 0);
  50. /// Add a quad with tiled texture.
  51. void AddQuad(int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight, bool tiled);
  52. /// Merge with another batch.
  53. bool Merge(const UIBatch& batch);
  54. /// Add or merge a batch.
  55. static void AddOrMerge(const UIBatch& batch, PODVector<UIBatch>& batches);
  56. /// Blending mode.
  57. BlendMode blendMode_;
  58. /// Scissor rectangle.
  59. IntRect scissor_;
  60. /// Texture.
  61. Texture* texture_;
  62. /// Inverse texture size.
  63. Vector2 invTextureSize_;
  64. /// Current color. By default calculated from the element.
  65. unsigned color_;
  66. /// Vertex data.
  67. PODVector<float>* vertexData_;
  68. /// Vertex data start index.
  69. unsigned vertexStart_;
  70. /// Vertex data end index.
  71. unsigned vertexEnd_;
  72. /// Gradient flag.
  73. bool useGradient_;
  74. };
  75. }