SPen.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { SColor, SLineCapStyle, SLineJoinStyle } from "./";
  2. /**
  3. * 画笔
  4. *
  5. * @author 庞利祥(sybotan@126.com)
  6. */
  7. export class SPen {
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. // 属性定义
  10. /** 画笔颜色 */
  11. color = SColor.Black;
  12. /** 线宽 */
  13. lineWidth = 1;
  14. /** 线段端点样式 */
  15. lineCapStyle = SLineCapStyle.Butt;
  16. /** 线段与线段间接合处的样式 */
  17. lineJoinStyle = SLineJoinStyle.Miter;
  18. /** 限制当两条线相交时交接处最大长度 (默认值是10.0)*/
  19. miterLimit = 10;
  20. /** 虚线样式 */
  21. lineDash: number[] | null = null;
  22. /** 虚线样式的起始偏移量 */
  23. dashOffset = 0;
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. // 构造函数
  26. /**
  27. * 构造函数
  28. */
  29. constructor();
  30. /**
  31. * 构造函数
  32. *
  33. * @param pen 画笔
  34. */
  35. constructor(pen: SPen);
  36. /**
  37. * 构造函数
  38. *
  39. * @param color 颜色
  40. * @param lineWidth 线宽
  41. */
  42. constructor(color: SColor, lineWidth?: number);
  43. /**
  44. * 构造函数
  45. *
  46. * @param color 颜色 | 画笔
  47. * @param lineWidth 线宽
  48. */
  49. constructor(color?: SColor | SPen, lineWidth?: number) {
  50. if (color == undefined) {
  51. return;
  52. }
  53. if (color instanceof SPen) {
  54. this.color = new SColor(color.color);
  55. this.lineWidth = color.lineWidth;
  56. this.lineCapStyle = color.lineCapStyle;
  57. this.lineJoinStyle = color.lineJoinStyle;
  58. this.miterLimit = color.miterLimit;
  59. this.dashOffset = color.dashOffset;
  60. this.lineDash =
  61. color.lineDash != null ? color.lineDash.slice() : null;
  62. } else {
  63. this.color = new SColor(color);
  64. this.lineWidth = lineWidth != undefined ? lineWidth : 1;
  65. }
  66. } // Constructor()
  67. } // Class SPen