TransformState.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "TransformState.h"
  29. namespace Rml {
  30. bool TransformState::SetTransform(const Matrix4f* in_transform)
  31. {
  32. bool is_changed = (have_transform != (bool)in_transform);
  33. if (in_transform)
  34. {
  35. is_changed |= (have_transform && transform != *in_transform);
  36. transform = *in_transform;
  37. have_transform = true;
  38. }
  39. else
  40. have_transform = false;
  41. if (is_changed)
  42. dirty_inverse_transform = true;
  43. return is_changed;
  44. }
  45. bool TransformState::SetLocalPerspective(const Matrix4f* in_perspective)
  46. {
  47. bool is_changed = (have_perspective != (bool)in_perspective);
  48. if (in_perspective)
  49. {
  50. is_changed |= (have_perspective && local_perspective != *in_perspective);
  51. local_perspective = *in_perspective;
  52. have_perspective = true;
  53. }
  54. else
  55. have_perspective = false;
  56. return is_changed;
  57. }
  58. const Matrix4f* TransformState::GetTransform() const
  59. {
  60. return have_transform ? &transform : nullptr;
  61. }
  62. const Matrix4f* TransformState::GetLocalPerspective() const
  63. {
  64. return have_perspective ? &local_perspective : nullptr;
  65. }
  66. const Matrix4f* TransformState::GetInverseTransform() const
  67. {
  68. if (!have_transform)
  69. return nullptr;
  70. if (dirty_inverse_transform)
  71. {
  72. inverse_transform = transform;
  73. have_inverse_transform = inverse_transform.Invert();
  74. dirty_inverse_transform = false;
  75. }
  76. if (have_inverse_transform)
  77. return &inverse_transform;
  78. return nullptr;
  79. }
  80. } // namespace Rml