2
0

main.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <RmlUi/Core.h>
  29. #include <RmlUi/Controls.h>
  30. #include <RmlUi/Debugger.h>
  31. #include <Input.h>
  32. #include <Shell.h>
  33. #include <ShellRenderInterfaceOpenGL.h>
  34. #include "FileFormatter.h"
  35. #include "FileSystem.h"
  36. Rml::Core::Context* context = nullptr;
  37. ShellRenderInterfaceExtensions *shell_renderer;
  38. void GameLoop()
  39. {
  40. context->Update();
  41. shell_renderer->PrepareRenderBuffer();
  42. context->Render();
  43. shell_renderer->PresentRenderBuffer();
  44. }
  45. #if defined RMLUI_PLATFORM_WIN32
  46. #include <windows.h>
  47. 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))
  48. #else
  49. int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
  50. #endif
  51. {
  52. #ifdef RMLUI_PLATFORM_WIN32
  53. RMLUI_UNUSED(instance_handle);
  54. RMLUI_UNUSED(previous_instance_handle);
  55. RMLUI_UNUSED(command_line);
  56. RMLUI_UNUSED(command_show);
  57. #else
  58. RMLUI_UNUSED(argc);
  59. RMLUI_UNUSED(argv);
  60. #endif
  61. #ifdef RMLUI_PLATFORM_WIN32
  62. AllocConsole();
  63. #endif
  64. int window_width = 1024;
  65. int window_height = 768;
  66. ShellRenderInterfaceOpenGL opengl_renderer;
  67. shell_renderer = &opengl_renderer;
  68. // Generic OS initialisation, creates a window and attaches OpenGL.
  69. if (!Shell::Initialise() ||
  70. !Shell::OpenWindow("Tree View Sample", shell_renderer, window_width, window_height, true))
  71. {
  72. Shell::Shutdown();
  73. return -1;
  74. }
  75. // RmlUi initialisation.
  76. Rml::Core::SetRenderInterface(&opengl_renderer);
  77. opengl_renderer.SetViewport(window_width, window_height);
  78. ShellSystemInterface system_interface;
  79. Rml::Core::SetSystemInterface(&system_interface);
  80. Rml::Core::Initialise();
  81. // Create the main RmlUi context and set it on the shell's input layer.
  82. context = Rml::Core::CreateContext("main", Rml::Core::Vector2i(window_width, window_height));
  83. if (context == nullptr)
  84. {
  85. Rml::Core::Shutdown();
  86. Shell::Shutdown();
  87. return -1;
  88. }
  89. Rml::Controls::Initialise();
  90. Rml::Debugger::Initialise(context);
  91. Input::SetContext(context);
  92. shell_renderer->SetContext(context);
  93. Shell::LoadFonts("assets/");
  94. // Create the file data source and formatter.
  95. Rml::Core::String root = Shell::FindSamplesRoot();
  96. FileSystem file_system(root + "basic/");
  97. FileFormatter file_formatter;
  98. // Load and show the demo document.
  99. Rml::Core::ElementDocument* document = context->LoadDocument("basic/treeview/data/treeview.rml");
  100. if (document)
  101. {
  102. document->GetElementById("title")->SetInnerRML(document->GetTitle());
  103. document->Show();
  104. }
  105. Shell::EventLoop(GameLoop);
  106. // Shutdown RmlUi.
  107. Rml::Core::Shutdown();
  108. Shell::CloseWindow();
  109. Shell::Shutdown();
  110. return 0;
  111. }