Animation.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  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 "../Common/TestsInterface.h"
  29. #include "../Common/TestsShell.h"
  30. #include <RmlUi/Core/Context.h>
  31. #include <RmlUi/Core/Element.h>
  32. #include <RmlUi/Core/ElementDocument.h>
  33. #include <doctest.h>
  34. using namespace Rml;
  35. static const String document_decorator_rml = R"(
  36. <rml>
  37. <head>
  38. <title>Test</title>
  39. <link type="text/rcss" href="/assets/rml.rcss"/>
  40. <style>
  41. body {
  42. left: 0;
  43. top: 0;
  44. right: 0;
  45. bottom: 0;
  46. }
  47. @decorator from_rule : gradient { %s }
  48. @decorator to_rule: gradient{ %s }
  49. @keyframes mix {
  50. from { decorator: %s; }
  51. to { decorator: %s; }
  52. }
  53. div {
  54. background: #333;
  55. height: 64px;
  56. width: 64px;
  57. animation: mix 0.1s;
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <div/>
  63. </body>
  64. </rml>
  65. )";
  66. TEST_CASE("animation.decorator")
  67. {
  68. struct Test {
  69. String from_rule;
  70. String to_rule;
  71. String from;
  72. String to;
  73. String expected_25p; // expected interpolated value at 25% progression
  74. };
  75. Vector<Test> tests{
  76. // Only standard declaration
  77. {
  78. "", "",
  79. "gradient(horizontal transparent transparent)",
  80. "gradient(horizontal white white)",
  81. "gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63))",
  82. },
  83. {
  84. "", "",
  85. "none",
  86. "gradient(horizontal transparent transparent)",
  87. "gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
  88. },
  89. {
  90. "", "",
  91. "none",
  92. "gradient(horizontal transparent transparent), gradient(vertical transparent transparent)",
  93. "gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191)), gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
  94. },
  95. {
  96. "", "",
  97. "gradient(horizontal transparent transparent), gradient(vertical transparent transparent)",
  98. "none",
  99. "gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63)), gradient(vertical rgba(127,127,127,63) rgba(127,127,127,63))",
  100. },
  101. /// Only rule declaration
  102. {
  103. "direction: horizontal; start-color: transparent; stop-color: transparent;",
  104. "direction: horizontal; start-color: white; stop-color: white;",
  105. "from_rule",
  106. "to_rule",
  107. "gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63))",
  108. },
  109. {
  110. "",
  111. "direction: horizontal; start-color: transparent; stop-color: transparent;",
  112. "from_rule",
  113. "to_rule",
  114. "gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
  115. },
  116. {
  117. "direction: vertical; start-color: transparent; stop-color: transparent;",
  118. "",
  119. "from_rule",
  120. "to_rule",
  121. "gradient(vertical rgba(127,127,127,63) rgba(127,127,127,63))",
  122. },
  123. /// Mix rule and standard declaration
  124. {
  125. "direction: horizontal; start-color: transparent; stop-color: transparent;",
  126. "",
  127. "from_rule",
  128. "gradient(horizontal white white)",
  129. "gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63))",
  130. },
  131. {
  132. "",
  133. "direction: horizontal; start-color: transparent; stop-color: transparent;",
  134. "none",
  135. "to_rule",
  136. "gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
  137. },
  138. {
  139. "direction: vertical; start-color: transparent; stop-color: transparent;",
  140. "",
  141. "from_rule",
  142. "none",
  143. "gradient(vertical rgba(127,127,127,63) rgba(127,127,127,63))",
  144. },
  145. {
  146. "", "",
  147. "from_rule, to_rule",
  148. "gradient(horizontal transparent transparent), gradient(vertical transparent transparent)",
  149. "gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191)), gradient(horizontal rgba(220,220,220,191) rgba(220,220,220,191))",
  150. },
  151. {
  152. "", "",
  153. "gradient(horizontal transparent transparent), gradient(vertical transparent transparent)",
  154. "from_rule, to_rule",
  155. "gradient(horizontal rgba(127,127,127,63) rgba(127,127,127,63)), gradient(vertical rgba(127,127,127,63) rgba(127,127,127,63))",
  156. },
  157. };
  158. TestsSystemInterface* system_interface = TestsShell::GetTestsSystemInterface();
  159. Context* context = TestsShell::GetContext();
  160. context->SetDensityIndependentPixelRatio(2.0f);
  161. for (const Test& test : tests)
  162. {
  163. const double t_final = 0.1;
  164. system_interface->SetTime(0.0);
  165. String document_rml = Rml::CreateString(document_decorator_rml.size() + 512, document_decorator_rml.c_str(), test.from_rule.c_str(),
  166. test.to_rule.c_str(), test.from.c_str(), test.to.c_str());
  167. ElementDocument* document = context->LoadDocumentFromMemory(document_rml, "assets/");
  168. Element* element = document->GetChild(0);
  169. document->Show();
  170. TestsShell::RenderLoop();
  171. system_interface->SetTime(0.25 * t_final);
  172. TestsShell::RenderLoop();
  173. CHECK_MESSAGE(element->GetProperty<String>("decorator") == test.expected_25p, "from: ", test.from, ", to: ", test.to);
  174. document->Close();
  175. }
  176. system_interface->SetTime(0.0);
  177. TestsShell::ShutdownShell();
  178. }