mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-09 22:56:53 +02:00
#15 Web platform: change window mode by Alt+Enter
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
<head><title>OpenLara</title></head>
|
||||
<body>
|
||||
<span id="status">Starting...</span>
|
||||
<input type="button" value="fullscreen" onclick="Module.requestFullScreen(false, true)"><br><br>
|
||||
<canvas id="canvas" width="160" height="120" oncontextmenu="event.preventDefault()"></canvas><br>
|
||||
<span id="info"><a target="_blank" href="https://github.com/XProger/OpenLara">OpenLara on github</a><br>controls:<br>keyboad: move - WASD / arrows, jump - Space, action - E/Ctrl, draw weapon - Q, change weapon - 1-4, walk - Shift, side steps - ZX/walk+direction, camera - MouseR)<br>gamepad: PSX controls on XBox controller</span>
|
||||
|
||||
|
@@ -96,10 +96,7 @@ void main_loop() {
|
||||
delta -= Core::deltaTime;
|
||||
}
|
||||
lastTime = time;
|
||||
|
||||
int f;
|
||||
emscripten_get_canvas_size(&Core::width, &Core::height, &f);
|
||||
|
||||
|
||||
Core::stats.dips = 0;
|
||||
Core::stats.tris = 0;
|
||||
Game::render();
|
||||
@@ -146,6 +143,39 @@ void freeGL() {
|
||||
eglTerminate(display);
|
||||
}
|
||||
|
||||
EM_BOOL resize() {
|
||||
int f;
|
||||
emscripten_get_canvas_size(&Core::width, &Core::height, &f);
|
||||
LOG("resize %d x %d\n", Core::width, Core::height);
|
||||
return 1;
|
||||
}
|
||||
|
||||
EM_BOOL resizeCallback(int eventType, const EmscriptenUiEvent *e, void *userData) {
|
||||
return resize();
|
||||
}
|
||||
|
||||
EM_BOOL fullscreenCallback(int eventType, const void *reserved, void *userData) {
|
||||
return resize();
|
||||
}
|
||||
|
||||
bool isFullScreen() {
|
||||
EmscriptenFullscreenChangeEvent status;
|
||||
emscripten_get_fullscreen_status(&status);
|
||||
return status.isFullscreen;
|
||||
}
|
||||
|
||||
void changeWindowMode() {
|
||||
if (!isFullScreen()) {
|
||||
EmscriptenFullscreenStrategy s;
|
||||
s.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;
|
||||
s.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
|
||||
s.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
|
||||
s.canvasResizedCallback = fullscreenCallback;
|
||||
emscripten_request_fullscreen_strategy(NULL, 1, &s);
|
||||
} else
|
||||
emscripten_exit_fullscreen();
|
||||
}
|
||||
|
||||
InputKey keyToInputKey(int code) {
|
||||
static const int codes[] = {
|
||||
0x25, 0x27, 0x26, 0x28, 0x20, 0x0D, 0x1B, 0x10, 0x11, 0x12,
|
||||
@@ -164,21 +194,16 @@ EM_BOOL keyCallback(int eventType, const EmscriptenKeyboardEvent *e, void *userD
|
||||
switch(eventType) {
|
||||
case EMSCRIPTEN_EVENT_KEYDOWN:
|
||||
case EMSCRIPTEN_EVENT_KEYUP:
|
||||
if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && e->altKey && e->keyCode == 0x0D) { // Alt + Enter
|
||||
changeWindowMode();
|
||||
break;
|
||||
}
|
||||
Input::setDown(keyToInputKey(e->keyCode), eventType == EMSCRIPTEN_EVENT_KEYDOWN);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
EM_BOOL resizeCallback(int eventType, const EmscriptenUiEvent *e, void *userData) {
|
||||
// Core::width = e->documentBodyClientWidth;
|
||||
// Core::height = e->documentBodyClientHeight;
|
||||
int f;
|
||||
emscripten_get_canvas_size(&Core::width, &Core::height, &f);
|
||||
LOG("resize %d x %d\n", Core::width, Core::height);
|
||||
return 1;
|
||||
}
|
||||
|
||||
EM_BOOL touchCallback(int eventType, const EmscriptenTouchEvent *e, void *userData) {
|
||||
bool flag = false;
|
||||
/*
|
||||
@@ -237,8 +262,8 @@ EM_BOOL mouseCallback(int eventType, const EmscriptenMouseEvent *e, void *userDa
|
||||
}
|
||||
|
||||
int main() {
|
||||
initGL();
|
||||
|
||||
initGL();
|
||||
|
||||
emscripten_set_canvas_size(Core::width = 854, Core::height = 480);
|
||||
|
||||
emscripten_set_keydown_callback(0, 0, 1, keyCallback);
|
||||
@@ -253,7 +278,7 @@ int main() {
|
||||
emscripten_set_mousedown_callback(0, 0, 1, mouseCallback);
|
||||
emscripten_set_mouseup_callback(0, 0, 1, mouseCallback);
|
||||
emscripten_set_mousemove_callback(0, 0, 1, mouseCallback);
|
||||
|
||||
|
||||
Game::init();
|
||||
|
||||
emscripten_run_script("snd_init()");
|
||||
|
Reference in New Issue
Block a user