BoxShadowHash.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #pragma once
  2. #include "../../Include/RmlUi/Core/ComputedValues.h"
  3. #include "../../Include/RmlUi/Core/NumericValue.h"
  4. #include "../../Include/RmlUi/Core/RenderBox.h"
  5. #include "../../Include/RmlUi/Core/Types.h"
  6. #include "../../Include/RmlUi/Core/Unit.h"
  7. #include "../../Include/RmlUi/Core/Utilities.h"
  8. #include "BoxShadowCache.h"
  9. #include "GeometryBoxShadow.h"
  10. namespace std {
  11. template <>
  12. struct hash<::Rml::Unit> {
  13. using utype = underlying_type_t<::Rml::Unit>;
  14. size_t operator()(const ::Rml::Unit& t) const noexcept
  15. {
  16. hash<utype> h;
  17. return h(static_cast<utype>(t));
  18. }
  19. };
  20. template <>
  21. struct hash<::Rml::Vector2i> {
  22. size_t operator()(const ::Rml::Vector2i& v) const noexcept
  23. {
  24. using namespace ::Rml::Utilities;
  25. size_t seed = hash<int>{}(v.x);
  26. HashCombine(seed, v.y);
  27. return seed;
  28. }
  29. };
  30. template <>
  31. struct hash<::Rml::Vector2f> {
  32. size_t operator()(const ::Rml::Vector2f& v) const noexcept
  33. {
  34. using namespace ::Rml::Utilities;
  35. size_t seed = hash<float>{}(v.x);
  36. HashCombine(seed, v.y);
  37. return seed;
  38. }
  39. };
  40. template <>
  41. struct hash<::Rml::Colourb> {
  42. size_t operator()(const ::Rml::Colourb& v) const noexcept { return static_cast<size_t>(hash<uint32_t>{}(reinterpret_cast<const uint32_t&>(v))); }
  43. };
  44. template <>
  45. struct hash<::Rml::ColourbPremultiplied> {
  46. size_t operator()(const ::Rml::ColourbPremultiplied& v) const noexcept
  47. {
  48. return static_cast<size_t>(hash<uint32_t>{}(reinterpret_cast<const uint32_t&>(v)));
  49. }
  50. };
  51. template <>
  52. struct hash<::Rml::NumericValue> {
  53. size_t operator()(const ::Rml::NumericValue& v) const noexcept
  54. {
  55. using namespace ::Rml::Utilities;
  56. size_t seed = hash<float>{}(v.number);
  57. HashCombine(seed, v.unit);
  58. return seed;
  59. }
  60. };
  61. template <>
  62. struct hash<::Rml::BoxShadow> {
  63. size_t operator()(const ::Rml::BoxShadow& s) const noexcept
  64. {
  65. using namespace ::Rml;
  66. using namespace ::Rml::Utilities;
  67. size_t seed = std::hash<ColourbPremultiplied>{}(s.color);
  68. HashCombine(seed, s.offset_x);
  69. HashCombine(seed, s.offset_y);
  70. HashCombine(seed, s.blur_radius);
  71. HashCombine(seed, s.spread_distance);
  72. HashCombine(seed, s.inset);
  73. return seed;
  74. }
  75. };
  76. template <>
  77. struct hash<::Rml::RenderBox> {
  78. size_t operator()(const ::Rml::RenderBox& box) const noexcept
  79. {
  80. using namespace ::Rml::Utilities;
  81. static auto HashArray4 = [](const ::Rml::Array<float, 4>& arr) -> size_t {
  82. size_t seed = 0;
  83. for (const auto& v : arr)
  84. HashCombine(seed, v);
  85. return seed;
  86. };
  87. size_t seed = 0;
  88. HashCombine(seed, box.GetFillSize());
  89. HashCombine(seed, box.GetBorderOffset());
  90. HashCombine(seed, HashArray4(box.GetBorderRadius()));
  91. HashCombine(seed, HashArray4(box.GetBorderWidths()));
  92. return seed;
  93. }
  94. };
  95. template <>
  96. struct hash<::Rml::BoxShadowGeometryInfo> {
  97. size_t operator()(const ::Rml::BoxShadowGeometryInfo& in) const noexcept
  98. {
  99. using namespace ::Rml::Utilities;
  100. size_t seed = size_t(849128392);
  101. HashCombine(seed, in.background_color);
  102. for (const auto& v : in.border_colors)
  103. {
  104. HashCombine(seed, v);
  105. }
  106. for (const auto& v : in.border_radius)
  107. {
  108. HashCombine(seed, v);
  109. }
  110. HashCombine(seed, in.texture_dimensions);
  111. HashCombine(seed, in.element_offset_in_texture);
  112. for (const auto& v : in.padding_render_boxes)
  113. {
  114. HashCombine(seed, v);
  115. }
  116. for (const auto& v : in.border_render_boxes)
  117. {
  118. HashCombine(seed, v);
  119. }
  120. for (const ::Rml::BoxShadow& v : in.shadow_list)
  121. {
  122. HashCombine(seed, v);
  123. }
  124. HashCombine(seed, in.opacity);
  125. return seed;
  126. }
  127. };
  128. } // namespace std