aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-20 21:02:49 +0800
committercrupest <crupest@outlook.com>2018-11-20 21:03:07 +0800
commite8589550140d20b675fa7736441d7cdd1daee4d7 (patch)
tree50b61f34dd63e235a6c89b84511f3910b566af00
parent30333294fcd5917a9f3572f0c4c6dfc2ec429a3c (diff)
downloadcru-e8589550140d20b675fa7736441d7cdd1daee4d7.tar.gz
cru-e8589550140d20b675fa7736441d7cdd1daee4d7.tar.bz2
cru-e8589550140d20b675fa7736441d7cdd1daee4d7.zip
Add clip to padding.
-rw-r--r--CruUI-Generate/cru_ui.cpp49
-rw-r--r--CruUI-Generate/cru_ui.hpp24
-rw-r--r--src/application.cpp15
-rw-r--r--src/system_headers.hpp2
-rw-r--r--src/ui/control.cpp25
-rw-r--r--src/ui/control.hpp18
-rw-r--r--src/ui/controls/text_control.cpp2
-rw-r--r--src/ui/cursor.cpp7
-rw-r--r--src/ui/cursor.hpp4
9 files changed, 106 insertions, 40 deletions
diff --git a/CruUI-Generate/cru_ui.cpp b/CruUI-Generate/cru_ui.cpp
index 497af786..f2cd94d3 100644
--- a/CruUI-Generate/cru_ui.cpp
+++ b/CruUI-Generate/cru_ui.cpp
@@ -123,16 +123,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) {
@@ -141,9 +131,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()
@@ -1012,6 +1005,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;
@@ -1020,11 +1022,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);
}
@@ -1195,9 +1206,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)
@@ -1215,7 +1226,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());
@@ -1867,6 +1881,13 @@ 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);
+ }
}
}
//--------------------------------------------------------
@@ -3640,6 +3661,8 @@ namespace cru::ui::controls
brush_ = init_brush;
selection_brush_ = UiManager::GetInstance()->GetPredefineResources()->text_control_selection_brush;
+
+ SetClipToPadding(true);
}
diff --git a/CruUI-Generate/cru_ui.hpp b/CruUI-Generate/cru_ui.hpp
index 93360e3a..ab070ba1 100644
--- a/CruUI-Generate/cru_ui.hpp
+++ b/CruUI-Generate/cru_ui.hpp
@@ -348,6 +348,8 @@ namespace cru
#include <dxgi1_2.h>
#include <wrl/client.h>
+
+#include <VersionHelpers.h>
//--------------------------------------------------------
//-------end of file: src\system_headers.hpp
//--------------------------------------------------------
@@ -1500,7 +1502,9 @@ namespace cru::ui
{
extern Cursor::Ptr arrow;
extern Cursor::Ptr hand;
- extern Cursor::Ptr i_beam;
+ extern Cursor::Ptr i_beam;
+
+ void LoadSystemCursors();
}
}
//--------------------------------------------------------
@@ -1618,6 +1622,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);
@@ -1758,12 +1769,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);
@@ -1858,10 +1868,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_{};
@@ -1891,6 +1899,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/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();
}
}