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.

95 lines
2.7 KiB

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