Decorator.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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-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 "../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. #include <float.h>
  35. using namespace Rml;
  36. static const String document_decorator_rml = R"(
  37. <rml>
  38. <head>
  39. <title>Test</title>
  40. <link type="text/rcss" href="/assets/rml.rcss"/>
  41. <style>
  42. body {
  43. left: 0;
  44. top: 0;
  45. right: 0;
  46. bottom: 0;
  47. }
  48. @decorator my-gradient : horizontal-gradient {
  49. start-color: #f0f;
  50. stop-color: #fff;
  51. }
  52. div {
  53. border: 20px transparent;
  54. padding: 30px;
  55. width: 50px;
  56. height: 50px;
  57. }
  58. #content_box {
  59. decorator: horizontal-gradient(#f00 #ff0) content-box;
  60. }
  61. #padding_box {
  62. decorator: horizontal-gradient(#f00 #ff0) padding-box;
  63. }
  64. #auto_box {
  65. decorator: horizontal-gradient(#f00 #ff0);
  66. }
  67. #border_box {
  68. decorator: horizontal-gradient(#f00 #ff0) border-box;
  69. }
  70. body.at_decorator #content_box {
  71. decorator: my-gradient content-box;
  72. }
  73. body.at_decorator #padding_box {
  74. decorator: my-gradient padding-box;
  75. }
  76. body.at_decorator #auto_box {
  77. decorator: my-gradient;
  78. }
  79. body.at_decorator #border_box {
  80. decorator: my-gradient border-box;
  81. }
  82. </style>
  83. </head>
  84. <body>
  85. <div id="content_box"/>
  86. <div id="padding_box"/>
  87. <div id="auto_box"/>
  88. <div id="border_box"/>
  89. </body>
  90. </rml>
  91. )";
  92. TEST_CASE("decorator.paint-area")
  93. {
  94. TestsRenderInterface* render_interface = TestsShell::GetTestsRenderInterface();
  95. // This test only works with the dummy renderer.
  96. if (!render_interface)
  97. return;
  98. Context* context = TestsShell::GetContext();
  99. ElementDocument* document = context->LoadDocumentFromMemory(document_decorator_rml, "assets/");
  100. document->Show();
  101. for (const bool set_at_decorator_class : {false, true})
  102. {
  103. document->SetClass("at_decorator", set_at_decorator_class);
  104. const byte blue = (set_at_decorator_class ? 255 : 0);
  105. render_interface->ExpectCompileGeometry({
  106. Mesh{
  107. Vector<Vertex>{
  108. {{50, 50}, {255, 0, blue, 255}, {0, 0}},
  109. {{100, 50}, {255, 255, blue, 255}, {0, 0}},
  110. {{100, 100}, {255, 255, blue, 255}, {0, 0}},
  111. {{50, 100}, {255, 0, blue, 255}, {0, 0}},
  112. },
  113. Vector<int>{0, 2, 1, 0, 3, 2},
  114. },
  115. Mesh{
  116. Vector<Vertex>{
  117. {{20, 20}, {255, 0, blue, 255}, {0, 0}},
  118. {{130, 20}, {255, 255, blue, 255}, {0, 0}},
  119. {{130, 130}, {255, 255, blue, 255}, {0, 0}},
  120. {{20, 130}, {255, 0, blue, 255}, {0, 0}},
  121. },
  122. Vector<int>{0, 2, 1, 0, 3, 2},
  123. },
  124. Mesh{
  125. Vector<Vertex>{
  126. {{20, 20}, {255, 0, blue, 255}, {0, 0}},
  127. {{130, 20}, {255, 255, blue, 255}, {0, 0}},
  128. {{130, 130}, {255, 255, blue, 255}, {0, 0}},
  129. {{20, 130}, {255, 0, blue, 255}, {0, 0}},
  130. },
  131. Vector<int>{0, 2, 1, 0, 3, 2},
  132. },
  133. Mesh{
  134. Vector<Vertex>{
  135. {{0, 0}, {255, 0, blue, 255}, {0, 0}},
  136. {{150, 0}, {255, 255, blue, 255}, {0, 0}},
  137. {{150, 150}, {255, 255, blue, 255}, {0, 0}},
  138. {{0, 150}, {255, 0, blue, 255}, {0, 0}},
  139. },
  140. Vector<int>{0, 2, 1, 0, 3, 2},
  141. },
  142. });
  143. context->Update();
  144. context->Render();
  145. }
  146. document->Close();
  147. TestsShell::ShutdownShell();
  148. }