Add StrokeStyle
This commit is contained in:
parent
f9598f3856
commit
8547397cc6
|
|
@ -138,6 +138,7 @@
|
|||
<ClCompile Include="..\..\src\kiwano\renderer\Geometry.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\renderer\GeometrySink.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\renderer\GifImage.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\renderer\StrokeStyle.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\renderer\Texture.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\renderer\TextureCache.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\renderer\LayerArea.cpp" />
|
||||
|
|
|
|||
|
|
@ -476,5 +476,8 @@
|
|||
<ClCompile Include="..\..\src\kiwano\2d\Button.cpp">
|
||||
<Filter>2d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\renderer\StrokeStyle.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -27,7 +27,7 @@ namespace kiwano
|
|||
Canvas::Canvas()
|
||||
: cache_expired_(false)
|
||||
, stroke_width_(1.0f)
|
||||
, stroke_style_(StrokeStyle::Miter)
|
||||
, stroke_style_()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ namespace kiwano
|
|||
/// \~chinese
|
||||
/// @brief 设置轮廓样式
|
||||
/// @param stroke_style 轮廓样式
|
||||
void SetStrokeStyle(StrokeStyle stroke_style);
|
||||
void SetStrokeStyle(const StrokeStyle& stroke_style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字画刷样式
|
||||
|
|
@ -289,7 +289,7 @@ namespace kiwano
|
|||
stroke_width_ = std::max(width, 0.f);
|
||||
}
|
||||
|
||||
inline void Canvas::SetStrokeStyle(StrokeStyle stroke_style)
|
||||
inline void Canvas::SetStrokeStyle(const StrokeStyle& stroke_style)
|
||||
{
|
||||
stroke_style_ = stroke_style;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace kiwano
|
|||
{
|
||||
ShapeActor::ShapeActor()
|
||||
: stroke_width_(1.f)
|
||||
, stroke_style_(StrokeStyle::Miter)
|
||||
, stroke_style_()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ namespace kiwano
|
|||
stroke_width_ = std::max(width, 0.f);
|
||||
}
|
||||
|
||||
void ShapeActor::SetStrokeStyle(StrokeStyle stroke_style)
|
||||
void ShapeActor::SetStrokeStyle(const StrokeStyle& stroke_style)
|
||||
{
|
||||
stroke_style_ = stroke_style;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 삿혤窟係湳駕
|
||||
StrokeStyle SetStrokeStyle() const;
|
||||
const StrokeStyle& GetStrokeStyle() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 삿혤近榴
|
||||
|
|
@ -113,7 +113,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief <20>零窟係湳駕
|
||||
void SetStrokeStyle(StrokeStyle stroke_style);
|
||||
void SetStrokeStyle(const StrokeStyle& stroke_style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief <20>零섯부近榴
|
||||
|
|
@ -378,25 +378,25 @@ namespace kiwano
|
|||
fill_brush_->SetColor(color);
|
||||
}
|
||||
|
||||
inline void ShapeActor::SetFillBrush(BrushPtr brush) { fill_brush_ = brush; }
|
||||
inline void ShapeActor::SetStrokeBrush(BrushPtr brush) { stroke_brush_ = brush; }
|
||||
inline BrushPtr ShapeActor::GetFillBrush() const { return fill_brush_; }
|
||||
inline BrushPtr ShapeActor::GetStrokeBrush() const { return stroke_brush_; }
|
||||
inline float ShapeActor::GetStrokeWidth() const { return stroke_width_; }
|
||||
inline StrokeStyle ShapeActor::SetStrokeStyle() const { return stroke_style_; }
|
||||
inline Geometry ShapeActor::GetGeometry() const { return geo_; }
|
||||
inline void ShapeActor::SetFillBrush(BrushPtr brush) { fill_brush_ = brush; }
|
||||
inline void ShapeActor::SetStrokeBrush(BrushPtr brush) { stroke_brush_ = brush; }
|
||||
inline BrushPtr ShapeActor::GetFillBrush() const { return fill_brush_; }
|
||||
inline BrushPtr ShapeActor::GetStrokeBrush() const { return stroke_brush_; }
|
||||
inline float ShapeActor::GetStrokeWidth() const { return stroke_width_; }
|
||||
inline const StrokeStyle& ShapeActor::GetStrokeStyle() const { return stroke_style_; }
|
||||
inline Geometry ShapeActor::GetGeometry() const { return geo_; }
|
||||
|
||||
inline Point const& LineActor::GetBeginPoint() const { return begin_; }
|
||||
inline Point const& LineActor::GetEndPoint() const { return end_; }
|
||||
inline void LineActor::SetBeginPoint(Point const& begin) { SetLine(begin, end_); }
|
||||
inline void LineActor::SetEndPoint(Point const& end) { SetLine(begin_, end); }
|
||||
inline Point const& LineActor::GetBeginPoint() const { return begin_; }
|
||||
inline Point const& LineActor::GetEndPoint() const { return end_; }
|
||||
inline void LineActor::SetBeginPoint(Point const& begin) { SetLine(begin, end_); }
|
||||
inline void LineActor::SetEndPoint(Point const& end) { SetLine(begin_, end); }
|
||||
|
||||
inline Size const& RectActor::GetRectSize() const { return rect_size_; }
|
||||
inline Size const& RectActor::GetRectSize() const { return rect_size_; }
|
||||
|
||||
inline Vec2 RoundRectActor::GetRadius() const { return radius_; }
|
||||
inline Size RoundRectActor::GetRectSize() const { return GetSize(); }
|
||||
inline Vec2 RoundRectActor::GetRadius() const { return radius_; }
|
||||
inline Size RoundRectActor::GetRectSize() const { return GetSize(); }
|
||||
|
||||
inline float CircleActor::GetRadius() const { return radius_; }
|
||||
inline float CircleActor::GetRadius() const { return radius_; }
|
||||
|
||||
inline Vec2 EllipseActor::GetRadius() const { return radius_; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,6 +94,8 @@ namespace kiwano
|
|||
|
||||
if (text_layout_.GetDirtyFlag() & TextLayout::DirtyFlag::Updated)
|
||||
{
|
||||
text_layout_.SetDirtyFlag(TextLayout::DirtyFlag::Clean);
|
||||
|
||||
if (show_underline_)
|
||||
text_layout_.SetUnderline(true, 0, text_layout_.GetText().length());
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字描边线相交样式
|
||||
void SetOutlineStroke(StrokeStyle outline_stroke);
|
||||
void SetOutlineStroke(const StrokeStyle& outline_stroke);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否显示下划线(默认值为 false)
|
||||
|
|
@ -295,7 +295,7 @@ namespace kiwano
|
|||
text_layout_.SetOutlineWidth(outline_width);
|
||||
}
|
||||
|
||||
inline void TextActor::SetOutlineStroke(StrokeStyle outline_stroke)
|
||||
inline void TextActor::SetOutlineStroke(const StrokeStyle& outline_stroke)
|
||||
{
|
||||
text_layout_.SetOutlineStroke(outline_stroke);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,53 +59,11 @@ namespace kiwano
|
|||
Resize(reinterpret_cast<const Size&>(GetRenderTarget()->GetSize()));
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
ComPtr<ID2D1StrokeStyle> miter_stroke_style;
|
||||
ComPtr<ID2D1StrokeStyle> bevel_stroke_style;
|
||||
ComPtr<ID2D1StrokeStyle> round_stroke_style;
|
||||
|
||||
D2D1_STROKE_STYLE_PROPERTIES stroke_style = D2D1::StrokeStyleProperties(
|
||||
D2D1_CAP_STYLE_FLAT,
|
||||
D2D1_CAP_STYLE_FLAT,
|
||||
D2D1_CAP_STYLE_FLAT,
|
||||
D2D1_LINE_JOIN_MITER,
|
||||
2.0f,
|
||||
D2D1_DASH_STYLE_SOLID,
|
||||
0.0f
|
||||
);
|
||||
|
||||
hr = factory->CreateStrokeStyle(stroke_style, nullptr, 0, &miter_stroke_style);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
stroke_style.lineJoin = D2D1_LINE_JOIN_BEVEL;
|
||||
hr = factory->CreateStrokeStyle(stroke_style, nullptr, 0, &bevel_stroke_style);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
stroke_style.lineJoin = D2D1_LINE_JOIN_ROUND;
|
||||
hr = factory->CreateStrokeStyle(stroke_style, nullptr, 0, &round_stroke_style);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
miter_stroke_style_ = miter_stroke_style;
|
||||
bevel_stroke_style_ = bevel_stroke_style;
|
||||
round_stroke_style_ = round_stroke_style;
|
||||
}
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
void RenderTarget::DiscardDeviceResources()
|
||||
{
|
||||
miter_stroke_style_.reset();
|
||||
bevel_stroke_style_.reset();
|
||||
round_stroke_style_.reset();
|
||||
|
||||
text_renderer_.reset();
|
||||
render_target_.reset();
|
||||
current_brush_.reset();
|
||||
|
|
@ -140,7 +98,7 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
void RenderTarget::DrawGeometry(Geometry const& geometry, float stroke_width, StrokeStyle stroke)
|
||||
void RenderTarget::DrawGeometry(Geometry const& geometry, float stroke_width, const StrokeStyle& stroke)
|
||||
{
|
||||
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
|
||||
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
|
||||
|
|
@ -151,7 +109,7 @@ namespace kiwano
|
|||
geometry.GetGeometry().get(),
|
||||
current_brush_->GetBrush().get(),
|
||||
stroke_width,
|
||||
GetStrokeStyle(stroke).get()
|
||||
stroke.GetStrokeStyle().get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
|
|
@ -174,7 +132,7 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
void RenderTarget::DrawLine(Point const& point1, Point const& point2, float stroke_width, StrokeStyle stroke)
|
||||
void RenderTarget::DrawLine(Point const& point1, Point const& point2, float stroke_width, const StrokeStyle& stroke)
|
||||
{
|
||||
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
|
||||
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
|
||||
|
|
@ -184,13 +142,13 @@ namespace kiwano
|
|||
DX::ConvertToPoint2F(point2),
|
||||
current_brush_->GetBrush().get(),
|
||||
stroke_width,
|
||||
GetStrokeStyle(stroke).get()
|
||||
stroke.GetStrokeStyle().get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
}
|
||||
|
||||
void RenderTarget::DrawRectangle(Rect const& rect, float stroke_width, StrokeStyle stroke)
|
||||
void RenderTarget::DrawRectangle(Rect const& rect, float stroke_width, const StrokeStyle& stroke)
|
||||
{
|
||||
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
|
||||
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
|
||||
|
|
@ -199,7 +157,7 @@ namespace kiwano
|
|||
DX::ConvertToRectF(rect),
|
||||
current_brush_->GetBrush().get(),
|
||||
stroke_width,
|
||||
GetStrokeStyle(stroke).get()
|
||||
stroke.GetStrokeStyle().get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
|
|
@ -218,7 +176,7 @@ namespace kiwano
|
|||
IncreasePrimitivesCount();
|
||||
}
|
||||
|
||||
void RenderTarget::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, float stroke_width, StrokeStyle stroke)
|
||||
void RenderTarget::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, float stroke_width, const StrokeStyle& stroke)
|
||||
{
|
||||
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
|
||||
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
|
||||
|
|
@ -231,7 +189,7 @@ namespace kiwano
|
|||
),
|
||||
current_brush_->GetBrush().get(),
|
||||
stroke_width,
|
||||
GetStrokeStyle(stroke).get()
|
||||
stroke.GetStrokeStyle().get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
|
|
@ -254,7 +212,7 @@ namespace kiwano
|
|||
IncreasePrimitivesCount();
|
||||
}
|
||||
|
||||
void RenderTarget::DrawEllipse(Point const& center, Vec2 const& radius, float stroke_width, StrokeStyle stroke)
|
||||
void RenderTarget::DrawEllipse(Point const& center, Vec2 const& radius, float stroke_width, const StrokeStyle& stroke)
|
||||
{
|
||||
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
|
||||
KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!");
|
||||
|
|
@ -267,7 +225,7 @@ namespace kiwano
|
|||
),
|
||||
current_brush_->GetBrush().get(),
|
||||
stroke_width,
|
||||
GetStrokeStyle(stroke).get()
|
||||
stroke.GetStrokeStyle().get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
|
|
@ -346,7 +304,7 @@ namespace kiwano
|
|||
fill_brush.get(),
|
||||
outline_brush.get(),
|
||||
style.outline_width,
|
||||
GetStrokeStyle(style.outline_stroke).get()
|
||||
style.outline_stroke.GetStrokeStyle().get()
|
||||
);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
|
|
@ -449,17 +407,6 @@ namespace kiwano
|
|||
render_target_->Clear(DX::ConvertToColorF(clear_color));
|
||||
}
|
||||
|
||||
ComPtr<ID2D1StrokeStyle> RenderTarget::GetStrokeStyle(StrokeStyle style)
|
||||
{
|
||||
switch (style)
|
||||
{
|
||||
case StrokeStyle::Miter: return miter_stroke_style_;
|
||||
case StrokeStyle::Bevel: return bevel_stroke_style_;
|
||||
case StrokeStyle::Round: return round_stroke_style_;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RenderTarget::SetTransform(const Matrix3x2& matrix)
|
||||
{
|
||||
KGE_ASSERT(render_target_ && "Render target has not been initialized!");
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ namespace kiwano
|
|||
void DrawGeometry(
|
||||
Geometry const& geometry,
|
||||
float stroke_width,
|
||||
StrokeStyle stroke = StrokeStyle::Miter
|
||||
const StrokeStyle& stroke = StrokeStyle()
|
||||
);
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -92,7 +92,7 @@ namespace kiwano
|
|||
Point const& point1,
|
||||
Point const& point2,
|
||||
float stroke_width,
|
||||
StrokeStyle stroke = StrokeStyle::Miter
|
||||
const StrokeStyle& stroke = StrokeStyle()
|
||||
);
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -100,7 +100,7 @@ namespace kiwano
|
|||
void DrawRectangle(
|
||||
Rect const& rect,
|
||||
float stroke_width,
|
||||
StrokeStyle stroke = StrokeStyle::Miter
|
||||
const StrokeStyle& stroke = StrokeStyle()
|
||||
);
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -115,7 +115,7 @@ namespace kiwano
|
|||
Rect const& rect,
|
||||
Vec2 const& radius,
|
||||
float stroke_width,
|
||||
StrokeStyle stroke = StrokeStyle::Miter
|
||||
const StrokeStyle& stroke = StrokeStyle()
|
||||
);
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -131,7 +131,7 @@ namespace kiwano
|
|||
Point const& center,
|
||||
Vec2 const& radius,
|
||||
float stroke_width,
|
||||
StrokeStyle stroke = StrokeStyle::Miter
|
||||
const StrokeStyle& stroke = StrokeStyle()
|
||||
);
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -288,8 +288,6 @@ namespace kiwano
|
|||
|
||||
ComPtr<ITextRenderer> GetTextRenderer() const;
|
||||
|
||||
ComPtr<ID2D1StrokeStyle> GetStrokeStyle(StrokeStyle style);
|
||||
|
||||
private:
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨É豸ÒÀÀµ×ÊÔ´
|
||||
|
|
@ -310,9 +308,6 @@ namespace kiwano
|
|||
TextAntialiasMode text_antialias_;
|
||||
ComPtr<ITextRenderer> text_renderer_;
|
||||
ComPtr<ID2D1RenderTarget> render_target_;
|
||||
ComPtr<ID2D1StrokeStyle> miter_stroke_style_;
|
||||
ComPtr<ID2D1StrokeStyle> bevel_stroke_style_;
|
||||
ComPtr<ID2D1StrokeStyle> round_stroke_style_;
|
||||
BrushPtr current_brush_;
|
||||
Rect visible_size_;
|
||||
Matrix3x2 global_transform_;
|
||||
|
|
|
|||
|
|
@ -968,6 +968,38 @@ namespace kiwano
|
|||
win32::ThrowIfFailed(hr);
|
||||
}
|
||||
|
||||
void Renderer::CreateStrokeStyle(StrokeStyle& stroke_style, CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size, float dash_offset)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
if (!d2d_res_)
|
||||
{
|
||||
hr = E_UNEXPECTED;
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
D2D1_STROKE_STYLE_PROPERTIES style = D2D1::StrokeStyleProperties(
|
||||
D2D1_CAP_STYLE(cap),
|
||||
D2D1_CAP_STYLE(cap),
|
||||
D2D1_CAP_STYLE(cap),
|
||||
D2D1_LINE_JOIN(line_join),
|
||||
10.0f,
|
||||
D2D1_DASH_STYLE_CUSTOM,
|
||||
dash_offset
|
||||
);
|
||||
|
||||
ComPtr<ID2D1StrokeStyle> output;
|
||||
hr = d2d_res_->GetFactory()->CreateStrokeStyle(style, dash_array, dash_size, &output);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
stroke_style.SetStrokeStyle(output);
|
||||
}
|
||||
}
|
||||
|
||||
win32::ThrowIfFailed(hr);
|
||||
}
|
||||
|
||||
void Renderer::SetDpi(float dpi)
|
||||
{
|
||||
KGE_ASSERT(d3d_res_ && d2d_res_);
|
||||
|
|
|
|||
|
|
@ -258,6 +258,23 @@ namespace kiwano
|
|||
RadialGradientStyle const& style
|
||||
);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线条样式
|
||||
/// @param[out] stroke_style 线条样式
|
||||
/// @param[in] cap 线段端点样式
|
||||
/// @param[in] line_join 线段相交样式
|
||||
/// @param[in] dash_array 虚线长度与间隙数组
|
||||
/// @param[in] dash_size 虚线数组大小
|
||||
/// @param[in] dash_offset 虚线偏移量
|
||||
void CreateStrokeStyle(
|
||||
StrokeStyle& stroke_style,
|
||||
CapStyle cap,
|
||||
LineJoinStyle line_join,
|
||||
const float* dash_array,
|
||||
size_t dash_size,
|
||||
float dash_offset
|
||||
);
|
||||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief »ñȡĿ±ê´°¿Ú
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
// Copyright (c) 2016-2019 Kiwano - Nomango
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include <kiwano/renderer/StrokeStyle.h>
|
||||
#include <kiwano/renderer/Renderer.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
StrokeStyle::StrokeStyle()
|
||||
{
|
||||
}
|
||||
|
||||
StrokeStyle StrokeStyle::Create(CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset)
|
||||
{
|
||||
switch (dash)
|
||||
{
|
||||
case DashStyle::Solid:
|
||||
{
|
||||
return StrokeStyle::Create(cap, line_join, nullptr, 0, dash_offset);
|
||||
}
|
||||
|
||||
case DashStyle::Dash:
|
||||
{
|
||||
float dash_array[] = { 2, 2 };
|
||||
return StrokeStyle::Create(cap, line_join, dash_array, dash_offset);
|
||||
}
|
||||
|
||||
case DashStyle::Dot:
|
||||
{
|
||||
float dash_array[] = { 0, 2 };
|
||||
return StrokeStyle::Create(cap, line_join, dash_array, dash_offset);
|
||||
}
|
||||
|
||||
case DashStyle::DashDot:
|
||||
{
|
||||
float dash_array[] = { 2, 2, 0, 2 };
|
||||
return StrokeStyle::Create(cap, line_join, dash_array, dash_offset);
|
||||
}
|
||||
|
||||
case DashStyle::DashDotDot:
|
||||
{
|
||||
float dash_array[] = { 2, 2, 0, 2, 0, 2 };
|
||||
return StrokeStyle::Create(cap, line_join, dash_array, dash_offset);
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return StrokeStyle();
|
||||
}
|
||||
|
||||
StrokeStyle StrokeStyle::Create(CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size, float dash_offset)
|
||||
{
|
||||
StrokeStyle stroke_style;
|
||||
Renderer::instance().CreateStrokeStyle(stroke_style, cap, line_join, dash_array, dash_size, dash_offset);
|
||||
return stroke_style;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,23 +19,119 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/renderer/win32/D2DDeviceResources.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
class RenderTarget;
|
||||
class Renderer;
|
||||
|
||||
/**
|
||||
* \addtogroup Render
|
||||
* @{
|
||||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 线条样式
|
||||
/// @details 线条样式表示渲染目标在绘制线条时,如何处理两条线相交部分
|
||||
enum class StrokeStyle
|
||||
/// @brief 线条端点样式
|
||||
/// @details 线条端点样式表示线段端点部分的形状
|
||||
enum class CapStyle
|
||||
{
|
||||
Miter = 0, ///< 斜切样式
|
||||
Bevel = 1, ///< 斜角样式
|
||||
Round = 2 ///< 圆角样式
|
||||
Flat, ///< 扁端点
|
||||
Square, ///< 方形端点,方形突出部分等于线段宽度的一半
|
||||
Round, ///< 圆形端点,圆直径等于线段宽度
|
||||
Triangle, ///< 三角样式,三角斜边长度等于线段宽度
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 线条交点样式
|
||||
/// @details 线条交点样式表示两条线相交部分的形状
|
||||
enum class LineJoinStyle
|
||||
{
|
||||
Miter, ///< 斜切样式
|
||||
Bevel, ///< 斜角样式
|
||||
Round ///< 圆角样式
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 线条虚线样式
|
||||
/// @details 线条虚线样式表示线段的间隙
|
||||
enum class DashStyle
|
||||
{
|
||||
Solid, ///< 无间断的实线
|
||||
Dash, ///< 斜角样式
|
||||
Dot, ///< 圆角样式
|
||||
DashDot, ///< 圆角样式
|
||||
DashDotDot, ///< 圆角样式
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 线条样式
|
||||
class StrokeStyle
|
||||
{
|
||||
friend class RenderTarget;
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
StrokeStyle();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线条样式
|
||||
/// @param cap 线条端点样式
|
||||
/// @param line_join 线条交点样式
|
||||
/// @param dash 线条虚线样式
|
||||
/// @param dash_offset 线条虚线偏移量
|
||||
static StrokeStyle Create(CapStyle cap, LineJoinStyle line_join = LineJoinStyle::Miter, DashStyle dash = DashStyle::Solid, float dash_offset = 0.0f);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线条样式
|
||||
/// @param cap 线条端点样式
|
||||
/// @param line_join 线条交点样式
|
||||
/// @param dash_array 线条虚线的长度与间隙数组
|
||||
/// @param dash_size 线条虚线数组大小
|
||||
/// @param dash_offset 线条虚线偏移量
|
||||
static StrokeStyle Create(CapStyle cap, LineJoinStyle line_join = LineJoinStyle::Miter, const float* dash_array = nullptr, size_t dash_size = 0, float dash_offset = 0.0f);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线条样式
|
||||
/// @tparam _DashSize 线条虚线数组大小
|
||||
/// @param cap 线条端点样式
|
||||
/// @param line_join 线条交点样式
|
||||
/// @param dash_array 线条虚线的长度与间隙数组
|
||||
/// @param dash_offset 线条虚线偏移量
|
||||
template <size_t _DashSize>
|
||||
static StrokeStyle Create(CapStyle cap, LineJoinStyle line_join = LineJoinStyle::Miter, float(&dash_array)[_DashSize] = nullptr, float dash_offset = 0.0f)
|
||||
{
|
||||
return StrokeStyle::Create(cap, line_join, dash_array, _DashSize, dash_offset);
|
||||
}
|
||||
|
||||
private:
|
||||
ComPtr<ID2D1StrokeStyle> GetStrokeStyle() const;
|
||||
|
||||
void SetStrokeStyle(ComPtr<ID2D1StrokeStyle> style);
|
||||
|
||||
private:
|
||||
ComPtr<ID2D1StrokeStyle> style_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
inline bool StrokeStyle::IsValid() const
|
||||
{
|
||||
return true; // Always valid
|
||||
}
|
||||
|
||||
inline ComPtr<ID2D1StrokeStyle> StrokeStyle::GetStrokeStyle() const
|
||||
{
|
||||
return style_;
|
||||
}
|
||||
|
||||
inline void StrokeStyle::SetStrokeStyle(ComPtr<ID2D1StrokeStyle> style)
|
||||
{
|
||||
style_ = style;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字描边线相交样式
|
||||
void SetOutlineStroke(StrokeStyle outline_stroke);
|
||||
void SetOutlineStroke(const StrokeStyle& outline_stroke);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置下划线
|
||||
|
|
@ -261,7 +261,7 @@ namespace kiwano
|
|||
style_.outline_width = outline_width;
|
||||
}
|
||||
|
||||
inline void TextLayout::SetOutlineStroke(StrokeStyle outline_stroke)
|
||||
inline void TextLayout::SetOutlineStroke(const StrokeStyle& outline_stroke)
|
||||
{
|
||||
style_.outline_stroke = outline_stroke;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ namespace kiwano
|
|||
BrushPtr fill_brush; ///< Ìî³ä»Ë¢
|
||||
BrushPtr outline_brush; ///< Ãè±ß»Ë¢
|
||||
float outline_width; ///< Ãè±ßÏß¿í
|
||||
StrokeStyle outline_stroke; ///< Ãè±ßÏßÏཻÑùʽ
|
||||
StrokeStyle outline_stroke; ///< Ãè±ßÏßÑùʽ
|
||||
|
||||
public:
|
||||
/**
|
||||
|
|
@ -116,7 +116,7 @@ namespace kiwano
|
|||
, wrap_width(0)
|
||||
, line_spacing(0)
|
||||
, outline_width(1.0f)
|
||||
, outline_stroke(StrokeStyle::Round)
|
||||
, outline_stroke()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue