SystemInterface.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "../../Include/RmlUi/Core/SystemInterface.h"
  2. #include "../../Include/RmlUi/Core/Log.h"
  3. #include "../../Include/RmlUi/Core/StringUtilities.h"
  4. #include "../../Include/RmlUi/Core/URL.h"
  5. #include "LogDefault.h"
  6. #include <chrono>
  7. namespace Rml {
  8. static String& GlobalClipBoardText()
  9. {
  10. static String clipboard_text;
  11. return clipboard_text;
  12. }
  13. SystemInterface::SystemInterface() {}
  14. SystemInterface::~SystemInterface() {}
  15. double SystemInterface::GetElapsedTime()
  16. {
  17. static const auto start = std::chrono::steady_clock::now();
  18. const auto current = std::chrono::steady_clock::now();
  19. std::chrono::duration<double> diff = current - start;
  20. return diff.count();
  21. }
  22. bool SystemInterface::LogMessage(Log::Type type, const String& message)
  23. {
  24. return LogDefault::LogMessage(type, message);
  25. }
  26. void SystemInterface::SetMouseCursor(const String& /*cursor_name*/) {}
  27. void SystemInterface::SetClipboardText(const String& text)
  28. {
  29. // The default implementation will only copy and paste within the application
  30. GlobalClipBoardText() = text;
  31. }
  32. void SystemInterface::GetClipboardText(String& text)
  33. {
  34. text = GlobalClipBoardText();
  35. }
  36. int SystemInterface::TranslateString(String& translated, const String& input)
  37. {
  38. translated = input;
  39. return 0;
  40. }
  41. void SystemInterface::JoinPath(String& translated_path, const String& document_path, const String& path)
  42. {
  43. // If the path is absolute, strip the leading / and return it.
  44. if (path.size() > 0 && path[0] == '/')
  45. {
  46. translated_path = path.substr(1);
  47. return;
  48. }
  49. // If the path is a Windows-style absolute path, return it directly.
  50. size_t drive_pos = path.find(':');
  51. size_t slash_pos = Math::Min(path.find('/'), path.find('\\'));
  52. if (drive_pos != String::npos && drive_pos < slash_pos)
  53. {
  54. translated_path = path;
  55. return;
  56. }
  57. using StringUtilities::Replace;
  58. // Strip off the referencing document name.
  59. translated_path = document_path;
  60. translated_path = Replace(translated_path, '\\', '/');
  61. size_t file_start = translated_path.rfind('/');
  62. if (file_start != String::npos)
  63. translated_path.resize(file_start + 1);
  64. else
  65. translated_path.clear();
  66. // Append the paths and send through URL to removing any '..'.
  67. URL url(Replace(translated_path, ':', '|') + Replace(path, '\\', '/'));
  68. translated_path = Replace(url.GetPathedFileName(), '|', ':');
  69. }
  70. void SystemInterface::ActivateKeyboard(Rml::Vector2f /*caret_position*/, float /*line_height*/) {}
  71. void SystemInterface::DeactivateKeyboard() {}
  72. } // namespace Rml