main.cpp 4.6 KB

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