diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/application.cpp | 15 | ||||
-rw-r--r-- | src/system_headers.hpp | 2 | ||||
-rw-r--r-- | src/ui/control.cpp | 25 | ||||
-rw-r--r-- | src/ui/control.hpp | 18 | ||||
-rw-r--r-- | src/ui/controls/text_control.cpp | 2 | ||||
-rw-r--r-- | src/ui/cursor.cpp | 7 | ||||
-rw-r--r-- | src/ui/cursor.hpp | 4 |
7 files changed, 53 insertions, 20 deletions
diff --git a/src/application.cpp b/src/application.cpp index fa71c37e..c3669f72 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -86,16 +86,6 @@ namespace cru { return instance_; } - namespace - { - void LoadSystemCursor(HINSTANCE h_instance) - { - ui::cursors::arrow = std::make_shared<ui::Cursor>(::LoadCursorW(nullptr, IDC_ARROW), false); - ui::cursors::hand = std::make_shared<ui::Cursor>(::LoadCursorW(nullptr, IDC_HAND), false); - ui::cursors::i_beam = std::make_shared<ui::Cursor>(::LoadCursorW(nullptr, IDC_IBEAM), false); - } - } - Application::Application(HINSTANCE h_instance) : h_instance_(h_instance) { @@ -104,9 +94,12 @@ namespace cru { instance_ = this; + if (!::IsWindows8OrGreater()) + throw std::runtime_error("Must run on Windows 8 or later."); + god_window_ = std::make_unique<GodWindow>(this); - LoadSystemCursor(h_instance); + ui::cursors::LoadSystemCursors(); } Application::~Application() diff --git a/src/system_headers.hpp b/src/system_headers.hpp index 99c091e1..d471678a 100644 --- a/src/system_headers.hpp +++ b/src/system_headers.hpp @@ -19,3 +19,5 @@ #include <dxgi1_2.h> #include <wrl/client.h> + +#include <VersionHelpers.h> diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 8b91b25a..9afa5497 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -211,6 +211,15 @@ namespace cru::ui return false; } + void Control::SetClipToPadding(const bool clip) + { + if (clip_to_padding_ == clip) + return; + + clip_to_padding_ = clip; + InvalidateDraw(); + } + void Control::Draw(ID2D1DeviceContext* device_context) { D2D1::Matrix3x2F old_transform; @@ -219,11 +228,20 @@ namespace cru::ui const auto position = GetPositionRelative(); device_context->SetTransform(old_transform * D2D1::Matrix3x2F::Translation(position.x, position.y)); + OnDrawDecoration(device_context); + + const auto set_layer = in_border_geometry_ != nullptr && IsClipToPadding(); + if (set_layer) + device_context->PushLayer(D2D1::LayerParameters(D2D1::InfiniteRect(), in_border_geometry_.Get()), nullptr); + OnDrawCore(device_context); for (auto child : GetChildren()) child->Draw(device_context); + if (set_layer) + device_context->PopLayer(); + device_context->SetTransform(old_transform); } @@ -394,9 +412,9 @@ namespace cru::ui window_ = nullptr; } - void Control::OnDrawCore(ID2D1DeviceContext* device_context) + void Control::OnDrawDecoration(ID2D1DeviceContext* device_context) { - #ifdef CRU_DEBUG_LAYOUT +#ifdef CRU_DEBUG_LAYOUT if (GetWindow()->IsDebugLayout()) { if (padding_geometry_ != nullptr) @@ -414,7 +432,10 @@ namespace cru::ui GetBorderProperty().GetStrokeWidth(), GetBorderProperty().GetStrokeStyle().Get() ); + } + void Control::OnDrawCore(ID2D1DeviceContext* device_context) + { //draw background. if (in_border_geometry_ != nullptr && background_brush_ != nullptr) device_context->FillGeometry(in_border_geometry_.Get(), background_brush_.Get()); diff --git a/src/ui/control.hpp b/src/ui/control.hpp index 2ca5fa9e..4374983b 100644 --- a/src/ui/control.hpp +++ b/src/ui/control.hpp @@ -124,6 +124,13 @@ namespace cru::ui //*************** region: graphic *************** + bool IsClipToPadding() const + { + return clip_to_padding_; + } + + void SetClipToPadding(bool clip); + //Draw this control and its child controls. void Draw(ID2D1DeviceContext* device_context); @@ -264,12 +271,11 @@ namespace cru::ui //Invoked when the control is detached to a window. Overrides should invoke base. virtual void OnDetachToWindow(Window* window); + //*************** region: graphic events *************** private: + void OnDrawDecoration(ID2D1DeviceContext* device_context); void OnDrawCore(ID2D1DeviceContext* device_context); - protected: - - //*************** region: graphic events *************** virtual void OnDrawContent(ID2D1DeviceContext* device_context); virtual void OnDrawForeground(ID2D1DeviceContext* device_context); virtual void OnDrawBackground(ID2D1DeviceContext* device_context); @@ -364,10 +370,8 @@ namespace cru::ui private: bool is_container_; - protected: - Window * window_ = nullptr; // protected for Window class to write it as itself in constructor. + Window * window_ = nullptr; - private: Control * parent_ = nullptr; std::vector<Control*> children_{}; @@ -397,6 +401,8 @@ namespace cru::ui bool is_bordered_ = false; BorderProperty border_property_; + bool clip_to_padding_ = false; + Microsoft::WRL::ComPtr<ID2D1Geometry> border_geometry_ = nullptr; Microsoft::WRL::ComPtr<ID2D1Geometry> in_border_geometry_ = nullptr; //used for foreground and background brush. diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp index f7f88d4e..c37441b3 100644 --- a/src/ui/controls/text_control.cpp +++ b/src/ui/controls/text_control.cpp @@ -19,6 +19,8 @@ namespace cru::ui::controls brush_ = init_brush; selection_brush_ = UiManager::GetInstance()->GetPredefineResources()->text_control_selection_brush; + + SetClipToPadding(true); } diff --git a/src/ui/cursor.cpp b/src/ui/cursor.cpp index cf88cd25..91b94b16 100644 --- a/src/ui/cursor.cpp +++ b/src/ui/cursor.cpp @@ -21,5 +21,12 @@ namespace cru::ui Cursor::Ptr arrow{}; Cursor::Ptr hand{}; Cursor::Ptr i_beam{}; + + void LoadSystemCursors() + { + arrow = std::make_shared<Cursor>(::LoadCursorW(nullptr, IDC_ARROW), false); + hand = std::make_shared<Cursor>(::LoadCursorW(nullptr, IDC_HAND), false); + i_beam = std::make_shared<Cursor>(::LoadCursorW(nullptr, IDC_IBEAM), false); + } } } diff --git a/src/ui/cursor.hpp b/src/ui/cursor.hpp index e3657171..0b056365 100644 --- a/src/ui/cursor.hpp +++ b/src/ui/cursor.hpp @@ -33,6 +33,8 @@ namespace cru::ui { extern Cursor::Ptr arrow; extern Cursor::Ptr hand; - extern Cursor::Ptr i_beam; + extern Cursor::Ptr i_beam; + + void LoadSystemCursors(); } } |