2019-09-09 22:02:53 +08:00
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2020-01-21 10:09:55 +08:00
|
|
|
//
|
2019-09-09 22:02:53 +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
|
|
|
//
|
2019-09-09 22:02:53 +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
|
|
|
//
|
2019-09-09 22:02:53 +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
|
2019-12-27 23:42:51 +08:00
|
|
|
#include <kiwano/core/ObjectBase.h>
|
2020-01-21 11:05:28 +08:00
|
|
|
#include <kiwano/render/DirectX/D2DDeviceResources.h>
|
2019-09-09 22:02:53 +08:00
|
|
|
|
|
|
|
|
namespace kiwano
|
|
|
|
|
{
|
2019-12-27 10:51:34 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
KGE_DECLARE_SMART_PTR(Brush);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \addtogroup Render
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 渐变转换点
|
2020-01-21 10:09:55 +08:00
|
|
|
struct GradientStop
|
|
|
|
|
{
|
2020-02-10 17:32:04 +08:00
|
|
|
float offset; ///< 偏移距离
|
|
|
|
|
Color color; ///< 渐变点颜色
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
GradientStop();
|
|
|
|
|
|
|
|
|
|
GradientStop(float offset, Color color);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 渐变扩充模式
|
|
|
|
|
/// @details 该模式用于指定画笔如何绘制正常区域外的部分
|
2020-01-21 10:09:55 +08:00
|
|
|
enum class GradientExtendMode
|
|
|
|
|
{
|
2020-02-10 17:32:04 +08:00
|
|
|
Clamp, ///< 夹模式,重复绘制边界颜色
|
|
|
|
|
Wrap, ///< 包裹模式,重复画笔内容
|
|
|
|
|
Mirror ///< 镜像模式,反转画笔内容
|
2020-01-21 10:09:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 线性渐变样式
|
2020-01-21 10:09:55 +08:00
|
|
|
struct LinearGradientStyle
|
|
|
|
|
{
|
2020-02-10 17:32:04 +08:00
|
|
|
Point begin; ///< 渐变起始点
|
|
|
|
|
Point end; ///< 渐变终止点
|
|
|
|
|
Vector<GradientStop> stops; ///< 渐变转换点集合
|
|
|
|
|
GradientExtendMode extend_mode; ///< 渐变扩充模式
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
LinearGradientStyle(Point const& begin, Point const& end, Vector<GradientStop> const& stops,
|
|
|
|
|
GradientExtendMode extend_mode = GradientExtendMode::Clamp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 径向渐变样式
|
2020-01-21 10:09:55 +08:00
|
|
|
struct RadialGradientStyle
|
|
|
|
|
{
|
2020-02-10 17:32:04 +08:00
|
|
|
Point center; ///< 径向渐变圆心
|
|
|
|
|
Vec2 offset; ///< 径向渐变偏移
|
|
|
|
|
Vec2 radius; ///< 径向渐变半径
|
|
|
|
|
Vector<GradientStop> stops; ///< 渐变转换点集合
|
|
|
|
|
GradientExtendMode extend_mode; ///< 渐变扩充模式
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
RadialGradientStyle(Point const& center, Vec2 const& offset, Vec2 const& radius, Vector<GradientStop> const& stops,
|
|
|
|
|
GradientExtendMode extend_mode = GradientExtendMode::Clamp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
* @brief 画刷
|
2020-01-21 10:09:55 +08:00
|
|
|
*/
|
|
|
|
|
class KGE_API Brush : public virtual ObjectBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建纯色画刷
|
|
|
|
|
/// @param color 画刷颜色
|
2020-02-06 16:54:47 +08:00
|
|
|
static BrushPtr Create(Color const& color);
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建线性渐变样式
|
|
|
|
|
/// @param style 线性渐变样式
|
2020-02-06 16:54:47 +08:00
|
|
|
static BrushPtr Create(LinearGradientStyle const& style);
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建径向渐变样式
|
|
|
|
|
/// @param style 径向渐变样式
|
2020-02-06 16:54:47 +08:00
|
|
|
static BrushPtr Create(RadialGradientStyle const& style);
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
Brush();
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 是否有效
|
2020-01-21 10:09:55 +08:00
|
|
|
bool IsValid() const;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 设置纯色画刷颜色
|
2020-01-21 10:09:55 +08:00
|
|
|
void SetColor(Color const& color);
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 设置线性渐变样式
|
2020-01-21 10:09:55 +08:00
|
|
|
void SetStyle(LinearGradientStyle const& style);
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 设置径向渐变样式
|
2020-01-21 10:09:55 +08:00
|
|
|
void SetStyle(RadialGradientStyle const& style);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 画刷类型
|
2020-01-21 10:09:55 +08:00
|
|
|
enum class Type
|
|
|
|
|
{
|
|
|
|
|
Unknown,
|
2020-02-10 17:32:04 +08:00
|
|
|
SolidColor, ///< 纯色填充画刷
|
|
|
|
|
LinearGradient, ///< 线性渐变画刷
|
|
|
|
|
RadialGradient ///< 径向渐变画刷
|
2020-01-21 10:09:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取画刷类型
|
2020-01-21 10:09:55 +08:00
|
|
|
Type GetType() const;
|
|
|
|
|
|
|
|
|
|
private:
|
2020-02-09 18:41:59 +08:00
|
|
|
Type type_;
|
2020-02-07 20:50:27 +08:00
|
|
|
|
|
|
|
|
#if defined(KGE_WIN32)
|
2020-02-09 18:41:59 +08:00
|
|
|
public:
|
2020-01-21 10:09:55 +08:00
|
|
|
void SetBrush(ComPtr<ID2D1Brush> brush, Type type);
|
|
|
|
|
|
|
|
|
|
ComPtr<ID2D1Brush> GetBrush() const;
|
|
|
|
|
|
2020-02-09 18:41:59 +08:00
|
|
|
private:
|
2020-01-21 10:09:55 +08:00
|
|
|
ComPtr<ID2D1Brush> raw_;
|
2020-02-07 20:50:27 +08:00
|
|
|
#endif
|
2020-01-21 10:09:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
|
|
inline Brush::Type Brush::GetType() const
|
|
|
|
|
{
|
|
|
|
|
return type_;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 20:50:27 +08:00
|
|
|
#if defined(KGE_WIN32)
|
|
|
|
|
inline void Brush::SetBrush(ComPtr<ID2D1Brush> brush, Type type)
|
|
|
|
|
{
|
|
|
|
|
type_ = type;
|
|
|
|
|
raw_ = brush;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
inline ComPtr<ID2D1Brush> Brush::GetBrush() const
|
|
|
|
|
{
|
|
|
|
|
return raw_;
|
2019-09-09 22:02:53 +08:00
|
|
|
}
|
2020-02-07 20:50:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
} // namespace kiwano
|