aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-29 17:35:09 +0800
committercrupest <crupest@outlook.com>2018-09-29 17:35:09 +0800
commit20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3 (patch)
tree40285fea213ab85fba79a9a13132c8497e36338e
parent398b8f3ba535bb43c4b8593e3027c14894a7a211 (diff)
downloadcru-20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3.tar.gz
cru-20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3.tar.bz2
cru-20dc75e2ce6a9c38dd1888fdbf793fd8a3bc9cd3.zip
Add PropertyChangedNotifyObject and BorderProperty.
-rw-r--r--CruUI.vcxproj2
-rw-r--r--CruUI.vcxproj.filters6
-rw-r--r--src/base.cpp21
-rw-r--r--src/base.h29
-rw-r--r--src/ui/controls/border_control.cpp34
-rw-r--r--src/ui/controls/border_control.h61
6 files changed, 153 insertions, 0 deletions
diff --git a/CruUI.vcxproj b/CruUI.vcxproj
index 5149d358..a6503833 100644
--- a/CruUI.vcxproj
+++ b/CruUI.vcxproj
@@ -122,12 +122,14 @@
<ClCompile Include="src\ui\animations\animation.cpp" />
<ClCompile Include="src\ui\control.cpp" />
<ClCompile Include="src\ui\controls\border.cpp" />
+ <ClCompile Include="src\ui\controls\border_control.cpp" />
<ClCompile Include="src\ui\controls\button.cpp" />
<ClCompile Include="src\ui\controls\linear_layout.cpp" />
<ClCompile Include="src\ui\controls\margin_container.cpp" />
<ClCompile Include="src\ui\controls\text_block.cpp" />
<ClCompile Include="src\ui\controls\text_box.cpp" />
<ClInclude Include="src\ui\controls\border.h" />
+ <ClInclude Include="src\ui\controls\border_control.h" />
<ClInclude Include="src\ui\controls\text_control.h" />
<ClCompile Include="src\ui\controls\toggle_button.cpp" />
<ClCompile Include="src\ui\events\ui_event.cpp" />
diff --git a/CruUI.vcxproj.filters b/CruUI.vcxproj.filters
index 58d9f369..c72ae54c 100644
--- a/CruUI.vcxproj.filters
+++ b/CruUI.vcxproj.filters
@@ -72,6 +72,9 @@
<ClCompile Include="src\ui\controls\border.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\ui\controls\border_control.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\application.h">
@@ -143,6 +146,9 @@
<ClInclude Include="src\ui\controls\border.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="src\ui\controls\border_control.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\application.cpp">
diff --git a/src/base.cpp b/src/base.cpp
index f5868170..57a4848e 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -17,4 +17,25 @@ namespace cru
throw Win32Error(::GetLastError(), "Failed to convert wide string to UTF-8.");
return result;
}
+
+ void PropertyChangedNotifyObject::AddPropertyChangedListener(FunctionPtr<void(String)> listener)
+ {
+ listeners_.push_back(std::move(listener));
+ }
+
+ void PropertyChangedNotifyObject::RemovePropertyChangedListener(const FunctionPtr<void(String)>& listener)
+ {
+ for (auto i = listeners_.cbegin(); i != listeners_.cend(); ++i)
+ if (*i == listener)
+ {
+ listeners_.erase(i);
+ break;
+ }
+ }
+
+ void PropertyChangedNotifyObject::RaisePropertyChangedEvent(String property_name)
+ {
+ for (const auto& listener : listeners_)
+ (*listener)(property_name);
+ }
}
diff --git a/src/base.h b/src/base.h
index 7ef78014..ce7a781d 100644
--- a/src/base.h
+++ b/src/base.h
@@ -20,6 +20,7 @@
#include <memory>
#include <string_view>
#include <chrono>
+#include <list>
namespace cru
{
@@ -60,6 +61,12 @@ namespace cru
return std::make_shared<typename Type::element_type>(std::forward<Args>(args)...);
}
+ template<typename Type>
+ Type CreateFunctionPtr(Function<Type>&& function)
+ {
+ return std::make_shared<FunctionPtr<Type>>(std::move(function));
+ }
+
inline ActionPtr CreateActionPtr(Action&& action)
{
return std::make_shared<Action>(std::move(action));
@@ -104,4 +111,26 @@ namespace cru
using CancelablePtr = std::shared_ptr<ICancelable>;
MultiByteString ToUtf8String(const StringView& string);
+
+
+ class PropertyChangedNotifyObject : public Object
+ {
+ public:
+ PropertyChangedNotifyObject() = default;
+ PropertyChangedNotifyObject(const PropertyChangedNotifyObject& other) = delete;
+ PropertyChangedNotifyObject(PropertyChangedNotifyObject&& other) = delete;
+ PropertyChangedNotifyObject& operator = (const PropertyChangedNotifyObject& other) = delete;
+ PropertyChangedNotifyObject& operator = (PropertyChangedNotifyObject&& other) = delete;
+ ~PropertyChangedNotifyObject() override = default;
+
+ void AddPropertyChangedListener(FunctionPtr<void(String)> listener);
+
+ void RemovePropertyChangedListener(const FunctionPtr<void(String)>& listener);
+
+ protected:
+ void RaisePropertyChangedEvent(String property_name);
+
+ private:
+ std::list<FunctionPtr<void(String)>> listeners_;
+ };
}
diff --git a/src/ui/controls/border_control.cpp b/src/ui/controls/border_control.cpp
new file mode 100644
index 00000000..9f33079c
--- /dev/null
+++ b/src/ui/controls/border_control.cpp
@@ -0,0 +1,34 @@
+#include "border_control.h"
+
+namespace cru::ui::controls
+{
+ void BorderProperty::SetBrush(Microsoft::WRL::ComPtr<ID2D1Brush> brush)
+ {
+ brush_ = std::move(brush);
+ RaisePropertyChangedEvent(L"Brush");
+ }
+
+ void BorderProperty::SetWidth(const float width)
+ {
+ width_ = width;
+ RaisePropertyChangedEvent(L"Width");
+ }
+
+ void BorderProperty::SetStrokeStyle(Microsoft::WRL::ComPtr<ID2D1StrokeStyle> stroke_style)
+ {
+ stroke_style_ = std::move(stroke_style);
+ RaisePropertyChangedEvent(L"StrokeStyle");
+ }
+
+ void BorderProperty::SetRadiusX(const float radius_x)
+ {
+ radius_x_ = radius_x;
+ RaisePropertyChangedEvent(L"RadiusX");
+ }
+
+ void BorderProperty::SetRadiusY(const float radius_y)
+ {
+ radius_y_ = radius_y;
+ RaisePropertyChangedEvent(L"RadiusY");
+ }
+}
diff --git a/src/ui/controls/border_control.h b/src/ui/controls/border_control.h
new file mode 100644
index 00000000..582d2436
--- /dev/null
+++ b/src/ui/controls/border_control.h
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "ui/control.h"
+
+namespace cru::ui::controls
+{
+ class BorderProperty : public PropertyChangedNotifyObject
+ {
+ public:
+ BorderProperty() = default;
+ BorderProperty(const BorderProperty& other) = delete;
+ BorderProperty(BorderProperty&& other) = delete;
+ BorderProperty& operator=(const BorderProperty& other) = delete;
+ BorderProperty& operator=(BorderProperty&& other) = delete;
+ ~BorderProperty() override = default;
+
+
+ Microsoft::WRL::ComPtr<ID2D1Brush> GetBrush() const
+ {
+ return brush_;
+ }
+
+ float GetWidth() const
+ {
+ return width_;
+ }
+
+ Microsoft::WRL::ComPtr<ID2D1StrokeStyle> GetStrokeStyle() const
+ {
+ return stroke_style_;
+ }
+
+ float GetRadiusX() const
+ {
+ return radius_x_;
+ }
+
+ float GetRadiusY() const
+ {
+ return radius_y_;
+ }
+
+ void SetBrush(Microsoft::WRL::ComPtr<ID2D1Brush> brush);
+ void SetWidth(float width);
+ void SetStrokeStyle(Microsoft::WRL::ComPtr<ID2D1StrokeStyle> stroke_style);
+ void SetRadiusX(float radius_x);
+ void SetRadiusY(float radius_y);
+
+ private:
+ Microsoft::WRL::ComPtr<ID2D1Brush> brush_ = nullptr;
+ float width_ = 1.0f;
+ Microsoft::WRL::ComPtr<ID2D1StrokeStyle> stroke_style_ = nullptr;
+ float radius_x_ = 0.0f;
+ float radius_y_ = 0.0f;
+ };
+
+ class BorderControl : public Control
+ {
+
+ };
+}