|
| 1 | +/* |
| 2 | + * Copyright 2014 The Emscripten Authors. All rights reserved. |
| 3 | + * Emscripten is available under two separate licenses, the MIT license and the |
| 4 | + * University of Illinois/NCSA Open Source License. Both these licenses can be |
| 5 | + * found in the LICENSE file. |
| 6 | + */ |
| 7 | + |
| 8 | +#include <stdio.h> |
| 9 | +#include <SDL/SDL.h> |
| 10 | +#include <SDL/SDL_ttf.h> |
| 11 | +#include <assert.h> |
| 12 | +#include <emscripten.h> |
| 13 | + |
| 14 | +int result = 1; |
| 15 | + |
| 16 | +SDL_Surface *screen = 0; |
| 17 | + |
| 18 | +int inFullscreen = 0; |
| 19 | + |
| 20 | +int wasFullscreen = 0; |
| 21 | + |
| 22 | +int finished = 0; |
| 23 | + |
| 24 | +void render() { |
| 25 | + int width, height, isfs; |
| 26 | + emscripten_get_canvas_size(&width, &height, &isfs); |
| 27 | + SDL_Rect rect = { 0, 0, width, height }; |
| 28 | + SDL_FillRect(screen, &rect, 0xff00ffff); |
| 29 | +} |
| 30 | + |
| 31 | +void mainloop() { |
| 32 | + render(); |
| 33 | + |
| 34 | + if (finished) return; |
| 35 | + |
| 36 | + SDL_Event event; |
| 37 | + int isInFullscreen = EM_ASM_INT(return !!(document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement)); |
| 38 | + if (isInFullscreen && !wasFullscreen) { |
| 39 | + printf("Successfully transitioned to fullscreen mode!\n"); |
| 40 | + wasFullscreen = isInFullscreen; |
| 41 | + } |
| 42 | + |
| 43 | + if (wasFullscreen && !isInFullscreen) { |
| 44 | + printf("Exited fullscreen. Test succeeded.\n"); |
| 45 | +#ifdef REPORT_RESULT |
| 46 | + REPORT_RESULT(1); |
| 47 | +#endif |
| 48 | + wasFullscreen = isInFullscreen; |
| 49 | + finished = 1; |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + int haveEvent = SDL_PollEvent(&event); |
| 54 | + if (haveEvent) { |
| 55 | + switch(event.type) { |
| 56 | + case SDL_MOUSEBUTTONDOWN: { |
| 57 | + SDL_WM_ToggleFullScreen(screen); |
| 58 | + inFullscreen = 1 - inFullscreen; |
| 59 | + if (inFullscreen == 0) { |
| 60 | + result = wasFullscreen; |
| 61 | + if (result) { |
| 62 | + printf("Exited fullscreen. Test succeeded.\n"); |
| 63 | + } else { |
| 64 | + printf("Exited fullscreen. Test failed, fullscreen transition did not happen!\n"); |
| 65 | + } |
| 66 | +#ifdef REPORT_RESULT |
| 67 | + REPORT_RESULT(result); |
| 68 | +#endif |
| 69 | + finished = 1; |
| 70 | + return; |
| 71 | + } else { |
| 72 | + printf("Entering fullscreen...\n"); |
| 73 | + } |
| 74 | + break; |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +int main() { |
| 81 | + int w, h, fs; |
| 82 | + emscripten_get_canvas_size(&w, &h, &fs); |
| 83 | + printf("w:%d,h:%d\n", w,h); |
| 84 | + |
| 85 | + SDL_Init(SDL_INIT_VIDEO); |
| 86 | + |
| 87 | + screen = SDL_SetVideoMode(w, h, 32, SDL_HWSURFACE); //set with the same size with canvas. this used to break full screen |
| 88 | + |
| 89 | + printf("You should see a yellow canvas.\n"); |
| 90 | + printf("Click on the canvas to enter full screen, and then click on the canvas again to finish the test.\n"); |
| 91 | + printf("When in full screen, you should see the whole screen filled yellow, and after exiting, the yellow canvas should be restored in the window.\n"); |
| 92 | + emscripten_set_main_loop(mainloop, 0, 0); |
| 93 | + return 0; |
| 94 | +} |
0 commit comments