aboutsummaryrefslogtreecommitdiff
path: root/src/ui/predefine.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-09 22:59:38 +0800
committercrupest <crupest@outlook.com>2018-11-09 22:59:38 +0800
commitac4b0f8d438e7a7c2ecd836af8332b5da1e035c9 (patch)
treee5b886f1884fa56dd90059523b1f4dc730bb5003 /src/ui/predefine.cpp
parent4b219b569c16db6027dd36e4656152f261321c60 (diff)
downloadcru-ac4b0f8d438e7a7c2ecd836af8332b5da1e035c9.tar.gz
cru-ac4b0f8d438e7a7c2ecd836af8332b5da1e035c9.tar.bz2
cru-ac4b0f8d438e7a7c2ecd836af8332b5da1e035c9.zip
Add predefine resource.
Diffstat (limited to 'src/ui/predefine.cpp')
-rw-r--r--src/ui/predefine.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/ui/predefine.cpp b/src/ui/predefine.cpp
new file mode 100644
index 00000000..259b3a2a
--- /dev/null
+++ b/src/ui/predefine.cpp
@@ -0,0 +1,73 @@
+#include "predefine.hpp"
+
+#include "border_property.hpp"
+#include "graph/graph.hpp"
+#include "exception.hpp"
+
+namespace cru::ui::predefine
+{
+ Microsoft::WRL::ComPtr<ID2D1Brush> CreateSolidBrush(const D2D1_COLOR_F& color)
+ {
+ const auto device_context = graph::GraphManager::GetInstance()->GetD2D1DeviceContext();
+ Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solid_color_brush;
+ device_context->CreateSolidColorBrush(color, &solid_color_brush);
+ return solid_color_brush;
+ }
+
+ void InitThemes(AnyMap* resource_map)
+ {
+ resource_map->SetValue(key_border_property_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)));
+
+ BorderProperty button_normal_border{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::RoyalBlue))};
+ button_normal_border.SetStrokeWidth(2);
+ button_normal_border.SetRadiusX(6);
+ button_normal_border.SetRadiusY(6);
+ resource_map->SetValue(key_button_normal_border, std::move(button_normal_border));
+
+ BorderProperty button_press_border{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Blue))};
+ button_press_border.SetStrokeWidth(2);
+ button_press_border.SetRadiusX(6);
+ button_press_border.SetRadiusY(6);
+ resource_map->SetValue(key_button_press_border, std::move(button_press_border));
+
+
+ const auto dwrite_factory = graph::GraphManager::GetInstance()->GetDWriteFactory();
+ Microsoft::WRL::ComPtr<IDWriteTextFormat> text_format;
+
+ ThrowIfFailed(dwrite_factory->CreateTextFormat(
+ L"等线", nullptr,
+ DWRITE_FONT_WEIGHT_NORMAL,
+ DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL,
+ 24.0, L"zh-cn",
+ &text_format
+ ));
+
+ ThrowIfFailed(text_format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER));
+ ThrowIfFailed(text_format->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER));
+
+ resource_map->SetValue(key_text_block_text_format, text_format);
+ resource_map->SetValue(key_text_box_text_format, text_format);
+
+ auto text_brush = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black));
+ resource_map->SetValue(key_text_block_text_brush, text_brush);
+ resource_map->SetValue(key_text_box_text_brush, text_brush);
+
+ auto text_selection_brush = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightSkyBlue));
+ resource_map->SetValue(key_text_control_selection_brush, text_selection_brush);
+
+ BorderProperty text_box_border;
+ resource_map->SetValue(key_text_box_border, text_box_border);
+
+ resource_map->SetValue(key_text_box_caret_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)));
+
+ resource_map->SetValue(key_toggle_button_on_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::DeepSkyBlue)));
+ resource_map->SetValue(key_toggle_button_off_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightGray)));
+
+#ifdef CRU_DEBUG_LAYOUT
+ resource_map->SetValue(key_debug_layout_out_border_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Crimson)));
+ resource_map->SetValue(key_debug_layout_margin_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightCoral, 0.25f)));
+ resource_map->SetValue(key_debug_layout_padding_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::SkyBlue, 0.25f)));
+#endif
+ }
+}