aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/controls')
-rw-r--r--src/ui/controls/button.cpp15
-rw-r--r--src/ui/controls/text_block.cpp7
-rw-r--r--src/ui/controls/text_block.hpp16
-rw-r--r--src/ui/controls/text_box.cpp12
-rw-r--r--src/ui/controls/text_box.hpp11
-rw-r--r--src/ui/controls/text_control.cpp12
-rw-r--r--src/ui/controls/toggle_button.cpp6
7 files changed, 32 insertions, 47 deletions
diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp
index 0422506b..a90c218d 100644
--- a/src/ui/controls/button.cpp
+++ b/src/ui/controls/button.cpp
@@ -1,23 +1,14 @@
#include "button.hpp"
#include "graph/graph.hpp"
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- using graph::CreateSolidBrush;
-
Button::Button() : Control(true),
- normal_border_{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::RoyalBlue))},
- pressed_border_{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Blue))}
+ normal_border_{predefine::GetPredefineResource<BorderProperty>(predefine::key_button_normal_border)},
+ pressed_border_{predefine::GetPredefineResource<BorderProperty>(predefine::key_button_press_border)}
{
- normal_border_.SetStrokeWidth(2);
- normal_border_.SetRadiusX(6);
- normal_border_.SetRadiusY(6);
-
- pressed_border_.SetStrokeWidth(2);
- pressed_border_.SetRadiusX(6);
- pressed_border_.SetRadiusY(6);
-
SetBordered(true);
GetBorderProperty() = normal_border_;
diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp
index b8a7e8a6..290ddd58 100644
--- a/src/ui/controls/text_block.cpp
+++ b/src/ui/controls/text_block.cpp
@@ -1,11 +1,14 @@
#include "text_block.hpp"
#include "ui/window.hpp"
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- TextBlock::TextBlock(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : TextControl(init_text_format, init_brush)
+ TextBlock::TextBlock() : TextControl(
+ predefine::GetPredefineResourceComPtr<IDWriteTextFormat>(predefine::key_text_block_text_format),
+ predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_text_block_text_brush)
+ )
{
}
diff --git a/src/ui/controls/text_block.hpp b/src/ui/controls/text_block.hpp
index b2b4aaf9..4d017da5 100644
--- a/src/ui/controls/text_block.hpp
+++ b/src/ui/controls/text_block.hpp
@@ -9,23 +9,15 @@ namespace cru::ui::controls
public:
static constexpr auto control_type = L"TextBlock";
- static TextBlock* Create(
- const String& text = L"",
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format = nullptr,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush = nullptr)
+ static TextBlock* Create(const String& text = L"")
{
- const auto text_block = new TextBlock(init_text_format, init_brush);
+ const auto text_block = new TextBlock();
text_block->SetText(text);
return text_block;
}
- using TextControl::SetSelectable; // Make this public.
-
protected:
- TextBlock(
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush
- );
+ TextBlock();
public:
TextBlock(const TextBlock& other) = delete;
TextBlock(TextBlock&& other) = delete;
@@ -34,5 +26,7 @@ namespace cru::ui::controls
~TextBlock() override = default;
StringView GetControlType() const override final;
+
+ using TextControl::SetSelectable; // Make this public.
};
}
diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp
index cb5d79a2..0ed1248c 100644
--- a/src/ui/controls/text_box.cpp
+++ b/src/ui/controls/text_box.cpp
@@ -6,23 +6,25 @@
#include "graph/graph.hpp"
#include "exception.hpp"
#include "application.hpp"
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- using graph::CreateSolidBrush;
-
inline Microsoft::WRL::ComPtr<IDWriteFactory> GetDWriteFactory()
{
return graph::GraphManager::GetInstance()->GetDWriteFactory();
}
- TextBox::TextBox(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : TextControl(init_text_format, init_brush)
+ TextBox::TextBox() : TextControl(
+ predefine::GetPredefineResourceComPtr<IDWriteTextFormat>(predefine::key_text_box_text_format),
+ predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_text_box_text_brush)
+ )
{
SetSelectable(true);
- caret_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black));
+ caret_brush_ = predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_text_box_caret_brush);
+ GetBorderProperty() = predefine::GetPredefineResource<BorderProperty>(predefine::key_text_box_border);
SetBordered(true);
}
diff --git a/src/ui/controls/text_box.hpp b/src/ui/controls/text_box.hpp
index 434aa232..65f81fc3 100644
--- a/src/ui/controls/text_box.hpp
+++ b/src/ui/controls/text_box.hpp
@@ -10,18 +10,13 @@ namespace cru::ui::controls
public:
static constexpr auto control_type = L"TextBox";
- static TextBox* Create(
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format = nullptr,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush = nullptr)
+ static TextBox* Create()
{
- return new TextBox(init_text_format, init_brush);
+ return new TextBox();
}
protected:
- explicit TextBox(
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush
- );
+ TextBox();
public:
TextBox(const TextBox& other) = delete;
TextBox(TextBox&& other) = delete;
diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp
index 5d2c840e..42214583 100644
--- a/src/ui/controls/text_control.cpp
+++ b/src/ui/controls/text_control.cpp
@@ -1,14 +1,14 @@
#include "text_control.hpp"
+#include <cassert>
+
#include "ui/window.hpp"
#include "graph/graph.hpp"
#include "exception.hpp"
-#include <cassert>
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- using graph::CreateSolidBrush;
-
inline Microsoft::WRL::ComPtr<IDWriteFactory> GetDWriteFactory()
{
return graph::GraphManager::GetInstance()->GetDWriteFactory();
@@ -17,13 +17,13 @@ namespace cru::ui::controls
TextControl::TextControl(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : Control(false)
{
- text_format_ = init_text_format == nullptr ? graph::CreateDefaultTextFormat() : init_text_format;
+ text_format_ = init_text_format;
RecreateTextLayout();
- brush_ = init_brush == nullptr ? CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)) : init_brush;
+ brush_ = init_brush;
- selection_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightSkyBlue));
+ selection_brush_ = predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_text_control_selection_brush);
}
diff --git a/src/ui/controls/toggle_button.cpp b/src/ui/controls/toggle_button.cpp
index f35b8bfe..a901f650 100644
--- a/src/ui/controls/toggle_button.cpp
+++ b/src/ui/controls/toggle_button.cpp
@@ -2,10 +2,10 @@
#include "graph/graph.hpp"
#include "ui/animations/animation.hpp"
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- using graph::CreateSolidBrush;
using animations::AnimationBuilder;
// ui length parameters of toggle button.
@@ -19,8 +19,8 @@ namespace cru::ui::controls
{
graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRoundedRectangleGeometry(D2D1::RoundedRect(D2D1::RectF(-half_width, -half_height, half_width, half_height), half_height, half_height), &frame_path_);
- on_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::DeepSkyBlue));
- off_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightGray));
+ on_brush_ = predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_toggle_button_on_brush);
+ off_brush_ = predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_toggle_button_off_brush);
}
inline D2D1_POINT_2F ConvertPoint(const Point& point)