UIBatch.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "../Math/Color.h"
  24. #include "../Graphics/GraphicsDefs.h"
  25. #include "../Math/Rect.h"
  26. namespace Atomic
  27. {
  28. class PixelShader;
  29. class Graphics;
  30. class Matrix3x4;
  31. class Texture;
  32. static const unsigned UI_VERTEX_SIZE = 6;
  33. /// %UI rendering draw call.
  34. class ATOMIC_API UIBatch
  35. {
  36. public:
  37. /// Construct with defaults.
  38. UIBatch();
  39. /// Construct.
  40. UIBatch(BlendMode blendMode, const IntRect& scissor, Texture* texture, PODVector<float>* vertexData);
  41. /// Set new color for the batch. Overrides gradient.
  42. void SetColor(const Color& color, bool overrideAlpha = false);
  43. /// Restore UI element's default color.
  44. void SetDefaultColor();
  45. /// Add a quad.
  46. void AddQuad(int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth = 0, int texHeight = 0);
  47. /// Add a quad using a transform matrix.
  48. void AddQuad(const Matrix3x4& transform, int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth = 0, int texHeight = 0);
  49. /// Add a quad with tiled texture.
  50. void AddQuad(int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight, bool tiled);
  51. /// Merge with another batch.
  52. bool Merge(const UIBatch& batch);
  53. /// Add or merge a batch.
  54. static void AddOrMerge(const UIBatch& batch, PODVector<UIBatch>& batches);
  55. /// Blending mode.
  56. BlendMode blendMode_;
  57. /// Scissor rectangle.
  58. IntRect scissor_;
  59. /// Texture.
  60. Texture* texture_;
  61. /// Inverse texture size.
  62. Vector2 invTextureSize_;
  63. /// Current color. By default calculated from the element.
  64. unsigned color_;
  65. /// Vertex data.
  66. PODVector<float>* vertexData_;
  67. /// Vertex data start index.
  68. unsigned vertexStart_;
  69. /// Vertex data end index.
  70. unsigned vertexEnd_;
  71. /// Gradient flag.
  72. bool useGradient_;
  73. };
  74. }