SBrush.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { SBrushType } from "./enums/SBrushType";
  2. import { SColor, SGradient } from "./";
  3. /**
  4. * 画刷
  5. *
  6. * @author 庞利祥(sybotan@126.com)
  7. */
  8. export class SBrush {
  9. /** 画笔类型 */
  10. type: SBrushType = SBrushType.Color;
  11. /** 画刷颜色 */
  12. private _color = SColor.Black;
  13. get color(): SColor {
  14. return this._color;
  15. } // Get color
  16. set color(value: SColor) {
  17. this.type = SBrushType.Color;
  18. this._color = value;
  19. } // Set color
  20. /** 画刷渐变 */
  21. private _gradient: SGradient | null = null;
  22. get gradient(): SGradient | null {
  23. return this._gradient;
  24. } // Get gradient
  25. set gradient(value: SGradient | null) {
  26. this._gradient = value;
  27. this.type = SBrushType.Gradient;
  28. } // Set gradient
  29. /**
  30. * 构造函数
  31. */
  32. constructor();
  33. /**
  34. * 构造函数
  35. *
  36. * @param brush 画刷
  37. */
  38. constructor(brush: SBrush);
  39. /**
  40. * 构造函数
  41. *
  42. * @param color 颜色
  43. */
  44. constructor(color: SColor);
  45. /**
  46. * 构造函数
  47. *
  48. * @param gradient 过渡
  49. */
  50. constructor(gradient: SGradient);
  51. /**
  52. * 构造函数(重载实现)
  53. *
  54. * @param brush 画笔
  55. */
  56. constructor(brush?: SColor | SGradient | SBrush) {
  57. if (brush == undefined) {
  58. return;
  59. }
  60. // 如果是渐变类型
  61. if (brush instanceof SGradient) {
  62. this.gradient = brush;
  63. } else if (brush instanceof SBrush) {
  64. this.type = brush.type;
  65. this.color = new SColor(brush.color);
  66. } else {
  67. this.color = new SColor(brush);
  68. }
  69. } // Constructor()
  70. } // Class SBrush