diff options
author | crupest <crupest@outlook.com> | 2021-08-12 21:44:32 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-08-12 21:44:32 +0800 |
commit | 2e379441f69c4fd3049d186f76b25457e6250282 (patch) | |
tree | 893771e5103ca9f3a34bb622251aaacb024cf1c2 /src | |
parent | d718b0f576aeae1fa853124caefc8b0078f1deed (diff) | |
download | cru-2e379441f69c4fd3049d186f76b25457e6250282.tar.gz cru-2e379441f69c4fd3049d186f76b25457e6250282.tar.bz2 cru-2e379441f69c4fd3049d186f76b25457e6250282.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/common/String.cpp | 10 | ||||
-rw-r--r-- | src/platform/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/platform/ForDllExport.cpp | 2 | ||||
-rw-r--r-- | src/platform/bootstrap/Bootstrap.cpp | 15 | ||||
-rw-r--r-- | src/platform/bootstrap/CMakeLists.txt | 13 | ||||
-rw-r--r-- | src/platform/gui/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/win/Exception.cpp | 24 | ||||
-rw-r--r-- | src/win/graphics/direct/Geometry.cpp | 2 | ||||
-rw-r--r-- | src/win/graphics/direct/Painter.cpp | 2 | ||||
-rw-r--r-- | src/win/graphics/direct/Resource.cpp | 2 | ||||
-rw-r--r-- | src/win/gui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/win/gui/Resource.cpp | 6 |
13 files changed, 72 insertions, 15 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d5d544ee..94961746 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -8,6 +8,7 @@ target_sources(cru_base PUBLIC ${CRU_BASE_INCLUDE_DIR}/Base.hpp ${CRU_BASE_INCLUDE_DIR}/Bitmask.hpp ${CRU_BASE_INCLUDE_DIR}/Event.hpp + ${CRU_BASE_INCLUDE_DIR}/Exception.hpp ${CRU_BASE_INCLUDE_DIR}/Format.hpp ${CRU_BASE_INCLUDE_DIR}/Logger.hpp ${CRU_BASE_INCLUDE_DIR}/PreConfig.hpp diff --git a/src/common/String.cpp b/src/common/String.cpp index ce124575..91422d48 100644 --- a/src/common/String.cpp +++ b/src/common/String.cpp @@ -1,8 +1,14 @@ #include "cru/common/String.hpp" +#include "cru/common/StringUtil.hpp" #include <cstring> +#include <string_view> namespace cru { +String String::FromUtf8(const char* str, Index size) { + return String{cru::ToUtf16(std::string_view(str, size))}; +} + std::uint16_t String::kEmptyBuffer[1] = {0}; template <typename C> @@ -138,4 +144,8 @@ String::iterator String::erase(const_iterator start, const_iterator end) { return s; } +std::string String::ToUtf8() const { + return cru::ToUtf8(std::u16string_view(Char16CStr(), size())); +} + } // namespace cru diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt index 23f4a0f6..f5f48795 100644 --- a/src/platform/CMakeLists.txt +++ b/src/platform/CMakeLists.txt @@ -1,8 +1,10 @@ set(CRU_PLATFORM_BASE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform) -add_library(cru_platform_base STATIC +add_library(cru_platform_base SHARED + ForDllExport.cpp Color.cpp ) target_sources(cru_platform_base PUBLIC + ${CRU_PLATFORM_BASE_INCLUDE_DIR}/Base.hpp ${CRU_PLATFORM_BASE_INCLUDE_DIR}/Check.hpp ${CRU_PLATFORM_BASE_INCLUDE_DIR}/Color.hpp ${CRU_PLATFORM_BASE_INCLUDE_DIR}/Exception.hpp @@ -12,6 +14,8 @@ target_sources(cru_platform_base PUBLIC ${CRU_PLATFORM_BASE_INCLUDE_DIR}/Resource.hpp ) target_link_libraries(cru_platform_base PUBLIC cru_base) +target_compile_definitions(cru_platform_base PRIVATE CRU_PLATFORM_EXPORT_API) add_subdirectory(graphics) add_subdirectory(gui) +add_subdirectory(bootstrap) diff --git a/src/platform/ForDllExport.cpp b/src/platform/ForDllExport.cpp new file mode 100644 index 00000000..743a9efa --- /dev/null +++ b/src/platform/ForDllExport.cpp @@ -0,0 +1,2 @@ +#include "cru/platform/Exception.hpp" +#include "cru/platform/Resource.hpp" diff --git a/src/platform/bootstrap/Bootstrap.cpp b/src/platform/bootstrap/Bootstrap.cpp new file mode 100644 index 00000000..99b5badb --- /dev/null +++ b/src/platform/bootstrap/Bootstrap.cpp @@ -0,0 +1,15 @@ +#include "cru/platform/bootstrap/Bootstrap.hpp" + +#ifdef CRU_PLATFORM_WINDOWS +#include "cru/win/gui/UiApplication.hpp" +#else +#endif + +namespace cru::platform::boostrap { +cru::platform::gui::IUiApplication* CreateUiApplication() { +#ifdef CRU_PLATFORM_WINDOWS + return new cru::platform::gui::win::WinUiApplication(); +#else +#endif +} +} // namespace cru::platform::boostrap diff --git a/src/platform/bootstrap/CMakeLists.txt b/src/platform/bootstrap/CMakeLists.txt new file mode 100644 index 00000000..7759415f --- /dev/null +++ b/src/platform/bootstrap/CMakeLists.txt @@ -0,0 +1,13 @@ +set(CRU_PLATFORM_BOOTSTRAP_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform/bootstrap) +add_library(cru_platform_boostrap SHARED + Bootstrap.cpp +) +target_sources(cru_platform_boostrap PUBLIC + ${CRU_PLATFORM_BOOTSTRAP_INCLUDE_DIR}/Bootstrap.hpp +) + +if(WIN32) + target_link_libraries(cru_platform_boostrap PUBLIC cru_win_gui) +endif() + +target_compile_definitions(cru_platform_boostrap PRIVATE CRU_PLATFORM_BOOTSTRAP_EXPORT_API) diff --git a/src/platform/gui/CMakeLists.txt b/src/platform/gui/CMakeLists.txt index aca7620c..7f16a0e0 100644 --- a/src/platform/gui/CMakeLists.txt +++ b/src/platform/gui/CMakeLists.txt @@ -1,5 +1,5 @@ set(CRU_PLATFORM_GUI_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform/gui) -add_library(cru_platform_gui STATIC +add_library(cru_platform_gui SHARED Keyboard.cpp UiApplication.cpp ) @@ -12,3 +12,4 @@ target_sources(cru_platform_gui PUBLIC ${CRU_PLATFORM_GUI_INCLUDE_DIR}/UiApplication.hpp ) target_link_libraries(cru_platform_gui PUBLIC cru_platform_graphics) +target_compile_definitions(cru_platform_gui PRIVATE CRU_PLATFORM_GUI_EXPORT_API) diff --git a/src/win/Exception.cpp b/src/win/Exception.cpp index 8d2eee23..df2103fd 100644 --- a/src/win/Exception.cpp +++ b/src/win/Exception.cpp @@ -5,13 +5,13 @@ namespace cru::platform::win { -inline std::string HResultMakeMessage( - HRESULT h_result, std::optional<std::string_view> message) { +inline String HResultMakeMessage(HRESULT h_result, + std::optional<String> message) { if (message.has_value()) - return fmt::format(FMT_STRING("HRESULT: {:#08x}. Message: {}"), h_result, - *message); + return fmt::format(FMT_STRING(L"HRESULT: {:#08x}. Message: {}"), h_result, + message->WinCStr()); else - return fmt::format(FMT_STRING("HRESULT: {:#08x}."), h_result); + return fmt::format(FMT_STRING(L"HRESULT: {:#08x}."), h_result); } HResultError::HResultError(HRESULT h_result) @@ -20,19 +20,21 @@ HResultError::HResultError(HRESULT h_result) HResultError::HResultError(HRESULT h_result, std::string_view additional_message) - : PlatformException(HResultMakeMessage(h_result, additional_message)), + : PlatformException(HResultMakeMessage( + h_result, String::FromUtf8(additional_message.data(), + additional_message.size()))), h_result_(h_result) {} -inline std::string Win32MakeMessage(DWORD error_code, - std::string_view message) { - return fmt::format("Last error code: {:#04x}.\nMessage: {}\n", error_code, - message); +inline String Win32MakeMessage(DWORD error_code, String message) { + return fmt::format(L"Last error code: {:#04x}.\nMessage: {}\n", error_code, + message.WinCStr()); } Win32Error::Win32Error(std::string_view message) : Win32Error(::GetLastError(), message) {} Win32Error::Win32Error(DWORD error_code, std::string_view message) - : PlatformException(Win32MakeMessage(error_code, message)), + : PlatformException(Win32MakeMessage( + error_code, String::FromUtf8(message.data(), message.size()))), error_code_(error_code) {} } // namespace cru::platform::win diff --git a/src/win/graphics/direct/Geometry.cpp b/src/win/graphics/direct/Geometry.cpp index 8aa961b2..d07a819f 100644 --- a/src/win/graphics/direct/Geometry.cpp +++ b/src/win/graphics/direct/Geometry.cpp @@ -13,7 +13,7 @@ D2DGeometryBuilder::D2DGeometryBuilder(DirectGraphFactory* factory) void D2DGeometryBuilder::CheckValidation() { if (!IsValid()) - throw ReuseException("The geometry builder is already disposed."); + throw ReuseException(L"The geometry builder is already disposed."); } void D2DGeometryBuilder::BeginFigure(const Point& point) { diff --git a/src/win/graphics/direct/Painter.cpp b/src/win/graphics/direct/Painter.cpp index d6999cfa..26ef92ec 100644 --- a/src/win/graphics/direct/Painter.cpp +++ b/src/win/graphics/direct/Painter.cpp @@ -106,7 +106,7 @@ void D2DPainter::EndDraw() { void D2DPainter::CheckValidation() { if (!is_drawing_) { throw cru::platform::ReuseException( - "Can't do that on painter after end drawing."); + L"Can't do that on painter after end drawing."); } } } // namespace cru::platform::graphics::win::direct diff --git a/src/win/graphics/direct/Resource.cpp b/src/win/graphics/direct/Resource.cpp index 2b4a0772..6ae74e64 100644 --- a/src/win/graphics/direct/Resource.cpp +++ b/src/win/graphics/direct/Resource.cpp @@ -3,6 +3,8 @@ #include "cru/win/graphics/direct/Factory.hpp" namespace cru::platform::graphics::win::direct { +String DirectResource::kPlatformId = u"Windows Direct"; + DirectGraphResource::DirectGraphResource(DirectGraphFactory* factory) : factory_(factory) { Expects(factory); diff --git a/src/win/gui/CMakeLists.txt b/src/win/gui/CMakeLists.txt index 48bed00d..53dfe69b 100644 --- a/src/win/gui/CMakeLists.txt +++ b/src/win/gui/CMakeLists.txt @@ -8,6 +8,7 @@ add_library(cru_win_gui STATIC GodWindow.cpp InputMethod.cpp Keyboard.cpp + Resource.cpp TimerManager.cpp UiApplication.cpp Window.cpp diff --git a/src/win/gui/Resource.cpp b/src/win/gui/Resource.cpp new file mode 100644 index 00000000..dc4de173 --- /dev/null +++ b/src/win/gui/Resource.cpp @@ -0,0 +1,6 @@ +#include "cru/win/gui/Resource.hpp" +#include "cru/win/gui/Window.hpp" + +namespace cru::platform::gui::win { +String WinNativeResource::kPlatformId = u"Windows"; +} |