aboutsummaryrefslogtreecommitdiff
path: root/src/ui
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/ui
parent8c5b05bcfce96495b4ffc4209ab8feda12597729 (diff)
downloadcru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.gz
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.bz2
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.zip
...
Diffstat (limited to 'src/ui')
-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
7 files changed, 32 insertions, 30 deletions
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) {