Magic_Game/src/kiwano/render/Shape.h

140 lines
3.7 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-05 19:56:22 +08:00
#include <kiwano/core/ObjectBase.h>
2020-01-21 11:05:28 +08:00
#include <kiwano/render/DirectX/D2DDeviceResources.h>
namespace kiwano
{
2020-01-21 10:09:55 +08:00
class RenderContext;
class Renderer;
2020-02-05 19:56:22 +08:00
class ShapeSink;
KGE_DECLARE_SMART_PTR(Shape);
2020-01-21 10:09:55 +08:00
/**
* \addtogroup Render
* @{
*/
/**
* \~chinese
2020-02-06 09:39:36 +08:00
* @brief <EFBFBD><EFBFBD>״
2020-01-21 10:09:55 +08:00
*/
2020-02-05 19:56:22 +08:00
class KGE_API Shape : public virtual ObjectBase
2020-01-21 10:09:55 +08:00
{
friend class RenderContext;
friend class Renderer;
2020-02-05 19:56:22 +08:00
friend class ShapeSink;
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>
static ShapePtr CreateLine(Point const& begin, Point const& end);
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param rect <20><><EFBFBD><EFBFBD>
static ShapePtr CreateRect(Rect const& rect);
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD>
/// @param rect <20><><EFBFBD><EFBFBD>
/// @param radius <20><><EFBFBD><EFBFBD>Բ<EFBFBD>ǰ뾶
static ShapePtr CreateRoundedRect(Rect const& rect, Vec2 const& radius);
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
/// @param center Բ<><D4B2>ԭ<EFBFBD><D4AD>
/// @param radius Բ<>ΰ뾶
static ShapePtr CreateCircle(Point const& center, float radius);
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
/// @param center <20><>Բԭ<D4B2><D4AD>
/// @param radius <20><>Բ<EFBFBD>
static ShapePtr CreateEllipse(Point const& center, Vec2 const& radius);
2020-02-05 19:56:22 +08:00
Shape();
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ч
bool IsValid() const;
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>а<EFBFBD>Χ<EFBFBD><CEA7>
Rect GetBoundingBox() const;
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>а<EFBFBD>Χ<EFBFBD><CEA7>
/// @param transform <20><>ά<EFBFBD>
Rect GetBoundingBox(Matrix3x2 const& transform) const;
/// \~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>
bool ContainsPoint(Point const& point, const Matrix3x2* transform = nullptr) const;
/// \~chinese
/// @brief <20><>ȡͼ<C8A1><CDBC>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>ߵij<DFB5><C4B3><EFBFBD>
float GetLength() const;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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>
bool ComputePointAtLength(float length, Point& point, Vec2& tangent) const;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״
void Clear();
private:
ComPtr<ID2D1Geometry> GetGeometry() const;
2020-02-05 19:56:22 +08:00
void SetGeometry(ComPtr<ID2D1Geometry> shape);
2020-01-21 10:09:55 +08:00
private:
ComPtr<ID2D1Geometry> geo_;
};
/** @} */
2020-02-05 19:56:22 +08:00
inline ComPtr<ID2D1Geometry> Shape::GetGeometry() const
2020-01-21 10:09:55 +08:00
{
return geo_;
}
2020-02-05 19:56:22 +08:00
inline void Shape::SetGeometry(ComPtr<ID2D1Geometry> shape)
2020-01-21 10:09:55 +08:00
{
2020-02-05 19:56:22 +08:00
geo_ = shape;
}
2020-02-05 19:56:22 +08:00
2020-01-21 10:09:55 +08:00
} // namespace kiwano