TextureLayoutRectangle.cpp 3.1 KB

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