SystemUIBatch.h 3.4 KB

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