TextureLayoutRectangle.cpp 3.1 KB

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