Magic_Game/src/kiwano/render/Geometry.h

137 lines
3.6 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-01-17 16:55:47 +08:00
#include <kiwano/render/dx/D2DDeviceResources.h>
namespace kiwano
{
2020-01-21 10:09:55 +08:00
class RenderContext;
class Renderer;
class GeometrySink;
/**
* \addtogroup Render
* @{
*/
/**
* \~chinese
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״
*/
class KGE_API Geometry
{
friend class RenderContext;
friend class Renderer;
friend class GeometrySink;
public:
Geometry();
/// \~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();
public:
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
/// @param begin <20>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD>
/// @param end <20>߶<EFBFBD><DFB6>յ<EFBFBD>
static Geometry CreateLine(Point const& begin, Point const& end);
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param rect <20><><EFBFBD><EFBFBD>
static Geometry 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 Geometry CreateRoundedRect(Rect const& rect, Vec2 const& radius);
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
/// @param center Բ<><D4B2>ԭ<EFBFBD><D4AD>
/// @param radius Բ<>ΰ뾶
static Geometry 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 Geometry CreateEllipse(Point const& center, Vec2 const& radius);
private:
ComPtr<ID2D1Geometry> GetGeometry() const;
void SetGeometry(ComPtr<ID2D1Geometry> geometry);
private:
ComPtr<ID2D1Geometry> geo_;
};
/** @} */
inline ComPtr<ID2D1Geometry> Geometry::GetGeometry() const
{
return geo_;
}
inline void Geometry::SetGeometry(ComPtr<ID2D1Geometry> geometry)
{
geo_ = geometry;
}
2020-01-21 10:09:55 +08:00
} // namespace kiwano