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.

57 lines
1.7 KiB

  1. define(function () {
  2. 'use strict';
  3. var grid = {};
  4. // Add a grid overlay with lines spaced by subcellSize, for visual
  5. // debugging. This is useful while doing the activity layout or
  6. // while developing widgets.
  7. grid.addGrid = function (subcellSize) {
  8. var canvas = document.createElement('canvas');
  9. canvas.className = "grid";
  10. document.body.appendChild(canvas);
  11. var updateGrid = function () {
  12. canvas.width = window.innerWidth;
  13. canvas.height = window.innerHeight;
  14. var ctx = canvas.getContext("2d");
  15. ctx.strokeStyle = "#00FFFF";
  16. var subcellsVertical = window.innerHeight / subcellSize;
  17. for (i = 0; i < subcellsVertical; i++) {
  18. if ((i + 1) % 5 === 0) {
  19. ctx.lineWidth = 1;
  20. } else {
  21. ctx.lineWidth = 0.5;
  22. }
  23. ctx.beginPath();
  24. ctx.moveTo(0, subcellSize * (i + 1));
  25. ctx.lineTo(canvas.width, subcellSize * (i + 1));
  26. ctx.stroke();
  27. }
  28. var subcellsHorizontal = window.innerWidth / subcellSize;
  29. for (i = 0; i < subcellsHorizontal; i++) {
  30. if ((i + 1) % 5 === 0) {
  31. ctx.lineWidth = 1;
  32. } else {
  33. ctx.lineWidth = 0.5;
  34. }
  35. ctx.beginPath();
  36. ctx.moveTo(subcellSize * (i + 1), 0);
  37. ctx.lineTo(subcellSize * (i + 1), canvas.height);
  38. ctx.stroke();
  39. }
  40. };
  41. updateGrid();
  42. window.onresize = function (event) {
  43. updateGrid();
  44. };
  45. };
  46. return grid;
  47. });