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.

88 lines
3.6 KiB

  1. /* Start of the app, we require everything that is needed */
  2. define(["sugar-web/activity/activity","activity/paint-activity","activity/paint-app","sugar-web/graphics/presencepalette","activity/palettes/color-palette","activity/palettes/stamp-palette","activity/palettes/text-palette","activity/palettes/drawings-palette","activity/palettes/filters-palette","activity/buttons/size-button","activity/buttons/clear-button","activity/buttons/undo-button","activity/buttons/redo-button","activity/modes/modes-pen","activity/modes/modes-eraser","activity/modes/modes-bucket","activity/modes/modes-text","activity/modes/modes-stamp","activity/modes/modes-copy","activity/modes/modes-paste","activity/collaboration","activity/buttons/insertimage-button"], function (activity,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21) {
  3. window.PaintApp = p2;
  4. PaintApp.libs.activity = activity;
  5. /* Fetching and storing of the palettes */
  6. PaintApp.palettes.presencePalette = p3;
  7. PaintApp.palettes.colorPalette = p4;
  8. PaintApp.palettes.stampPalette = p5;
  9. PaintApp.palettes.textPalette = p6;
  10. PaintApp.palettes.drawingsPalette = p7;
  11. PaintApp.palettes.filtersPalette = p8;
  12. /* Fetching and storing of the buttons */
  13. PaintApp.buttons.sizeButton = p9;
  14. PaintApp.buttons.clearButton = p10;
  15. PaintApp.buttons.undoButton = p11;
  16. PaintApp.buttons.redoButton = p12;
  17. PaintApp.buttons.insertImageButton = p21;
  18. /* Fetching and storing of the modes */
  19. PaintApp.modes.Pen = p13;
  20. PaintApp.modes.Eraser = p14;
  21. PaintApp.modes.Bucket = p15;
  22. PaintApp.modes.Text = p16;
  23. PaintApp.modes.Stamp = p17;
  24. PaintApp.modes.Copy = p18;
  25. PaintApp.modes.Paste = p19;
  26. PaintApp.collaboration = p20;
  27. requirejs(['domReady!', 'sugar-web/datastore', 'paper-core', 'mustache', 'lzstring', 'humane'], function(doc, datastore, _paper, mustache, lzstring, humane) {
  28. /* Fetching and storing libraries */
  29. PaintApp.libs.mustache = mustache;
  30. PaintApp.libs.humane = humane;
  31. PaintApp.libs.lzstring = lzstring;
  32. //Setup of the activity
  33. activity.setup();
  34. /* Fetch and store UI elements */
  35. initGui();
  36. document.getElementById("stop-button").addEventListener('click', function(event) {
  37. var data = {
  38. width: PaintApp.elements.canvas.width / window.devicePixelRatio,
  39. height: PaintApp.elements.canvas.height / window.devicePixelRatio,
  40. src: PaintApp.collaboration.compress(PaintApp.elements.canvas.toDataURL())
  41. }
  42. var jsonData = JSON.stringify(data);
  43. activity.getDatastoreObject().setDataAsText(jsonData);
  44. activity.getDatastoreObject().save(function(error) {});
  45. });
  46. //Fetch of the history if not starting shared
  47. if (!window.top.sugar || !window.top.sugar.environment || !window.top.sugar.environment.sharedId) {
  48. activity.getDatastoreObject().loadAsText(function(error, metadata, jsonData) {
  49. if (jsonData == null) {
  50. return;
  51. }
  52. var data = JSON.parse(jsonData);
  53. PaintApp.clearCanvas();
  54. img = new Image();
  55. img.onload = function() {
  56. PaintApp.elements.canvas.getContext('2d').drawImage(img, 0, 0, data.width, data.height);
  57. PaintApp.saveCanvas();
  58. };
  59. img.src = PaintApp.collaboration.decompress(data.src);
  60. //DISPLAY
  61. });
  62. }
  63. // If starting in shared mode, we disable undo/redo
  64. if (window.top && window.top.sugar && window.top.sugar.environment && window.top.sugar.environment.sharedId) {
  65. PaintApp.data.isHost = false;
  66. PaintApp.buttons.undoButton.hideGui();
  67. PaintApp.buttons.redoButton.hideGui();
  68. PaintApp.displayUndoRedoButtons();
  69. PaintApp.collaboration.shareActivity();
  70. }
  71. });
  72. });