Geometry.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #include "Geometry.h"
  29. #include "../../Include/RmlUi/Core/Context.h"
  30. #include "../../Include/RmlUi/Core/Core.h"
  31. #include "../../Include/RmlUi/Core/GeometryUtilities.h"
  32. #include "../../Include/RmlUi/Core/RenderInterface.h"
  33. namespace Rml {
  34. namespace Debugger {
  35. static Context* context;
  36. Geometry::Geometry() {}
  37. void Geometry::SetContext(Context* _context)
  38. {
  39. context = _context;
  40. }
  41. void Geometry::RenderOutline(const Vector2f origin, const Vector2f dimensions, const Colourb colour, float width)
  42. {
  43. RenderInterface* render_interface = ::Rml::GetRenderInterface();
  44. if (!context || !render_interface)
  45. return;
  46. Vertex vertices[4 * 4];
  47. int indices[6 * 4];
  48. ColourbPremultiplied colour_pre = colour.ToPremultiplied();
  49. GeometryUtilities::GenerateQuad(vertices + 0, indices + 0, Vector2f(0, 0), Vector2f(dimensions.x, width), colour_pre, 0);
  50. GeometryUtilities::GenerateQuad(vertices + 4, indices + 6, Vector2f(0, dimensions.y - width), Vector2f(dimensions.x, width), colour_pre, 4);
  51. GeometryUtilities::GenerateQuad(vertices + 8, indices + 12, Vector2f(0, 0), Vector2f(width, dimensions.y), colour_pre, 8);
  52. GeometryUtilities::GenerateQuad(vertices + 12, indices + 18, Vector2f(dimensions.x - width, 0), Vector2f(width, dimensions.y), colour_pre, 12);
  53. render_interface->RenderGeometry(vertices, 4 * 4, indices, 6 * 4, 0, origin);
  54. }
  55. void Geometry::RenderBox(const Vector2f origin, const Vector2f dimensions, const Colourb colour)
  56. {
  57. RenderInterface* render_interface = ::Rml::GetRenderInterface();
  58. if (!context || !render_interface)
  59. return;
  60. Vertex vertices[4];
  61. int indices[6];
  62. GeometryUtilities::GenerateQuad(vertices, indices, Vector2f(0, 0), Vector2f(dimensions.x, dimensions.y), colour.ToPremultiplied(), 0);
  63. render_interface->RenderGeometry(vertices, 4, indices, 6, 0, origin);
  64. }
  65. void Geometry::RenderBox(const Vector2f origin, const Vector2f dimensions, const Vector2f hole_origin, const Vector2f hole_dimensions,
  66. const Colourb colour)
  67. {
  68. // Top box.
  69. float top_y_dimensions = hole_origin.y - origin.y;
  70. if (top_y_dimensions > 0)
  71. {
  72. RenderBox(origin, Vector2f(dimensions.x, top_y_dimensions), colour);
  73. }
  74. // Bottom box.
  75. float bottom_y_dimensions = (origin.y + dimensions.y) - (hole_origin.y + hole_dimensions.y);
  76. if (bottom_y_dimensions > 0)
  77. {
  78. RenderBox(Vector2f(origin.x, hole_origin.y + hole_dimensions.y), Vector2f(dimensions.x, bottom_y_dimensions), colour);
  79. }
  80. // Left box.
  81. float left_x_dimensions = hole_origin.x - origin.x;
  82. if (left_x_dimensions > 0)
  83. {
  84. RenderBox(Vector2f(origin.x, hole_origin.y), Vector2f(left_x_dimensions, hole_dimensions.y), colour);
  85. }
  86. // Right box.
  87. float right_x_dimensions = (origin.x + dimensions.x) - (hole_origin.x + hole_dimensions.x);
  88. if (right_x_dimensions > 0)
  89. {
  90. RenderBox(Vector2f(hole_origin.x + hole_dimensions.x, hole_origin.y), Vector2f(right_x_dimensions, hole_dimensions.y), colour);
  91. }
  92. }
  93. } // namespace Debugger
  94. } // namespace Rml