SGradient.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { SColor, SGradientStop, SPoint } from "./";
  2. /**
  3. * 渐变颜色节点
  4. *
  5. * @author 庞利祥(sybotan@126.com)
  6. */
  7. export abstract class SGradient {
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. // 属性定义
  10. /** 起点 */
  11. start = new SPoint();
  12. /** 结束点 */
  13. end = new SPoint();
  14. /** 起点X坐标 */
  15. get x1(): number {
  16. return this.start.x;
  17. } // Get x1
  18. set x1(value: number) {
  19. this.start.x = value;
  20. } // Set x1
  21. /** 起点Y坐标 */
  22. get y1(): number {
  23. return this.start.y;
  24. } // Get y1
  25. set y1(value: number) {
  26. this.start.y = value;
  27. } // Set y1
  28. /** 终点X坐标 */
  29. get x2(): number {
  30. return this.end.x;
  31. } // Get x2
  32. set x2(value: number) {
  33. this.end.x = value;
  34. } // Set x2
  35. /** 终点Y坐标 */
  36. get y2(): number {
  37. return this.end.y;
  38. } // Get y2
  39. set y2(value: number) {
  40. this.end.y = value;
  41. } // Set y2
  42. /** 渐变颜色节点列表 */
  43. stopList: SGradientStop[] = [];
  44. /**
  45. * 添加渐变颜色节点
  46. *
  47. * @param pos 位置[0-1]
  48. * @param color 颜色
  49. */
  50. addColorStop(pos: number, color: SColor): void {
  51. this.stopList.push(new SGradientStop(pos, color));
  52. } // Function addColorStop()
  53. /**
  54. * 设置起点坐标
  55. *
  56. * @param x X坐标
  57. * @param y Y坐标
  58. */
  59. setStart(x: number, y: number): void {
  60. this.start.x = x;
  61. this.start.y = y;
  62. } // Function setStart()
  63. /**
  64. * 设置终点坐标
  65. *
  66. * @param x X坐标
  67. * @param y Y坐标
  68. */
  69. setEnd(x: number, y: number): void {
  70. this.end.x = x;
  71. this.end.y = y;
  72. } // Function setEnd()
  73. } // Class SGradientStop