TransformState.cpp 2.7 KB

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