From 425d13e14e60e6dfb36109a7bebf13472f58f0e8 Mon Sep 17 00:00:00 2001 From: kou_yeung Date: Wed, 15 May 2024 20:51:05 +0900 Subject: [PATCH 1/2] support WASM table ( #149 ) --- .../WebGLSupport/WebGLInput/WebGLInput.jslib | 26 +++++++++++++------ .../WebGLWindow/WebGLWindow.jslib | 22 +++++++++++----- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Assets/WebGLSupport/WebGLInput/WebGLInput.jslib b/Assets/WebGLSupport/WebGLInput/WebGLInput.jslib index 7b00374..ea065e7 100644 --- a/Assets/WebGLSupport/WebGLInput/WebGLInput.jslib +++ b/Assets/WebGLSupport/WebGLInput/WebGLInput.jslib @@ -1,9 +1,19 @@ var WebGLInput = { $instances: [], WebGLInputInit : function() { - // Remove the `Runtime` object from "v1.37.27: 12/24/2017" - // if Runtime not defined. create and add functon!! - if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall } + // use WebAssembly.Table : makeDynCall + // when enable. dynCall is undefined + if(typeof dynCall === "undefined") + { + // make Runtime.dynCall to undefined + Runtime = { dynCall : undefined } + } + else + { + // Remove the `Runtime` object from "v1.37.27: 12/24/2017" + // if Runtime not defined. create and add functon!! + if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall } + } }, WebGLInputCreate: function (canvasId, x, y, width, height, fontsize, text, placeholder, isMultiLine, isPassword, isHidden, isMobile) { @@ -102,7 +112,7 @@ var WebGLInput = { input.setSelectionRange(start + 1, start + 1); input.oninput(); // call oninput to exe ValueChange function!! } else { - Runtime.dynCall("vii", cb, [id, e.shiftKey ? -1 : 1]); + (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, e.shiftKey ? -1 : 1]) : {{{ makeDynCall("vii", "cb") }}}(id, e.shiftKey ? -1 : 1); } } }); @@ -114,13 +124,13 @@ var WebGLInput = { WebGLInputOnFocus: function (id, cb) { var input = instances[id]; input.onfocus = function () { - Runtime.dynCall("vi", cb, [id]); + (!!Runtime.dynCall) ? Runtime.dynCall("vi", cb, [id]) : {{{ makeDynCall("vi", "cb") }}}(id); }; }, WebGLInputOnBlur: function (id, cb) { var input = instances[id]; input.onblur = function () { - Runtime.dynCall("vi", cb, [id]); + (!!Runtime.dynCall) ? Runtime.dynCall("vi", cb, [id]) : {{{ makeDynCall("vi", "cb") }}}(id); }; }, WebGLInputIsFocus: function (id) { @@ -133,7 +143,7 @@ var WebGLInput = { var bufferSize = lengthBytesUTF8(returnStr) + 1; var buffer = _malloc(bufferSize); stringToUTF8(returnStr, buffer, bufferSize); - Runtime.dynCall("vii", cb, [id, buffer]); + (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, buffer]) : {{{ makeDynCall("vii", "cb") }}}(id, buffer); }; }, WebGLInputOnEditEnd:function(id, cb){ @@ -143,7 +153,7 @@ var WebGLInput = { var bufferSize = lengthBytesUTF8(returnStr) + 1; var buffer = _malloc(bufferSize); stringToUTF8(returnStr, buffer, bufferSize); - Runtime.dynCall("vii", cb, [id, buffer]); + (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, buffer]) : {{{ makeDynCall("vii", "cb") }}}(id, buffer); }; }, WebGLInputSelectionStart:function(id){ diff --git a/Assets/WebGLSupport/WebGLWindow/WebGLWindow.jslib b/Assets/WebGLSupport/WebGLWindow/WebGLWindow.jslib index b737da4..57c1aa9 100644 --- a/Assets/WebGLSupport/WebGLWindow/WebGLWindow.jslib +++ b/Assets/WebGLSupport/WebGLWindow/WebGLWindow.jslib @@ -1,8 +1,18 @@ var WebGLWindow = { WebGLWindowInit : function() { - // Remove the `Runtime` object from "v1.37.27: 12/24/2017" - // if Runtime not defined. create and add functon!! - if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall } + // use WebAssembly.Table : makeDynCall + // when enable. dynCall is undefined + if(typeof dynCall === "undefined") + { + // make Runtime.dynCall to undefined + Runtime = { dynCall : undefined } + } + else + { + // Remove the `Runtime` object from "v1.37.27: 12/24/2017" + // if Runtime not defined. create and add functon!! + if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall } + } }, WebGLWindowGetCanvasName: function() { var elements = document.getElementsByTagName('canvas'); @@ -23,17 +33,17 @@ var WebGLWindow = { }, WebGLWindowOnFocus: function (cb) { window.addEventListener('focus', function () { - Runtime.dynCall("v", cb, []); + (!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}(); }); }, WebGLWindowOnBlur: function (cb) { window.addEventListener('blur', function () { - Runtime.dynCall("v", cb, []); + (!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}(); }); }, WebGLWindowOnResize: function(cb) { window.addEventListener('resize', function () { - Runtime.dynCall("v", cb, []); + (!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}(); }); }, WebGLWindowInjectFullscreen : function () { From 9308d1cc78121b68d97b648a7cc4e1632a8203f2 Mon Sep 17 00:00:00 2001 From: kou_yeung Date: Wed, 15 May 2024 20:54:10 +0900 Subject: [PATCH 2/2] [ refactoring ] tab to space --- .../WebGLSupport/WebGLInput/WebGLInput.jslib | 238 +++++++++--------- .../WebGLWindow/WebGLWindow.jslib | 34 +-- 2 files changed, 136 insertions(+), 136 deletions(-) diff --git a/Assets/WebGLSupport/WebGLInput/WebGLInput.jslib b/Assets/WebGLSupport/WebGLInput/WebGLInput.jslib index ea065e7..877eea8 100644 --- a/Assets/WebGLSupport/WebGLInput/WebGLInput.jslib +++ b/Assets/WebGLSupport/WebGLInput/WebGLInput.jslib @@ -1,20 +1,20 @@ var WebGLInput = { $instances: [], - WebGLInputInit : function() { + WebGLInputInit : function() { // use WebAssembly.Table : makeDynCall // when enable. dynCall is undefined if(typeof dynCall === "undefined") { - // make Runtime.dynCall to undefined + // make Runtime.dynCall to undefined Runtime = { dynCall : undefined } } else { - // Remove the `Runtime` object from "v1.37.27: 12/24/2017" - // if Runtime not defined. create and add functon!! - if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall } + // Remove the `Runtime` object from "v1.37.27: 12/24/2017" + // if Runtime not defined. create and add functon!! + if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall } } - }, + }, WebGLInputCreate: function (canvasId, x, y, width, height, fontsize, text, placeholder, isMultiLine, isPassword, isHidden, isMobile) { var container = document.getElementById(UTF8ToString(canvasId)); @@ -27,99 +27,99 @@ var WebGLInput = { container = canvas.parentNode; } - if(canvas) - { - var scaleX = container.offsetWidth / canvas.width; - var scaleY = container.offsetHeight / canvas.height; + if(canvas) + { + var scaleX = container.offsetWidth / canvas.width; + var scaleY = container.offsetHeight / canvas.height; - if(scaleX && scaleY) - { - x *= scaleX; - width *= scaleX; - y *= scaleY; - height *= scaleY; - } - } + if(scaleX && scaleY) + { + x *= scaleX; + width *= scaleX; + y *= scaleY; + height *= scaleY; + } + } var input = document.createElement(isMultiLine?"textarea":"input"); input.style.position = "absolute"; - if(isMobile) { - input.style.bottom = 1 + "vh"; - input.style.left = 5 + "vw"; - input.style.width = 90 + "vw"; - input.style.height = (isMultiLine? 18 : 10) + "vh"; - input.style.fontSize = 5 + "vh"; - input.style.borderWidth = 5 + "px"; - input.style.borderColor = "#000000"; - } else { - input.style.top = y + "px"; - input.style.left = x + "px"; - input.style.width = width + "px"; - input.style.height = height + "px"; - input.style.fontSize = fontsize + "px"; - } + if(isMobile) { + input.style.bottom = 1 + "vh"; + input.style.left = 5 + "vw"; + input.style.width = 90 + "vw"; + input.style.height = (isMultiLine? 18 : 10) + "vh"; + input.style.fontSize = 5 + "vh"; + input.style.borderWidth = 5 + "px"; + input.style.borderColor = "#000000"; + } else { + input.style.top = y + "px"; + input.style.left = x + "px"; + input.style.width = width + "px"; + input.style.height = height + "px"; + input.style.fontSize = fontsize + "px"; + } - input.style.outlineWidth = 1 + 'px'; - input.style.opacity = isHidden?0:1; - input.style.resize = 'none'; // for textarea - input.style.padding = '0px 1px'; - input.style.cursor = "default"; - input.style.touchAction = 'none'; + input.style.outlineWidth = 1 + 'px'; + input.style.opacity = isHidden?0:1; + input.style.resize = 'none'; // for textarea + input.style.padding = '0px 1px'; + input.style.cursor = "default"; + input.style.touchAction = 'none'; - input.spellcheck = false; - input.value = UTF8ToString(text); - input.placeholder = UTF8ToString(placeholder); - input.style.outlineColor = 'black'; - - if(isPassword){ - input.type = 'password'; - } + input.spellcheck = false; + input.value = UTF8ToString(text); + input.placeholder = UTF8ToString(placeholder); + input.style.outlineColor = 'black'; + + if(isPassword){ + input.type = 'password'; + } - if(isMobile) { - document.body.appendChild(input); - } else { - container.appendChild(input); - } + if(isMobile) { + document.body.appendChild(input); + } else { + container.appendChild(input); + } return instances.push(input) - 1; }, - WebGLInputEnterSubmit: function(id, falg){ - var input = instances[id]; - // for enter key - input.addEventListener('keydown', function(e) { - if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) { - if(falg) - { - e.preventDefault(); - input.blur(); - } - } - }); - }, - WebGLInputTab:function(id, cb) { - var input = instances[id]; - // for tab key + WebGLInputEnterSubmit: function(id, falg){ + var input = instances[id]; + // for enter key + input.addEventListener('keydown', function(e) { + if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) { + if(falg) + { + e.preventDefault(); + input.blur(); + } + } + }); + }, + WebGLInputTab:function(id, cb) { + var input = instances[id]; + // for tab key input.addEventListener('keydown', function (e) { if ((e.which && e.which === 9) || (e.keyCode && e.keyCode === 9)) { e.preventDefault(); - // if enable tab text - if(input.enableTabText){ + // if enable tab text + if(input.enableTabText){ var val = input.value; var start = input.selectionStart; var end = input.selectionEnd; input.value = val.substr(0, start) + '\t' + val.substr(end, val.length); input.setSelectionRange(start + 1, start + 1); input.oninput(); // call oninput to exe ValueChange function!! - } else { - (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, e.shiftKey ? -1 : 1]) : {{{ makeDynCall("vii", "cb") }}}(id, e.shiftKey ? -1 : 1); - } + } else { + (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, e.shiftKey ? -1 : 1]) : {{{ makeDynCall("vii", "cb") }}}(id, e.shiftKey ? -1 : 1); + } } - }); - }, - WebGLInputFocus: function(id){ - var input = instances[id]; - input.focus(); + }); + }, + WebGLInputFocus: function(id){ + var input = instances[id]; + input.focus(); }, WebGLInputOnFocus: function (id, cb) { var input = instances[id]; @@ -133,66 +133,66 @@ var WebGLInput = { (!!Runtime.dynCall) ? Runtime.dynCall("vi", cb, [id]) : {{{ makeDynCall("vi", "cb") }}}(id); }; }, - WebGLInputIsFocus: function (id) { - return instances[id] === document.activeElement; - }, - WebGLInputOnValueChange:function(id, cb){ + WebGLInputIsFocus: function (id) { + return instances[id] === document.activeElement; + }, + WebGLInputOnValueChange:function(id, cb){ var input = instances[id]; input.oninput = function () { - var returnStr = input.value; - var bufferSize = lengthBytesUTF8(returnStr) + 1; - var buffer = _malloc(bufferSize); - stringToUTF8(returnStr, buffer, bufferSize); - (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, buffer]) : {{{ makeDynCall("vii", "cb") }}}(id, buffer); + var returnStr = input.value; + var bufferSize = lengthBytesUTF8(returnStr) + 1; + var buffer = _malloc(bufferSize); + stringToUTF8(returnStr, buffer, bufferSize); + (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, buffer]) : {{{ makeDynCall("vii", "cb") }}}(id, buffer); }; }, - WebGLInputOnEditEnd:function(id, cb){ + WebGLInputOnEditEnd:function(id, cb){ var input = instances[id]; input.onchange = function () { - var returnStr = input.value; - var bufferSize = lengthBytesUTF8(returnStr) + 1; - var buffer = _malloc(bufferSize); - stringToUTF8(returnStr, buffer, bufferSize); - (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, buffer]) : {{{ makeDynCall("vii", "cb") }}}(id, buffer); + var returnStr = input.value; + var bufferSize = lengthBytesUTF8(returnStr) + 1; + var buffer = _malloc(bufferSize); + stringToUTF8(returnStr, buffer, bufferSize); + (!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, buffer]) : {{{ makeDynCall("vii", "cb") }}}(id, buffer); }; }, - WebGLInputSelectionStart:function(id){ + WebGLInputSelectionStart:function(id){ var input = instances[id]; - return input.selectionStart; - }, - WebGLInputSelectionEnd:function(id){ + return input.selectionStart; + }, + WebGLInputSelectionEnd:function(id){ var input = instances[id]; - return input.selectionEnd; - }, - WebGLInputSelectionDirection:function(id){ + return input.selectionEnd; + }, + WebGLInputSelectionDirection:function(id){ var input = instances[id]; - return (input.selectionDirection == "backward")?-1:1; - }, - WebGLInputSetSelectionRange:function(id, start, end){ - var input = instances[id]; - input.setSelectionRange(start, end); - }, - WebGLInputMaxLength:function(id, maxlength){ + return (input.selectionDirection == "backward")?-1:1; + }, + WebGLInputSetSelectionRange:function(id, start, end){ var input = instances[id]; - input.maxLength = maxlength; - }, - WebGLInputText:function(id, text){ + input.setSelectionRange(start, end); + }, + WebGLInputMaxLength:function(id, maxlength){ var input = instances[id]; - input.value = UTF8ToString(text); - }, - WebGLInputDelete:function(id){ + input.maxLength = maxlength; + }, + WebGLInputText:function(id, text){ + var input = instances[id]; + input.value = UTF8ToString(text); + }, + WebGLInputDelete:function(id){ var input = instances[id]; input.parentNode.removeChild(input); instances[id] = null; }, - WebGLInputEnableTabText:function(id, enable) { + WebGLInputEnableTabText:function(id, enable) { var input = instances[id]; - input.enableTabText = enable; - }, - WebGLInputForceBlur:function(id) { + input.enableTabText = enable; + }, + WebGLInputForceBlur:function(id) { var input = instances[id]; - input.blur(); - }, + input.blur(); + }, } autoAddDeps(WebGLInput, '$instances'); diff --git a/Assets/WebGLSupport/WebGLWindow/WebGLWindow.jslib b/Assets/WebGLSupport/WebGLWindow/WebGLWindow.jslib index 57c1aa9..aa6c41e 100644 --- a/Assets/WebGLSupport/WebGLWindow/WebGLWindow.jslib +++ b/Assets/WebGLSupport/WebGLWindow/WebGLWindow.jslib @@ -1,19 +1,19 @@ var WebGLWindow = { - WebGLWindowInit : function() { + WebGLWindowInit : function() { // use WebAssembly.Table : makeDynCall // when enable. dynCall is undefined if(typeof dynCall === "undefined") { - // make Runtime.dynCall to undefined + // make Runtime.dynCall to undefined Runtime = { dynCall : undefined } } else { - // Remove the `Runtime` object from "v1.37.27: 12/24/2017" - // if Runtime not defined. create and add functon!! - if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall } + // Remove the `Runtime` object from "v1.37.27: 12/24/2017" + // if Runtime not defined. create and add functon!! + if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall } } - }, + }, WebGLWindowGetCanvasName: function() { var elements = document.getElementsByTagName('canvas'); var returnStr = ""; @@ -26,11 +26,11 @@ var WebGLWindow = { returnStr = elements[0].parentNode.id = 'WebGLWindow:Canvas:ParentNode'; } } - var bufferSize = lengthBytesUTF8(returnStr) + 1; - var buffer = _malloc(bufferSize); - stringToUTF8(returnStr, buffer, bufferSize); + var bufferSize = lengthBytesUTF8(returnStr) + 1; + var buffer = _malloc(bufferSize); + stringToUTF8(returnStr, buffer, bufferSize); return buffer; - }, + }, WebGLWindowOnFocus: function (cb) { window.addEventListener('focus', function () { (!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}(); @@ -41,12 +41,12 @@ var WebGLWindow = { (!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}(); }); }, - WebGLWindowOnResize: function(cb) { + WebGLWindowOnResize: function(cb) { window.addEventListener('resize', function () { (!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}(); }); - }, - WebGLWindowInjectFullscreen : function () { + }, + WebGLWindowInjectFullscreen : function () { document.makeFullscreen = function (id, keepAspectRatio) { // get fullscreen object var getFullScreenObject = function () { @@ -124,7 +124,7 @@ var WebGLWindow = { canvas.style.height = "100%"; } else { - fullscreenRoot.style.width = beforeWidth + 'px'; + fullscreenRoot.style.width = beforeWidth + 'px'; fullscreenRoot.style.height = beforeHeight + 'px'; beforeParent.insertBefore(fullscreenRoot, Array.from(beforeParent.children)[index]); @@ -151,11 +151,11 @@ var WebGLWindow = { else if (div.webkitRequestFullScreen) div.webkitRequestFullScreen(); else if (div.msRequestFullscreen) div.msRequestFullscreen(); else if (div.requestFullscreen) div.requestFullscreen(); - } - }, + } + }, MakeFullscreen : function (str) { document.makeFullscreen(UTF8ToString(str)); - }, + }, ExitFullscreen : function() { // get fullscreen object var doc = window.document;