diff --git a/joy.html b/joy.html index 5f24cc8..c40f9dd 100644 --- a/joy.html +++ b/joy.html @@ -73,7 +73,12 @@ border: 1px solid #0000FF; } - +
diff --git a/joy.js b/joy.js index 09608c4..dbd1bcd 100644 --- a/joy.js +++ b/joy.js @@ -1,48 +1,5 @@ /* - * Name : joy.js - * @author : Roberto D'Amico (Bobboteck) - * Last modified : 09.06.2020 - * Revision : 1.1.6 - * - * Modification History: - * Date Version Modified By Description - * 2021-12-21 2.0.0 Roberto D'Amico New version of the project that integrates the callback functions, while - * maintaining compatibility with previous versions. Fixed Issue #27 too, - * thanks to @artisticfox8 for the suggestion. - * 2020-06-09 1.1.6 Roberto D'Amico Fixed Issue #10 and #11 - * 2020-04-20 1.1.5 Roberto D'Amico Correct: Two sticks in a row, thanks to @liamw9534 for the suggestion - * 2020-04-03 Roberto D'Amico Correct: InternalRadius when change the size of canvas, thanks to - * @vanslipon for the suggestion - * 2020-01-07 1.1.4 Roberto D'Amico Close #6 by implementing a new parameter to set the functionality of - * auto-return to 0 position - * 2019-11-18 1.1.3 Roberto D'Amico Close #5 correct indication of East direction - * 2019-11-12 1.1.2 Roberto D'Amico Removed Fix #4 incorrectly introduced and restored operation with touch - * devices - * 2019-11-12 1.1.1 Roberto D'Amico Fixed Issue #4 - Now JoyStick work in any position in the page, not only - * at 0,0 - * - * The MIT License (MIT) - * - * This file is part of the JoyStick Project (https://github.com/bobboteck/JoyStick). - * Copyright (c) 2015 Roberto D'Amico (Bobboteck). - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * @author Roberto D'Amico (Bobboteck) https://github.com/bobboteck/JoyStick/blob/master/joy.js */ let StickStatus = @@ -115,19 +72,14 @@ var JoyStick = (function(container, parameters, callback) var movedX=centerX; var movedY=centerY; - // Check if the device support the touch or not - if("ontouchstart" in document.documentElement) - { - canvas.addEventListener("touchstart", onTouchStart, false); - document.addEventListener("touchmove", onTouchMove, false); - document.addEventListener("touchend", onTouchEnd, false); - } - else - { - canvas.addEventListener("mousedown", onMouseDown, false); - document.addEventListener("mousemove", onMouseMove, false); - document.addEventListener("mouseup", onMouseUp, false); - } + canvas.addEventListener("touchstart", onTouchStart, false); + document.addEventListener("touchmove", onTouchMove, false); + document.addEventListener("touchend", onTouchEnd, false); + + canvas.addEventListener("mousedown", onMouseDown, false); + document.addEventListener("mousemove", onMouseMove, false); + document.addEventListener("mouseup", onMouseUp, false); + // Draw the object drawExternal(); drawInternal(); diff --git a/joy.min.js b/joy.min.js index 98c4e7f..21ec4ec 100644 --- a/joy.min.js +++ b/joy.min.js @@ -1,47 +1,4 @@ /* - * Name : joy.js - * @author : Roberto D'Amico (Bobboteck) - * Last modified : 09.06.2020 - * Revision : 1.1.6 - * - * Modification History: - * Date Version Modified By Description - * 2021-12-21 2.0.0 Roberto D'Amico New version of the project that integrates the callback functions, while - * maintaining compatibility with previous versions. Fixed Issue #27 too, - * thanks to @artisticfox8 for the suggestion. - * 2020-06-09 1.1.6 Roberto D'Amico Fixed Issue #10 and #11 - * 2020-04-20 1.1.5 Roberto D'Amico Correct: Two sticks in a row, thanks to @liamw9534 for the suggestion - * 2020-04-03 Roberto D'Amico Correct: InternalRadius when change the size of canvas, thanks to - * @vanslipon for the suggestion - * 2020-01-07 1.1.4 Roberto D'Amico Close #6 by implementing a new parameter to set the functionality of - * auto-return to 0 position - * 2019-11-18 1.1.3 Roberto D'Amico Close #5 correct indication of East direction - * 2019-11-12 1.1.2 Roberto D'Amico Removed Fix #4 incorrectly introduced and restored operation with touch - * devices - * 2019-11-12 1.1.1 Roberto D'Amico Fixed Issue #4 - Now JoyStick work in any position in the page, not only - * at 0,0 - * - * The MIT License (MIT) - * - * This file is part of the JoyStick Project (https://github.com/bobboteck/JoyStick). - * Copyright (c) 2015 Roberto D'Amico (Bobboteck). - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * @author Roberto D'Amico (Bobboteck) https://github.com/bobboteck/JoyStick/blob/master/joy.js */ -let StickStatus={xPosition:0,yPosition:0,x:0,y:0,cardinalDirection:"C"};var JoyStick=function(t,e,i){var o=void 0===(e=e||{}).title?"joystick":e.title,n=void 0===e.width?0:e.width,a=void 0===e.height?0:e.height,r=void 0===e.internalFillColor?"#00AA00":e.internalFillColor,c=void 0===e.internalLineWidth?2:e.internalLineWidth,s=void 0===e.internalStrokeColor?"#003300":e.internalStrokeColor,d=void 0===e.externalLineWidth?2:e.externalLineWidth,u=void 0===e.externalStrokeColor?"#008000":e.externalStrokeColor,h=void 0===e.autoReturnToCenter||e.autoReturnToCenter;i=i||function(t){};var S=document.getElementById(t);S.style.touchAction="none";var f=document.createElement("canvas");f.id=o,0===n&&(n=S.clientWidth),0===a&&(a=S.clientHeight),f.width=n,f.height=a,S.appendChild(f);var l=f.getContext("2d"),k=0,g=2*Math.PI,x=(f.width-(f.width/2+10))/2,v=x+5,P=x+30,m=f.width/2,C=f.height/2,p=f.width/10,y=-1*p,w=f.height/10,L=-1*w,F=m,E=C;function W(){l.beginPath(),l.arc(m,C,P,0,g,!1),l.lineWidth=d,l.strokeStyle=u,l.stroke()}function T(){l.beginPath(),F