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-05-15 16:29:20 +08:00
|
|
|
|
#include <kiwano/render/Color.h>
|
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-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
|
2020-01-21 10:09:55 +08:00
|
|
|
|
struct GradientStop
|
|
|
|
|
|
{
|
2020-03-19 14:28:50 +08:00
|
|
|
|
float offset; ///< ƫ<>ƾ<EFBFBD><C6BE><EFBFBD>
|
|
|
|
|
|
Color color; ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
GradientStop();
|
|
|
|
|
|
|
|
|
|
|
|
GradientStop(float offset, Color color);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
|
/// @details <20><>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
2020-01-21 10:09:55 +08:00
|
|
|
|
enum class GradientExtendMode
|
|
|
|
|
|
{
|
2020-03-19 14:28:50 +08:00
|
|
|
|
Clamp, ///< <20><>ģʽ<C4A3><CABD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>Ʊ߽<C6B1><DFBD><EFBFBD>ɫ
|
|
|
|
|
|
Wrap, ///< <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
Mirror ///< <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2020-01-21 10:09:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
2020-01-21 10:09:55 +08:00
|
|
|
|
struct LinearGradientStyle
|
|
|
|
|
|
{
|
2020-03-19 14:28:50 +08:00
|
|
|
|
Point begin; ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
|
|
|
|
|
Point end; ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9>
|
|
|
|
|
|
Vector<GradientStop> stops; ///< <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>㼯<EFBFBD><E3BCAF>
|
|
|
|
|
|
GradientExtendMode extend_mode; ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
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-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><F2BDA5B1><EFBFBD>ʽ
|
2020-01-21 10:09:55 +08:00
|
|
|
|
struct RadialGradientStyle
|
|
|
|
|
|
{
|
2020-03-19 14:28:50 +08:00
|
|
|
|
Point center; ///< <20><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
|
|
|
|
|
|
Vec2 offset; ///< <20><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
|
|
|
|
|
|
Vec2 radius; ///< <20><><EFBFBD><EFBFBD><F2BDA5B1>뾶
|
|
|
|
|
|
Vector<GradientStop> stops; ///< <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>㼯<EFBFBD><E3BCAF>
|
|
|
|
|
|
GradientExtendMode extend_mode; ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
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-03-19 14:28:50 +08:00
|
|
|
|
* @brief <EFBFBD><EFBFBD>ˢ
|
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-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>ˢ
|
|
|
|
|
|
/// @param color <20><>ˢ<EFBFBD><CBA2>ɫ
|
2020-07-22 21:08:48 +08:00
|
|
|
|
Brush(const Color& color);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
/// @param style <20><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
2020-07-22 21:08:48 +08:00
|
|
|
|
Brush(const LinearGradientStyle& style);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2BDA5B1><EFBFBD>ʽ
|
|
|
|
|
|
/// @param style <20><><EFBFBD><EFBFBD><F2BDA5B1><EFBFBD>ʽ
|
2020-07-22 21:08:48 +08:00
|
|
|
|
Brush(const RadialGradientStyle& style);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
Brush();
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD>ô<EFBFBD>ɫ<EFBFBD><C9AB>ˢ<EFBFBD><CBA2>ɫ
|
2020-02-19 12:09:50 +08:00
|
|
|
|
void SetColor(const Color& color);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
2020-02-19 12:09:50 +08:00
|
|
|
|
void SetStyle(const LinearGradientStyle& style);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD>þ<EFBFBD><C3BE><EFBFBD><F2BDA5B1><EFBFBD>ʽ
|
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
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2020-02-16 20:32:08 +08:00
|
|
|
|
void SetTexture(TexturePtr texture);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD>ö<EFBFBD>ά<EFBFBD>任
|
2020-02-16 20:32:08 +08:00
|
|
|
|
void SetTransform(const Transform& transform);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><><EFBFBD>ö<EFBFBD>ά<EFBFBD>任
|
2020-02-16 20:32:08 +08:00
|
|
|
|
void SetTransform(const Matrix3x2& transform);
|
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
|
public:
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><>ˢ<EFBFBD><CBA2><EFBFBD><EFBFBD>
|
2020-01-21 10:09:55 +08:00
|
|
|
|
enum class Type
|
|
|
|
|
|
{
|
2020-02-16 20:32:08 +08:00
|
|
|
|
None,
|
2020-03-19 14:28:50 +08:00
|
|
|
|
SolidColor, ///< <20><>ɫ<EFBFBD><C9AB><EFBFBD>仭ˢ
|
|
|
|
|
|
LinearGradient, ///< <20><><EFBFBD>Խ<EFBFBD><D4BD>仭ˢ
|
|
|
|
|
|
RadialGradient, ///< <20><><EFBFBD>仭ˢ
|
|
|
|
|
|
Texture ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
|
2020-01-21 10:09:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-03-19 14:28:50 +08:00
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1>ˢ<EFBFBD><CBA2><EFBFBD><EFBFBD>
|
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
|