UIBatch.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "Color.h"
  24. #include "GraphicsDefs.h"
  25. #include "Rect.h"
  26. namespace Urho3D
  27. {
  28. class PixelShader;
  29. class Graphics;
  30. class Matrix3x4;
  31. class Texture;
  32. class UIElement;
  33. static const unsigned UI_VERTEX_SIZE = 6;
  34. /// %UI rendering draw call.
  35. class URHO3D_API UIBatch
  36. {
  37. public:
  38. /// Construct with defaults.
  39. UIBatch();
  40. /// Construct.
  41. UIBatch(UIElement* 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, 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. /// Return an interpolated color for the UI element.
  55. unsigned GetInterpolatedColor(int x, int y);
  56. /// Add or merge a batch.
  57. static void AddOrMerge(const UIBatch& batch, PODVector<UIBatch>& batches);
  58. /// Element this batch represents.
  59. UIElement* element_;
  60. /// Blending mode.
  61. BlendMode blendMode_;
  62. /// Scissor rectangle.
  63. IntRect scissor_;
  64. /// Texture.
  65. Texture* texture_;
  66. /// Inverse texture size.
  67. Vector2 invTextureSize_;
  68. /// Current color. By default calculated from the element.
  69. unsigned color_;
  70. /// Vertex data.
  71. PODVector<float>* vertexData_;
  72. /// Vertex data start index.
  73. unsigned vertexStart_;
  74. /// Vertex data end index.
  75. unsigned vertexEnd_;
  76. /// Gradient flag.
  77. bool useGradient_;
  78. };
  79. }