2
0

BoxShadowHash.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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-2025 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_BOXSHADOWHASH_H
  29. #define RMLUI_CORE_BOXSHADOWHASH_H
  30. #include "../../Include/RmlUi/Core/ComputedValues.h"
  31. #include "../../Include/RmlUi/Core/NumericValue.h"
  32. #include "../../Include/RmlUi/Core/RenderBox.h"
  33. #include "../../Include/RmlUi/Core/Types.h"
  34. #include "../../Include/RmlUi/Core/Unit.h"
  35. #include "../../Include/RmlUi/Core/Utilities.h"
  36. #include "BoxShadowCache.h"
  37. #include "GeometryBoxShadow.h"
  38. namespace std {
  39. template <>
  40. struct hash<::Rml::Unit> {
  41. using utype = underlying_type_t<::Rml::Unit>;
  42. size_t operator()(const ::Rml::Unit& t) const noexcept
  43. {
  44. hash<utype> h;
  45. return h(static_cast<utype>(t));
  46. }
  47. };
  48. template <>
  49. struct hash<::Rml::Vector2i> {
  50. size_t operator()(const ::Rml::Vector2i& v) const noexcept
  51. {
  52. using namespace ::Rml::Utilities;
  53. size_t seed = hash<int>{}(v.x);
  54. HashCombine(seed, v.y);
  55. return seed;
  56. }
  57. };
  58. template <>
  59. struct hash<::Rml::Vector2f> {
  60. size_t operator()(const ::Rml::Vector2f& v) const noexcept
  61. {
  62. using namespace ::Rml::Utilities;
  63. size_t seed = hash<float>{}(v.x);
  64. HashCombine(seed, v.y);
  65. return seed;
  66. }
  67. };
  68. template <>
  69. struct hash<::Rml::Colourb> {
  70. size_t operator()(const ::Rml::Colourb& v) const noexcept { return static_cast<size_t>(hash<uint32_t>{}(reinterpret_cast<const uint32_t&>(v))); }
  71. };
  72. template <>
  73. struct hash<::Rml::ColourbPremultiplied> {
  74. size_t operator()(const ::Rml::ColourbPremultiplied& v) const noexcept
  75. {
  76. return static_cast<size_t>(hash<uint32_t>{}(reinterpret_cast<const uint32_t&>(v)));
  77. }
  78. };
  79. template <>
  80. struct hash<::Rml::NumericValue> {
  81. size_t operator()(const ::Rml::NumericValue& v) const noexcept
  82. {
  83. using namespace ::Rml::Utilities;
  84. size_t seed = hash<float>{}(v.number);
  85. HashCombine(seed, v.unit);
  86. return seed;
  87. }
  88. };
  89. template <>
  90. struct hash<::Rml::BoxShadow> {
  91. size_t operator()(const ::Rml::BoxShadow& s) const noexcept
  92. {
  93. using namespace ::Rml;
  94. using namespace ::Rml::Utilities;
  95. size_t seed = std::hash<ColourbPremultiplied>{}(s.color);
  96. HashCombine(seed, s.offset_x);
  97. HashCombine(seed, s.offset_y);
  98. HashCombine(seed, s.blur_radius);
  99. HashCombine(seed, s.spread_distance);
  100. HashCombine(seed, s.inset);
  101. return seed;
  102. }
  103. };
  104. template <>
  105. struct hash<::Rml::RenderBox> {
  106. size_t operator()(const ::Rml::RenderBox& box) const noexcept
  107. {
  108. using namespace ::Rml::Utilities;
  109. static auto HashArray4 = [](const ::Rml::Array<float, 4>& arr) -> size_t {
  110. size_t seed = 0;
  111. for (const auto& v : arr)
  112. HashCombine(seed, v);
  113. return seed;
  114. };
  115. size_t seed = 0;
  116. HashCombine(seed, box.GetFillSize());
  117. HashCombine(seed, box.GetBorderOffset());
  118. HashCombine(seed, HashArray4(box.GetBorderRadius()));
  119. HashCombine(seed, HashArray4(box.GetBorderWidths()));
  120. return seed;
  121. }
  122. };
  123. template <>
  124. struct hash<::Rml::BoxShadowGeometryInfo> {
  125. size_t operator()(const ::Rml::BoxShadowGeometryInfo& in) const noexcept
  126. {
  127. using namespace ::Rml::Utilities;
  128. size_t seed = size_t(849128392);
  129. HashCombine(seed, in.background_color);
  130. for (const auto& v : in.border_colors)
  131. {
  132. HashCombine(seed, v);
  133. }
  134. for (const auto& v : in.border_radius)
  135. {
  136. HashCombine(seed, v);
  137. }
  138. HashCombine(seed, in.texture_dimensions);
  139. HashCombine(seed, in.element_offset_in_texture);
  140. for (const auto& v : in.padding_render_boxes)
  141. {
  142. HashCombine(seed, v);
  143. }
  144. for (const auto& v : in.border_render_boxes)
  145. {
  146. HashCombine(seed, v);
  147. }
  148. for (const ::Rml::BoxShadow& v : in.shadow_list)
  149. {
  150. HashCombine(seed, v);
  151. }
  152. HashCombine(seed, in.opacity);
  153. return seed;
  154. }
  155. };
  156. } // namespace std
  157. #endif