Geometry.cpp 4.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-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. GeometryUtilities::GenerateQuad(vertices + 0, indices + 0, Vector2f(0, 0), Vector2f(dimensions.x, width), colour, 0);
  49. GeometryUtilities::GenerateQuad(vertices + 4, indices + 6, Vector2f(0, dimensions.y - width), Vector2f(dimensions.x, width), colour, 4);
  50. GeometryUtilities::GenerateQuad(vertices + 8, indices + 12, Vector2f(0, 0), Vector2f(width, dimensions.y), colour, 8);
  51. GeometryUtilities::GenerateQuad(vertices + 12, indices + 18, Vector2f(dimensions.x - width, 0), Vector2f(width, dimensions.y), colour, 12);
  52. render_interface->RenderGeometry(vertices, 4 * 4, indices, 6 * 4, 0, origin);
  53. }
  54. void Geometry::RenderBox(const Vector2f origin, const Vector2f dimensions, const Colourb colour)
  55. {
  56. RenderInterface* render_interface = ::Rml::GetRenderInterface();
  57. if (!context || !render_interface)
  58. return;
  59. Vertex vertices[4];
  60. int indices[6];
  61. GeometryUtilities::GenerateQuad(vertices, indices, Vector2f(0, 0), Vector2f(dimensions.x, dimensions.y), colour, 0);
  62. render_interface->RenderGeometry(vertices, 4, indices, 6, 0, origin);
  63. }
  64. void Geometry::RenderBox(const Vector2f origin, const Vector2f dimensions, const Vector2f hole_origin, const Vector2f hole_dimensions,
  65. const Colourb colour)
  66. {
  67. // Top box.
  68. float top_y_dimensions = hole_origin.y - origin.y;
  69. if (top_y_dimensions > 0)
  70. {
  71. RenderBox(origin, Vector2f(dimensions.x, top_y_dimensions), colour);
  72. }
  73. // Bottom box.
  74. float bottom_y_dimensions = (origin.y + dimensions.y) - (hole_origin.y + hole_dimensions.y);
  75. if (bottom_y_dimensions > 0)
  76. {
  77. RenderBox(Vector2f(origin.x, hole_origin.y + hole_dimensions.y), Vector2f(dimensions.x, bottom_y_dimensions), colour);
  78. }
  79. // Left box.
  80. float left_x_dimensions = hole_origin.x - origin.x;
  81. if (left_x_dimensions > 0)
  82. {
  83. RenderBox(Vector2f(origin.x, hole_origin.y), Vector2f(left_x_dimensions, hole_dimensions.y), colour);
  84. }
  85. // Right box.
  86. float right_x_dimensions = (origin.x + dimensions.x) - (hole_origin.x + hole_dimensions.x);
  87. if (right_x_dimensions > 0)
  88. {
  89. RenderBox(Vector2f(hole_origin.x + hole_dimensions.x, hole_origin.y), Vector2f(right_x_dimensions, hole_dimensions.y), colour);
  90. }
  91. }
  92. } // namespace Debugger
  93. } // namespace Rml