From baa7cf141b8121473edceae16c1a20a6d47bd202 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 27 Jun 2019 00:18:48 +0800 Subject: ...... --- include/cru/common/auto_delete.hpp | 14 -- include/cru/common/endable.hpp | 21 --- include/cru/common/ui_base.hpp | 257 ------------------------------------- 3 files changed, 292 deletions(-) delete mode 100644 include/cru/common/auto_delete.hpp delete mode 100644 include/cru/common/endable.hpp delete mode 100644 include/cru/common/ui_base.hpp (limited to 'include/cru/common') diff --git a/include/cru/common/auto_delete.hpp b/include/cru/common/auto_delete.hpp deleted file mode 100644 index ae66f7bf..00000000 --- a/include/cru/common/auto_delete.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "base.hpp" - -namespace cru { -// A instance of class implementing this interface is able to -// delete itseft when program exits. Such as IGraphFactory, -// IUiApplication. -struct IAutoDelete : virtual Interface { - // Get whether it will delete itself when program exits. - virtual bool IsAutoDelete() const = 0; - // Set whether it will delete itself when program exits. - virtual void SetAutoDelete(bool value) = 0; -}; -} // namespace cru diff --git a/include/cru/common/endable.hpp b/include/cru/common/endable.hpp deleted file mode 100644 index 4459b069..00000000 --- a/include/cru/common/endable.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include "base.hpp" - -namespace cru { -// Although c++ has destructor called automatically. But there is -// occasion when an instance of class needs to end with a result -// and release all internal resources. -// eg. IGeometryBuild will end with building a Geometry and release -// some resources. IPainter will end drawing and release some -// resources and map the drawing result onto target. -// note: You can't call End twice. And most methods on the object -// is invalid to call after End is called. Get whether it is ended -// by IsEnded. -template -struct IEndable : virtual Interface { - // Get whether the object is ended. - virtual bool IsEnded() const = 0; - // End the object with a result. - virtual TResult End() = 0; -}; -} diff --git a/include/cru/common/ui_base.hpp b/include/cru/common/ui_base.hpp deleted file mode 100644 index 017e3bd1..00000000 --- a/include/cru/common/ui_base.hpp +++ /dev/null @@ -1,257 +0,0 @@ -#pragma once -#include "pre_config.hpp" - -#include -#include -#include - -namespace cru::ui { -struct Point final { - constexpr Point() = default; - constexpr Point(const float x, const float y) : x(x), y(y) {} - - float x = 0; - float y = 0; -}; - -constexpr bool operator==(const Point& left, const Point& right) { - return left.x == right.x && left.y == right.y; -} - -constexpr bool operator!=(const Point& left, const Point& right) { - return !(left == right); -} - -struct Size final { - constexpr Size() = default; - constexpr Size(const float width, const float height) - : width(width), height(height) {} - - float width = 0; - float height = 0; -}; - -constexpr Size operator+(const Size& left, const Size& right) { - return Size(left.width + right.width, left.height + right.height); -} - -constexpr Size operator-(const Size& left, const Size& right) { - return Size(left.width - right.width, left.height - right.height); -} - -constexpr bool operator==(const Size& left, const Size& right) { - return left.width == right.width && left.height == right.height; -} - -constexpr bool operator!=(const Size& left, const Size& right) { - return !(left == right); -} - -struct Thickness final { - constexpr Thickness() : Thickness(0) {} - - constexpr explicit Thickness(const float width) - : left(width), top(width), right(width), bottom(width) {} - - constexpr explicit Thickness(const float horizontal, const float vertical) - : left(horizontal), top(vertical), right(horizontal), bottom(vertical) {} - - constexpr Thickness(const float left, const float top, const float right, - const float bottom) - : left(left), top(top), right(right), bottom(bottom) {} - - constexpr float GetHorizontalTotal() const { return left + right; } - - constexpr float GetVerticalTotal() const { return top + bottom; } - - void SetLeftRight(const float value) { left = right = value; } - - void SetTopBottom(const float value) { top = bottom = value; } - - void SetAll(const float value) { left = top = right = bottom = value; } - - constexpr float Validate() const { - return left >= 0.0 && top >= 0.0 && right >= 0.0 && bottom >= 0.0; - } - - float left; - float top; - float right; - float bottom; -}; - -constexpr bool operator==(const Thickness& left, const Thickness& right) { - return left.left == right.left && left.top == right.top && - left.right == right.right && left.bottom == right.bottom; -} - -constexpr bool operator!=(const Thickness& left, const Thickness& right) { - return !(left == right); -} - -struct Rect final { - constexpr Rect() = default; - constexpr Rect(const float left, const float top, const float width, - const float height) - : left(left), top(top), width(width), height(height) {} - constexpr Rect(const Point& lefttop, const Size& size) - : left(lefttop.x), - top(lefttop.y), - width(size.width), - height(size.height) {} - - constexpr static Rect FromVertices(const float left, const float top, - const float right, const float bottom) { - return Rect(left, top, right - left, bottom - top); - } - - constexpr static Rect FromCenter(const Point& center, const float width, - const float height) { - return Rect(center.x - width / 2.0f, center.y - height / 2.0f, width, - height); - } - - constexpr float GetRight() const { return left + width; } - - constexpr float GetBottom() const { return top + height; } - - constexpr Point GetLeftTop() const { return Point(left, top); } - - constexpr Point GetRightBottom() const { - return Point(left + width, top + height); - } - - constexpr Point GetLeftBottom() const { return Point(left, top + height); } - - constexpr Point GetRightTop() const { return Point(left + width, top); } - - constexpr Point GetCenter() const { - return Point(left + width / 2.0f, top + height / 2.0f); - } - - constexpr Size GetSize() const { return Size(width, height); } - - constexpr Rect Shrink(const Thickness& thickness) const { - return Rect(left + thickness.left, top + thickness.top, - width - thickness.GetHorizontalTotal(), - height - thickness.GetVerticalTotal()); - } - - constexpr 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; -}; - -constexpr bool operator==(const Rect& left, const Rect& right) { - return left.left == right.left && left.top == right.top && - left.width == right.width && left.height == right.height; -} - -constexpr bool operator!=(const Rect& left, const Rect& right) { - return !(left == right); -} - -struct RoundedRect final { - constexpr RoundedRect() = default; - constexpr RoundedRect(const Rect& rect, const float radius_x, - const float radius_y) - : rect(rect), radius_x(radius_x), radius_y(radius_y) {} - - Rect rect{}; - float radius_x = 0.0f; - float radius_y = 0.0f; -}; - -constexpr bool operator==(const RoundedRect& left, const RoundedRect& right) { - return left.rect == right.rect && left.radius_x == right.radius_x && - left.radius_y == right.radius_y; -} - -constexpr bool operator!=(const RoundedRect& left, const RoundedRect& right) { - return !(left == right); -} - -struct Ellipse final { - constexpr Ellipse() = default; - constexpr Ellipse(const Point& center, const float radius_x, - const float radius_y) - : center(center), radius_x(radius_x), radius_y(radius_y) {} - - constexpr static Ellipse FromRect(const Rect& rect) { - return Ellipse(rect.GetCenter(), rect.width / 2.0f, rect.height / 2.0f); - } - - constexpr Rect GetBoundRect() const { - return Rect::FromCenter(center, radius_x * 2.0f, radius_y * 2.0f); - } - - Point center{}; - float radius_x = 0.0f; - float radius_y = 0.0f; -}; - -constexpr bool operator==(const Ellipse& left, const Ellipse& right) { - return left.center == right.center && left.radius_x == right.radius_x && - left.radius_y == right.radius_y; -} - -constexpr bool operator!=(const Ellipse& left, const Ellipse& right) { - return !(left == right); -} - -struct TextRange final { - constexpr static std::optional FromTwoSides(unsigned first, - unsigned second) { - if (first > second) - return std::make_optional(second, first - second); - if (first < second) - return std::make_optional(first, second - first); - return std::nullopt; - } - - constexpr static std::pair ToTwoSides( - std::optional text_range, unsigned default_position = 0) { - if (text_range.has_value()) - return std::make_pair( - text_range.value().position, - text_range.value().position + text_range.value().count); - return std::make_pair(default_position, default_position); - } - - constexpr TextRange() = default; - constexpr TextRange(const unsigned position, const unsigned count) - : position(position), count(count) {} - - unsigned position = 0; - unsigned count = 0; -}; - -struct Color { - constexpr Color() : Color(0, 0, 0, 255) {} - constexpr Color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, - std::uint8_t alpha = 255) - : red(red), green(green), blue(blue), alpha(alpha) {} - - constexpr static Color FromHex(std::uint32_t hex) { - return Color(hex & (0b11111111 << 16), hex & (0b11111111 << 8), - hex & (0b11111111), hex & (0b11111111 << 24)); - } - - std::uint8_t red; - std::uint8_t green; - std::uint8_t blue; - std::uint8_t alpha; -}; - -namespace colors { -constexpr Color black{0, 0, 0}; -constexpr Color white{255, 255, 255}; -constexpr Color skyblue = Color::FromHex(0x87ceeb); -} // namespace colors -} // namespace cru::ui -- cgit v1.2.3