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
|
2020-02-16 20:14:01 +08:00
|
|
|
#include <kiwano/render/NativeObject.h>
|
2020-02-16 20:32:08 +08:00
|
|
|
#include <kiwano/render/Texture.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
|
|
|
|
2020-02-19 12:09:50 +08:00
|
|
|
LinearGradientStyle(const Point& begin, const Point& end, const Vector<GradientStop>& stops,
|
2020-01-21 10:09:55 +08:00
|
|
|
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
|
|
|
|
2020-02-19 12:09:50 +08:00
|
|
|
RadialGradientStyle(const Point& center, const Vec2& offset, const Vec2& radius, const Vector<GradientStop>& stops,
|
2020-01-21 10:09:55 +08:00
|
|
|
GradientExtendMode extend_mode = GradientExtendMode::Clamp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
* @brief 画刷
|
2020-01-21 10:09:55 +08:00
|
|
|
*/
|
2020-02-16 20:14:01 +08:00
|
|
|
class KGE_API Brush : public NativeObject
|
2020-01-21 10:09:55 +08:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建纯色画刷
|
|
|
|
|
/// @param color 画刷颜色
|
2020-02-19 12:09:50 +08:00
|
|
|
static BrushPtr Create(const Color& color);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建线性渐变样式
|
|
|
|
|
/// @param style 线性渐变样式
|
2020-02-19 12:09:50 +08:00
|
|
|
static BrushPtr Create(const LinearGradientStyle& style);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建径向渐变样式
|
|
|
|
|
/// @param style 径向渐变样式
|
2020-02-19 12:09:50 +08:00
|
|
|
static BrushPtr Create(const RadialGradientStyle& style);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
Brush();
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 设置纯色画刷颜色
|
2020-02-19 12:09:50 +08:00
|
|
|
void SetColor(const Color& color);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 设置线性渐变样式
|
2020-02-19 12:09:50 +08:00
|
|
|
void SetStyle(const LinearGradientStyle& style);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 设置径向渐变样式
|
2020-02-19 12:09:50 +08:00
|
|
|
void SetStyle(const RadialGradientStyle& style);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
2020-02-16 20:32:08 +08:00
|
|
|
/// \~chinese
|
|
|
|
|
/// @brief 设置纹理
|
|
|
|
|
void SetTexture(TexturePtr texture);
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
/// @brief 设置二维变换
|
|
|
|
|
void SetTransform(const Transform& transform);
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
/// @brief 设置二维变换
|
|
|
|
|
void SetTransform(const Matrix3x2& transform);
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
public:
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 画刷类型
|
2020-01-21 10:09:55 +08:00
|
|
|
enum class Type
|
|
|
|
|
{
|
2020-02-16 20:32:08 +08:00
|
|
|
None,
|
2020-02-10 17:32:04 +08:00
|
|
|
SolidColor, ///< 纯色填充画刷
|
|
|
|
|
LinearGradient, ///< 线性渐变画刷
|
2020-02-16 20:32:08 +08:00
|
|
|
RadialGradient, ///< 径向渐变画刷
|
|
|
|
|
Texture ///< 纹理画刷
|
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-01-21 10:09:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
|
|
inline Brush::Type Brush::GetType() const
|
|
|
|
|
{
|
|
|
|
|
return type_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace kiwano
|