diff options
author | crupest <crupest@outlook.com> | 2018-09-01 23:28:28 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-01 23:28:28 +0800 |
commit | 956a401f9c955f26b7e661dc80f76bfc43fc4124 (patch) | |
tree | 8af088933c7bc08942478daddd55c92de8668359 /CruUI/ui/ui_base.h | |
download | cru-956a401f9c955f26b7e661dc80f76bfc43fc4124.tar.gz cru-956a401f9c955f26b7e661dc80f76bfc43fc4124.tar.bz2 cru-956a401f9c955f26b7e661dc80f76bfc43fc4124.zip |
Initial commit
Diffstat (limited to 'CruUI/ui/ui_base.h')
-rw-r--r-- | CruUI/ui/ui_base.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/CruUI/ui/ui_base.h b/CruUI/ui/ui_base.h new file mode 100644 index 00000000..8dfbf53d --- /dev/null +++ b/CruUI/ui/ui_base.h @@ -0,0 +1,105 @@ +#pragma once + +namespace cru +{ + namespace ui + { + struct Point + { + static const Point zero; + + Point() = default; + Point(const float x, const float y) : x(x), y(y) { } + + float x; + float y; + }; + + struct Size + { + static const Size zero; + + Size() = default; + Size(const float width, const float height) : width(width), height(height) { } + + float width; + float height; + }; + + struct Rect + { + Rect() = default; + Rect(const float left, const float top, const float width, const float height) + : left(left), top(top), width(width), height(height) { } + Rect(const Point& lefttop, const Size& size) + : left(lefttop.x), top(lefttop.y), width(size.width), height(size.height) { } + + static Rect FromVertices(const float left, const float top, const float right, const float bottom) + { + return Rect(left, top, right - left, bottom - top); + } + + float GetRight() const + { + return left + width; + } + + float GetBottom() const + { + return top + height; + } + + Point GetLeftTop() const + { + return Point(left, top); + } + + Point GetRightBottom() const + { + return Point(left + width, top + height); + } + + Size GetSize() const + { + return Size(width, height); + } + + bool IsPointInside(const Point& point) const + { + return + point.x >= left && + point.x < GetRight() && + point.y >= top && + point.y < GetBottom(); + } + + float left = 0.0f; + float top = 0.0f; + float width = 0.0f; + float height = 0.0f; + }; + + struct Thickness + { + Thickness() : Thickness(0) { } + explicit Thickness(const float width) + : left(width), top(width), right(width), bottom(width) { } + + Thickness(const float left, const float top, const float right, const float bottom) + : left(left), top(top), right(right), bottom(bottom) { } + + + float left; + float top; + float right; + float bottom; + }; + + enum class MouseButton + { + Left, + Right, + Middle + }; + } +} |