Update Brush & TextActor
This commit is contained in:
parent
a3d425b008
commit
f9598f3856
|
|
@ -49,6 +49,7 @@ namespace kiwano
|
|||
|
||||
const TextStyle& TextActor::GetDefaultStyle()
|
||||
{
|
||||
InitDefaultTextStyle();
|
||||
return text_default_style;
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ namespace kiwano
|
|||
}
|
||||
|
||||
TextActor::TextActor(String const& text)
|
||||
: TextActor(text, text_default_style)
|
||||
: TextActor(text, GetDefaultStyle())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -66,8 +67,6 @@ namespace kiwano
|
|||
: show_underline_(false)
|
||||
, show_strikethrough_(false)
|
||||
{
|
||||
InitDefaultTextStyle();
|
||||
|
||||
SetText(text);
|
||||
SetStyle(style);
|
||||
}
|
||||
|
|
@ -91,7 +90,10 @@ namespace kiwano
|
|||
if (text_layout_.IsDirty())
|
||||
{
|
||||
text_layout_.Update();
|
||||
}
|
||||
|
||||
if (text_layout_.GetDirtyFlag() & TextLayout::DirtyFlag::Updated)
|
||||
{
|
||||
if (show_underline_)
|
||||
text_layout_.SetUnderline(true, 0, text_layout_.GetText().length());
|
||||
|
||||
|
|
@ -109,7 +111,7 @@ namespace kiwano
|
|||
|
||||
void TextActor::SetFillColor(Color const& color)
|
||||
{
|
||||
if (!text_layout_.GetFillBrush())
|
||||
if (!text_layout_.GetFillBrush() || text_layout_.GetFillBrush() == GetDefaultStyle().fill_brush)
|
||||
{
|
||||
BrushPtr brush = new Brush;
|
||||
text_layout_.SetFillBrush(brush);
|
||||
|
|
@ -119,11 +121,12 @@ namespace kiwano
|
|||
|
||||
void TextActor::SetOutlineColor(Color const& outline_color)
|
||||
{
|
||||
if (!text_layout_.GetOutlineBrush())
|
||||
if (!text_layout_.GetOutlineBrush() || text_layout_.GetOutlineBrush() == GetDefaultStyle().outline_brush)
|
||||
{
|
||||
BrushPtr brush = new Brush;
|
||||
text_layout_.SetOutlineBrush(brush);
|
||||
}
|
||||
text_layout_.GetOutlineBrush()->SetColor(outline_color);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,25 +82,25 @@ namespace kiwano
|
|||
{
|
||||
if (type_ == Type::SolidColor && raw_)
|
||||
{
|
||||
auto solid_brush = dynamic_cast<ID2D1SolidColorBrush*>(raw_.get());
|
||||
KGE_ASSERT(solid_brush != nullptr);
|
||||
ComPtr<ID2D1SolidColorBrush> solid_brush;
|
||||
|
||||
solid_brush->SetColor(DX::ConvertToColorF(color));
|
||||
}
|
||||
else
|
||||
{
|
||||
Renderer::instance().CreateSolidBrush(*this, color);
|
||||
if (SUCCEEDED(raw_->QueryInterface(&solid_brush)))
|
||||
{
|
||||
solid_brush->SetColor(DX::ConvertToColorF(color));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Renderer::instance().CreateSolidBrush(*this, color);
|
||||
}
|
||||
|
||||
void Brush::SetStyle(LinearGradientStyle const& style)
|
||||
{
|
||||
Renderer::instance().CreateLinearGradientBrush(*this, style.begin, style.end, style.stops, style.extend_mode);
|
||||
Renderer::instance().CreateLinearGradientBrush(*this, style);
|
||||
}
|
||||
|
||||
void Brush::SetStyle(RadialGradientStyle const& style)
|
||||
{
|
||||
Renderer::instance().CreateRadialGradientBrush(*this, style.center, style.offset, style.radius, style.stops, style.extend_mode);
|
||||
Renderer::instance().CreateRadialGradientBrush(*this, style);
|
||||
}
|
||||
|
||||
void Brush::SetBrush(ComPtr<ID2D1Brush> brush, Type type)
|
||||
|
|
|
|||
|
|
@ -884,7 +884,7 @@ namespace kiwano
|
|||
win32::ThrowIfFailed(hr);
|
||||
}
|
||||
|
||||
void Renderer::CreateLinearGradientBrush(Brush& brush, Point const& begin, Point const& end, Vector<GradientStop> const& stops, GradientExtendMode extend_mode)
|
||||
void Renderer::CreateLinearGradientBrush(Brush& brush, LinearGradientStyle const& style)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
if (!d2d_res_)
|
||||
|
|
@ -896,10 +896,10 @@ namespace kiwano
|
|||
{
|
||||
ComPtr<ID2D1GradientStopCollection> collection;
|
||||
hr = d2d_res_->GetDeviceContext()->CreateGradientStopCollection(
|
||||
reinterpret_cast<const D2D1_GRADIENT_STOP*>(&stops[0]),
|
||||
UINT32(stops.size()),
|
||||
reinterpret_cast<const D2D1_GRADIENT_STOP*>(&style.stops[0]),
|
||||
UINT32(style.stops.size()),
|
||||
D2D1_GAMMA_2_2,
|
||||
D2D1_EXTEND_MODE(extend_mode),
|
||||
D2D1_EXTEND_MODE(style.extend_mode),
|
||||
&collection
|
||||
);
|
||||
|
||||
|
|
@ -908,8 +908,8 @@ namespace kiwano
|
|||
ComPtr<ID2D1LinearGradientBrush> output;
|
||||
hr = d2d_res_->GetDeviceContext()->CreateLinearGradientBrush(
|
||||
D2D1::LinearGradientBrushProperties(
|
||||
DX::ConvertToPoint2F(begin),
|
||||
DX::ConvertToPoint2F(end)
|
||||
DX::ConvertToPoint2F(style.begin),
|
||||
DX::ConvertToPoint2F(style.end)
|
||||
),
|
||||
collection.get(),
|
||||
&output
|
||||
|
|
@ -925,8 +925,7 @@ namespace kiwano
|
|||
win32::ThrowIfFailed(hr);
|
||||
}
|
||||
|
||||
void Renderer::CreateRadialGradientBrush(Brush& brush, Point const& center, Vec2 const& offset, Vec2 const& radius,
|
||||
Vector<GradientStop> const& stops, GradientExtendMode extend_mode)
|
||||
void Renderer::CreateRadialGradientBrush(Brush& brush, RadialGradientStyle const& style)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
if (!d2d_res_)
|
||||
|
|
@ -938,10 +937,10 @@ namespace kiwano
|
|||
{
|
||||
ComPtr<ID2D1GradientStopCollection> collection;
|
||||
hr = d2d_res_->GetDeviceContext()->CreateGradientStopCollection(
|
||||
reinterpret_cast<const D2D1_GRADIENT_STOP*>(&stops[0]),
|
||||
UINT32(stops.size()),
|
||||
reinterpret_cast<const D2D1_GRADIENT_STOP*>(&style.stops[0]),
|
||||
UINT32(style.stops.size()),
|
||||
D2D1_GAMMA_2_2,
|
||||
D2D1_EXTEND_MODE(extend_mode),
|
||||
D2D1_EXTEND_MODE(style.extend_mode),
|
||||
&collection
|
||||
);
|
||||
|
||||
|
|
@ -950,10 +949,10 @@ namespace kiwano
|
|||
ComPtr<ID2D1RadialGradientBrush> output;
|
||||
hr = d2d_res_->GetDeviceContext()->CreateRadialGradientBrush(
|
||||
D2D1::RadialGradientBrushProperties(
|
||||
DX::ConvertToPoint2F(center),
|
||||
DX::ConvertToPoint2F(offset),
|
||||
radius.x,
|
||||
radius.y
|
||||
DX::ConvertToPoint2F(style.center),
|
||||
DX::ConvertToPoint2F(style.offset),
|
||||
style.radius.x,
|
||||
style.radius.y
|
||||
),
|
||||
collection.get(),
|
||||
&output
|
||||
|
|
|
|||
|
|
@ -243,33 +243,19 @@ namespace kiwano
|
|||
/// \~chinese
|
||||
/// @brief 创建线性渐变画刷
|
||||
/// @param[out] brush 画刷
|
||||
/// @param[in] begin 渐变起始点
|
||||
/// @param[in] end 渐变终止点
|
||||
/// @param[in] stops 渐变转换点集合
|
||||
/// @param[in] extend_mode 渐变扩充模式
|
||||
/// @param[in] style 线性渐变样式
|
||||
void CreateLinearGradientBrush(
|
||||
Brush& brush,
|
||||
Point const& begin,
|
||||
Point const& end,
|
||||
Vector<GradientStop> const& stops,
|
||||
GradientExtendMode extend_mode
|
||||
LinearGradientStyle const& style
|
||||
);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建径向渐变画刷
|
||||
/// @param[out] brush 画刷
|
||||
/// @param[in] center 径向渐变圆心
|
||||
/// @param[in] offset 径向渐变偏移
|
||||
/// @param[in] radius 径向渐变半径
|
||||
/// @param[in] stops 渐变转换点集合
|
||||
/// @param[in] extend_mode 渐变扩充模式
|
||||
/// @param[in] style 径向渐变样式
|
||||
void CreateRadialGradientBrush(
|
||||
Brush& brush,
|
||||
Point const& center,
|
||||
Vec2 const& offset,
|
||||
Vec2 const& radius,
|
||||
Vector<GradientStop> const& stops,
|
||||
GradientExtendMode extend_mode
|
||||
RadialGradientStyle const& style
|
||||
);
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
dirty_flag_ = DirtyFlag::Clean;
|
||||
dirty_flag_ = DirtyFlag::Updated;
|
||||
}
|
||||
|
||||
void TextLayout::SetText(const String& text)
|
||||
|
|
|
|||
|
|
@ -151,6 +151,20 @@ namespace kiwano
|
|||
/// @param length ³¤¶È
|
||||
void SetStrikethrough(bool enable, uint32_t start, uint32_t length);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 脏数据标志
|
||||
enum DirtyFlag : uint8_t
|
||||
{
|
||||
Clean = 0, ///< 干净数据
|
||||
DirtyFormat = 1, ///< 文字格式待更新
|
||||
DirtyLayout = 1 << 1, ///< 文字布局待更新
|
||||
Updated = 1 << 2, ///< 数据已更新
|
||||
};
|
||||
|
||||
uint8_t GetDirtyFlag() const;
|
||||
|
||||
void SetDirtyFlag(uint8_t flag);
|
||||
|
||||
private:
|
||||
ComPtr<IDWriteTextFormat> GetTextFormat() const;
|
||||
|
||||
|
|
@ -161,12 +175,6 @@ namespace kiwano
|
|||
void SetTextLayout(ComPtr<IDWriteTextLayout> layout);
|
||||
|
||||
private:
|
||||
enum DirtyFlag : uint8_t
|
||||
{
|
||||
Clean = 0,
|
||||
DirtyFormat = 1,
|
||||
DirtyLayout = 1 << 1,
|
||||
};
|
||||
uint8_t dirty_flag_;
|
||||
|
||||
ComPtr<IDWriteTextFormat> text_format_;
|
||||
|
|
@ -198,6 +206,16 @@ namespace kiwano
|
|||
return style_;
|
||||
}
|
||||
|
||||
inline uint8_t TextLayout::GetDirtyFlag() const
|
||||
{
|
||||
return dirty_flag_;
|
||||
}
|
||||
|
||||
inline void TextLayout::SetDirtyFlag(uint8_t flag)
|
||||
{
|
||||
dirty_flag_ = flag;
|
||||
}
|
||||
|
||||
inline ComPtr<IDWriteTextFormat> TextLayout::GetTextFormat() const
|
||||
{
|
||||
return text_format_;
|
||||
|
|
|
|||
Loading…
Reference in New Issue