Skip to content

Commit

Permalink
#15 Web platform: change window mode by Alt+Enter
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed Nov 16, 2016
1 parent 0921c61 commit ff6e3f8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/platform/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
57 changes: 41 additions & 16 deletions src/platform/web/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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;
/*
Expand Down Expand Up @@ -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);
Expand All @@ -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()");
Expand Down

0 comments on commit ff6e3f8

Please sign in to comment.