()
| 776 | } |
| 777 | |
| 778 | function inputRender() |
| 779 | { |
| 780 | touchGamepadRender(); |
| 781 | |
| 782 | function touchGamepadRender() |
| 783 | { |
| 784 | if (!touchInputEnable || !isTouchDevice || headlessMode) return; |
| 785 | if (!touchGamepadEnable || !touchGamepadTimer.isSet() && touchGamepadDisplayTime) return; |
| 786 | |
| 787 | // fade off when not touching or paused |
| 788 | const alpha = touchGamepadDisplayTime ? percent(touchGamepadTimer.get(), touchGamepadDisplayTime+1, touchGamepadDisplayTime) : 1; |
| 789 | if (!alpha || paused) return; |
| 790 | |
| 791 | // setup the canvas |
| 792 | const context = mainContext; |
| 793 | context.save(); |
| 794 | context.globalAlpha = alpha*touchGamepadAlpha; |
| 795 | context.strokeStyle = '#fff'; |
| 796 | context.lineWidth = 3; |
| 797 | |
| 798 | // draw left analog stick |
| 799 | const leftTouchStick = touchGamepadSticks[0] ?? vec2(); |
| 800 | context.fillStyle = leftTouchStick.lengthSquared() > 0 ? '#fff' : '#000'; |
| 801 | context.beginPath(); |
| 802 | const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize); |
| 803 | if (touchGamepadAnalog) |
| 804 | { |
| 805 | // draw circle shaped gamepad |
| 806 | context.arc(stickCenter.x, stickCenter.y, touchGamepadSize/2, 0, 9); |
| 807 | } |
| 808 | else |
| 809 | { |
| 810 | // draw cross shaped gamepad |
| 811 | for (let i=10; --i;) |
| 812 | { |
| 813 | const angle = i*PI/4; |
| 814 | context.arc(stickCenter.x, stickCenter.y,touchGamepadSize*.6, angle + PI/8, angle + PI/8); |
| 815 | i%2 && context.arc(stickCenter.x, stickCenter.y, touchGamepadSize*.33, angle, angle); |
| 816 | } |
| 817 | } |
| 818 | context.fill(); |
| 819 | context.stroke(); |
| 820 | |
| 821 | // draw right face buttons |
| 822 | { |
| 823 | const buttonCenter = touchGamepadButtonCenter(); |
| 824 | const buttonSize = touchGamepadButtonCount > 1 ? |
| 825 | touchGamepadSize/4 : touchGamepadSize/2; |
| 826 | for (let i=0; i<touchGamepadButtonCount; i++) |
| 827 | { |
| 828 | const j = mod(i-1, 4); |
| 829 | let button = touchGamepadButtonCount > 2 ? |
| 830 | j : min(j, touchGamepadButtonCount-1); |
| 831 | // fix button locations (swap 2 and 3 to match gamepad layout) |
| 832 | button = button === 3 ? 2 : button === 2 ? 3 : button; |
| 833 | const pos = touchGamepadButtonCount < 2 ? buttonCenter : |
| 834 | buttonCenter.add(vec2().setDirection(j, touchGamepadSize/2)); |
| 835 | context.fillStyle = touchGamepadButtons[button] ? '#fff' : '#000'; |
no test coverage detected