From efdce672123284847bd7fb6f12ac1ec96f28f3ef Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 7 Nov 2018 21:40:04 +0800 Subject: Make all header *.hpp . --- src/ui/controls/button.cpp | 4 +- src/ui/controls/button.h | 42 ---------------- src/ui/controls/button.hpp | 42 ++++++++++++++++ src/ui/controls/linear_layout.cpp | 2 +- src/ui/controls/linear_layout.h | 47 ------------------ src/ui/controls/linear_layout.hpp | 47 ++++++++++++++++++ src/ui/controls/text_block.cpp | 4 +- src/ui/controls/text_block.h | 38 -------------- src/ui/controls/text_block.hpp | 38 ++++++++++++++ src/ui/controls/text_box.cpp | 6 +-- src/ui/controls/text_box.h | 57 --------------------- src/ui/controls/text_box.hpp | 57 +++++++++++++++++++++ src/ui/controls/text_control.cpp | 8 +-- src/ui/controls/text_control.h | 101 -------------------------------------- src/ui/controls/text_control.hpp | 101 ++++++++++++++++++++++++++++++++++++++ src/ui/controls/toggle_button.cpp | 6 +-- src/ui/controls/toggle_button.h | 65 ------------------------ src/ui/controls/toggle_button.hpp | 65 ++++++++++++++++++++++++ 18 files changed, 365 insertions(+), 365 deletions(-) delete mode 100644 src/ui/controls/button.h create mode 100644 src/ui/controls/button.hpp delete mode 100644 src/ui/controls/linear_layout.h create mode 100644 src/ui/controls/linear_layout.hpp delete mode 100644 src/ui/controls/text_block.h create mode 100644 src/ui/controls/text_block.hpp delete mode 100644 src/ui/controls/text_box.h create mode 100644 src/ui/controls/text_box.hpp delete mode 100644 src/ui/controls/text_control.h create mode 100644 src/ui/controls/text_control.hpp delete mode 100644 src/ui/controls/toggle_button.h create mode 100644 src/ui/controls/toggle_button.hpp (limited to 'src/ui/controls') diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 11f8e31b..0422506b 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -1,6 +1,6 @@ -#include "button.h" +#include "button.hpp" -#include "graph/graph.h" +#include "graph/graph.hpp" namespace cru::ui::controls { diff --git a/src/ui/controls/button.h b/src/ui/controls/button.h deleted file mode 100644 index f50a6cbd..00000000 --- a/src/ui/controls/button.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include - -#include "ui/control.h" - -namespace cru::ui::controls -{ - class Button : public Control - { - public: - static constexpr auto control_type = L"Button"; - - static Button* Create(const std::initializer_list& children = std::initializer_list()) - { - const auto button = new Button(); - for (const auto control : children) - button->AddChild(control); - return button; - } - - protected: - Button(); - - public: - Button(const Button& other) = delete; - Button(Button&& other) = delete; - Button& operator=(const Button& other) = delete; - Button& operator=(Button&& other) = delete; - ~Button() override = default; - - StringView GetControlType() const override final; - - protected: - void OnMouseClickBegin(MouseButton button) override final; - void OnMouseClickEnd(MouseButton button) override final; - - private: - BorderProperty normal_border_; - BorderProperty pressed_border_; - }; -} diff --git a/src/ui/controls/button.hpp b/src/ui/controls/button.hpp new file mode 100644 index 00000000..50640b11 --- /dev/null +++ b/src/ui/controls/button.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include + +#include "ui/control.hpp" + +namespace cru::ui::controls +{ + class Button : public Control + { + public: + static constexpr auto control_type = L"Button"; + + static Button* Create(const std::initializer_list& children = std::initializer_list()) + { + const auto button = new Button(); + for (const auto control : children) + button->AddChild(control); + return button; + } + + protected: + Button(); + + public: + Button(const Button& other) = delete; + Button(Button&& other) = delete; + Button& operator=(const Button& other) = delete; + Button& operator=(Button&& other) = delete; + ~Button() override = default; + + StringView GetControlType() const override final; + + protected: + void OnMouseClickBegin(MouseButton button) override final; + void OnMouseClickEnd(MouseButton button) override final; + + private: + BorderProperty normal_border_; + BorderProperty pressed_border_; + }; +} diff --git a/src/ui/controls/linear_layout.cpp b/src/ui/controls/linear_layout.cpp index ed445f4c..f21a9933 100644 --- a/src/ui/controls/linear_layout.cpp +++ b/src/ui/controls/linear_layout.cpp @@ -1,4 +1,4 @@ -#include "linear_layout.h" +#include "linear_layout.hpp" #include diff --git a/src/ui/controls/linear_layout.h b/src/ui/controls/linear_layout.h deleted file mode 100644 index 021f4b7d..00000000 --- a/src/ui/controls/linear_layout.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "ui/control.h" - -namespace cru::ui::controls -{ - // Min length of main side in layout params is of no meaning. - // All children will layout from start and redundant length is blank. - class LinearLayout : public Control - { - public: - static constexpr auto control_type = L"LinearLayout"; - - enum class Orientation - { - Horizontal, - Vertical - }; - - static LinearLayout* Create(const Orientation orientation = Orientation::Vertical, const std::initializer_list& children = std::initializer_list()) - { - const auto linear_layout = new LinearLayout(orientation); - for (const auto control : children) - linear_layout->AddChild(control); - return linear_layout; - } - - protected: - explicit LinearLayout(Orientation orientation = Orientation::Vertical); - - public: - LinearLayout(const LinearLayout& other) = delete; - LinearLayout(LinearLayout&& other) = delete; - LinearLayout& operator=(const LinearLayout& other) = delete; - LinearLayout& operator=(LinearLayout&& other) = delete; - ~LinearLayout() override = default; - - StringView GetControlType() const override final; - - protected: - Size OnMeasureContent(const Size& available_size) override; - void OnLayoutContent(const Rect& rect) override; - - private: - Orientation orientation_; - }; -} diff --git a/src/ui/controls/linear_layout.hpp b/src/ui/controls/linear_layout.hpp new file mode 100644 index 00000000..b7ca42ec --- /dev/null +++ b/src/ui/controls/linear_layout.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include "ui/control.hpp" + +namespace cru::ui::controls +{ + // Min length of main side in layout params is of no meaning. + // All children will layout from start and redundant length is blank. + class LinearLayout : public Control + { + public: + static constexpr auto control_type = L"LinearLayout"; + + enum class Orientation + { + Horizontal, + Vertical + }; + + static LinearLayout* Create(const Orientation orientation = Orientation::Vertical, const std::initializer_list& children = std::initializer_list()) + { + const auto linear_layout = new LinearLayout(orientation); + for (const auto control : children) + linear_layout->AddChild(control); + return linear_layout; + } + + protected: + explicit LinearLayout(Orientation orientation = Orientation::Vertical); + + public: + LinearLayout(const LinearLayout& other) = delete; + LinearLayout(LinearLayout&& other) = delete; + LinearLayout& operator=(const LinearLayout& other) = delete; + LinearLayout& operator=(LinearLayout&& other) = delete; + ~LinearLayout() override = default; + + StringView GetControlType() const override final; + + protected: + Size OnMeasureContent(const Size& available_size) override; + void OnLayoutContent(const Rect& rect) override; + + private: + Orientation orientation_; + }; +} diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp index e6c7fd7e..b8a7e8a6 100644 --- a/src/ui/controls/text_block.cpp +++ b/src/ui/controls/text_block.cpp @@ -1,6 +1,6 @@ -#include "text_block.h" +#include "text_block.hpp" -#include "ui/window.h" +#include "ui/window.hpp" namespace cru::ui::controls { diff --git a/src/ui/controls/text_block.h b/src/ui/controls/text_block.h deleted file mode 100644 index 681dc47b..00000000 --- a/src/ui/controls/text_block.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include "text_control.h" - -namespace cru::ui::controls -{ - class TextBlock : public TextControl - { - public: - static constexpr auto control_type = L"TextBlock"; - - static TextBlock* Create( - const String& text = L"", - const Microsoft::WRL::ComPtr& init_text_format = nullptr, - const Microsoft::WRL::ComPtr& init_brush = nullptr) - { - const auto text_block = new TextBlock(init_text_format, init_brush); - text_block->SetText(text); - return text_block; - } - - using TextControl::SetSelectable; // Make this public. - - protected: - TextBlock( - const Microsoft::WRL::ComPtr& init_text_format, - const Microsoft::WRL::ComPtr& init_brush - ); - public: - TextBlock(const TextBlock& other) = delete; - TextBlock(TextBlock&& other) = delete; - TextBlock& operator=(const TextBlock& other) = delete; - TextBlock& operator=(TextBlock&& other) = delete; - ~TextBlock() override = default; - - StringView GetControlType() const override final; - }; -} diff --git a/src/ui/controls/text_block.hpp b/src/ui/controls/text_block.hpp new file mode 100644 index 00000000..b2b4aaf9 --- /dev/null +++ b/src/ui/controls/text_block.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "text_control.hpp" + +namespace cru::ui::controls +{ + class TextBlock : public TextControl + { + public: + static constexpr auto control_type = L"TextBlock"; + + static TextBlock* Create( + const String& text = L"", + const Microsoft::WRL::ComPtr& init_text_format = nullptr, + const Microsoft::WRL::ComPtr& init_brush = nullptr) + { + const auto text_block = new TextBlock(init_text_format, init_brush); + text_block->SetText(text); + return text_block; + } + + using TextControl::SetSelectable; // Make this public. + + protected: + TextBlock( + const Microsoft::WRL::ComPtr& init_text_format, + const Microsoft::WRL::ComPtr& init_brush + ); + public: + TextBlock(const TextBlock& other) = delete; + TextBlock(TextBlock&& other) = delete; + TextBlock& operator=(const TextBlock& other) = delete; + TextBlock& operator=(TextBlock&& other) = delete; + ~TextBlock() override = default; + + StringView GetControlType() const override final; + }; +} diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp index a132ba67..605e1a24 100644 --- a/src/ui/controls/text_box.cpp +++ b/src/ui/controls/text_box.cpp @@ -1,10 +1,10 @@ -#include "text_box.h" +#include "text_box.hpp" #include #include -#include "graph/graph.h" -#include "exception.h" +#include "graph/graph.hpp" +#include "exception.hpp" namespace cru::ui::controls { diff --git a/src/ui/controls/text_box.h b/src/ui/controls/text_box.h deleted file mode 100644 index 85a5942d..00000000 --- a/src/ui/controls/text_box.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include "text_control.h" -#include "timer.h" - -namespace cru::ui::controls -{ - class TextBox : public TextControl - { - public: - static constexpr auto control_type = L"TextBox"; - - static TextBox* Create( - const Microsoft::WRL::ComPtr& init_text_format = nullptr, - const Microsoft::WRL::ComPtr& init_brush = nullptr) - { - return new TextBox(init_text_format, init_brush); - } - - protected: - explicit TextBox( - const Microsoft::WRL::ComPtr& init_text_format, - const Microsoft::WRL::ComPtr& init_brush - ); - public: - TextBox(const TextBox& other) = delete; - TextBox(TextBox&& other) = delete; - TextBox& operator=(const TextBox& other) = delete; - TextBox& operator=(TextBox&& other) = delete; - ~TextBox() override; - - StringView GetControlType() const override final; - - protected: - void OnDrawContent(ID2D1DeviceContext* device_context) override; - - void OnGetFocusCore(events::FocusChangeEventArgs& args) override final; - void OnLoseFocusCore(events::FocusChangeEventArgs& args) override final; - - void OnKeyDownCore(events::KeyEventArgs& args) override final; - void OnCharCore(events::CharEventArgs& args) override final; - - void RequestChangeCaretPosition(unsigned position) override final; - - private: - // return true if left - bool GetCaretSelectionSide() const; - void ShiftLeftSelectionRange(int count); - void ShiftRightSelectionRange(int count); - - private: - unsigned caret_position_ = 0; - std::optional caret_timer_{}; - Microsoft::WRL::ComPtr caret_brush_; - bool is_caret_show_ = false; - }; -} diff --git a/src/ui/controls/text_box.hpp b/src/ui/controls/text_box.hpp new file mode 100644 index 00000000..434aa232 --- /dev/null +++ b/src/ui/controls/text_box.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include "text_control.hpp" +#include "timer.hpp" + +namespace cru::ui::controls +{ + class TextBox : public TextControl + { + public: + static constexpr auto control_type = L"TextBox"; + + static TextBox* Create( + const Microsoft::WRL::ComPtr& init_text_format = nullptr, + const Microsoft::WRL::ComPtr& init_brush = nullptr) + { + return new TextBox(init_text_format, init_brush); + } + + protected: + explicit TextBox( + const Microsoft::WRL::ComPtr& init_text_format, + const Microsoft::WRL::ComPtr& init_brush + ); + public: + TextBox(const TextBox& other) = delete; + TextBox(TextBox&& other) = delete; + TextBox& operator=(const TextBox& other) = delete; + TextBox& operator=(TextBox&& other) = delete; + ~TextBox() override; + + StringView GetControlType() const override final; + + protected: + void OnDrawContent(ID2D1DeviceContext* device_context) override; + + void OnGetFocusCore(events::FocusChangeEventArgs& args) override final; + void OnLoseFocusCore(events::FocusChangeEventArgs& args) override final; + + void OnKeyDownCore(events::KeyEventArgs& args) override final; + void OnCharCore(events::CharEventArgs& args) override final; + + void RequestChangeCaretPosition(unsigned position) override final; + + private: + // return true if left + bool GetCaretSelectionSide() const; + void ShiftLeftSelectionRange(int count); + void ShiftRightSelectionRange(int count); + + private: + unsigned caret_position_ = 0; + std::optional caret_timer_{}; + Microsoft::WRL::ComPtr caret_brush_; + bool is_caret_show_ = false; + }; +} diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp index 6ccb8a02..5d2c840e 100644 --- a/src/ui/controls/text_control.cpp +++ b/src/ui/controls/text_control.cpp @@ -1,8 +1,8 @@ -#include "text_control.h" +#include "text_control.hpp" -#include "ui/window.h" -#include "graph/graph.h" -#include "exception.h" +#include "ui/window.hpp" +#include "graph/graph.hpp" +#include "exception.hpp" #include namespace cru::ui::controls diff --git a/src/ui/controls/text_control.h b/src/ui/controls/text_control.h deleted file mode 100644 index bfdfe20f..00000000 --- a/src/ui/controls/text_control.h +++ /dev/null @@ -1,101 +0,0 @@ -#pragma once - -#include "ui/control.h" - -namespace cru::ui::controls -{ - class TextControl : public Control - { - protected: - TextControl( - const Microsoft::WRL::ComPtr& init_text_format, - const Microsoft::WRL::ComPtr& init_brush - ); - public: - TextControl(const TextControl& other) = delete; - TextControl(TextControl&& other) = delete; - TextControl& operator=(const TextControl& other) = delete; - TextControl& operator=(TextControl&& other) = delete; - ~TextControl() override = default; - - String GetText() const - { - return text_; - } - - void SetText(const String& text); - - Microsoft::WRL::ComPtr GetBrush() const - { - return brush_; - } - - void SetBrush(const Microsoft::WRL::ComPtr& brush); - - Microsoft::WRL::ComPtr GetTextFormat() const - { - return text_format_; - } - - void SetTextFormat(const Microsoft::WRL::ComPtr& text_format); - - bool IsSelectable() const - { - return is_selectable_; - } - - std::optional GetSelectedRange() const - { - return selected_range_; - } - - void SetSelectedRange(std::optional text_range); - - void ClearSelection() - { - SetSelectedRange(std::nullopt); - } - - protected: - void SetSelectable(bool is_selectable); - - protected: - void OnSizeChangedCore(events::SizeChangedEventArgs& args) override final; - void OnDrawContent(ID2D1DeviceContext* device_context) override; - - void OnMouseDownCore(events::MouseButtonEventArgs& args) override final; - void OnMouseMoveCore(events::MouseEventArgs& args) override final; - void OnMouseUpCore(events::MouseButtonEventArgs& args) override final; - - void OnLoseFocusCore(events::FocusChangeEventArgs& args) override; - - Size OnMeasureContent(const Size& available_size) override; - - - virtual void RequestChangeCaretPosition(unsigned position); - - private: - void OnTextChangedCore(const String& old_text, const String& new_text); - - void RecreateTextLayout(); - - // param point is the mouse point relative to this control. - void UpdateCursor(const std::optional& point); - - private: - String text_; - - Microsoft::WRL::ComPtr brush_; - Microsoft::WRL::ComPtr selection_brush_; - Microsoft::WRL::ComPtr text_format_; - protected: - Microsoft::WRL::ComPtr text_layout_; - - private: - bool is_selectable_ = false; - - bool is_selecting_ = false; - unsigned mouse_down_position_ = 0; - std::optional selected_range_ = std::nullopt; - }; -} diff --git a/src/ui/controls/text_control.hpp b/src/ui/controls/text_control.hpp new file mode 100644 index 00000000..93120a44 --- /dev/null +++ b/src/ui/controls/text_control.hpp @@ -0,0 +1,101 @@ +#pragma once + +#include "ui/control.hpp" + +namespace cru::ui::controls +{ + class TextControl : public Control + { + protected: + TextControl( + const Microsoft::WRL::ComPtr& init_text_format, + const Microsoft::WRL::ComPtr& init_brush + ); + public: + TextControl(const TextControl& other) = delete; + TextControl(TextControl&& other) = delete; + TextControl& operator=(const TextControl& other) = delete; + TextControl& operator=(TextControl&& other) = delete; + ~TextControl() override = default; + + String GetText() const + { + return text_; + } + + void SetText(const String& text); + + Microsoft::WRL::ComPtr GetBrush() const + { + return brush_; + } + + void SetBrush(const Microsoft::WRL::ComPtr& brush); + + Microsoft::WRL::ComPtr GetTextFormat() const + { + return text_format_; + } + + void SetTextFormat(const Microsoft::WRL::ComPtr& text_format); + + bool IsSelectable() const + { + return is_selectable_; + } + + std::optional GetSelectedRange() const + { + return selected_range_; + } + + void SetSelectedRange(std::optional text_range); + + void ClearSelection() + { + SetSelectedRange(std::nullopt); + } + + protected: + void SetSelectable(bool is_selectable); + + protected: + void OnSizeChangedCore(events::SizeChangedEventArgs& args) override final; + void OnDrawContent(ID2D1DeviceContext* device_context) override; + + void OnMouseDownCore(events::MouseButtonEventArgs& args) override final; + void OnMouseMoveCore(events::MouseEventArgs& args) override final; + void OnMouseUpCore(events::MouseButtonEventArgs& args) override final; + + void OnLoseFocusCore(events::FocusChangeEventArgs& args) override; + + Size OnMeasureContent(const Size& available_size) override; + + + virtual void RequestChangeCaretPosition(unsigned position); + + private: + void OnTextChangedCore(const String& old_text, const String& new_text); + + void RecreateTextLayout(); + + // param point is the mouse point relative to this control. + void UpdateCursor(const std::optional& point); + + private: + String text_; + + Microsoft::WRL::ComPtr brush_; + Microsoft::WRL::ComPtr selection_brush_; + Microsoft::WRL::ComPtr text_format_; + protected: + Microsoft::WRL::ComPtr text_layout_; + + private: + bool is_selectable_ = false; + + bool is_selecting_ = false; + unsigned mouse_down_position_ = 0; + std::optional selected_range_ = std::nullopt; + }; +} diff --git a/src/ui/controls/toggle_button.cpp b/src/ui/controls/toggle_button.cpp index 9bcd7a26..f35b8bfe 100644 --- a/src/ui/controls/toggle_button.cpp +++ b/src/ui/controls/toggle_button.cpp @@ -1,7 +1,7 @@ -#include "toggle_button.h" +#include "toggle_button.hpp" -#include "graph/graph.h" -#include "ui/animations/animation.h" +#include "graph/graph.hpp" +#include "ui/animations/animation.hpp" namespace cru::ui::controls { diff --git a/src/ui/controls/toggle_button.h b/src/ui/controls/toggle_button.h deleted file mode 100644 index 6f3683de..00000000 --- a/src/ui/controls/toggle_button.h +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include "ui/control.h" - -namespace cru::ui::controls -{ - class ToggleButton : public Control - { - public: - static constexpr auto control_type = L"ToggleButton"; - - static ToggleButton* Create() - { - return new ToggleButton(); - } - - protected: - ToggleButton(); - - public: - ToggleButton(const ToggleButton& other) = delete; - ToggleButton(ToggleButton&& other) = delete; - ToggleButton& operator=(const ToggleButton& other) = delete; - ToggleButton& operator=(ToggleButton&& other) = delete; - ~ToggleButton() override = default; - - StringView GetControlType() const override final; - - bool IsPointInside(const Point& point) override; - - bool GetState() const - { - return state_; - } - - void SetState(bool state); - - void Toggle(); - - public: - events::ToggleEvent toggle_event; - - protected: - virtual void OnToggle(events::ToggleEventArgs& args); - - protected: - void OnDrawContent(ID2D1DeviceContext* device_context) override; - - void OnMouseClickCore(events::MouseButtonEventArgs& args) override; - - Size OnMeasureContent(const Size& available_size) override; - - private: - void RaiseToggleEvent(bool new_state); - - private: - bool state_ = false; - - float current_circle_position_; - - Microsoft::WRL::ComPtr frame_path_; - Microsoft::WRL::ComPtr on_brush_; - Microsoft::WRL::ComPtr off_brush_; - }; -} diff --git a/src/ui/controls/toggle_button.hpp b/src/ui/controls/toggle_button.hpp new file mode 100644 index 00000000..5de40ca5 --- /dev/null +++ b/src/ui/controls/toggle_button.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include "ui/control.hpp" + +namespace cru::ui::controls +{ + class ToggleButton : public Control + { + public: + static constexpr auto control_type = L"ToggleButton"; + + static ToggleButton* Create() + { + return new ToggleButton(); + } + + protected: + ToggleButton(); + + public: + ToggleButton(const ToggleButton& other) = delete; + ToggleButton(ToggleButton&& other) = delete; + ToggleButton& operator=(const ToggleButton& other) = delete; + ToggleButton& operator=(ToggleButton&& other) = delete; + ~ToggleButton() override = default; + + StringView GetControlType() const override final; + + bool IsPointInside(const Point& point) override; + + bool GetState() const + { + return state_; + } + + void SetState(bool state); + + void Toggle(); + + public: + events::ToggleEvent toggle_event; + + protected: + virtual void OnToggle(events::ToggleEventArgs& args); + + protected: + void OnDrawContent(ID2D1DeviceContext* device_context) override; + + void OnMouseClickCore(events::MouseButtonEventArgs& args) override; + + Size OnMeasureContent(const Size& available_size) override; + + private: + void RaiseToggleEvent(bool new_state); + + private: + bool state_ = false; + + float current_circle_position_; + + Microsoft::WRL::ComPtr frame_path_; + Microsoft::WRL::ComPtr on_brush_; + Microsoft::WRL::ComPtr off_brush_; + }; +} -- cgit v1.2.3