Magic_Game/src/kiwano/render/Shape.h

113 lines
3.2 KiB
C
Raw Normal View History

// Copyright (c) 2016-2018 Kiwano - Nomango
2020-01-21 10:09:55 +08:00
//
// 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:
2020-01-21 10:09:55 +08:00
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
2020-01-21 10:09:55 +08:00
//
// 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
2020-02-16 20:14:01 +08:00
#include <kiwano/render/NativeObject.h>
namespace kiwano
{
2020-02-16 20:14:01 +08:00
class ShapeMaker;
2020-02-05 19:56:22 +08:00
KGE_DECLARE_SMART_PTR(Shape);
2020-01-21 10:09:55 +08:00
/**
* \addtogroup Render
* @{
*/
/**
* \~chinese
* @brief <EFBFBD><EFBFBD>״
2020-01-21 10:09:55 +08:00
*/
2020-02-16 20:14:01 +08:00
class KGE_API Shape : public NativeObject
2020-01-21 10:09:55 +08:00
{
2020-02-16 20:14:01 +08:00
friend class ShapeMaker;
2020-01-21 10:09:55 +08:00
public:
2020-02-06 16:54:47 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><DFB6><EFBFBD>״
/// @param begin <20>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD>
/// @param end <20>߶<EFBFBD><DFB6>յ<EFBFBD>
2020-02-19 12:09:50 +08:00
static ShapePtr CreateLine(const Point& begin, const Point& end);
2020-02-06 16:54:47 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param rect <20><><EFBFBD><EFBFBD>
2020-02-19 12:09:50 +08:00
static ShapePtr CreateRect(const Rect& rect);
2020-02-06 16:54:47 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD>
/// @param rect <20><><EFBFBD><EFBFBD>
/// @param radius <20><><EFBFBD><EFBFBD>Բ<EFBFBD>ǰ뾶
2020-02-19 12:09:50 +08:00
static ShapePtr CreateRoundedRect(const Rect& rect, const Vec2& radius);
2020-02-06 16:54:47 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
/// @param center Բ<><D4B2>ԭ<EFBFBD><D4AD>
/// @param radius Բ<>ΰ뾶
2020-02-19 12:09:50 +08:00
static ShapePtr CreateCircle(const Point& center, float radius);
2020-02-06 16:54:47 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
/// @param center <20><>Բԭ<D4B2><D4AD>
/// @param radius <20><>Բ<EFBFBD>
2020-02-19 12:09:50 +08:00
static ShapePtr CreateEllipse(const Point& center, const Vec2& radius);
2020-02-06 16:54:47 +08:00
2020-02-05 19:56:22 +08:00
Shape();
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>а<EFBFBD>Χ<EFBFBD><CEA7>
2020-01-21 10:09:55 +08:00
Rect GetBoundingBox() const;
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>а<EFBFBD>Χ<EFBFBD><CEA7>
/// @param transform <20><>ά<EFBFBD>
2020-02-19 12:09:50 +08:00
Rect GetBoundingBox(const Matrix3x2& transform) const;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20>ж<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param point <20><>
/// @param transform Ӧ<>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ϵĶ<CFB5>ά<EFBFBD>
2020-02-19 12:09:50 +08:00
bool ContainsPoint(const Point& point, const Matrix3x2* transform = nullptr) const;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ȡͼ<C8A1><CDBC>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>ߵij<DFB5><C4B3><EFBFBD>
2020-01-21 10:09:55 +08:00
float GetLength() const;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2020-01-21 10:09:55 +08:00
float ComputeArea() const;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>λ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param[in] length <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ϵ<EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD>Χ [0.0 - 1.0]
/// @param[out] point <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
/// @param[out] tangent <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2020-01-21 10:09:55 +08:00
bool ComputePointAtLength(float length, Point& point, Vec2& tangent) const;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״
2020-01-21 10:09:55 +08:00
void Clear();
};
/** @} */
} // namespace kiwano