aboutsummaryrefslogtreecommitdiff
path: root/src/ui/Control.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-08 17:45:41 +0800
committercrupest <crupest@outlook.com>2020-11-08 17:45:41 +0800
commit2188845a7acffa653015a1000139ec0a9a3984bc (patch)
tree7e8ed6eca5868a0943af6fcad6467115f369987c /src/ui/Control.cpp
parent93265251d56c91b05f160423077ce95339786f87 (diff)
downloadcru-2188845a7acffa653015a1000139ec0a9a3984bc.tar.gz
cru-2188845a7acffa653015a1000139ec0a9a3984bc.tar.bz2
cru-2188845a7acffa653015a1000139ec0a9a3984bc.zip
...
Diffstat (limited to 'src/ui/Control.cpp')
-rw-r--r--src/ui/Control.cpp157
1 files changed, 0 insertions, 157 deletions
diff --git a/src/ui/Control.cpp b/src/ui/Control.cpp
deleted file mode 100644
index 23a3cef2..00000000
--- a/src/ui/Control.cpp
+++ /dev/null
@@ -1,157 +0,0 @@
-#include "cru/ui/Control.hpp"
-
-#include "cru/common/Base.hpp"
-#include "cru/platform/gui/Cursor.hpp"
-#include "cru/platform/gui/UiApplication.hpp"
-#include "cru/ui/Base.hpp"
-#include "cru/ui/host/WindowHost.hpp"
-#include "cru/ui/render/RenderObject.hpp"
-
-#include <memory>
-
-namespace cru::ui {
-using platform::gui::ICursor;
-using platform::gui::IUiApplication;
-using platform::gui::SystemCursorType;
-
-Control::Control() {
- MouseEnterEvent()->Direct()->AddHandler([this](event::MouseEventArgs&) {
- this->is_mouse_over_ = true;
- this->OnMouseHoverChange(true);
- });
-
- MouseLeaveEvent()->Direct()->AddHandler([this](event::MouseEventArgs&) {
- this->is_mouse_over_ = false;
- this->OnMouseHoverChange(true);
- });
-}
-
-Control::~Control() {
- for (const auto child : children_) delete child;
-}
-
-host::WindowHost* Control::GetWindowHost() const { return window_host_; }
-
-void Control::TraverseDescendants(
- const std::function<void(Control*)>& predicate) {
- predicate(this);
- for (auto c : GetChildren()) c->TraverseDescendants(predicate);
-}
-
-bool Control::HasFocus() {
- auto host = GetWindowHost();
- if (host == nullptr) return false;
-
- return host->GetFocusControl() == this;
-}
-
-bool Control::CaptureMouse() {
- auto host = GetWindowHost();
- if (host == nullptr) return false;
-
- return host->CaptureMouseFor(this);
-}
-
-void Control::SetFocus() {
- auto host = GetWindowHost();
- if (host == nullptr) return;
-
- host->SetFocusControl(this);
-}
-
-bool Control::ReleaseMouse() {
- auto host = GetWindowHost();
- if (host == nullptr) return false;
-
- return host->CaptureMouseFor(nullptr);
-}
-
-bool Control::IsMouseCaptured() {
- auto host = GetWindowHost();
- if (host == nullptr) return false;
-
- return host->GetMouseCaptureControl() == this;
-}
-
-std::shared_ptr<ICursor> Control::GetCursor() { return cursor_; }
-
-std::shared_ptr<ICursor> Control::GetInheritedCursor() {
- Control* control = this;
- while (control != nullptr) {
- const auto cursor = control->GetCursor();
- if (cursor != nullptr) return cursor;
- control = control->GetParent();
- }
- return IUiApplication::GetInstance()->GetCursorManager()->GetSystemCursor(
- SystemCursorType::Arrow);
-}
-
-void Control::SetCursor(std::shared_ptr<ICursor> cursor) {
- cursor_ = std::move(cursor);
- const auto host = GetWindowHost();
- if (host != nullptr) {
- host->UpdateCursor();
- }
-}
-
-void Control::AddChild(Control* control, const Index position) {
- Expects(control->GetParent() ==
- nullptr); // The control already has a parent.
- Expects(position >= 0);
- Expects(position <= static_cast<Index>(
- children_.size())); // The position is out of range.
-
- children_.insert(children_.cbegin() + position, control);
-
- const auto old_parent = control->parent_;
- control->parent_ = this;
-
- OnAddChild(control, position);
- control->OnParentChanged(old_parent, this);
-
- if (window_host_)
- control->TraverseDescendants([this](Control* control) {
- control->window_host_ = window_host_;
- control->OnAttachToHost(window_host_);
- });
-}
-
-void Control::RemoveChild(const Index position) {
- Expects(position >= 0);
- Expects(position < static_cast<Index>(
- children_.size())); // The position is out of range.
-
- const auto i = children_.cbegin() + position;
- const auto control = *i;
-
- children_.erase(i);
- control->parent_ = nullptr;
-
- OnRemoveChild(control, position);
- control->OnParentChanged(this, nullptr);
-
- if (window_host_)
- control->TraverseDescendants([this](Control* control) {
- control->window_host_ = nullptr;
- control->OnDetachFromHost(window_host_);
- });
-}
-
-void Control::OnAddChild(Control* child, Index position) {
- CRU_UNUSED(child)
- CRU_UNUSED(position)
-}
-void Control::OnRemoveChild(Control* child, Index position) {
- CRU_UNUSED(child)
- CRU_UNUSED(position)
-}
-
-void Control::OnParentChanged(Control* old_parent, Control* new_parent) {
- CRU_UNUSED(old_parent)
- CRU_UNUSED(new_parent)
-}
-
-void Control::OnAttachToHost(host::WindowHost* host) { CRU_UNUSED(host) }
-
-void Control::OnDetachFromHost(host::WindowHost* host) { CRU_UNUSED(host) }
-} // namespace cru::ui