Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * WHITEBOPHIR
  3. *********************************************************
  4. * @licstart The following is the entire license notice for the
  5. * JavaScript code in this page.
  6. *
  7. * Copyright (C) 2020 Ophir LOJKINE
  8. *
  9. *
  10. * The JavaScript code in this page is free software: you can
  11. * redistribute it and/or modify it under the terms of the GNU
  12. * General Public License (GNU GPL) as published by the Free Software
  13. * Foundation, either version 3 of the License, or (at your option)
  14. * any later version. The code is distributed WITHOUT ANY WARRANTY;
  15. * without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  17. *
  18. * As additional permission under GNU GPL version 3 section 7, you
  19. * may distribute non-source (e.g., minimized or compacted) forms of
  20. * that code without the copy of the GNU GPL normally required by
  21. * section 4, provided you include this license notice and a URL
  22. * through which recipients can access the Corresponding Source.
  23. *
  24. * @licend
  25. */
  26. (function grid() { //Code isolation
  27. var index = 0; //grid off by default
  28. var states = ["none", "url(#grid)", "url(#dots)"];
  29. function toggleGrid(evt) {
  30. index = (index + 1) % states.length;
  31. gridContainer.setAttributeNS(null, "fill", states[index]);
  32. }
  33. function createPatterns() {
  34. // create patterns
  35. // small (inner) grid
  36. var smallGrid = Tools.createSVGElement("pattern", {
  37. id: "smallGrid",
  38. width: "30",
  39. height: "30",
  40. patternUnits: "userSpaceOnUse"
  41. });
  42. smallGrid.appendChild(
  43. Tools.createSVGElement("path", {
  44. d: "M 30 0 L 0 0 0 30",
  45. fill: "none",
  46. stroke: "gray",
  47. 'stroke-width': "0.5"
  48. })
  49. );
  50. // (outer) grid
  51. var grid = Tools.createSVGElement("pattern", {
  52. id: "grid",
  53. width: "300",
  54. height: "300",
  55. patternUnits: "userSpaceOnUse"
  56. });
  57. grid.appendChild(Tools.createSVGElement("rect", {
  58. width: "300",
  59. height: "300",
  60. fill: "url(#smallGrid)"
  61. }));
  62. grid.appendChild(
  63. Tools.createSVGElement("path", {
  64. d: "M 300 0 L 0 0 0 300",
  65. fill: "none",
  66. stroke: "gray", 'stroke-width': "1"
  67. })
  68. );
  69. // dots
  70. var dots = Tools.createSVGElement("pattern", {
  71. id: "dots",
  72. width: "30",
  73. height: "30",
  74. x: "-10",
  75. y: "-10",
  76. patternUnits: "userSpaceOnUse"
  77. });
  78. dots.appendChild(Tools.createSVGElement("circle", {
  79. fill: "gray",
  80. cx: "10",
  81. cy: "10",
  82. r: "2"
  83. }));
  84. var defs = Tools.svg.getElementById("defs");
  85. defs.appendChild(smallGrid);
  86. defs.appendChild(grid);
  87. defs.appendChild(dots);
  88. }
  89. var gridContainer = (function init() {
  90. // initialize patterns
  91. createPatterns();
  92. // create grid container
  93. var gridContainer = Tools.createSVGElement("rect", {
  94. id: "gridContainer",
  95. width: "100%", height: "100%",
  96. fill: states[index]
  97. });
  98. Tools.svg.insertBefore(gridContainer, Tools.drawingArea);
  99. return gridContainer;
  100. })();
  101. Tools.add({ //The new tool
  102. "name": "Grid",
  103. "shortcut": "g",
  104. "listeners": {},
  105. "icon": "tools/grid/icon.svg",
  106. "oneTouch": true,
  107. "onstart": toggleGrid,
  108. "mouseCursor": "crosshair",
  109. });
  110. })(); //End of code isolation