diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2013-03-30 15:01:00 +0100 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2013-03-30 15:23:05 +0100 |
commit | e218dcfdf2c58f8841e7ebd220527d08e870a6d5 (patch) | |
tree | a567db04a8a51e2db87f80e259faf222a7d4becd /src/app/system_windows.h | |
parent | bfc701e286259d9a7aa2ff8240704eab2ba3a237 (diff) | |
parent | e607fed265070be8c518d4302d8b76f738421fb3 (diff) | |
download | colobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.tar.gz colobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.tar.bz2 colobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.zip |
Merge branch 'dev'
Merging content from dev
Diffstat (limited to 'src/app/system_windows.h')
-rw-r--r-- | src/app/system_windows.h | 105 |
1 files changed, 18 insertions, 87 deletions
diff --git a/src/app/system_windows.h b/src/app/system_windows.h index c9743e6..88e7507 100644 --- a/src/app/system_windows.h +++ b/src/app/system_windows.h @@ -20,106 +20,37 @@ * \brief Windows-specific implementation of system functions */ -/* NOTE: code is contained in this header; - * there is no separate .cpp module for simplicity */ +#include "app/system.h" -#include <windows.h> - - -std::string UTF8_Encode_Windows(const std::wstring &wstr); -std::wstring UTF8_Decode_Windows(const std::string &str); -SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string& title, const std::string& message); - -void GetCurrentTimeStamp_Windows(SystemTimeStamp *stamp); -long long GetTimeStampExactResolution_Windows(); -long long TimeStampExactDiff_Windows(SystemTimeStamp *before, SystemTimeStamp *after); struct SystemTimeStamp { - FILETIME fileTime; + long long counterValue; SystemTimeStamp() { - fileTime.dwHighDateTime = fileTime.dwLowDateTime = 0; + counterValue = 0; } }; - -// Convert a wide Unicode string to an UTF8 string -std::string UTF8_Encode_Windows(const std::wstring &wstr) +class CSystemUtilsWindows : public CSystemUtils { - int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast<int>(wstr.size()), NULL, 0, NULL, NULL); - std::string strTo(size_needed, 0); - WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast<int>(wstr.size()), &strTo[0], size_needed, NULL, NULL); - return strTo; -} - -// Convert an UTF8 string to a wide Unicode String -std::wstring UTF8_Decode_Windows(const std::string &str) -{ - int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast<int>(str.size()), NULL, 0); - std::wstring wstrTo(size_needed, 0); - MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast<int>(str.size()), &wstrTo[0], size_needed); - return wstrTo; -} - -SystemDialogResult SystemDialog_Windows(SystemDialogType type, const std::string& title, const std::string& message) -{ - unsigned int windowsType = 0; - std::wstring windowsMessage = UTF8_Decode_Windows(message); - std::wstring windowsTitle = UTF8_Decode_Windows(title); - - switch (type) - { - case SDT_INFO: - default: - windowsType = MB_ICONINFORMATION|MB_OK; - break; - case SDT_WARNING: - windowsType = MB_ICONWARNING|MB_OK; - break; - case SDT_ERROR: - windowsType = MB_ICONERROR|MB_OK; - break; - case SDT_YES_NO: - windowsType = MB_ICONQUESTION|MB_YESNO; - break; - case SDT_OK_CANCEL: - windowsType = MB_ICONWARNING|MB_OKCANCEL; - break; - } +public: + virtual void Init() override; - switch (MessageBoxW(NULL, windowsMessage.c_str(), windowsTitle.c_str(), windowsType)) - { - case IDOK: - return SDR_OK; - case IDCANCEL: - return SDR_CANCEL; - case IDYES: - return SDR_YES; - case IDNO: - return SDR_NO; - default: - break; - } + virtual SystemDialogResult SystemDialog(SystemDialogType type, const std::string& title, const std::string& message) override; - return SDR_OK; -} + virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) override; + virtual long long GetTimeStampExactResolution() override; + virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override; + virtual std::string profileFileLocation() override; + virtual std::string savegameDirectoryLocation() override; -void GetCurrentTimeStamp_Windows(SystemTimeStamp *stamp) -{ - GetSystemTimeAsFileTime(&stamp->fileTime); -} +private: + std::string UTF8_Encode(const std::wstring &wstr); + std::wstring UTF8_Decode(const std::string &str); -long long GetTimeStampExactResolution_Windows() -{ - return 100ll; -} - -long long TimeStampExactDiff_Windows(SystemTimeStamp *before, SystemTimeStamp *after) -{ - long long tH = (1ll << 32) * (after->fileTime.dwHighDateTime - before->fileTime.dwHighDateTime); - long long tL = after->fileTime.dwLowDateTime - before->fileTime.dwLowDateTime; - return (tH + tL) * 100ll; -} +protected: + long long m_counterFrequency; +}; |