TestsShell.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 "TestsShell.h"
  29. #include <RmlUi/Core/Context.h>
  30. #include <RmlUi/Core/Core.h>
  31. #include <RmlUi/Debugger.h>
  32. #include <Shell.h>
  33. #include <Input.h>
  34. #include <ShellRenderInterfaceOpenGL.h>
  35. #include <doctest.h>
  36. namespace {
  37. bool shell_initialized = false;
  38. ShellRenderInterfaceOpenGL shell_render_interface;
  39. ShellSystemInterface shell_system_interface;
  40. Rml::Context* shell_context = nullptr;
  41. const Rml::Vector2i window_size(1500, 800);
  42. }
  43. static void InitializeShell()
  44. {
  45. if (!shell_initialized)
  46. {
  47. Rml::SetSystemInterface(&shell_system_interface);
  48. Rml::SetRenderInterface(&shell_render_interface);
  49. shell_initialized = true;
  50. // Generic OS initialisation, creates a window and attaches OpenGL.
  51. REQUIRE(Shell::Initialise());
  52. REQUIRE(Shell::OpenWindow("Element benchmark", &shell_render_interface, window_size.x, window_size.y, true));
  53. // RmlUi initialisation.
  54. shell_render_interface.SetViewport(window_size.x, window_size.y);
  55. REQUIRE(Rml::Initialise());
  56. REQUIRE(!shell_context);
  57. shell_context = Rml::CreateContext("main", window_size);
  58. REQUIRE(shell_context);
  59. REQUIRE(Rml::Debugger::Initialise(shell_context));
  60. ::Input::SetContext(shell_context);
  61. shell_render_interface.SetContext(shell_context);
  62. Shell::LoadFonts("assets/");
  63. }
  64. }
  65. Rml::Context* TestsShell::GetMainContext()
  66. {
  67. InitializeShell();
  68. return shell_context;
  69. }
  70. Rml::Context* TestsShell::CreateContext(const Rml::String& name, Rml::RenderInterface* render_interface)
  71. {
  72. InitializeShell();
  73. if (!render_interface)
  74. render_interface = &shell_render_interface;
  75. Rml::Context* context = Rml::CreateContext(name, window_size, render_interface);
  76. REQUIRE(context);
  77. return context;
  78. }
  79. void TestsShell::RemoveContext(Rml::Context* context)
  80. {
  81. REQUIRE(context);
  82. REQUIRE(context != shell_context);
  83. const Rml::String& name = context->GetName();
  84. REQUIRE(name != "main");
  85. REQUIRE(Rml::RemoveContext(name));
  86. }
  87. void TestsShell::EventLoop(ShellIdleFunction idle_func)
  88. {
  89. Shell::EventLoop(idle_func);
  90. }
  91. void TestsShell::PrepareRenderBuffer()
  92. {
  93. shell_render_interface.PrepareRenderBuffer();
  94. }
  95. void TestsShell::PresentRenderBuffer()
  96. {
  97. shell_render_interface.PresentRenderBuffer();
  98. }
  99. void TestsShell::RequestExit()
  100. {
  101. Shell::RequestExit();
  102. }
  103. void TestsShell::ShutdownShell()
  104. {
  105. if (shell_initialized)
  106. {
  107. Rml::Shutdown();
  108. Shell::CloseWindow();
  109. Shell::Shutdown();
  110. shell_context = nullptr;
  111. shell_initialized = false;
  112. }
  113. }