Kiwano Engine v1.2.x
StrokeStyle.h
1// Copyright (c) 2016-2019 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/platform/NativeObject.hpp>
23
24namespace kiwano
25{
26
27KGE_DECLARE_SMART_PTR(StrokeStyle);
28
37enum class CapStyle
38{
39 Flat,
40 Square,
41 Round,
42 Triangle,
43};
44
48enum class LineJoinStyle
49{
50 Miter,
51 Bevel,
52 Round
53};
54
58enum class DashStyle
59{
60 Solid,
61 Dash,
62 Dot,
63 DashDot,
65};
66
70{
71public:
78
86 StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset = 0.0f);
87
96 StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size,
97 float dash_offset = 0.0f);
98
107 template <size_t _DashSize>
108 StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, float (&dash_array)[_DashSize],
109 float dash_offset = 0.0f)
110 : StrokeStyle(width, cap, line_join, dash_array, _DashSize, dash_offset)
111 {
112 }
113
114 StrokeStyle();
115
118 float GetWidth() const;
119
122 CapStyle GetCapStyle() const;
123
127
130 const Vector<float>& GetDashArray() const;
131
134 float GetDashOffset() const;
135
139 void SetWidth(float width);
140
143 void SetCapStyle(CapStyle cap);
144
147 void SetLineJoinStyle(LineJoinStyle line_join);
148
152 void SetDashStyle(DashStyle dash_style);
153
157 void SetDashStyle(const Vector<float>& dash_array);
158
163 void SetDashStyle(const float* dash_array, size_t dash_size);
164
169 template <size_t _DashSize>
170 inline void SetDashStyle(float (&dash_array)[_DashSize])
171 {
172 SetDashStyle(dash_array, _DashSize);
173 }
174
178 void SetDashOffset(float dash_offset);
179
180private:
181 CapStyle cap_;
182 LineJoinStyle line_join_;
183 float stroke_width_;
184 float dash_offset_;
185 Vector<float> dash_array_;
186};
187
190inline float StrokeStyle::GetWidth() const
191{
192 return stroke_width_;
193}
194
196{
197 return cap_;
198}
199
201{
202 return line_join_;
203}
204
205inline const Vector<float>& StrokeStyle::GetDashArray() const
206{
207 return dash_array_;
208}
209
210inline float StrokeStyle::GetDashOffset() const
211{
212 return dash_offset_;
213}
214
215inline void StrokeStyle::SetWidth(float width)
216{
217 stroke_width_ = width;
218}
219
221{
222 cap_ = cap;
223}
224
226{
227 line_join_ = line_join;
228}
229
230inline void StrokeStyle::SetDashOffset(float dash_offset)
231{
232 dash_offset_ = dash_offset;
233}
234
235} // namespace kiwano
含有本地指针的对象
Definition: NativeObject.hpp:34
线条样式
Definition: StrokeStyle.h:70
float GetDashOffset() const
获取虚线偏移量
Definition: StrokeStyle.h:210
void SetDashStyle(DashStyle dash_style)
设置虚线样式
Definition: StrokeStyle.cpp:60
float GetWidth() const
获取线条宽度
Definition: StrokeStyle.h:190
StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, float(&dash_array)[_DashSize], float dash_offset=0.0f)
创建线条样式
Definition: StrokeStyle.h:108
void SetDashOffset(float dash_offset)
设置虚线偏移量
Definition: StrokeStyle.h:230
void SetCapStyle(CapStyle cap)
设置线条端点样式
Definition: StrokeStyle.h:220
CapStyle GetCapStyle() const
获取线条端点样式
Definition: StrokeStyle.h:195
void SetLineJoinStyle(LineJoinStyle line_join)
设置线条交点样式
Definition: StrokeStyle.h:225
LineJoinStyle GetLineJoinStyle() const
获取线条交点样式
Definition: StrokeStyle.h:200
void SetDashStyle(float(&dash_array)[_DashSize])
设置虚线样式
Definition: StrokeStyle.h:170
void SetWidth(float width)
设置线条宽度
Definition: StrokeStyle.h:215
const Vector< float > & GetDashArray() const
获取线条虚线的长度与间隙数组
Definition: StrokeStyle.h:205
CapStyle
线条端点样式
Definition: StrokeStyle.h:38
LineJoinStyle
线条交点样式
Definition: StrokeStyle.h:49
DashStyle
线条虚线样式
Definition: StrokeStyle.h:59
@ Triangle
三角样式,三角斜边长度等于线段宽度
@ Flat
扁端点
@ Round
圆形端点,圆直径等于线段宽度
@ Square
方形端点,方形突出部分等于线段宽度的一半
@ Bevel
斜角样式
@ Miter
斜切样式
@ Dash
斜角样式
@ Dot
圆角样式
@ DashDotDot
圆角样式
@ Solid
无间断的实线
@ DashDot
圆角样式