Add texture brush
This commit is contained in:
parent
14df3ae55e
commit
60899a6a9b
|
|
@ -22,6 +22,10 @@
|
|||
#include <kiwano/render/Brush.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
|
||||
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
|
||||
#include <kiwano/render/DirectX/NativePtr.h>
|
||||
#endif
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
GradientStop::GradientStop()
|
||||
|
|
@ -86,7 +90,7 @@ BrushPtr Brush::Create(RadialGradientStyle const& style)
|
|||
}
|
||||
|
||||
Brush::Brush()
|
||||
: type_(Type::Unknown)
|
||||
: type_(Type::None)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -108,4 +112,30 @@ void Brush::SetStyle(RadialGradientStyle const& style)
|
|||
type_ = Brush::Type::RadialGradient;
|
||||
}
|
||||
|
||||
void Brush::SetTexture(TexturePtr texture)
|
||||
{
|
||||
Renderer::GetInstance().CreateBrush(*this, texture);
|
||||
type_ = Brush::Type::Texture;
|
||||
}
|
||||
|
||||
void Brush::SetTransform(const Transform& transform)
|
||||
{
|
||||
SetTransform(transform.ToMatrix());
|
||||
}
|
||||
|
||||
void Brush::SetTransform(const Matrix3x2& transform)
|
||||
{
|
||||
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
|
||||
auto native = NativePtr::Get<ID2D1Brush>(this);
|
||||
KGE_ASSERT(native);
|
||||
|
||||
if (native)
|
||||
{
|
||||
native->SetTransform(DX::ConvertToMatrix3x2F(transform));
|
||||
}
|
||||
#else
|
||||
// not supported
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/render/NativeObject.h>
|
||||
#include <kiwano/render/Texture.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -116,15 +117,28 @@ public:
|
|||
/// @brief 设置径向渐变样式
|
||||
void SetStyle(RadialGradientStyle const& style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置纹理
|
||||
void SetTexture(TexturePtr texture);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置二维变换
|
||||
void SetTransform(const Transform& transform);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置二维变换
|
||||
void SetTransform(const Matrix3x2& transform);
|
||||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 画刷类型
|
||||
enum class Type
|
||||
{
|
||||
Unknown,
|
||||
None,
|
||||
SolidColor, ///< 纯色填充画刷
|
||||
LinearGradient, ///< 线性渐变画刷
|
||||
RadialGradient ///< 径向渐变画刷
|
||||
RadialGradient, ///< 径向渐变画刷
|
||||
Texture ///< 纹理画刷
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <kiwano/render/DirectX/RenderContextImpl.h>
|
||||
#include <kiwano/render/DirectX/NativePtr.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -384,6 +385,16 @@ void RenderContextImpl::SetCurrentBrush(BrushPtr brush)
|
|||
}
|
||||
}
|
||||
|
||||
void RenderContextImpl::SetCurrentStrokeStyle(StrokeStylePtr stroke_style)
|
||||
{
|
||||
RenderContext::SetCurrentStrokeStyle(stroke_style);
|
||||
|
||||
if (current_stroke_ && !current_stroke_->IsValid())
|
||||
{
|
||||
Renderer::GetInstance().CreateStrokeStyle(*current_stroke_);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderContextImpl::SetTransform(const Matrix3x2& matrix)
|
||||
{
|
||||
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@ public:
|
|||
|
||||
void SetCurrentBrush(BrushPtr brush) override;
|
||||
|
||||
void SetCurrentStrokeStyle(StrokeStylePtr stroke_style) override;
|
||||
|
||||
void SetTransform(const Matrix3x2& matrix) override;
|
||||
|
||||
void SetAntialiasMode(bool enabled) override;
|
||||
|
|
|
|||
|
|
@ -871,6 +871,33 @@ void RendererImpl::CreateBrush(Brush& brush, RadialGradientStyle const& style)
|
|||
KGE_THROW_IF_FAILED(hr, "Create ID2D1RadialGradientBrush failed");
|
||||
}
|
||||
|
||||
void RendererImpl::CreateBrush(Brush& brush, TexturePtr texture)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
if (!d2d_res_)
|
||||
{
|
||||
hr = E_UNEXPECTED;
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
auto bitmap = NativePtr::Get<ID2D1Bitmap>(texture);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
ComPtr<ID2D1BitmapBrush> output;
|
||||
hr = d2d_res_->GetDeviceContext()->CreateBitmapBrush(bitmap.Get(), &output);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
NativePtr::Set(brush, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KGE_THROW_IF_FAILED(hr, "Create ID2D1RadialGradientBrush failed");
|
||||
}
|
||||
|
||||
void RendererImpl::CreateStrokeStyle(StrokeStyle& stroke_style)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ public:
|
|||
|
||||
void CreateBrush(Brush& brush, RadialGradientStyle const& style) override;
|
||||
|
||||
void CreateBrush(Brush& brush, TexturePtr texture) override;
|
||||
|
||||
void CreateStrokeStyle(StrokeStyle& stroke_style) override;
|
||||
|
||||
TextureRenderContextPtr CreateTextureRenderContext(const Size* desired_size = nullptr) override;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -108,15 +107,7 @@ void RenderContext::SetCurrentBrush(BrushPtr brush)
|
|||
|
||||
void RenderContext::SetCurrentStrokeStyle(StrokeStylePtr stroke)
|
||||
{
|
||||
if (current_stroke_ != stroke)
|
||||
{
|
||||
current_stroke_ = stroke;
|
||||
|
||||
if (current_stroke_ && !current_stroke_->IsValid())
|
||||
{
|
||||
Renderer::GetInstance().CreateStrokeStyle(*current_stroke_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -179,6 +179,13 @@ public:
|
|||
/// @throw kiwano::SystemError 创建失败时抛出
|
||||
virtual void CreateBrush(Brush& brush, RadialGradientStyle const& style) = 0;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建纹理画刷内部资源
|
||||
/// @param[out] brush 画刷
|
||||
/// @param[in] texture 纹理
|
||||
/// @throw kiwano::SystemError 创建失败时抛出
|
||||
virtual void CreateBrush(Brush& brush, TexturePtr texture) = 0;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线条样式内部资源
|
||||
/// @param[out] stroke_style 线条样式
|
||||
|
|
|
|||
Loading…
Reference in New Issue