main.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "TestConfig.h"
  29. #include "TestViewer.h"
  30. #include "TestNavigator.h"
  31. #include "CaptureScreen.h"
  32. #include "TestSuite.h"
  33. #include <RmlUi/Core/Context.h>
  34. #include <RmlUi/Core/Core.h>
  35. #include <RmlUi/Core/Element.h>
  36. #include <RmlUi/Debugger.h>
  37. #include <Shell.h>
  38. #include <Input.h>
  39. #include <ShellRenderInterfaceOpenGL.h>
  40. Rml::Context* context = nullptr;
  41. ShellRenderInterfaceOpenGL* shell_renderer = nullptr;
  42. TestNavigator* g_navigator = nullptr;
  43. void GameLoop()
  44. {
  45. context->Update();
  46. shell_renderer->PrepareRenderBuffer();
  47. context->Render();
  48. if (g_navigator)
  49. g_navigator->Render();
  50. shell_renderer->PresentRenderBuffer();
  51. if (g_navigator)
  52. g_navigator->Update();
  53. }
  54. #if defined RMLUI_PLATFORM_WIN32
  55. #include <windows.h>
  56. int APIENTRY WinMain(HINSTANCE RMLUI_UNUSED_PARAMETER(instance_handle), HINSTANCE RMLUI_UNUSED_PARAMETER(previous_instance_handle), char* command_line, int RMLUI_UNUSED_PARAMETER(command_show))
  57. #else
  58. int main(int argc, char** argv)
  59. #endif
  60. {
  61. int load_test_case_index = -1;
  62. #ifdef RMLUI_PLATFORM_WIN32
  63. RMLUI_UNUSED(instance_handle);
  64. RMLUI_UNUSED(previous_instance_handle);
  65. RMLUI_UNUSED(command_show);
  66. load_test_case_index = std::atoi(command_line) - 1;
  67. #else
  68. if (argc > 1)
  69. load_test_case_index = std::atoi(argv[1]) - 1;
  70. #endif
  71. int window_width = 1500;
  72. int window_height = 800;
  73. ShellRenderInterfaceOpenGL opengl_renderer;
  74. shell_renderer = &opengl_renderer;
  75. // Generic OS initialisation, creates a window and attaches OpenGL.
  76. if (!Shell::Initialise() ||
  77. !Shell::OpenWindow("Visual tests", shell_renderer, window_width, window_height, true))
  78. {
  79. Shell::Shutdown();
  80. return -1;
  81. }
  82. // RmlUi initialisation.
  83. Rml::SetRenderInterface(&opengl_renderer);
  84. shell_renderer->SetViewport(window_width, window_height);
  85. ShellSystemInterface system_interface;
  86. Rml::SetSystemInterface(&system_interface);
  87. Rml::Initialise();
  88. // Create the main RmlUi context and set it on the shell's input layer.
  89. context = Rml::CreateContext("main", Rml::Vector2i(window_width, window_height));
  90. if (context == nullptr)
  91. {
  92. Rml::Shutdown();
  93. Shell::Shutdown();
  94. return -1;
  95. }
  96. Rml::Debugger::Initialise(context);
  97. Input::SetContext(context);
  98. Shell::SetContext(context);
  99. Shell::LoadFonts("assets/");
  100. {
  101. const Rml::StringList directories = GetTestInputDirectories();
  102. TestSuiteList test_suites;
  103. for (const Rml::String& directory : directories)
  104. {
  105. const Rml::StringList files = Shell::ListFiles(directory, "rml");
  106. if (files.empty())
  107. {
  108. Rml::Log::Message(Rml::Log::LT_WARNING, "Could not find any *.rml files in directory '%s'. Ignoring.", directory.c_str());
  109. }
  110. else
  111. {
  112. test_suites.emplace_back(directory, std::move(files));
  113. }
  114. }
  115. RMLUI_ASSERTMSG(!test_suites.empty(), "RML test files directory not found or empty.");
  116. TestViewer viewer(context);
  117. TestNavigator navigator(shell_renderer, context, &viewer, std::move(test_suites), load_test_case_index);
  118. g_navigator = &navigator;
  119. Shell::EventLoop(GameLoop);
  120. g_navigator = nullptr;
  121. }
  122. Rml::Shutdown();
  123. Shell::CloseWindow();
  124. Shell::Shutdown();
  125. return 0;
  126. }