Transform.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2014 Markus Schöngart
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include <Rocket/Core/Transform.h>
  29. #include <Rocket/Core/TransformPrimitive.h>
  30. #include <Rocket/Core/ViewState.h>
  31. namespace Rocket {
  32. namespace Core {
  33. // Default constructor, initializes an identity transform
  34. Transform::Transform()
  35. : primitives()
  36. {
  37. }
  38. Transform::Transform(const Transform& other)
  39. : primitives()
  40. {
  41. primitives.reserve(other.primitives.size());
  42. Primitives::const_iterator i = other.primitives.begin();
  43. Primitives::const_iterator end = other.primitives.end();
  44. for (; i != end; ++i)
  45. {
  46. try
  47. {
  48. AddPrimitive(**i);
  49. }
  50. catch(...)
  51. {
  52. ClearPrimitives();
  53. throw;
  54. }
  55. }
  56. }
  57. Transform::~Transform()
  58. {
  59. ClearPrimitives();
  60. }
  61. // Swap the content of two Transfrom instances
  62. void Transform::Swap(Transform& other)
  63. {
  64. primitives.swap(other.primitives);
  65. }
  66. // Assignment operato
  67. const Transform& Transform::operator=(const Transform& other)
  68. {
  69. Transform result(other);
  70. Swap(result);
  71. return *this;
  72. }
  73. // Remove all Primitives from this Transform
  74. void Transform::ClearPrimitives()
  75. {
  76. Primitives::iterator i = primitives.begin();
  77. Primitives::iterator end = primitives.end();
  78. for (; i != end; ++i)
  79. {
  80. try
  81. {
  82. delete *i;
  83. *i = 0;
  84. }
  85. catch(...)
  86. {
  87. }
  88. }
  89. primitives.clear();
  90. }
  91. // Add a Primitive to this Transform
  92. void Transform::AddPrimitive(const Transforms::Primitive& p)
  93. {
  94. Transforms::Primitive* q = p.Clone();
  95. if (!q)
  96. {
  97. throw std::bad_alloc();
  98. }
  99. try
  100. {
  101. primitives.push_back(q);
  102. }
  103. catch (...)
  104. {
  105. delete q;
  106. throw;
  107. }
  108. }
  109. }
  110. }