TransformUtilities.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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) 2014 Markus Schöngart
  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_TRANSFORMUTILITIES_H
  29. #define RMLUI_CORE_TRANSFORMUTILITIES_H
  30. #include "../../Include/RmlUi/Core/Header.h"
  31. #include "../../Include/RmlUi/Core/Types.h"
  32. namespace Rml {
  33. struct TransformPrimitive;
  34. namespace Transforms {
  35. struct DecomposedMatrix4;
  36. }
  37. namespace TransformUtilities {
  38. // Set the primitive to its identity value.
  39. void SetIdentity(TransformPrimitive& primitive) noexcept;
  40. // Resolve the primitive into a transformation matrix, given the current element properties and layout.
  41. Matrix4f ResolveTransform(const TransformPrimitive& primitive, Element& e) noexcept;
  42. // Prepares the primitive for interpolation. This must be done before calling InterpolateWith().
  43. // Promote units to basic types which can be interpolated, that is, convert 'length -> pixel' for unresolved primitives.
  44. // Returns false if the owning transform must to be converted to a DecomposedMatrix4 primitive.
  45. bool PrepareForInterpolation(TransformPrimitive& primitive, Element& e) noexcept;
  46. // If primitives do not match, try to convert them to a common generic type, e.g. TranslateX -> Translate3D.
  47. // Returns true if they are already the same type or were converted to a common generic type.
  48. bool TryConvertToMatchingGenericType(TransformPrimitive& p0, TransformPrimitive& p1) noexcept;
  49. // Interpolate the target primitive with another primitive, weighted by alpha [0, 1].
  50. // Primitives must be of the same type, and PrepareForInterpolation() must previously have been called on both.
  51. bool InterpolateWith(TransformPrimitive& target, const TransformPrimitive& other, float alpha) noexcept;
  52. // Decompose a Matrix4 into its decomposed components.
  53. // Returns true on success, or false if the matrix is singular.
  54. bool Decompose(Transforms::DecomposedMatrix4& decomposed_matrix, const Matrix4f& matrix) noexcept;
  55. String ToString(const TransformPrimitive& primitive) noexcept;
  56. } // namespace TransformUtilities
  57. } // namespace Rml
  58. #endif