Magic_Game/src/kiwano/render/Shape.h

118 lines
3.3 KiB
C++

// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/render/NativeObject.h>
namespace kiwano
{
class ShapeMaker;
KGE_DECLARE_SMART_PTR(Shape);
/**
* \addtogroup Render
* @{
*/
/**
* \~chinese
* @brief ÐÎ×´
*/
class KGE_API Shape : public NativeObject
{
friend class ShapeMaker;
public:
/// \~chinese
/// @brief ´´½¨Ïß¶ÎÐÎ×´
/// @param begin Ïß¶ÎÆðµã
/// @param end Ïß¶ÎÖÕµã
static ShapePtr CreateLine(const Point& begin, const Point& end);
/// \~chinese
/// @brief ´´½¨¾ØÐÎ
/// @param rect ¾ØÐÎ
static ShapePtr CreateRect(const Rect& rect);
/// \~chinese
/// @brief ´´½¨Ô²½Ç¾ØÐÎ
/// @param rect ¾ØÐÎ
/// @param radius ¾ØÐÎÔ²½Ç°ë¾¶
static ShapePtr CreateRoundedRect(const Rect& rect, const Vec2& radius);
/// \~chinese
/// @brief ´´½¨Ô²ÐÎ
/// @param center Ô²ÐÎÔ­µã
/// @param radius Ô²Ðΰ뾶
static ShapePtr CreateCircle(const Point& center, float radius);
/// \~chinese
/// @brief ´´½¨ÍÖÔ²ÐÎ
/// @param center ÍÖÔ²Ô­µã
/// @param radius ÍÖÔ²°ë¾¶
static ShapePtr CreateEllipse(const Point& center, const Vec2& radius);
/// \~chinese
/// @brief ´´½¨¶à±ßÐÎ
/// @param vertices ¶à±ßÐζ˵㼯ºÏ
static ShapePtr CreatePolygon(const Vector<Point>& vertices);
Shape();
/// \~chinese
/// @brief »ñÈ¡ÍâÇаüΧºÐ
Rect GetBoundingBox() const;
/// \~chinese
/// @brief »ñÈ¡ÍâÇаüΧºÐ
/// @param transform ¶þά±ä»»
Rect GetBoundingBox(const Matrix3x2& transform) const;
/// \~chinese
/// @brief ÅжÏͼÐÎÊÇ·ñ°üº¬µã
/// @param point µã
/// @param transform Ó¦Óõ½µãÉϵĶþά±ä»»
bool ContainsPoint(const Point& point, const Matrix3x2* transform = nullptr) const;
/// \~chinese
/// @brief »ñȡͼÐÎÕ¹¿ª³ÉÒ»ÌõÖ±Ïߵij¤¶È
float GetLength() const;
/// \~chinese
/// @brief ¼ÆËãͼÐÎÃæ»ý
float ComputeArea() const;
/// \~chinese
/// @brief ¼ÆËãͼÐÎÉϵãµÄλÖúÍÇÐÏßÏòÁ¿
/// @param[in] length µãÔÚͼÐÎÉϵÄλÖ㬷¶Î§ [0.0 - 1.0]
/// @param[out] point µãµÄλÖÃ
/// @param[out] tangent µãµÄÇÐÏßÏòÁ¿
bool ComputePointAtLength(float length, Point& point, Vec2& tangent) const;
/// \~chinese
/// @brief Çå³ýÐÎ×´
void Clear();
};
/** @} */
} // namespace kiwano