GeometryBoxShadow.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef RMLUI_CORE_GEOMETRYBOXSHADOW_H
  29. #define RMLUI_CORE_GEOMETRYBOXSHADOW_H
  30. #include "../../Include/RmlUi/Core/DecorationTypes.h"
  31. #include "../../Include/RmlUi/Core/RenderBox.h"
  32. #include "../../Include/RmlUi/Core/Types.h"
  33. namespace Rml {
  34. using RenderBoxList = Vector<RenderBox>;
  35. struct BoxShadowGeometryInfo {
  36. ColourbPremultiplied background_color;
  37. Array<ColourbPremultiplied, 4> border_colors;
  38. CornerSizes border_radius;
  39. Vector2i texture_dimensions;
  40. Vector2f element_offset_in_texture;
  41. RenderBoxList padding_render_boxes;
  42. RenderBoxList border_render_boxes;
  43. BoxShadowList shadow_list;
  44. float opacity;
  45. };
  46. inline bool operator==(const BoxShadowGeometryInfo& a, const BoxShadowGeometryInfo& b)
  47. {
  48. return a.background_color == b.background_color && a.border_colors == b.border_colors && a.border_radius == b.border_radius &&
  49. a.texture_dimensions == b.texture_dimensions && a.element_offset_in_texture == b.element_offset_in_texture &&
  50. a.padding_render_boxes == b.padding_render_boxes && a.border_render_boxes == b.border_render_boxes && a.shadow_list == b.shadow_list &&
  51. a.opacity == b.opacity;
  52. }
  53. inline bool operator!=(const BoxShadowGeometryInfo& a, const BoxShadowGeometryInfo& b)
  54. {
  55. return !(a == b);
  56. }
  57. class Geometry;
  58. class CallbackTexture;
  59. class RenderManager;
  60. class GeometryBoxShadow {
  61. public:
  62. /// Resolve the element's properties into its box geometry info.
  63. /// @param[in] element The element to resolve.
  64. /// @param[in] border_radius The border radius of the element.
  65. /// @param[in] background_color The background colour of the element.
  66. /// @param[in] border_colors The border colours of the element.
  67. /// @param[in] opacity The computed opacity of the element.
  68. static BoxShadowGeometryInfo Resolve(Element* element, const CornerSizes& border_radius, ColourbPremultiplied background_color,
  69. const Array<ColourbPremultiplied, 4>& border_colors, float opacity);
  70. /// Generate the texture and geometry for a box shadow and including the element's background and border.
  71. /// @param[out] out_shadow_texture The target texture, assumes pointer stability during the lifetime of the shadow geometry.
  72. /// @param[out] out_background_border_geometry The generated geometry for the element's background and border.
  73. /// @param[in] render_manager The render manager to generate the shadow for.
  74. /// @param[in] shadow_geometry_info The resolved box shadow geometry of a given element.
  75. /// @see GeometryBoxShadow::Resolve()
  76. static void GenerateTexture(CallbackTexture& out_shadow_texture, Geometry& out_background_border_geometry, RenderManager& render_manager,
  77. const BoxShadowGeometryInfo& shadow_geometry_info);
  78. };
  79. } // namespace Rml
  80. #endif