aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/win/CMakeLists.txt6
-rw-r--r--src/win/DebugLogger.hpp23
-rw-r--r--src/win/ForDllExport.cpp2
-rw-r--r--src/win/StdOutLogger.hpp25
-rw-r--r--src/win/graphics/direct/CMakeLists.txt3
-rw-r--r--src/win/graphics/direct/Font.cpp2
-rw-r--r--src/win/gui/CMakeLists.txt3
-rw-r--r--src/win/gui/Cursor.cpp2
-rw-r--r--src/win/gui/TimerManager.cpp2
-rw-r--r--src/win/gui/UiApplication.cpp6
-rw-r--r--src/win/gui/Window.cpp26
-rw-r--r--src/win/gui/WindowClass.cpp2
12 files changed, 29 insertions, 73 deletions
diff --git a/src/win/CMakeLists.txt b/src/win/CMakeLists.txt
index e190e9a0..ff3d6f96 100644
--- a/src/win/CMakeLists.txt
+++ b/src/win/CMakeLists.txt
@@ -1,8 +1,8 @@
-add_library(cru_win_base STATIC
- DebugLogger.hpp
- StdOutLogger.hpp
+add_library(cru_win_base SHARED
+ ForDllExport.cpp
)
target_compile_definitions(cru_win_base PUBLIC UNICODE _UNICODE) # use unicode
+target_compile_definitions(cru_win_base PRIVATE CRU_WIN_EXPORT_API)
target_link_libraries(cru_win_base PUBLIC cru_base)
add_subdirectory(graphics)
diff --git a/src/win/DebugLogger.hpp b/src/win/DebugLogger.hpp
deleted file mode 100644
index 5e78af22..00000000
--- a/src/win/DebugLogger.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "cru/win/WinPreConfig.hpp"
-
-#include "cru/common/Logger.hpp"
-
-namespace cru::platform::win {
-
-class WinDebugLoggerSource : public ::cru::log::ILogSource {
- public:
- WinDebugLoggerSource() = default;
-
- CRU_DELETE_COPY(WinDebugLoggerSource)
- CRU_DELETE_MOVE(WinDebugLoggerSource)
-
- ~WinDebugLoggerSource() = default;
-
- void Write(::cru::log::LogLevel level, StringView s) override {
- CRU_UNUSED(level)
-
- String m = s.ToString();
- ::OutputDebugStringW(reinterpret_cast<const wchar_t*>(m.c_str()));
- }
-};
-} // namespace cru::platform::win
diff --git a/src/win/ForDllExport.cpp b/src/win/ForDllExport.cpp
new file mode 100644
index 00000000..4662461b
--- /dev/null
+++ b/src/win/ForDllExport.cpp
@@ -0,0 +1,2 @@
+#include "cru/win/DebugLogger.hpp"
+#include "cru/win/StdOutLogger.hpp"
diff --git a/src/win/StdOutLogger.hpp b/src/win/StdOutLogger.hpp
deleted file mode 100644
index b3a22dd5..00000000
--- a/src/win/StdOutLogger.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "cru/common/Base.hpp"
-#include "cru/win/WinPreConfig.hpp"
-
-#include "cru/common/Logger.hpp"
-
-#include <cwchar>
-
-namespace cru::platform::win {
-class WinStdOutLoggerSource : public ::cru::log::ILogSource {
- public:
- WinStdOutLoggerSource() = default;
-
- CRU_DELETE_COPY(WinStdOutLoggerSource)
- CRU_DELETE_MOVE(WinStdOutLoggerSource)
-
- ~WinStdOutLoggerSource() = default;
-
- void Write(::cru::log::LogLevel level, StringView s) override {
- CRU_UNUSED(level)
-
- String m = s.ToString();
- std::fputws(reinterpret_cast<const wchar_t*>(m.c_str()), stdout);
- }
-};
-} // namespace cru::platform::win
diff --git a/src/win/graphics/direct/CMakeLists.txt b/src/win/graphics/direct/CMakeLists.txt
index ecd72b13..84c2af61 100644
--- a/src/win/graphics/direct/CMakeLists.txt
+++ b/src/win/graphics/direct/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_library(cru_win_graphics_direct STATIC
+add_library(cru_win_graphics_direct SHARED
Brush.cpp
Font.cpp
Geometry.cpp
@@ -11,3 +11,4 @@ add_library(cru_win_graphics_direct STATIC
)
target_link_libraries(cru_win_graphics_direct PUBLIC D3D11 D2d1 DWrite)
target_link_libraries(cru_win_graphics_direct PUBLIC cru_win_base cru_platform_graphics)
+target_compile_definitions(cru_win_graphics_direct PRIVATE CRU_WIN_GRAPHICS_DIRECT_EXPORT_API)
diff --git a/src/win/graphics/direct/Font.cpp b/src/win/graphics/direct/Font.cpp
index ffc16214..39ba2d8b 100644
--- a/src/win/graphics/direct/Font.cpp
+++ b/src/win/graphics/direct/Font.cpp
@@ -16,7 +16,7 @@ DWriteFont::DWriteFont(DirectGraphicsFactory* factory, String font_family,
if (!::GetUserDefaultLocaleName(buffer.data(),
static_cast<int>(buffer.size())))
throw platform::win::Win32Error(
- ::GetLastError(), "Failed to get locale when create dwrite font.");
+ ::GetLastError(), u"Failed to get locale when create dwrite font.");
ThrowIfFailed(factory->GetDWriteFactory()->CreateTextFormat(
reinterpret_cast<const wchar_t*>(font_family_.c_str()), nullptr,
diff --git a/src/win/gui/CMakeLists.txt b/src/win/gui/CMakeLists.txt
index 2c8d1aab..b9d2862f 100644
--- a/src/win/gui/CMakeLists.txt
+++ b/src/win/gui/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_library(cru_win_gui STATIC
+add_library(cru_win_gui SHARED
TimerManager.hpp
WindowManager.hpp
@@ -15,3 +15,4 @@ add_library(cru_win_gui STATIC
)
target_link_libraries(cru_win_gui PUBLIC imm32)
target_link_libraries(cru_win_gui PUBLIC cru_win_graphics_direct cru_platform_gui)
+target_compile_definitions(cru_win_gui PRIVATE CRU_WIN_GUI_EXPORT_API)
diff --git a/src/win/gui/Cursor.cpp b/src/win/gui/Cursor.cpp
index 80e8a749..a3a7f824 100644
--- a/src/win/gui/Cursor.cpp
+++ b/src/win/gui/Cursor.cpp
@@ -27,7 +27,7 @@ WinCursor* LoadWinCursor(const wchar_t* name) {
const auto handle = static_cast<HCURSOR>(::LoadImageW(
NULL, name, IMAGE_CURSOR, SM_CYCURSOR, SM_CYCURSOR, LR_SHARED));
if (handle == NULL) {
- throw Win32Error(::GetLastError(), "Failed to load system cursor.");
+ throw Win32Error(::GetLastError(), u"Failed to load system cursor.");
}
return new WinCursor(handle, false);
}
diff --git a/src/win/gui/TimerManager.cpp b/src/win/gui/TimerManager.cpp
index fc26b6c4..f3da1f09 100644
--- a/src/win/gui/TimerManager.cpp
+++ b/src/win/gui/TimerManager.cpp
@@ -26,7 +26,7 @@ long long TimerManager::SetTimer(TimerType type, int period,
gsl::narrow<UINT_PTR>(id), 0)) {
throw Win32Error(
::GetLastError(),
- "Failed to post window message to god window for set immediate.");
+ u"Failed to post window message to god window for set immediate.");
}
} else {
CreateNativeTimer(&timer_info);
diff --git a/src/win/gui/UiApplication.cpp b/src/win/gui/UiApplication.cpp
index cb0f0a4c..dadcfc75 100644
--- a/src/win/gui/UiApplication.cpp
+++ b/src/win/gui/UiApplication.cpp
@@ -1,11 +1,11 @@
#include "cru/win/gui/UiApplication.hpp"
-#include "../DebugLogger.hpp"
-#include "../StdOutLogger.hpp"
#include "TimerManager.hpp"
#include "WindowManager.hpp"
#include "cru/common/Logger.hpp"
#include "cru/platform/Check.hpp"
+#include "cru/win/DebugLogger.hpp"
+#include "cru/win/StdOutLogger.hpp"
#include "cru/win/graphics/direct/Factory.hpp"
#include "cru/win/gui/Cursor.hpp"
#include "cru/win/gui/Exception.hpp"
@@ -27,7 +27,7 @@ WinUiApplication::WinUiApplication() {
instance_handle_ = ::GetModuleHandleW(nullptr);
if (!instance_handle_)
- throw Win32Error("Failed to get module(instance) handle.");
+ throw Win32Error(u"Failed to get module(instance) handle.");
::SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
diff --git a/src/win/gui/Window.cpp b/src/win/gui/Window.cpp
index 7ee2fb71..b3cf7065 100644
--- a/src/win/gui/Window.cpp
+++ b/src/win/gui/Window.cpp
@@ -42,7 +42,7 @@ Rect CalcWindowRectFromClient(const Rect& rect, WindowStyleFlag style_flag,
r.right = DipToPixel(rect.GetRight(), dpi);
r.bottom = DipToPixel(rect.GetBottom(), dpi);
if (!AdjustWindowRectEx(&r, CalcWindowStyle(style_flag), FALSE, 0))
- throw Win32Error(::GetLastError(), "Failed to invoke AdjustWindowRectEx.");
+ throw Win32Error(::GetLastError(), u"Failed to invoke AdjustWindowRectEx.");
Rect result =
Rect::FromVertices(PixelToDip(r.left, dpi), PixelToDip(r.top, dpi),
@@ -55,7 +55,7 @@ Rect CalcClientRectFromWindow(const Rect& rect, WindowStyleFlag style_flag,
RECT o{100, 100, 500, 500};
RECT s = o;
if (!AdjustWindowRectEx(&s, CalcWindowStyle(style_flag), FALSE, 0))
- throw Win32Error(::GetLastError(), "Failed to invoke AdjustWindowRectEx.");
+ throw Win32Error(::GetLastError(), u"Failed to invoke AdjustWindowRectEx.");
Rect result = rect;
result.Shrink(Thickness(PixelToDip(s.left - o.left, dpi),
@@ -125,7 +125,7 @@ void WinNativeWindow::SetClientSize(const Size& size) {
if (!SetWindowPos(hwnd_, nullptr, 0, 0, rect.right - rect.left,
rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE))
- throw Win32Error(::GetLastError(), "Failed to invoke SetWindowPos.");
+ throw Win32Error(::GetLastError(), u"Failed to invoke SetWindowPos.");
}
}
@@ -140,7 +140,7 @@ void WinNativeWindow::SetClientRect(const Rect& rect) {
if (!SetWindowPos(hwnd_, nullptr, 0, 0, r.right - r.left, r.bottom - r.top,
SWP_NOZORDER | SWP_NOMOVE))
- throw Win32Error(::GetLastError(), "Failed to invoke SetWindowPos.");
+ throw Win32Error(::GetLastError(), u"Failed to invoke SetWindowPos.");
}
}
@@ -148,7 +148,7 @@ Rect WinNativeWindow::GetWindowRect() {
if (hwnd_) {
RECT rect;
if (!::GetWindowRect(hwnd_, &rect))
- throw Win32Error(::GetLastError(), "Failed to invoke GetWindowRect.");
+ throw Win32Error(::GetLastError(), u"Failed to invoke GetWindowRect.");
return Rect::FromVertices(PixelToDip(rect.left), PixelToDip(rect.top),
PixelToDip(rect.right), PixelToDip(rect.bottom));
@@ -164,7 +164,7 @@ void WinNativeWindow::SetWindowRect(const Rect& rect) {
if (!SetWindowPos(hwnd_, nullptr, DipToPixel(rect.left),
DipToPixel(rect.top), DipToPixel(rect.GetRight()),
DipToPixel(rect.GetBottom()), SWP_NOZORDER))
- throw Win32Error(::GetLastError(), "Failed to invoke SetWindowPos.");
+ throw Win32Error(::GetLastError(), u"Failed to invoke SetWindowPos.");
}
}
@@ -179,9 +179,9 @@ bool WinNativeWindow::RequestFocus() {
Point WinNativeWindow::GetMousePosition() {
POINT p;
if (!::GetCursorPos(&p))
- throw Win32Error(::GetLastError(), "Failed to get cursor position.");
+ throw Win32Error(::GetLastError(), u"Failed to get cursor position.");
if (!::ScreenToClient(hwnd_, &p))
- throw Win32Error(::GetLastError(), "Failed to call ScreenToClient.");
+ throw Win32Error(::GetLastError(), u"Failed to call ScreenToClient.");
return PixelToDip(p);
}
@@ -200,9 +200,9 @@ void WinNativeWindow::RequestRepaint() {
log::TagDebug(log_tag, u"A repaint is requested.");
}
if (!::InvalidateRect(hwnd_, nullptr, FALSE))
- throw Win32Error(::GetLastError(), "Failed to invalidate window.");
+ throw Win32Error(::GetLastError(), u"Failed to invalidate window.");
if (!::UpdateWindow(hwnd_))
- throw Win32Error(::GetLastError(), "Failed to update window.");
+ throw Win32Error(::GetLastError(), u"Failed to update window.");
}
std::unique_ptr<graphics::IPainter> WinNativeWindow::BeginPaint() {
@@ -438,7 +438,7 @@ bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg,
RECT WinNativeWindow::GetClientRectPixel() {
RECT rect;
if (!::GetClientRect(hwnd_, &rect))
- throw Win32Error(::GetLastError(), "Failed to invoke GetClientRect.");
+ throw Win32Error(::GetLastError(), u"Failed to invoke GetClientRect.");
return rect;
}
@@ -453,11 +453,11 @@ void WinNativeWindow::RecreateWindow() {
nullptr, application_->GetInstanceHandle(), nullptr);
if (hwnd_ == nullptr)
- throw Win32Error(::GetLastError(), "Failed to create window.");
+ throw Win32Error(::GetLastError(), u"Failed to create window.");
auto dpi = ::GetDpiForWindow(hwnd_);
if (dpi == 0)
- throw Win32Error(::GetLastError(), "Failed to get dpi of window.");
+ throw Win32Error(::GetLastError(), u"Failed to get dpi of window.");
dpi_ = static_cast<float>(dpi);
log::Debug(u"Dpi of window is {}.", dpi_);
diff --git a/src/win/gui/WindowClass.cpp b/src/win/gui/WindowClass.cpp
index a033d091..9d86d791 100644
--- a/src/win/gui/WindowClass.cpp
+++ b/src/win/gui/WindowClass.cpp
@@ -23,6 +23,6 @@ WindowClass::WindowClass(std::wstring name, WNDPROC window_proc,
atom_ = ::RegisterClassExW(&window_class);
if (atom_ == 0)
- throw Win32Error(::GetLastError(), "Failed to create window class.");
+ throw Win32Error(::GetLastError(), u"Failed to create window class.");
}
} // namespace cru::platform::gui::win