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.

93 lines
3.1 KiB

  1. /* Initialization of the UI */
  2. function initGui() {
  3. /* Fetching and init of the painting zone */
  4. PaintApp.elements.canvas = document.getElementById('paint-canvas');
  5. PaintApp.elements.canvas.style.height = parseInt(window.innerHeight) - 55 + "px";
  6. PaintApp.elements.canvas.style.width = parseInt(window.innerWidth) + "px";
  7. paper.setup(PaintApp.elements.canvas);
  8. /* We are using paper.Tool to register to onMouseDown / onMouseDrag / onMouseUp */
  9. PaintApp.data.tool = new paper.Tool();
  10. PaintApp.data.tool.distanceThreshold = 0;
  11. /* Calling initGui of our modes */
  12. PaintApp.modes.Text.initGui();
  13. PaintApp.modes.Eraser.initGui();
  14. PaintApp.modes.Pen.initGui();
  15. PaintApp.modes.Bucket.initGui();
  16. PaintApp.modes.Stamp.initGui();
  17. PaintApp.modes.Copy.initGui();
  18. PaintApp.modes.Paste.initGui();
  19. /* Calling initGui of our palettes */
  20. PaintApp.palettes.filtersPalette.initGui();
  21. PaintApp.palettes.drawingsPalette.initGui();
  22. PaintApp.palettes.colorPalette.initGui();
  23. /* Enabling the presence palette */
  24. initPresencePalette();
  25. /* Calling initGui of our buttons */
  26. PaintApp.buttons.sizeButton.initGui();
  27. PaintApp.buttons.clearButton.initGui();
  28. PaintApp.buttons.undoButton.initGui();
  29. PaintApp.buttons.redoButton.initGui();
  30. PaintApp.buttons.insertImageButton.initGui();
  31. /* Refreshing undo / redo */
  32. PaintApp.displayUndoRedoButtons();
  33. /* Selecting the pen tool */
  34. PaintApp.elements.penButton.click();
  35. PaintApp.switchMode("Pen");
  36. /* Scrolling top prevent any overflow */
  37. window.scrollTo(0, -1000);
  38. /* Registering onResize function to handle window size changes */
  39. window.onresize = onResize;
  40. PaintApp.clearCanvas();
  41. }
  42. /* When onResize, update the attributes width and height used by paperJS */
  43. function onResize() {
  44. return;
  45. var canvas = PaintApp.elements.canvas;
  46. try {
  47. var image = canvas.toDataURL();
  48. } catch (e) {
  49. return;
  50. }
  51. PaintApp.elements.canvas.style.height = parseInt(window.innerHeight) - 55 + "px";
  52. PaintApp.elements.canvas.style.width = parseInt(window.innerWidth) + "px";
  53. PaintApp.elements.canvas.setAttribute("width", PaintApp.elements.canvas.getBoundingClientRect().width);
  54. PaintApp.elements.canvas.setAttribute("height", parseInt(window.innerHeight) - 55);
  55. var ctx = canvas.getContext('2d');
  56. var img = new Image();
  57. img.onload = function() {
  58. ctx.save();
  59. ctx.setTransform(1, 0, 0, 1, 0, 0);
  60. ctx.clearRect(0, 0, canvas.style.width, canvas.style.height);
  61. ctx.drawImage(img, 0, 0);
  62. ctx.restore();
  63. };
  64. img.src = image;
  65. }
  66. /* Initialization of the presence palette */
  67. function initPresencePalette() {
  68. var networkButton = document.getElementById("network-button");
  69. presencepalette = new PaintApp.palettes.presencePalette.PresencePalette(networkButton, undefined);
  70. presencepalette.addEventListener('shared', PaintApp.collaboration.shareActivity);
  71. // Launched with a shared id, activity is already shared
  72. if (window.top && window.top.sugar && window.top.sugar.environment && window.top.sugar.environment.sharedId) {
  73. PaintApp.collaboration.shareActivity();
  74. presencepalette.setShared(true);
  75. }
  76. }