number-bucket-tool.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import NumberEditLayer from './number-edit-layer';
  2. import NumberEditTool from './number-edit-tool';
  3. import { FillTask, FILL_TYPE } from '../common/filltask';
  4. export default class BucketTool extends NumberEditTool {
  5. fastfill: boolean;
  6. constructor(numberEditLayer) {
  7. super(numberEditLayer, 'number-edit-bucket', 'url("/static/cursor/cursor-fill-color.png") 24 24, default');
  8. this.setProp('fastfill', true);
  9. }
  10. isFastfillEnabled() { return this.getProp('fastfill'); }
  11. isFastfilled() { }
  12. override onclick(evt: MouseEvent) {
  13. if (!this.numberEditLayer) return;
  14. if (this.fastfill) return;
  15. console.log('BucketTool@onclick');
  16. let task = new FillTask(FILL_TYPE.SOLID);
  17. // let task = new FillTask(FillTask.FILL_TYPE_LINEAR_GRADIENT);
  18. // let task = new FillTask(FillTask.FILL_TYPE_RADIAL_GRADIENT);
  19. task.color = this.numberEditLayer.color;
  20. //task.color = Utils.randomColor();
  21. //task.textureImage = this.getProp('textureImage');
  22. //task.textureImage = null;
  23. let pp = this.numberEditLayer.translate(evt._contentPoint);
  24. task.x = pp.x;
  25. task.y = pp.y;
  26. this.numberEditLayer.fill(task);
  27. }
  28. override onmousedown(evt: MouseEvent) {
  29. console.log('BucketTool@onmousedown()');
  30. if (!this.numberEditLayer)
  31. return;
  32. this.fastfill = false;
  33. }
  34. override onmouseup(evt: MouseEvent) { console.log('BucketTool@onmouseup()'); }
  35. override onDragStart(evt: MouseEvent) {
  36. if (!this.numberEditLayer)
  37. return;
  38. console.log('BucketTool@onDragStart()');
  39. if (!this.isFastfillEnabled())
  40. return;
  41. this.fastfill = true;
  42. let task = new FillTask(FILL_TYPE.SOLID);
  43. task.color = this.numberEditLayer.color;
  44. let pp = this.numberEditLayer.translate(evt._contentPoint);
  45. task.x = pp.x;
  46. task.y = pp.y;
  47. this.numberEditLayer.fastfillStart(task);
  48. }
  49. override onDragMove(evt: MouseEvent) {
  50. console.log('ondragmove......');
  51. if (!this.numberEditLayer)
  52. return;
  53. console.log('BucketTool@onDragMove()');
  54. if (!this.isFastfillEnabled())
  55. return;
  56. let pp = this.numberEditLayer.translate(evt._contentPoint);
  57. this.numberEditLayer.fastfillAddPoint(pp.x, pp.y);
  58. }
  59. override onDragEnd(evt: MouseEvent) {
  60. if (!this.numberEditLayer)
  61. return;
  62. if (!this.isFastfillEnabled())
  63. return;
  64. console.log('BucketTool@onDragEnd()');
  65. this.numberEditLayer.fastfillEnd();
  66. }
  67. override onSelect(): void {
  68. if (!this.numberEditLayer) return;
  69. this.numberEditLayer.showUnorderMask = false;
  70. this.numberEditLayer.invalidate();
  71. }
  72. }