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.

85 lines
3.0 KiB

  1. //Copyright (c) 2013, Playful Invention Company.
  2. //Permission is hereby granted, free of charge, to any person obtaining a copy
  3. //of this software and associated documentation files (the "Software"), to deal
  4. //in the Software without restriction, including without limitation the rights
  5. //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6. //copies of the Software, and to permit persons to whom the Software is
  7. //furnished to do so, subject to the following conditions:
  8. //The above copyright notice and this permission notice shall be included in
  9. //all copies or substantial portions of the Software.
  10. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  16. //THE SOFTWARE.
  17. // -----
  18. // GridPaint has been kept extremely minimal as an explicit design choice.
  19. // If you want to add features please make a fork with a different name.
  20. // Thanks in advance
  21. var onStart, onMove, onEnd;
  22. var zoom;
  23. var touchScreen = false;
  24. function eventInit(){
  25. touchScreen = ("ontouchstart" in document.documentElement);
  26. if (touchScreen) {
  27. document.getElementById("canvas").addEventListener("touchstart", evMousedown, false);
  28. frame.addEventListener("touchmove", evMousemove, false);
  29. frame.addEventListener("touchend", evMouseup, false);
  30. } else {
  31. document.getElementById("canvas").onmousedown = evMousedown;
  32. frame.onmousemove = evMousemove;
  33. frame.onmouseup = evMouseup;
  34. }
  35. var wsize = document.body.clientHeight-55;
  36. zoom = wsize/748;
  37. document.getElementById("canvas").style.zoom = zoom;
  38. var useragent = navigator.userAgent.toLowerCase();
  39. if (useragent.indexOf('chrome') == -1) {
  40. document.getElementById("canvas").style.MozTransform = "scale("+zoom+")";
  41. document.getElementById("canvas").style.MozTransformOrigin = "0 0";
  42. document.getElementById("canvas").style.width = "1024px";
  43. document.getElementById("canvas").style.height = "748px";
  44. }
  45. }
  46. function evMousedown(e){
  47. e.preventDefault();
  48. if (touchScreen) e = e.touches[0];
  49. var x=localx(e.clientX), y=localy(e.clientY);
  50. onStart(x,y);
  51. // HACK: Force refresh on Android
  52. if (/Android/i.test(navigator.userAgent) && document.location.protocol.substr(0,4) != "http") {
  53. cnv.style.display='none';
  54. cnv.offsetHeight;
  55. cnv.style.display='block';
  56. }
  57. }
  58. function evMousemove(e){
  59. e.preventDefault();
  60. if (touchScreen) e = e.touches[0];
  61. if(!onMove) return;
  62. var x=localx(e.clientX), y=localy(e.clientY);
  63. onMove(x,y);
  64. }
  65. function evMouseup(e){
  66. e.preventDefault();
  67. if(!onEnd) return;
  68. onEnd();
  69. }
  70. function localx(gx){return (gx/zoom-frame.getBoundingClientRect().left);}
  71. function localy(gy){
  72. return (gy/zoom-frame.getBoundingClientRect().top);
  73. }