TextureLayoutRectangle.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef TEXTSHAPER_TEXTURELAYOUTRECTANGLE_H
  29. #define TEXTSHAPER_TEXTURELAYOUTRECTANGLE_H
  30. #include <RmlUi/Core.h>
  31. using Rml::byte;
  32. using Rml::Vector2i;
  33. /**
  34. A texture layout rectangle is an area positioned with a texture layout.
  35. Modified to support 64-bit IDs.
  36. @author Peter
  37. */
  38. class TextureLayoutRectangle {
  39. public:
  40. TextureLayoutRectangle(uint64_t id, Vector2i dimensions);
  41. ~TextureLayoutRectangle();
  42. /// Returns the rectangle's id.
  43. /// @return The rectangle's id.
  44. uint64_t GetId() const;
  45. /// Returns the rectangle's position; this is only valid if it has been placed.
  46. /// @return The rectangle's position within its texture.
  47. Vector2i GetPosition() const;
  48. /// Returns the rectangle's dimensions.
  49. /// @return The rectangle's dimensions.
  50. Vector2i GetDimensions() const;
  51. /// Places the rectangle within a texture.
  52. /// @param[in] texture_index The index of the texture this rectangle is placed on.
  53. /// @param[in] position The position within the texture of this rectangle's top-left corner.
  54. void Place(int texture_index, Vector2i position);
  55. /// Unplaces the rectangle.
  56. void Unplace();
  57. /// Returns the rectangle's placed state.
  58. /// @return True if the rectangle has been placed, false if not.
  59. bool IsPlaced() const;
  60. /// Sets the rectangle's texture data and stride.
  61. /// @param[in] texture_data The pointer to the top-left corner of the texture's data.
  62. /// @param[in] texture_stride The stride of the texture data, in bytes.
  63. void Allocate(byte* texture_data, int texture_stride);
  64. /// Returns the index of the texture this rectangle is placed on.
  65. /// @return The texture index.
  66. int GetTextureIndex();
  67. /// Returns the rectangle's allocated texture data.
  68. /// @return The texture data.
  69. byte* GetTextureData();
  70. /// Returns the stride of the rectangle's texture data.
  71. /// @return The texture data stride.
  72. int GetTextureStride() const;
  73. private:
  74. uint64_t id;
  75. Vector2i dimensions;
  76. int texture_index;
  77. Vector2i texture_position;
  78. byte* texture_data;
  79. int texture_stride;
  80. };
  81. #endif