main.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 "CaptureScreen.h"
  29. #include "TestConfig.h"
  30. #include "TestNavigator.h"
  31. #include "TestSuite.h"
  32. #include "TestViewer.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 <PlatformExtensions.h>
  38. #include <RmlUi_Backend.h>
  39. #include <Shell.h>
  40. #include <stdio.h>
  41. #if defined RMLUI_PLATFORM_WIN32
  42. #include <RmlUi_Include_Windows.h>
  43. int APIENTRY WinMain(HINSTANCE /*instance_handle*/, HINSTANCE /*previous_instance_handle*/, char* win_command_line, int /*command_show*/)
  44. #else
  45. int main(int argc, char** argv)
  46. #endif
  47. {
  48. const char* command_line = nullptr;
  49. #ifdef RMLUI_PLATFORM_WIN32
  50. command_line = win_command_line;
  51. #else
  52. if (argc > 1)
  53. command_line = argv[1];
  54. #endif
  55. int load_suite_index = -1;
  56. int load_case_index = -1;
  57. // Parse command line as <case_index> *or* <suite_index>:<case_index>.
  58. if (command_line)
  59. {
  60. int first_argument = -1;
  61. int second_argument = -1;
  62. const int num_arguments = sscanf(command_line, "%d:%d", &first_argument, &second_argument);
  63. switch (num_arguments)
  64. {
  65. case 1: load_case_index = first_argument - 1; break;
  66. case 2:
  67. load_suite_index = first_argument - 1;
  68. load_case_index = second_argument - 1;
  69. break;
  70. }
  71. }
  72. int window_width = 1500;
  73. int window_height = 800;
  74. // Initializes the shell which provides common functionality used by the included samples.
  75. if (!Shell::Initialize())
  76. return -1;
  77. // Constructs the system and render interfaces, creates a window, and attaches the renderer.
  78. if (!Backend::Initialize("Visual tests", window_width, window_height, true))
  79. {
  80. Shell::Shutdown();
  81. return -1;
  82. }
  83. // Install the custom interfaces constructed by the backend before initializing RmlUi.
  84. Rml::SetSystemInterface(Backend::GetSystemInterface());
  85. Rml::SetRenderInterface(Backend::GetRenderInterface());
  86. // RmlUi initialisation.
  87. Rml::Initialise();
  88. // Create the main RmlUi context.
  89. Rml::Context* context = Rml::CreateContext("main", Rml::Vector2i(window_width, window_height));
  90. if (!context)
  91. {
  92. Rml::Shutdown();
  93. Shell::Shutdown();
  94. return -1;
  95. }
  96. Rml::Debugger::Initialise(context);
  97. Shell::LoadFonts();
  98. context->SetDefaultScrollBehavior(Rml::ScrollBehavior::Instant, 1.f);
  99. {
  100. const Rml::StringList directories = GetTestInputDirectories();
  101. TestSuiteList test_suites;
  102. for (const Rml::String& directory : directories)
  103. {
  104. const Rml::StringList files = PlatformExtensions::ListFiles(directory, "rml");
  105. if (files.empty())
  106. Rml::Log::Message(Rml::Log::LT_WARNING, "Could not find any *.rml files in directory '%s'. Ignoring.", directory.c_str());
  107. else
  108. test_suites.emplace_back(directory, std::move(files));
  109. }
  110. RMLUI_ASSERTMSG(!test_suites.empty(), "RML test files directory not found or empty.");
  111. TestViewer viewer(context);
  112. TestNavigator navigator(Backend::GetRenderInterface(), context, &viewer, std::move(test_suites), load_suite_index, load_case_index);
  113. bool running = true;
  114. while (running)
  115. {
  116. running = Backend::ProcessEvents(context, &Shell::ProcessKeyDownShortcuts);
  117. context->Update();
  118. Backend::BeginFrame();
  119. context->Render();
  120. navigator.Render();
  121. Backend::PresentFrame();
  122. navigator.Update();
  123. }
  124. }
  125. Rml::Shutdown();
  126. Shell::Shutdown();
  127. Backend::Shutdown();
  128. return 0;
  129. }