Kiwano Engine v1.3.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
35enum class CapStyle
36{
37 Flat,
38 Square,
39 Round,
40 Triangle,
41};
42
46enum class LineJoinStyle
47{
48 Miter,
49 Bevel,
50 Round
51};
52
56enum class DashStyle
57{
58 Solid,
59 Dash,
60 Dot,
61 DashDot,
63};
64
68{
69public:
76
84 StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset = 0.0f);
85
94 StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size,
95 float dash_offset = 0.0f);
96
105 template <size_t _DashSize>
106 StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, float (&dash_array)[_DashSize],
107 float dash_offset = 0.0f)
108 : StrokeStyle(width, cap, line_join, dash_array, _DashSize, dash_offset)
109 {
110 }
111
112 StrokeStyle();
113
116 float GetWidth() const;
117
120 CapStyle GetCapStyle() const;
121
125
128 const Vector<float>& GetDashArray() const;
129
132 float GetDashOffset() const;
133
137 void SetWidth(float width);
138
141 void SetCapStyle(CapStyle cap);
142
145 void SetLineJoinStyle(LineJoinStyle line_join);
146
150 void SetDashStyle(DashStyle dash_style);
151
155 void SetDashStyle(const Vector<float>& dash_array);
156
161 void SetDashStyle(const float* dash_array, size_t dash_size);
162
167 template <size_t _DashSize>
168 inline void SetDashStyle(float (&dash_array)[_DashSize])
169 {
170 SetDashStyle(dash_array, _DashSize);
171 }
172
176 void SetDashOffset(float dash_offset);
177
178private:
179 CapStyle cap_;
180 LineJoinStyle line_join_;
181 float stroke_width_;
182 float dash_offset_;
183 Vector<float> dash_array_;
184};
185
188inline float StrokeStyle::GetWidth() const
189{
190 return stroke_width_;
191}
192
194{
195 return cap_;
196}
197
199{
200 return line_join_;
201}
202
203inline const Vector<float>& StrokeStyle::GetDashArray() const
204{
205 return dash_array_;
206}
207
208inline float StrokeStyle::GetDashOffset() const
209{
210 return dash_offset_;
211}
212
213inline void StrokeStyle::SetWidth(float width)
214{
215 stroke_width_ = width;
216}
217
219{
220 cap_ = cap;
221}
222
224{
225 line_join_ = line_join;
226}
227
228inline void StrokeStyle::SetDashOffset(float dash_offset)
229{
230 dash_offset_ = dash_offset;
231}
232
233} // namespace kiwano
含有本地指针的对象
Definition: NativeObject.hpp:32
线条样式
Definition: StrokeStyle.h:68
float GetDashOffset() const
获取虚线偏移量
Definition: StrokeStyle.h:208
void SetDashStyle(DashStyle dash_style)
设置虚线样式
Definition: StrokeStyle.cpp:60
float GetWidth() const
获取线条宽度
Definition: StrokeStyle.h:188
StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, float(&dash_array)[_DashSize], float dash_offset=0.0f)
创建线条样式
Definition: StrokeStyle.h:106
void SetDashOffset(float dash_offset)
设置虚线偏移量
Definition: StrokeStyle.h:228
void SetCapStyle(CapStyle cap)
设置线条端点样式
Definition: StrokeStyle.h:218
CapStyle GetCapStyle() const
获取线条端点样式
Definition: StrokeStyle.h:193
void SetLineJoinStyle(LineJoinStyle line_join)
设置线条交点样式
Definition: StrokeStyle.h:223
LineJoinStyle GetLineJoinStyle() const
获取线条交点样式
Definition: StrokeStyle.h:198
void SetDashStyle(float(&dash_array)[_DashSize])
设置虚线样式
Definition: StrokeStyle.h:168
void SetWidth(float width)
设置线条宽度
Definition: StrokeStyle.h:213
const Vector< float > & GetDashArray() const
获取线条虚线的长度与间隙数组
Definition: StrokeStyle.h:203
CapStyle
线条端点样式
Definition: StrokeStyle.h:36
LineJoinStyle
线条交点样式
Definition: StrokeStyle.h:47
DashStyle
线条虚线样式
Definition: StrokeStyle.h:57
@ Triangle
三角样式,三角斜边长度等于线段宽度
@ Flat
扁端点
@ Round
圆形端点,圆直径等于线段宽度
@ Square
方形端点,方形突出部分等于线段宽度的一半
@ Bevel
斜角样式
@ Miter
斜切样式
@ Dash
斜角样式
@ Dot
圆角样式
@ DashDotDot
圆角样式
@ Solid
无间断的实线
@ DashDot
圆角样式