线条样式对象
在 HiEasyX 中,线条样式对象指的是 HXLineStyle 对象:HXLineStyle 对象定义在 include/impl/hex_impl.h 下。大致定义如下:
HX_IMPL_API struct HXLineStyle {
HXColInt Thickness = 1;
HXLineShapeStyle Shape = HXLineShapeStyle::Solid;
};
| 变量 | 含义 | 默认取值 |
|---|---|---|
| Thickness | 线条的粗细,值越大,线条越粗,否则反之 | 1 |
| Shape | 线条的形状,值为 HXLineShapeStyle 枚举类 | HXLineShapeStyle::Solid |
线条形状枚举类
HXLineShapeStyle 枚举类的定义如下:
enum class HXLineShapeStyle {
Solid, Dash, Dotted, DashDotted
};
| 值 | 含义 |
|---|---|
| Solid | 填充的正常线条 |
| Dash | 虚线条 |
| Dotted | 点状线条 |
| DashDotted | 点、虚线交替的线条 |
示例代码
以下代码展示了不同形状的直线的具体视觉效果:
HXLineStyle style;
style.Thickness = 3;
style.Shape = HXLineShapeStyle::Solid;
Painter->DrawLineStyled({0, 0 * 4}, {60, 30 * 4}, HXColor{255, 255, 255, 255}, style);
style.Shape = HXLineShapeStyle::Dash;
Painter->DrawLineStyled({0, 20 * 4}, {60, 50 * 4}, HXColor{255, 255, 255, 255}, style);
style.Shape = HXLineShapeStyle::Dotted;
Painter->DrawLineStyled({0, 40 * 4}, {60, 70 * 4}, HXColor{255, 255, 255, 255}, style);
style.Shape = HXLineShapeStyle::DashDotted;
Painter->DrawLineStyled({0, 60 * 4}, {60, 90 * 4}, HXColor{255, 255, 255, 255}, style);
运行结果如下图,从上到下分别 HXLineShapeStyle::Solid、HXLineShapeStyle::Dash、HXLineShapeStyle::Dotted、HXLineShapeStyle::DashDotted: