not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

  1. /* Eraser mode is like pen mode but with #fff color */
  2. define([], function() {
  3. function initGui() {
  4. PaintApp.elements.eraserButton = document.getElementById('eraser-button');
  5. PaintApp.paletteModesButtons.push(PaintApp.elements.eraserButton);
  6. PaintApp.elements.eraserButton.addEventListener('click', function() {
  7. PaintApp.paletteRemoveActiveClass();
  8. PaintApp.addActiveClassToElement(PaintApp.elements.eraserButton);
  9. PaintApp.switchMode('Eraser');
  10. });
  11. }
  12. var Eraser = {
  13. initGui: initGui,
  14. onMouseDown: function(event) {
  15. PaintApp.modes.Eraser.point = event.point;
  16. var ctx = PaintApp.elements.canvas.getContext('2d');
  17. /* We draw a single point on mouse down */
  18. ctx.beginPath();
  19. ctx.strokeStyle = '#fff';
  20. ctx.lineCap = 'round';
  21. ctx.lineWidth = PaintApp.data.size;
  22. ctx.moveTo(event.point.x + 1, event.point.y + 1);
  23. ctx.lineTo(event.point.x, event.point.y);
  24. ctx.stroke();
  25. /* If the activity is shared, we send the point to everyone */
  26. if (PaintApp.data.isShared) {
  27. PaintApp.collaboration.sendMessage({
  28. action: 'path',
  29. data: {
  30. lineWidth: PaintApp.data.size,
  31. lineCap: 'round',
  32. strokeStyle: '#fff',
  33. from: {
  34. x: event.point.x + 1,
  35. y: event.point.y + 1
  36. },
  37. to: {
  38. x: event.point.x,
  39. y: event.point.y
  40. }
  41. }
  42. });
  43. }
  44. },
  45. onMouseDrag: function(event) {
  46. if (!PaintApp.modes.Eraser.point) {
  47. return;
  48. }
  49. var ctx = PaintApp.elements.canvas.getContext('2d');
  50. /* We draw the move between points on mouse drag */
  51. ctx.beginPath();
  52. ctx.strokeStyle = '#fff';
  53. ctx.lineCap = 'round';
  54. ctx.lineWidth = PaintApp.data.size;
  55. ctx.moveTo(PaintApp.modes.Eraser.point.x, PaintApp.modes.Eraser.point.y);
  56. ctx.lineTo(event.point.x, event.point.y);
  57. ctx.stroke();
  58. /* If the activity is shared, we send the move to everyone */
  59. if (PaintApp.data.isShared) {
  60. PaintApp.collaboration.sendMessage({
  61. action: 'path',
  62. data: {
  63. lineWidth: PaintApp.data.size,
  64. lineCap: 'round',
  65. strokeStyle: '#fff',
  66. from: {
  67. x: event.point.x + 1,
  68. y: event.point.y + 1
  69. },
  70. to: {
  71. x: event.point.x,
  72. y: event.point.y
  73. }
  74. }
  75. });
  76. }
  77. PaintApp.modes.Eraser.point = event.point;
  78. },
  79. onMouseUp: function(event) {
  80. PaintApp.saveCanvas();
  81. }
  82. };
  83. return Eraser;
  84. });