TextureLayoutRectangle.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 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. #include "TextureLayoutRectangle.h"
  29. namespace Rml {
  30. TextureLayoutRectangle::TextureLayoutRectangle(const int _id, const Vector2i dimensions) : dimensions(dimensions), texture_position(0, 0)
  31. {
  32. id = _id;
  33. texture_index = -1;
  34. texture_data = nullptr;
  35. texture_stride = 0;
  36. }
  37. TextureLayoutRectangle::~TextureLayoutRectangle()
  38. {
  39. }
  40. // Returns the rectangle's id.
  41. int TextureLayoutRectangle::GetId() const
  42. {
  43. return id;
  44. }
  45. // Returns the rectangle's position; this is only valid if it has been placed.
  46. Vector2i TextureLayoutRectangle::GetPosition() const
  47. {
  48. return texture_position;
  49. }
  50. // Returns the rectangle's dimensions.
  51. Vector2i TextureLayoutRectangle::GetDimensions() const
  52. {
  53. return dimensions;
  54. }
  55. // Places the rectangle within a texture.
  56. void TextureLayoutRectangle::Place(const int _texture_index, const Vector2i position)
  57. {
  58. texture_index = _texture_index;
  59. texture_position = position;
  60. }
  61. // Unplaces the rectangle.
  62. void TextureLayoutRectangle::Unplace()
  63. {
  64. texture_index = -1;
  65. }
  66. // Returns the rectangle's placed state.
  67. bool TextureLayoutRectangle::IsPlaced() const
  68. {
  69. return texture_index > -1;
  70. }
  71. // Sets the rectangle's texture data and stride.
  72. void TextureLayoutRectangle::Allocate(byte* _texture_data, int _texture_stride)
  73. {
  74. texture_data = _texture_data + ((texture_position.y * _texture_stride) + texture_position.x * 4);
  75. texture_stride = _texture_stride;
  76. }
  77. // Returns the index of the texture this rectangle is placed on.
  78. int TextureLayoutRectangle::GetTextureIndex()
  79. {
  80. return texture_index;
  81. }
  82. // Returns the rectangle's allocated texture data.
  83. byte* TextureLayoutRectangle::GetTextureData()
  84. {
  85. return texture_data;
  86. }
  87. // Returns the stride of the rectangle's texture data.
  88. int TextureLayoutRectangle::GetTextureStride() const
  89. {
  90. return texture_stride;
  91. }
  92. } // namespace Rml