mirror of
https://github.com/libretro/RetroArch
synced 2025-04-03 01:21:10 +00:00
Add focus to canvas (SDL2 input)
When the canvas in focus SDL2 input should be work
This commit is contained in:
parent
af09bd1751
commit
c6870cfb8e
@ -1,205 +1,229 @@
|
|||||||
var count = 0;
|
var count = 0;
|
||||||
var filename = "";
|
var filename = "";
|
||||||
var firstRun = true;
|
var firstRun = true;
|
||||||
|
|
||||||
|
|
||||||
function setupFolders()
|
function setupFolders()
|
||||||
{
|
{
|
||||||
console.log("setupFolders");
|
console.log("setupFolders");
|
||||||
|
|
||||||
if(localStorage.getItem("folders_inited")!="true")
|
if(localStorage.getItem("folders_inited")!="true")
|
||||||
{
|
{
|
||||||
FS.createFolder('/home','web_user',true,true);
|
FS.createFolder('/home','web_user',true,true);
|
||||||
FS.createFolder('/home/web_user','retroarch',true,true);
|
FS.createFolder('/home/web_user','retroarch',true,true);
|
||||||
FS.createFolder('/home/web_user/retroarch','saves',true,true);
|
FS.createFolder('/home/web_user/retroarch','saves',true,true);
|
||||||
FS.createFolder('/home/web_user/retroarch','states',true,true);
|
FS.createFolder('/home/web_user/retroarch','states',true,true);
|
||||||
FS.createFolder('/home/web_user/retroarch','system',true,true);
|
FS.createFolder('/home/web_user/retroarch','system',true,true);
|
||||||
FS.createFolder('/home/web_user/retroarch','cheat',true,true);
|
FS.createFolder('/home/web_user/retroarch','cheat',true,true);
|
||||||
FS.createFolder('/home/web_user/retroarch','remap',true,true);
|
FS.createFolder('/home/web_user/retroarch','remap',true,true);
|
||||||
FS.createFolder('/home/web_user','.config',true,true);
|
FS.createFolder('/home/web_user','.config',true,true);
|
||||||
FS.createFolder('/home/web_user/.config','retroarch',true,true);
|
FS.createFolder('/home/web_user/.config','retroarch',true,true);
|
||||||
|
|
||||||
localStorage.setItem("folders_inited","true");
|
localStorage.setItem("folders_inited","true");
|
||||||
console.log('Folders initialized: ' + localStorage.getItem("folders_inited"));
|
console.log('Folders initialized: ' + localStorage.getItem("folders_inited"));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createConfig()
|
|
||||||
{
|
|
||||||
console.log("createConfig");
|
|
||||||
|
|
||||||
if(localStorage.getItem("cfg_inited")!="true")
|
|
||||||
{
|
|
||||||
var config = 'input_player1_select = shift\n';
|
|
||||||
config += 'audio_latency = 96\n'
|
|
||||||
config += 'video_font_size = 16\n'
|
|
||||||
config += 'rgui_browser_directory = /content\n';
|
|
||||||
config += 'savefile_directory = /home/web_user/retroarch/saves/\n';
|
|
||||||
config += 'savestate_directory = /home/web_user/retroarch/states/\n';
|
|
||||||
config += 'system_directory = /home/web_user/retroarch/system/\n';
|
|
||||||
config += 'rgui_config_directory = /home/web_user/.config/retroarch/\n';
|
|
||||||
config += 'input_remapping_directory = /home/web_user/retroarch/remap/\n';
|
|
||||||
config += 'cheat_database_path = /home/web_user/retroarch/cheat/\n';
|
|
||||||
FS.writeFile('/home/web_user/.config/retroarch/retroarch.cfg',config);
|
|
||||||
|
|
||||||
localStorage.setItem("cfg_inited","true");
|
|
||||||
console.log('Config initialized: ' + localStorage.getItem("cfg_inited"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupFileSystem()
|
function createConfig()
|
||||||
{
|
{
|
||||||
console.log("setupFileSystem");
|
console.log("createConfig");
|
||||||
|
|
||||||
if(localStorage.getItem("fs_inited")!="true")
|
if(localStorage.getItem("cfg_inited")!="true")
|
||||||
{
|
{
|
||||||
var lsfs = new BrowserFS.FileSystem.LocalStorage();
|
var config = 'input_player1_select = shift\n';
|
||||||
BrowserFS.initialize(lsfs);
|
|
||||||
var BFS = new BrowserFS.EmscriptenFS();
|
//SDL2 ADD focus to html element
|
||||||
|
|
||||||
FS.mount(BFS, {root: '/'}, '/home');
|
if (document.getElementById('sdl2').checked) {
|
||||||
|
config += 'video_driver = sdl2\n';
|
||||||
console.log('Filesystem initialized');
|
config +="input_driver = sdl2\n";
|
||||||
}
|
config +="input_joypad_driver = sdl2\n";
|
||||||
else
|
config += "video_context_driver = sdl_gl\n";
|
||||||
{
|
document.getElementById("canvas").focus();
|
||||||
|
document.getElementById("canvas").addEventListener("keydown",function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("canvas").onclick = function(){
|
||||||
|
document.getElementById("canvas").focus();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}else{
|
||||||
|
config += "video_context_driver = emscripten\n";
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
config += 'audio_latency = 96\n'
|
||||||
|
config += 'video_font_size = 16\n'
|
||||||
|
config += 'rgui_browser_directory = /content\n';
|
||||||
|
config += 'savefile_directory = /home/web_user/retroarch/saves/\n';
|
||||||
|
config += 'savestate_directory = /home/web_user/retroarch/states/\n';
|
||||||
|
config += 'system_directory = /home/web_user/retroarch/system/\n';
|
||||||
|
config += 'rgui_config_directory = /home/web_user/.config/retroarch/\n';
|
||||||
|
config += 'input_remapping_directory = /home/web_user/retroarch/remap/\n';
|
||||||
|
config += 'cheat_database_path = /home/web_user/retroarch/cheat/\n';
|
||||||
|
FS.writeFile('/home/web_user/.config/retroarch/retroarch.cfg',config);
|
||||||
|
|
||||||
|
localStorage.setItem("cfg_inited","true");
|
||||||
|
console.log('Config initialized: ' + localStorage.getItem("cfg_inited"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupFileSystem()
|
||||||
|
{
|
||||||
|
console.log("setupFileSystem");
|
||||||
|
|
||||||
|
if(localStorage.getItem("fs_inited")!="true")
|
||||||
|
{
|
||||||
|
var lsfs = new BrowserFS.FileSystem.LocalStorage();
|
||||||
|
BrowserFS.initialize(lsfs);
|
||||||
|
var BFS = new BrowserFS.EmscriptenFS();
|
||||||
|
|
||||||
|
FS.mount(BFS, {root: '/'}, '/home');
|
||||||
|
|
||||||
|
console.log('Filesystem initialized');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
console.log('Filesystem already initialized');
|
console.log('Filesystem already initialized');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function runEmulator(files)
|
function runEmulator(files)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Modernizr.localstorage)
|
if (Modernizr.localstorage)
|
||||||
{
|
{
|
||||||
if(firstRun)
|
if(firstRun)
|
||||||
setupFileSystem();
|
setupFileSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
setupFolders();
|
setupFolders();
|
||||||
createConfig();
|
createConfig();
|
||||||
|
|
||||||
if(firstRun)
|
if(firstRun)
|
||||||
FS.createFolder('/','content',true,true);
|
FS.createFolder('/','content',true,true);
|
||||||
|
|
||||||
count = files.length;
|
count = files.length;
|
||||||
for (var i = 0; i < files.length; i++)
|
for (var i = 0; i < files.length; i++)
|
||||||
{
|
{
|
||||||
filereader = new FileReader();
|
filereader = new FileReader();
|
||||||
filereader.file_name = files[i].name;
|
filereader.file_name = files[i].name;
|
||||||
filereader.readAsArrayBuffer(files[i]);
|
filereader.readAsArrayBuffer(files[i]);
|
||||||
if(firstRun)
|
if(firstRun)
|
||||||
{
|
{
|
||||||
filereader.onload = function(){uploadContent(this.result, '/content/' + this.file_name)};
|
filereader.onload = function(){uploadContent(this.result, '/content/' + this.file_name)};
|
||||||
firstRun = false;
|
firstRun = false;
|
||||||
initFromData();
|
initFromData();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
filereader.onload = function(){uploadContent(this.result, '/content/' + this.file_name)};
|
filereader.onload = function(){uploadContent(this.result, '/content/' + this.file_name)};
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function uploadContent(data, name)
|
|
||||||
{
|
|
||||||
var dataView = new Uint8Array(data);
|
|
||||||
FS.createDataFile('/', name, dataView, true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyFile(src,dest)
|
|
||||||
{
|
|
||||||
console.log('copying: ' + src + ' to: ' + dest);
|
|
||||||
var contents = FS.readFile(src,{ encoding: 'binary' });
|
|
||||||
console.log(contents);
|
|
||||||
FS.writeFile(dest,contents,{ encoding: 'binary' });
|
|
||||||
}
|
|
||||||
|
|
||||||
function uploadData(files, path)
|
|
||||||
{
|
|
||||||
count = files.length;
|
|
||||||
for (var i = 0; i < files.length; i++)
|
|
||||||
{
|
|
||||||
filereader = new FileReader();
|
|
||||||
filereader.file_name = files[i].name;
|
|
||||||
filereader.readAsArrayBuffer(files[i]);
|
|
||||||
filereader.onload = function(){uploadContent(this.result, '/tmp/' + this.file_name)};
|
|
||||||
filereader.onloadend = function(){copyFile('/tmp/' + this.file_name,'/home/web_user/retroarch/' + path + '/' + this.file_name)};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initFromData()
|
function uploadContent(data, name)
|
||||||
{
|
{
|
||||||
|
var dataView = new Uint8Array(data);
|
||||||
count--;
|
FS.createDataFile('/', name, dataView, true, false);
|
||||||
if (count === 0)
|
}
|
||||||
{
|
|
||||||
document.getElementById('canvas_div').style.display = 'block';
|
function copyFile(src,dest)
|
||||||
Module['callMain'](Module['arguments']);
|
{
|
||||||
}
|
console.log('copying: ' + src + ' to: ' + dest);
|
||||||
}
|
var contents = FS.readFile(src,{ encoding: 'binary' });
|
||||||
|
console.log(contents);
|
||||||
var Module =
|
FS.writeFile(dest,contents,{ encoding: 'binary' });
|
||||||
{
|
}
|
||||||
noInitialRun: true,
|
|
||||||
arguments: ["--verbose", "--menu"],
|
function uploadData(files, path)
|
||||||
preRun: [],
|
{
|
||||||
postRun: [],
|
count = files.length;
|
||||||
print: (function()
|
for (var i = 0; i < files.length; i++)
|
||||||
{
|
{
|
||||||
var element = document.getElementById('output');
|
filereader = new FileReader();
|
||||||
element.value = ''; // clear browser cache
|
filereader.file_name = files[i].name;
|
||||||
return function(text)
|
filereader.readAsArrayBuffer(files[i]);
|
||||||
{
|
filereader.onload = function(){uploadContent(this.result, '/tmp/' + this.file_name)};
|
||||||
text = Array.prototype.slice.call(arguments).join(' ');
|
filereader.onloadend = function(){copyFile('/tmp/' + this.file_name,'/home/web_user/retroarch/' + path + '/' + this.file_name)};
|
||||||
// These replacements are necessary if you render to raw HTML
|
|
||||||
//text = text.replace(/&/g, "&");
|
}
|
||||||
//text = text.replace(/</g, "<");
|
}
|
||||||
//text = text.replace(/>/g, ">");
|
|
||||||
//text = text.replace('\n', '<br>', 'g');
|
function initFromData()
|
||||||
element.value += text + "\n";
|
{
|
||||||
element.scrollTop = 99999; // focus on bottom
|
|
||||||
};
|
count--;
|
||||||
})(),
|
if (count === 0)
|
||||||
|
{
|
||||||
printErr: function(text)
|
document.getElementById('canvas_div').style.display = 'block';
|
||||||
{
|
Module['callMain'](Module['arguments']);
|
||||||
var text = Array.prototype.slice.call(arguments).join(' ');
|
}
|
||||||
var element = document.getElementById('output');
|
}
|
||||||
element.value += text + "\n";
|
|
||||||
element.scrollTop = 99999; // focus on bottom
|
var Module =
|
||||||
},
|
{
|
||||||
|
noInitialRun: true,
|
||||||
canvas: document.getElementById('canvas'),
|
arguments: ["--verbose", "--menu"],
|
||||||
setStatus: function(text)
|
preRun: [],
|
||||||
{
|
postRun: [],
|
||||||
if (Module.setStatus.interval)
|
print: (function()
|
||||||
clearInterval(Module.setStatus.interval);
|
{
|
||||||
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
|
var element = document.getElementById('output');
|
||||||
var statusElement = document.getElementById('status');
|
element.value = ''; // clear browser cache
|
||||||
var progressElement = document.getElementById('progress');
|
return function(text)
|
||||||
if (m)
|
{
|
||||||
{
|
text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
text = m[1];
|
// These replacements are necessary if you render to raw HTML
|
||||||
progressElement.value = parseInt(m[2])*100;
|
//text = text.replace(/&/g, "&");
|
||||||
progressElement.max = parseInt(m[4])*100;
|
//text = text.replace(/</g, "<");
|
||||||
progressElement.hidden = false;
|
//text = text.replace(/>/g, ">");
|
||||||
}
|
//text = text.replace('\n', '<br>', 'g');
|
||||||
else
|
element.value += text + "\n";
|
||||||
{
|
element.scrollTop = 99999; // focus on bottom
|
||||||
progressElement.value = null;
|
};
|
||||||
progressElement.max = null;
|
})(),
|
||||||
progressElement.hidden = true;
|
|
||||||
}
|
printErr: function(text)
|
||||||
statusElement.innerHTML = text;
|
{
|
||||||
},
|
var text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
var element = document.getElementById('output');
|
||||||
totalDependencies: 0,
|
element.value += text + "\n";
|
||||||
monitorRunDependencies: function(left)
|
element.scrollTop = 99999; // focus on bottom
|
||||||
{
|
},
|
||||||
this.totalDependencies = Math.max(this.totalDependencies, left);
|
|
||||||
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
|
canvas: document.getElementById('canvas'),
|
||||||
}
|
setStatus: function(text)
|
||||||
};
|
{
|
||||||
|
if (Module.setStatus.interval)
|
||||||
Module.setStatus('Downloading...');
|
clearInterval(Module.setStatus.interval);
|
||||||
|
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
|
||||||
|
var statusElement = document.getElementById('status');
|
||||||
|
var progressElement = document.getElementById('progress');
|
||||||
|
if (m)
|
||||||
|
{
|
||||||
|
text = m[1];
|
||||||
|
progressElement.value = parseInt(m[2])*100;
|
||||||
|
progressElement.max = parseInt(m[4])*100;
|
||||||
|
progressElement.hidden = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
progressElement.value = null;
|
||||||
|
progressElement.max = null;
|
||||||
|
progressElement.hidden = true;
|
||||||
|
}
|
||||||
|
statusElement.innerHTML = text;
|
||||||
|
},
|
||||||
|
|
||||||
|
totalDependencies: 0,
|
||||||
|
monitorRunDependencies: function(left)
|
||||||
|
{
|
||||||
|
this.totalDependencies = Math.max(this.totalDependencies, left);
|
||||||
|
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Module.setStatus('Downloading...');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user