diff options
author | 杨宇千 <crupest@outlook.com> | 2018-11-27 21:12:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-27 21:12:10 +0800 |
commit | ee22597122612cd75fe62f5d808cb51478373fad (patch) | |
tree | 19b39da16f155451d5817e82e045d69d7410acbe /src/ui/control.hpp | |
parent | 30333294fcd5917a9f3572f0c4c6dfc2ec429a3c (diff) | |
parent | 5b770e3bf0f3f9e22454d9e092630b22f5916ebe (diff) | |
download | cru-ee22597122612cd75fe62f5d808cb51478373fad.tar.gz cru-ee22597122612cd75fe62f5d808cb51478373fad.tar.bz2 cru-ee22597122612cd75fe62f5d808cb51478373fad.zip |
Merge pull request #26 from crupest/3-scrollview
Develop scrollview.
Diffstat (limited to 'src/ui/control.hpp')
-rw-r--r-- | src/ui/control.hpp | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/src/ui/control.hpp b/src/ui/control.hpp index 2ca5fa9e..d6ad9f02 100644 --- a/src/ui/control.hpp +++ b/src/ui/control.hpp @@ -1,5 +1,8 @@ #pragma once +// ReSharper disable once CppUnusedIncludeDirective +#include "pre.hpp" + #include "system_headers.hpp" #include <unordered_map> #include <any> @@ -26,12 +29,22 @@ namespace cru::ui Point lefttop_position_absolute; }; + class Control : public Object { friend class Window; friend class LayoutManager; protected: + struct GeometryInfo + { + Microsoft::WRL::ComPtr<ID2D1Geometry> border_geometry = nullptr; + Microsoft::WRL::ComPtr<ID2D1Geometry> padding_content_geometry = nullptr; + Microsoft::WRL::ComPtr<ID2D1Geometry> content_geometry = nullptr; + }; + + + protected: struct WindowConstructorTag {}; //Used for constructor for class Window. explicit Control(bool container = false); @@ -121,9 +134,18 @@ namespace cru::ui // fill and stroke with width of border. virtual bool IsPointInside(const Point& point); + // Get the top control among all descendants (including self) in local coordinate. + virtual Control* HitTest(const Point& point); //*************** region: graphic *************** + bool IsClipContent() const + { + return clip_content_; + } + + void SetClipContent(bool clip); + //Draw this control and its child controls. void Draw(ID2D1DeviceContext* device_context); @@ -239,6 +261,8 @@ namespace cru::ui //Raised when a mouse button is pressed in the control and released in the control with mouse not leaving it between two operations. events::MouseButtonEvent mouse_click_event; + events::MouseWheelEvent mouse_wheel_event; + events::KeyEvent key_down_event; events::KeyEvent key_up_event; events::CharEvent char_event; @@ -264,12 +288,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); @@ -291,7 +314,12 @@ namespace cru::ui void RaisePositionChangedEvent(events::PositionChangedEventArgs& args); void RaiseSizeChangedEvent(events::SizeChangedEventArgs& args); - void RegenerateBorderGeometry(); + void RegenerateGeometryInfo(); + + const GeometryInfo& GetGeometryInfo() const + { + return geometry_info_; + } //*************** region: mouse event *************** virtual void OnMouseEnter(events::MouseEventArgs& args); @@ -308,6 +336,9 @@ namespace cru::ui virtual void OnMouseUpCore(events::MouseButtonEventArgs& args); virtual void OnMouseClickCore(events::MouseButtonEventArgs& args); + virtual void OnMouseWheel(events::MouseWheelEventArgs& args); + virtual void OnMouseWheelCore(events::MouseWheelEventArgs& args); + void RaiseMouseEnterEvent(events::MouseEventArgs& args); void RaiseMouseLeaveEvent(events::MouseEventArgs& args); void RaiseMouseMoveEvent(events::MouseEventArgs& args); @@ -315,6 +346,8 @@ namespace cru::ui void RaiseMouseUpEvent(events::MouseButtonEventArgs& args); void RaiseMouseClickEvent(events::MouseButtonEventArgs& args); + void RaiseMouseWheelEvent(events::MouseWheelEventArgs& args); + virtual void OnMouseClickBegin(MouseButton button); virtual void OnMouseClickEnd(MouseButton button); @@ -348,6 +381,9 @@ namespace cru::ui virtual Size OnMeasureContent(const Size& available_size); virtual void OnLayoutContent(const Rect& rect); + // Called by Layout after set position and size. + virtual void AfterLayoutSelf(); + private: // Only for layout manager to use. // Check if the old position is updated to current position. @@ -364,10 +400,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,8 +431,9 @@ namespace cru::ui bool is_bordered_ = false; BorderProperty border_property_; - Microsoft::WRL::ComPtr<ID2D1Geometry> border_geometry_ = nullptr; - Microsoft::WRL::ComPtr<ID2D1Geometry> in_border_geometry_ = nullptr; //used for foreground and background brush. + GeometryInfo geometry_info_{}; + + bool clip_content_ = false; Microsoft::WRL::ComPtr<ID2D1Brush> foreground_brush_ = nullptr; Microsoft::WRL::ComPtr<ID2D1Brush> background_brush_ = nullptr; |