SGraphyImageItem.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * 图片
  3. *
  4. *
  5. */
  6. import SGraphyItem from '../../node-templete/SGraphy/SGraphyItem'
  7. import SRect from '../../node-templete/SGraphy/types/SRect'
  8. export default class SGraphyImageItem extends SGraphyItem {
  9. /**
  10. * 构造函数
  11. *
  12. * @param width 图片宽度
  13. * @param height 图片高度
  14. * @param url 图片url
  15. * @param id point的Id
  16. * @param X 图片向x轴的偏移量
  17. * @param Y 图片向y轴的偏移量
  18. * @param downUrl 图片按下时的url
  19. * @param parent 指向父元素
  20. */
  21. constructor(width, height, url, id, X, Y, downUrl, parent = null) {
  22. super(parent)
  23. this.width = width
  24. this.height = height
  25. this.url = url
  26. this.id = id
  27. this.X = X
  28. this.Y = Y
  29. this.downUrl = downUrl
  30. this.imgFalg = false
  31. this.img = new Image()
  32. this.img.src = this.url
  33. this.img.style.width = this.width
  34. this.img.style.height = this.height
  35. this.canMove = true
  36. this.type = 1
  37. } //constructor
  38. /**
  39. * Item对象边界区域
  40. *
  41. * @return SRect
  42. */
  43. boundingRect() {
  44. return new SRect(0, 0, this.width * 100, this.height * 100)
  45. } // Function boundingRect()
  46. /**
  47. * 绘制图片
  48. *
  49. * @param canvas 画布
  50. * @param rect 绘制区域
  51. */
  52. onDraw(canvas, rect) {
  53. // canvas.moveTo(this.X, this.Y)
  54. // canvas.drawImage(this.img, 0, 0, this.width, this.height, this.X, this.Y, this.width * 100, this.height * 100)
  55. canvas.drawImage(this.img, 0, 0, this.width, this.height, 0, 0, this.width * 100, this.height * 100)
  56. }
  57. }