aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-06-27 17:02:58 +0800
committercrupest <crupest@outlook.com>2019-06-27 17:02:58 +0800
commitb53527fbe50a953ad0e3225cc812eb76b8a1f82d (patch)
treeeb81cd14d0a165c47f841ad94835f8987109de7e /src
parent8c5b05bcfce96495b4ffc4209ab8feda12597729 (diff)
downloadcru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.gz
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.bz2
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp11
-rw-r--r--src/ui/CMakeLists.txt1
-rw-r--r--src/ui/render/border_render_object.cpp14
-rw-r--r--src/ui/render/flex_layout_render_object.cpp2
-rw-r--r--src/ui/render/text_render_object.cpp16
-rw-r--r--src/ui/render/window_render_object.cpp4
-rw-r--r--src/ui/ui_manager.cpp17
-rw-r--r--src/ui/window.cpp8
-rw-r--r--src/win/exception.cpp2
-rw-r--r--src/win/graph/direct/CMakeLists.txt1
-rw-r--r--src/win/graph/direct/exception.cpp29
-rw-r--r--src/win/native/CMakeLists.txt16
-rw-r--r--src/win/native/dpi_util.hpp4
-rw-r--r--src/win/native/god_window.cpp12
-rw-r--r--src/win/native/god_window_message.hpp2
-rw-r--r--src/win/native/native_window.cpp (renamed from src/win/native/win_native_window.cpp)44
-rw-r--r--src/win/native/timer.cpp4
-rw-r--r--src/win/native/timer.hpp2
-rw-r--r--src/win/native/ui_application.cpp (renamed from src/win/native/win_application.cpp)66
-rw-r--r--src/win/native/window_class.cpp6
-rw-r--r--src/win/native/window_d2d_painter.cpp (renamed from src/win/native/window_painter.cpp)20
-rw-r--r--src/win/native/window_d2d_painter.hpp21
-rw-r--r--src/win/native/window_manager.cpp15
-rw-r--r--src/win/native/window_manager.hpp8
-rw-r--r--src/win/native/window_painter.hpp21
-rw-r--r--src/win/native/window_render_target.cpp12
26 files changed, 170 insertions, 188 deletions
diff --git a/src/main.cpp b/src/main.cpp
index ee381430..f9c0e56b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,7 +5,7 @@
#include "cru/ui/controls/text_block.hpp"
#include "cru/ui/window.hpp"
-using cru::platform::native::IUiApplication;
+using cru::platform::native::UiApplication;
using cru::ui::Rect;
using cru::ui::Thickness;
using cru::ui::Window;
@@ -15,13 +15,16 @@ using cru::ui::controls::TextBlock;
/*
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
+
+*/
+
+int main() {
+
#ifdef CRU_DEBUG
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
-*/
-int main() {
- std::unique_ptr<IUiApplication> application(IUiApplication::CreateInstance());
+ std::unique_ptr<UiApplication> application(UiApplication::CreateInstance());
const auto window = Window::CreateOverlapped();
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index a725c54b..6d6fc02d 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -17,6 +17,7 @@ add_library(cru_ui STATIC
render/window_render_object.cpp
)
target_sources(cru_ui PUBLIC
+ ${CRU_UI_INCLUDE_DIR}/base.hpp
${CRU_UI_INCLUDE_DIR}/content_control.hpp
${CRU_UI_INCLUDE_DIR}/control.hpp
${CRU_UI_INCLUDE_DIR}/layout_control.hpp
diff --git a/src/ui/render/border_render_object.cpp b/src/ui/render/border_render_object.cpp
index 99c2cb4c..16d2f1ea 100644
--- a/src/ui/render/border_render_object.cpp
+++ b/src/ui/render/border_render_object.cpp
@@ -10,13 +10,13 @@
namespace cru::ui::render {
BorderRenderObject::BorderRenderObject(
- std::shared_ptr<platform::graph::IBrush> brush) {
+ std::shared_ptr<platform::graph::Brush> brush) {
assert(brush);
this->border_brush_ = std::move(brush);
RecreateGeometry();
}
-void BorderRenderObject::Draw(platform::graph::IPainter* painter) {
+void BorderRenderObject::Draw(platform::graph::Painter* painter) {
painter->FillGeometry(geometry_.get(), border_brush_.get());
if (const auto child = GetChild()) {
auto offset = child->GetOffset();
@@ -154,7 +154,7 @@ void BorderRenderObject::RecreateGeometry() {
geometry_.reset();
border_outer_geometry_.reset();
- auto f = [](platform::graph::IGeometryBuilder* builder, const Rect& rect,
+ auto f = [](platform::graph::GeometryBuilder* builder, const Rect& rect,
const CornerRadius& corner) {
builder->BeginFigure(Point(rect.left + corner.left_top.x, rect.top));
builder->LineTo(Point(rect.GetRight() - corner.right_top.x, rect.top));
@@ -181,18 +181,18 @@ void BorderRenderObject::RecreateGeometry() {
const Rect outer_rect{margin.left, margin.top,
size.width - margin.GetHorizontalTotal(),
size.height - margin.GetVerticalTotal()};
- const auto graph_factory = platform::graph::IGraphFactory::GetInstance();
- std::unique_ptr<platform::graph::IGeometryBuilder> builder{
+ const auto graph_factory = platform::graph::GraphFactory::GetInstance();
+ std::unique_ptr<platform::graph::GeometryBuilder> builder{
graph_factory->CreateGeometryBuilder()};
f(builder.get(), outer_rect, corner_radius_);
- border_outer_geometry_.reset(builder->End());
+ border_outer_geometry_.reset(builder->Build());
builder.reset();
const Rect inner_rect = outer_rect.Shrink(border_thickness_);
builder.reset(graph_factory->CreateGeometryBuilder());
f(builder.get(), outer_rect, corner_radius_);
f(builder.get(), inner_rect, corner_radius_);
- geometry_.reset(builder->End());
+ geometry_.reset(builder->Build());
builder.reset();
}
} // namespace cru::ui::render
diff --git a/src/ui/render/flex_layout_render_object.cpp b/src/ui/render/flex_layout_render_object.cpp
index a9841813..8ce2db0a 100644
--- a/src/ui/render/flex_layout_render_object.cpp
+++ b/src/ui/render/flex_layout_render_object.cpp
@@ -15,7 +15,7 @@ FlexChildLayoutData* FlexLayoutRenderObject::GetChildLayoutData(int position) {
return &child_layout_data_[position];
}
-void FlexLayoutRenderObject::Draw(platform::graph::IPainter* painter) {
+void FlexLayoutRenderObject::Draw(platform::graph::Painter* painter) {
for (const auto child : GetChildren()) {
auto offset = child->GetOffset();
platform::graph::util::WithTransform(
diff --git a/src/ui/render/text_render_object.cpp b/src/ui/render/text_render_object.cpp
index 849bff11..64a34b6c 100644
--- a/src/ui/render/text_render_object.cpp
+++ b/src/ui/render/text_render_object.cpp
@@ -9,9 +9,9 @@
namespace cru::ui::render {
TextRenderObject::TextRenderObject(
- std::shared_ptr<platform::graph::IBrush> brush,
- std::shared_ptr<platform::graph::IFontDescriptor> font,
- std::shared_ptr<platform::graph::IBrush> selection_brush) {
+ std::shared_ptr<platform::graph::Brush> brush,
+ std::shared_ptr<platform::graph::Font> font,
+ std::shared_ptr<platform::graph::Brush> selection_brush) {
assert(brush);
assert(font);
assert(selection_brush);
@@ -20,7 +20,7 @@ TextRenderObject::TextRenderObject(
font.swap(font_);
selection_brush.swap(selection_brush_);
- const auto graph_factory = platform::graph::IGraphFactory::GetInstance();
+ const auto graph_factory = platform::graph::GraphFactory::GetInstance();
text_layout_.reset(graph_factory->CreateTextLayout(font_, L""));
}
@@ -32,22 +32,22 @@ void TextRenderObject::SetText(std::wstring new_text) {
text_layout_->SetText(std::move(new_text));
}
-std::shared_ptr<platform::graph::IFontDescriptor> TextRenderObject::GetFont()
+std::shared_ptr<platform::graph::Font> TextRenderObject::GetFont()
const {
return text_layout_->GetFont();
}
void TextRenderObject::SetFont(
- std::shared_ptr<platform::graph::IFontDescriptor> font) {
+ std::shared_ptr<platform::graph::Font> font) {
text_layout_->SetFont(std::move(font));
}
-void TextRenderObject::Draw(platform::graph::IPainter* painter) {
+void TextRenderObject::Draw(platform::graph::Painter* painter) {
platform::graph::util::WithTransform(
painter,
platform::Matrix::Translation(GetMargin().left + GetPadding().left,
GetMargin().top + GetPadding().top),
- [this](platform::graph::IPainter* p) {
+ [this](platform::graph::Painter* p) {
if (this->selection_range_.has_value()) {
const auto&& rects =
text_layout_->TextRangeRect(this->selection_range_.value());
diff --git a/src/ui/render/window_render_object.cpp b/src/ui/render/window_render_object.cpp
index f2e29603..89bb0beb 100644
--- a/src/ui/render/window_render_object.cpp
+++ b/src/ui/render/window_render_object.cpp
@@ -13,13 +13,13 @@ void WindowRenderObject::MeasureAndLayout() {
Layout(Rect{Point{}, client_size});
}
-void WindowRenderObject::Draw(platform::graph::IPainter* painter) {
+void WindowRenderObject::Draw(platform::graph::Painter* painter) {
painter->Clear(colors::white);
if (const auto child = GetChild()) {
auto offset = child->GetOffset();
platform::graph::util::WithTransform(
painter, platform::Matrix::Translation(offset.x, offset.y),
- [child](platform::graph::IPainter* p) { child->Draw(p); });
+ [child](platform::graph::Painter* p) { child->Draw(p); });
}
}
diff --git a/src/ui/ui_manager.cpp b/src/ui/ui_manager.cpp
index cc741ec5..376b1b45 100644
--- a/src/ui/ui_manager.cpp
+++ b/src/ui/ui_manager.cpp
@@ -6,21 +6,22 @@
#include "cru/platform/native/ui_applicaition.hpp"
namespace cru::ui {
+using namespace cru::platform::graph;
PredefineResources::PredefineResources() {
- const auto graph_factory = platform::graph::IGraphFactory::GetInstance();
+ const auto graph_factory = GraphFactory::GetInstance();
- button_normal_border_brush.reset(static_cast<platform::graph::IBrush*>(
- graph_factory->CreateSolidColorBrush(colors::black)));
- text_block_selection_brush.reset(static_cast<platform::graph::IBrush*>(
+ button_normal_border_brush.reset(
+ static_cast<Brush*>(graph_factory->CreateSolidColorBrush(colors::black)));
+ text_block_selection_brush.reset(static_cast<Brush*>(
graph_factory->CreateSolidColorBrush(colors::skyblue)));
- text_block_text_brush.reset(static_cast<platform::graph::IBrush*>(
- graph_factory->CreateSolidColorBrush(colors::black)));
- text_block_font.reset(graph_factory->CreateFontDescriptor(L"等线", 24.0f));
+ text_block_text_brush.reset(
+ static_cast<Brush*>(graph_factory->CreateSolidColorBrush(colors::black)));
+ text_block_font.reset(graph_factory->CreateFont(L"等线", 24.0f));
}
UiManager* UiManager::GetInstance() {
static UiManager* instance = new UiManager();
- platform::native::IUiApplication::GetInstance()->AddOnQuitHandler([] {
+ platform::native::UiApplication::GetInstance()->AddOnQuitHandler([] {
delete instance;
instance = nullptr;
});
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index 4a1bc108..9eabc4a6 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -111,7 +111,7 @@ void BindNativeEvent(Window* window, IEvent<T>* event,
Window::Window(tag_overlapped_constructor)
: mouse_hover_control_(nullptr), focus_control_(this) {
native_window_ =
- platform::native::IUiApplication::GetInstance()->CreateWindow(nullptr);
+ platform::native::UiApplication::GetInstance()->CreateWindow(nullptr);
render_object_.reset(new render::WindowRenderObject(this));
BindNativeEvent(this, native_window_->DestroyEvent(),
@@ -151,7 +151,7 @@ void Window::Relayout() { this->render_object_->MeasureAndLayout(); }
void Window::InvalidateLayout() {
if (!need_layout_) {
- platform::native::IUiApplication::GetInstance()->InvokeLater(
+ platform::native::UiApplication::GetInstance()->InvokeLater(
[resolver = this->CreateResolver()] {
if (const auto window = resolver.Resolve()) {
window->Relayout();
@@ -192,9 +192,9 @@ void Window::OnNativeDestroy(std::nullptr_t) { delete this; }
void Window::OnNativePaint(std::nullptr_t) {
const auto painter =
- std::unique_ptr<platform::graph::IPainter>(native_window_->BeginPaint());
+ std::unique_ptr<platform::graph::Painter>(native_window_->BeginPaint());
render_object_->Draw(painter.get());
- painter->End();
+ painter->EndDraw();
}
void Window::OnNativeResize(const Size& size) {
diff --git a/src/win/exception.cpp b/src/win/exception.cpp
index 62305329..4cac66bb 100644
--- a/src/win/exception.cpp
+++ b/src/win/exception.cpp
@@ -2,7 +2,7 @@
#include "cru/common/format.hpp"
-namespace cru::win {
+namespace cru::platform::win {
using util::Format;
inline std::string HResultMakeMessage(HRESULT h_result,
diff --git a/src/win/graph/direct/CMakeLists.txt b/src/win/graph/direct/CMakeLists.txt
index 7cbbb080..7228802c 100644
--- a/src/win/graph/direct/CMakeLists.txt
+++ b/src/win/graph/direct/CMakeLists.txt
@@ -2,7 +2,6 @@ set(CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/win/graph/direct)
add_library(cru_win_graph_direct STATIC
brush.cpp
- exception.cpp
font.cpp
geometry.cpp
graph_factory.cpp
diff --git a/src/win/graph/direct/exception.cpp b/src/win/graph/direct/exception.cpp
deleted file mode 100644
index 23c267c1..00000000
--- a/src/win/graph/direct/exception.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "cru/win/graph/direct/exception.hpp"
-
-#include "cru/common/format.hpp"
-
-namespace cru::platform::graph::win::direct {
-using util::Format;
-
-inline std::string HResultMakeMessage(HRESULT h_result,
- const std::string_view* message) {
- char buffer[10];
- sprintf_s(buffer, "%#08x", h_result);
-
- if (message)
- return Format(
- "An HResultError is thrown. HRESULT: {}.\nAdditional message: {}\n",
- buffer, *message);
- else
- return Format("An HResultError is thrown. HRESULT: {}.\n", buffer);
-}
-
-HResultError::HResultError(HRESULT h_result)
- : PlatformException(HResultMakeMessage(h_result, nullptr)),
- h_result_(h_result) {}
-
-HResultError::HResultError(HRESULT h_result,
- const std::string_view& additional_message)
- : PlatformException(HResultMakeMessage(h_result, &additional_message)),
- h_result_(h_result) {}
-} // namespace cru::platform::graph::win::direct
diff --git a/src/win/native/CMakeLists.txt b/src/win/native/CMakeLists.txt
index a9ee84e7..757eae57 100644
--- a/src/win/native/CMakeLists.txt
+++ b/src/win/native/CMakeLists.txt
@@ -4,24 +4,26 @@ add_library(cru_win_native STATIC
dpi_util.hpp
god_window_message.hpp
timer.hpp
+ window_d2d_painter.hpp
window_manager.hpp
- window_painter.hpp
god_window.cpp
+ native_window.cpp
timer.cpp
- win_application.cpp
- win_native_window.cpp
+ ui_application.cpp
window_class.cpp
+ window_d2d_painter.cpp
window_manager.cpp
- window_painter.cpp
window_render_target.cpp
)
target_sources(cru_win_native PUBLIC
+ ${CRU_WIN_NATIVE_INCLUDE_DIR}/exception.hpp
${CRU_WIN_NATIVE_INCLUDE_DIR}/god_window.hpp
- ${CRU_WIN_NATIVE_INCLUDE_DIR}/win_application.hpp
- ${CRU_WIN_NATIVE_INCLUDE_DIR}/win_native_window.hpp
+ ${CRU_WIN_NATIVE_INCLUDE_DIR}/native_window.hpp
+ ${CRU_WIN_NATIVE_INCLUDE_DIR}/platform_id.hpp
+ ${CRU_WIN_NATIVE_INCLUDE_DIR}/ui_application.hpp
${CRU_WIN_NATIVE_INCLUDE_DIR}/window_class.hpp
${CRU_WIN_NATIVE_INCLUDE_DIR}/window_native_message_event_args.hpp
${CRU_WIN_NATIVE_INCLUDE_DIR}/window_render_target.hpp
)
-target_link_libraries(cru_win_native PUBLIC cru_win_graph)
+target_link_libraries(cru_win_native PUBLIC cru_win_graph_direct)
diff --git a/src/win/native/dpi_util.hpp b/src/win/native/dpi_util.hpp
index d459e8c6..a642fd79 100644
--- a/src/win/native/dpi_util.hpp
+++ b/src/win/native/dpi_util.hpp
@@ -5,7 +5,7 @@
// The dpi awareness needs to be implemented in the future. Currently we use 96
// as default.
-namespace cru::win::native {
+namespace cru::platform::native::win {
inline platform::native::Dpi GetDpi() {
return platform::native::Dpi{96.0f, 96.0f};
}
@@ -33,4 +33,4 @@ inline float PixelToDipX(const int pixel_x) {
inline float PixelToDipY(const int pixel_y) {
return DipToPixelInternal(pixel_y, GetDpi().y);
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
diff --git a/src/win/native/god_window.cpp b/src/win/native/god_window.cpp
index 58fb663c..5f1d7b53 100644
--- a/src/win/native/god_window.cpp
+++ b/src/win/native/god_window.cpp
@@ -1,17 +1,17 @@
#include "cru/win/native/god_window.hpp"
-#include "cru/win/exception.hpp"
-#include "cru/win/native/win_application.hpp"
+#include "cru/win/native/exception.hpp"
+#include "cru/win/native/ui_application.hpp"
#include "cru/win/native/window_class.hpp"
#include "god_window_message.hpp"
#include "timer.hpp"
-namespace cru::win::native {
+namespace cru::platform::native::win {
constexpr auto god_window_class_name = L"GodWindowClass";
LRESULT CALLBACK GodWndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam) {
- const auto app = WinApplication::GetInstance();
+ const auto app = WinUiApplication::GetInstance();
if (app) {
LRESULT result;
@@ -25,7 +25,7 @@ LRESULT CALLBACK GodWndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
-GodWindow::GodWindow(WinApplication* application) {
+GodWindow::GodWindow(WinUiApplication* application) {
application_ = application;
const auto h_instance = application->GetInstanceHandle();
@@ -70,4 +70,4 @@ bool GodWindow::HandleGodWindowMessage(HWND hwnd, UINT msg, WPARAM w_param,
}
return false;
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
diff --git a/src/win/native/god_window_message.hpp b/src/win/native/god_window_message.hpp
index 10268625..591270d9 100644
--- a/src/win/native/god_window_message.hpp
+++ b/src/win/native/god_window_message.hpp
@@ -1,6 +1,6 @@
#pragma once
#include "cru/win/win_pre_config.hpp"
-namespace cru::win::native {
+namespace cru::platform::native::win {
constexpr int invoke_later_message_id = WM_USER + 2000;
}
diff --git a/src/win/native/win_native_window.cpp b/src/win/native/native_window.cpp
index 9ca37321..fd29f9c5 100644
--- a/src/win/native/win_native_window.cpp
+++ b/src/win/native/native_window.cpp
@@ -1,19 +1,19 @@
-#include "cru/win/native/win_native_window.hpp"
+#include "cru/win/native/native_window.hpp"
-#include "cru/win/exception.hpp"
-#include "cru/win/graph/win_graph_factory.hpp"
-#include "cru/win/native/win_application.hpp"
+#include "cru/win/graph/direct/graph_factory.hpp"
+#include "cru/win/native/exception.hpp"
+#include "cru/win/native/ui_application.hpp"
#include "cru/win/native/window_class.hpp"
#include "cru/win/native/window_render_target.hpp"
#include "dpi_util.hpp"
+#include "window_d2d_painter.hpp"
#include "window_manager.hpp"
-#include "window_painter.hpp"
#include <assert.h>
#include <windowsx.h>
-namespace cru::win::native {
-WinNativeWindow::WinNativeWindow(WinApplication* application,
+namespace cru::platform::native::win {
+WinNativeWindow::WinNativeWindow(WinUiApplication* application,
std::shared_ptr<WindowClass> window_class,
DWORD window_style, WinNativeWindow* parent) {
assert(application); // application can't be null.
@@ -37,7 +37,7 @@ WinNativeWindow::WinNativeWindow(WinApplication* application,
window_manager->RegisterWindow(hwnd_, this);
window_render_target_.reset(
- new WindowRenderTarget(graph::WinGraphFactory::GetInstance(), hwnd_));
+ new WindowRenderTarget(graph::win::direct::DirectGraphFactory::GetInstance(), hwnd_));
}
WinNativeWindow::~WinNativeWindow() {
@@ -66,15 +66,15 @@ void WinNativeWindow::SetVisible(bool is_visible) {
if (!IsValid()) return;
is_visible ? ShowWindow(hwnd_, SW_SHOWNORMAL) : ShowWindow(hwnd_, SW_HIDE);
}
-ui::Size WinNativeWindow::GetClientSize() {
- if (!IsValid()) return ui::Size{};
+Size WinNativeWindow::GetClientSize() {
+ if (!IsValid()) return Size{};
const auto pixel_rect = GetClientRectPixel();
- return ui::Size(PixelToDipX(pixel_rect.right),
+ return Size(PixelToDipX(pixel_rect.right),
PixelToDipY(pixel_rect.bottom));
}
-void WinNativeWindow::SetClientSize(const ui::Size& size) {
+void WinNativeWindow::SetClientSize(const Size& size) {
if (IsValid()) {
const auto window_style =
static_cast<DWORD>(GetWindowLongPtr(hwnd_, GWL_STYLE));
@@ -96,19 +96,19 @@ void WinNativeWindow::SetClientSize(const ui::Size& size) {
}
}
-ui::Rect WinNativeWindow::GetWindowRect() {
- if (!IsValid()) return ui::Rect{};
+Rect WinNativeWindow::GetWindowRect() {
+ if (!IsValid()) return Rect{};
RECT rect;
if (!::GetWindowRect(hwnd_, &rect))
throw Win32Error(::GetLastError(), "Failed to invoke GetWindowRect.");
- return ui::Rect::FromVertices(PixelToDipX(rect.left), PixelToDipY(rect.top),
+ return Rect::FromVertices(PixelToDipX(rect.left), PixelToDipY(rect.top),
PixelToDipX(rect.right),
PixelToDipY(rect.bottom));
}
-void WinNativeWindow::SetWindowRect(const ui::Rect& rect) {
+void WinNativeWindow::SetWindowRect(const Rect& rect) {
if (IsValid()) {
if (!SetWindowPos(hwnd_, nullptr, DipToPixelX(rect.left),
DipToPixelY(rect.top), DipToPixelX(rect.GetRight()),
@@ -117,8 +117,8 @@ void WinNativeWindow::SetWindowRect(const ui::Rect& rect) {
}
}
-platform::graph::IPainter* WinNativeWindow::BeginPaint() {
- return new WindowPainter(this);
+graph::Painter* WinNativeWindow::BeginPaint() {
+ return new WindowD2DPainter(this);
}
bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg,
@@ -269,7 +269,7 @@ void WinNativeWindow::OnResizeInternal(const int new_width,
if (!(new_width == 0 && new_height == 0)) {
window_render_target_->ResizeBuffer(new_width, new_height);
resize_event_.Raise(
- ui::Size{PixelToDipX(new_width), PixelToDipY(new_height)});
+ Size{PixelToDipX(new_width), PixelToDipY(new_height)});
}
}
@@ -283,8 +283,8 @@ void WinNativeWindow::OnKillFocusInternal() {
focus_event_.Raise(false);
}
-inline ui::Point PiToDip(const POINT& pi_point) {
- return ui::Point(PixelToDipX(pi_point.x), PixelToDipY(pi_point.y));
+inline Point PiToDip(const POINT& pi_point) {
+ return Point(PixelToDipX(pi_point.x), PixelToDipY(pi_point.y));
}
void WinNativeWindow::OnMouseMoveInternal(const POINT point) {
@@ -337,4 +337,4 @@ void WinNativeWindow::OnCharInternal(wchar_t c) {}
void WinNativeWindow::OnActivatedInternal() {}
void WinNativeWindow::OnDeactivatedInternal() {}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
diff --git a/src/win/native/timer.cpp b/src/win/native/timer.cpp
index 9e3bbde6..ed2ae069 100644
--- a/src/win/native/timer.cpp
+++ b/src/win/native/timer.cpp
@@ -1,6 +1,6 @@
#include "timer.hpp"
-namespace cru::win::native {
+namespace cru::platform::native::win {
TimerManager::TimerManager(GodWindow* god_window) { god_window_ = god_window; }
UINT_PTR TimerManager::CreateTimer(const UINT milliseconds, const bool loop,
@@ -25,4 +25,4 @@ std::optional<std::pair<bool, TimerAction>> TimerManager::GetAction(
if (find_result == map_.cend()) return std::nullopt;
return find_result->second;
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
diff --git a/src/win/native/timer.hpp b/src/win/native/timer.hpp
index f30d9b91..08749768 100644
--- a/src/win/native/timer.hpp
+++ b/src/win/native/timer.hpp
@@ -9,7 +9,7 @@
#include <map>
#include <optional>
-namespace cru::win::native {
+namespace cru::platform::native::win {
using TimerAction = std::function<void()>;
class TimerManager : public Object {
diff --git a/src/win/native/win_application.cpp b/src/win/native/ui_application.cpp
index 586af331..360f6e41 100644
--- a/src/win/native/win_application.cpp
+++ b/src/win/native/ui_application.cpp
@@ -1,9 +1,9 @@
-#include "cru/win/native/win_application.hpp"
+#include "cru/win/native/ui_application.hpp"
-#include "cru/win/exception.hpp"
-#include "cru/win/graph/win_graph_factory.hpp"
+#include "cru/win/graph/direct/graph_factory.hpp"
+#include "cru/win/native/exception.hpp"
#include "cru/win/native/god_window.hpp"
-#include "cru/win/native/win_native_window.hpp"
+#include "cru/win/native/native_window.hpp"
#include "god_window_message.hpp"
#include "timer.hpp"
#include "window_manager.hpp"
@@ -11,35 +11,37 @@
#include <VersionHelpers.h>
#include <cassert>
-namespace cru::win::native {
+namespace cru::platform::native::win {
namespace {
-WinApplication* instance = nullptr;
+WinUiApplication* instance = nullptr;
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
namespace cru::platform::native {
-IUiApplication* IUiApplication::CreateInstance() {
- auto& i = ::cru::win::native::instance; // avoid long namespace prefix
+UiApplication* UiApplication::CreateInstance() {
+ auto& i =
+ ::cru::platform::native::win::instance; // avoid long namespace prefix
assert(i == nullptr);
- i = new win::native::WinApplication(::GetModuleHandleW(nullptr));
+ i = new win::WinUiApplication(::GetModuleHandleW(nullptr));
return i;
}
-IUiApplication* IUiApplication::GetInstance() {
- return ::cru::win::native::instance;
+UiApplication* UiApplication::GetInstance() {
+ return ::cru::platform::native::win::instance;
}
} // namespace cru::platform::native
-namespace cru::win::native {
-WinApplication* WinApplication::GetInstance() { return instance; }
+namespace cru::platform::native::win {
+WinUiApplication* WinUiApplication::GetInstance() { return instance; }
-WinApplication::WinApplication(HINSTANCE h_instance) : h_instance_(h_instance) {
+WinUiApplication::WinUiApplication(HINSTANCE h_instance)
+ : h_instance_(h_instance) {
assert(instance == nullptr);
if (!::IsWindows8OrGreater())
throw std::runtime_error("Must run on Windows 8 or later.");
- const auto graph_factory = platform::graph::IGraphFactory::CreateInstance();
+ const auto graph_factory = graph::GraphFactory::CreateInstance();
graph_factory->SetAutoDelete(true);
god_window_ = std::make_shared<GodWindow>(this);
@@ -47,9 +49,9 @@ WinApplication::WinApplication(HINSTANCE h_instance) : h_instance_(h_instance) {
window_manager_ = std::make_shared<WindowManager>(this);
}
-WinApplication::~WinApplication() { instance = nullptr; }
+WinUiApplication::~WinUiApplication() { instance = nullptr; }
-int WinApplication::Run() {
+int WinUiApplication::Run() {
MSG msg;
while (GetMessageW(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
@@ -63,13 +65,15 @@ int WinApplication::Run() {
return static_cast<int>(msg.wParam);
}
-void WinApplication::Quit(const int quit_code) { ::PostQuitMessage(quit_code); }
+void WinUiApplication::Quit(const int quit_code) {
+ ::PostQuitMessage(quit_code);
+}
-void WinApplication::AddOnQuitHandler(const std::function<void()>& handler) {
+void WinUiApplication::AddOnQuitHandler(const std::function<void()>& handler) {
quit_handlers_.push_back(handler);
}
-void WinApplication::InvokeLater(const std::function<void()>& action) {
+void WinUiApplication::InvokeLater(const std::function<void()>& action) {
// copy the action to a safe place
auto p_action_copy = new std::function<void()>(action);
@@ -78,34 +82,34 @@ void WinApplication::InvokeLater(const std::function<void()>& action) {
throw Win32Error(::GetLastError(), "InvokeLater failed to post message.");
}
-unsigned long WinApplication::SetTimeout(std::chrono::milliseconds milliseconds,
- const std::function<void()>& action) {
+unsigned long WinUiApplication::SetTimeout(
+ std::chrono::milliseconds milliseconds,
+ const std::function<void()>& action) {
return static_cast<unsigned long>(timer_manager_->CreateTimer(
static_cast<UINT>(milliseconds.count()), false, action));
}
-unsigned long WinApplication::SetInterval(
+unsigned long WinUiApplication::SetInterval(
std::chrono::milliseconds milliseconds,
const std::function<void()>& action) {
return static_cast<unsigned long>(timer_manager_->CreateTimer(
static_cast<UINT>(milliseconds.count()), true, action));
}
-void WinApplication::CancelTimer(unsigned long id) {
+void WinUiApplication::CancelTimer(unsigned long id) {
timer_manager_->KillTimer(static_cast<UINT_PTR>(id));
}
-std::vector<platform::native::INativeWindow*> WinApplication::GetAllWindow() {
+std::vector<NativeWindow*> WinUiApplication::GetAllWindow() {
const auto&& windows = window_manager_->GetAllWindows();
- std::vector<platform::native::INativeWindow*> result;
+ std::vector<NativeWindow*> result;
for (const auto w : windows) {
- result.push_back(static_cast<platform::native::INativeWindow*>(w));
+ result.push_back(static_cast<NativeWindow*>(w));
}
return result;
}
-platform::native::INativeWindow* WinApplication::CreateWindow(
- platform::native::INativeWindow* parent) {
+NativeWindow* WinUiApplication::CreateWindow(NativeWindow* parent) {
WinNativeWindow* p = nullptr;
if (parent != nullptr) {
p = dynamic_cast<WinNativeWindow*>(parent);
@@ -114,4 +118,4 @@ platform::native::INativeWindow* WinApplication::CreateWindow(
return new WinNativeWindow(this, window_manager_->GetGeneralWindowClass(),
WS_OVERLAPPEDWINDOW, p);
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
diff --git a/src/win/native/window_class.cpp b/src/win/native/window_class.cpp
index 6c7d0d3d..d69160ab 100644
--- a/src/win/native/window_class.cpp
+++ b/src/win/native/window_class.cpp
@@ -1,8 +1,8 @@
#include "cru/win/native/window_class.hpp"
-#include "cru/win/exception.hpp"
+#include "cru/win/native/exception.hpp"
-namespace cru::win::native {
+namespace cru::platform::native::win {
WindowClass::WindowClass(const std::wstring& name, WNDPROC window_proc,
HINSTANCE h_instance)
: name_(name) {
@@ -25,4 +25,4 @@ WindowClass::WindowClass(const std::wstring& name, WNDPROC window_proc,
if (atom_ == 0)
throw Win32Error(::GetLastError(), "Failed to create window class.");
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
diff --git a/src/win/native/window_painter.cpp b/src/win/native/window_d2d_painter.cpp
index 463be128..16d276ef 100644
--- a/src/win/native/window_painter.cpp
+++ b/src/win/native/window_d2d_painter.cpp
@@ -1,14 +1,16 @@
-#include "window_painter.hpp"
+#include "window_d2d_painter.hpp"
-#include "cru/win/exception.hpp"
-#include "cru/win/graph/win_native_factory.hpp"
+#include "cru/win/graph/direct/direct_factory.hpp"
+#include "cru/win/graph/direct/exception.hpp"
#include "cru/win/native/window_render_target.hpp"
#include <cassert>
-namespace cru::win::native {
-WindowPainter::WindowPainter(WinNativeWindow* window)
- : WinPainter(window->GetWindowRenderTarget()
+namespace cru::platform::native::win {
+using namespace cru::platform::graph::win::direct;
+
+WindowD2DPainter::WindowD2DPainter(WinNativeWindow* window)
+ : D2DPainter(window->GetWindowRenderTarget()
->GetWinNativeFactory()
->GetD2D1DeviceContext()),
window_(window) {
@@ -19,13 +21,13 @@ WindowPainter::WindowPainter(WinNativeWindow* window)
->BeginDraw();
}
-WindowPainter::~WindowPainter() { End(); }
+WindowD2DPainter::~WindowD2DPainter() { EndDraw(); }
-void WindowPainter::DoEndDraw() {
+void WindowD2DPainter::DoEndDraw() {
ThrowIfFailed(window_->GetWindowRenderTarget()
->GetWinNativeFactory()
->GetD2D1DeviceContext()
->EndDraw());
window_->GetWindowRenderTarget()->Present();
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
diff --git a/src/win/native/window_d2d_painter.hpp b/src/win/native/window_d2d_painter.hpp
new file mode 100644
index 00000000..1c90e8ab
--- /dev/null
+++ b/src/win/native/window_d2d_painter.hpp
@@ -0,0 +1,21 @@
+#pragma once
+#include "cru/win/graph/direct/painter.hpp"
+#include "cru/win/native/native_window.hpp"
+
+namespace cru::platform::native::win {
+class WindowD2DPainter : public graph::win::direct::D2DPainter {
+ public:
+ explicit WindowD2DPainter(WinNativeWindow* window);
+ WindowD2DPainter(const WindowD2DPainter& other) = delete;
+ WindowD2DPainter& operator=(const WindowD2DPainter& other) = delete;
+ WindowD2DPainter(WindowD2DPainter&& other) = delete;
+ WindowD2DPainter& operator=(WindowD2DPainter&& other) = delete;
+ ~WindowD2DPainter() override;
+
+ protected:
+ void DoEndDraw() override;
+
+ private:
+ WinNativeWindow* window_;
+};
+} // namespace cru::win::native
diff --git a/src/win/native/window_manager.cpp b/src/win/native/window_manager.cpp
index 5fea5a27..7f70d3cc 100644
--- a/src/win/native/window_manager.cpp
+++ b/src/win/native/window_manager.cpp
@@ -1,16 +1,16 @@
#include "window_manager.hpp"
-#include "cru/win/native/win_application.hpp"
-#include "cru/win/native/win_native_window.hpp"
+#include "cru/win/native/ui_application.hpp"
+#include "cru/win/native/native_window.hpp"
#include "cru/win/native/window_class.hpp"
#include <assert.h>
-namespace cru::win::native {
+namespace cru::platform::native::win {
LRESULT __stdcall GeneralWndProc(HWND hWnd, UINT Msg, WPARAM wParam,
LPARAM lParam) {
auto window =
- WinApplication::GetInstance()->GetWindowManager()->FromHandle(hWnd);
+ WinUiApplication::GetInstance()->GetWindowManager()->FromHandle(hWnd);
LRESULT result;
if (window != nullptr &&
@@ -20,15 +20,14 @@ LRESULT __stdcall GeneralWndProc(HWND hWnd, UINT Msg, WPARAM wParam,
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
-WindowManager::WindowManager(WinApplication* application) {
+WindowManager::WindowManager(WinUiApplication* application) {
application_ = application;
general_window_class_ = std::make_shared<WindowClass>(
L"CruUIWindowClass", GeneralWndProc, application->GetInstanceHandle());
}
WindowManager::~WindowManager() {
- for (const auto [key, window] : window_map_)
- delete window;
+ for (const auto [key, window] : window_map_) delete window;
}
void WindowManager::RegisterWindow(HWND hwnd, WinNativeWindow* window) {
@@ -56,4 +55,4 @@ std::vector<WinNativeWindow*> WindowManager::GetAllWindows() const {
for (auto [key, value] : window_map_) windows.push_back(value);
return windows;
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win
diff --git a/src/win/native/window_manager.hpp b/src/win/native/window_manager.hpp
index 8fab9cfc..a0661556 100644
--- a/src/win/native/window_manager.hpp
+++ b/src/win/native/window_manager.hpp
@@ -7,14 +7,14 @@
#include <memory>
#include <vector>
-namespace cru::win::native {
-class WinApplication;
+namespace cru::platform::native::win {
+class WinUiApplication;
class WinNativeWindow;
class WindowClass;
class WindowManager : public Object {
public:
- WindowManager(WinApplication* application);
+ WindowManager(WinUiApplication* application);
WindowManager(const WindowManager& other) = delete;
WindowManager(WindowManager&& other) = delete;
WindowManager& operator=(const WindowManager& other) = delete;
@@ -43,7 +43,7 @@ class WindowManager : public Object {
std::vector<WinNativeWindow*> GetAllWindows() const;
private:
- WinApplication* application_;
+ WinUiApplication* application_;
std::shared_ptr<WindowClass> general_window_class_;
std::map<HWND, WinNativeWindow*> window_map_;
diff --git a/src/win/native/window_painter.hpp b/src/win/native/window_painter.hpp
deleted file mode 100644
index 78731ef3..00000000
--- a/src/win/native/window_painter.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-#include "cru/win/graph/win_painter.hpp"
-#include "cru/win/native/win_native_window.hpp"
-
-namespace cru::win::native {
-class WindowPainter : public graph::WinPainter {
- public:
- explicit WindowPainter(WinNativeWindow* window);
- WindowPainter(const WindowPainter& other) = delete;
- WindowPainter& operator=(const WindowPainter& other) = delete;
- WindowPainter(WindowPainter&& other) = delete;
- WindowPainter& operator=(WindowPainter&& other) = delete;
- ~WindowPainter() override;
-
- protected:
- void DoEndDraw() override;
-
- private:
- WinNativeWindow* window_;
-};
-} // namespace cru::win::native
diff --git a/src/win/native/window_render_target.cpp b/src/win/native/window_render_target.cpp
index 606b51f8..426afdf6 100644
--- a/src/win/native/window_render_target.cpp
+++ b/src/win/native/window_render_target.cpp
@@ -1,14 +1,14 @@
#include "cru/win/native/window_render_target.hpp"
-#include "cru/win/exception.hpp"
-#include "cru/win/graph/win_native_factory.hpp"
+#include "cru/win/graph/direct/direct_factory.hpp"
+#include "cru/win/graph/direct/exception.hpp"
#include "dpi_util.hpp"
#include <cassert>
-namespace cru::win::native {
-WindowRenderTarget::WindowRenderTarget(graph::IWinNativeFactory* factory,
- HWND hwnd) {
+namespace cru::platform::native::win {
+using namespace cru::platform::graph::win::direct;
+WindowRenderTarget::WindowRenderTarget(IDirectFactory* factory, HWND hwnd) {
this->factory_ = factory;
const auto d3d11_device = factory->GetD3D11Device();
@@ -86,4 +86,4 @@ void WindowRenderTarget::CreateTargetBitmap() {
ThrowIfFailed(factory_->GetD2D1DeviceContext()->CreateBitmapFromDxgiSurface(
dxgi_back_buffer.Get(), &bitmap_properties, &target_bitmap_));
}
-} // namespace cru::win::native
+} // namespace cru::platform::native::win