5
5
* found in the LICENSE file.
6
6
*/
7
7
8
+ #include <assert.h>
8
9
#include <stdio.h>
9
10
#include <emscripten.h>
10
11
#include <string.h>
11
12
#include <emscripten/html5.h>
12
13
#include <GLES2/gl2.h>
13
14
#include <math.h>
14
15
15
- void report_result (int result ) {
16
- if (result == 0 ) {
17
- printf ("Test successful!\n" );
18
- } else {
19
- printf ("Test failed!\n" );
20
- }
21
- #ifdef REPORT_RESULT
22
- REPORT_RESULT (result );
23
- #endif
24
- }
25
-
26
16
static inline const char * emscripten_event_type_to_string (int eventType ) {
27
17
const char * events [] = { "(invalid)" , "(none)" , "keypress" , "keydown" , "keyup" , "click" , "mousedown" , "mouseup" , "dblclick" , "mousemove" , "wheel" , "resize" ,
28
18
"scroll" , "blur" , "focus" , "focusin" , "focusout" , "deviceorientation" , "devicemotion" , "orientationchange" , "fullscreenchange" , "pointerlockchange" ,
@@ -47,12 +37,14 @@ const char *emscripten_result_to_string(EMSCRIPTEN_RESULT result) {
47
37
return "Unknown EMSCRIPTEN_RESULT!" ;
48
38
}
49
39
50
- #define TEST_RESULT (x ) if (ret != EMSCRIPTEN_RESULT_SUCCESS) printf("%s returned %s.\n", #x, emscripten_result_to_string(ret));
40
+ #define TEST_RESULT (x ) if (ret != EMSCRIPTEN_RESULT_SUCCESS) { \
41
+ printf("%s returned %s.\n", #x, emscripten_result_to_string(ret)); \
42
+ assert(false && #x); \
43
+ }
51
44
52
45
// The event handler functions can return 1 to suppress the event and disable the default action. That calls event.preventDefault();
53
46
// Returning 0 signals that the event was not consumed by the code, and will allow the event to pass on and bubble up normally.
54
- bool key_callback (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
55
- {
47
+ bool key_callback (int eventType , const EmscriptenKeyboardEvent * e , void * userData ) {
56
48
if (eventType == EMSCRIPTEN_EVENT_KEYPRESS && (!strcmp (e -> key , "f" ) || e -> which == 102 )) {
57
49
EmscriptenFullscreenChangeEvent fsce ;
58
50
EMSCRIPTEN_RESULT ret = emscripten_get_fullscreen_status (& fsce );
@@ -71,8 +63,7 @@ bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userDat
71
63
fprintf (stderr , "Fullscreen exit did not work!\n" );
72
64
}
73
65
}
74
- }
75
- else if (eventType == EMSCRIPTEN_EVENT_KEYPRESS && (!strcmp (e -> key , "Esc" ) || !strcmp (e -> key , "Escape" ) || e -> which == 27 )) {
66
+ } else if (eventType == EMSCRIPTEN_EVENT_KEYPRESS && (!strcmp (e -> key , "Esc" ) || !strcmp (e -> key , "Escape" ) || e -> which == 27 )) {
76
67
emscripten_exit_soft_fullscreen ();
77
68
}
78
69
return 0 ;
@@ -81,20 +72,24 @@ bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userDat
81
72
int callCount = 0 ;
82
73
83
74
bool fullscreenchange_callback (int eventType , const EmscriptenFullscreenChangeEvent * e , void * userData ) {
84
- printf ("%s, isFullscreen: %d, fullscreenEnabled: %d, fs element nodeName: \"%s\", fs element id: \"%s\". New size: %dx%d pixels. Screen size: %dx%d pixels.\n" ,
85
- emscripten_event_type_to_string (eventType ), e -> isFullscreen , e -> fullscreenEnabled , e -> nodeName , e -> id , e -> elementWidth , e -> elementHeight , e -> screenWidth , e -> screenHeight );
75
+ printf ("%s, isFullscreen: %d, fullscreenEnabled: %d, fs element nodeName: "
76
+ "'%s', fs element id: '%s'. New size: %dx%d pixels. Screen size: "
77
+ "%dx%d pixels.\n" ,
78
+ emscripten_event_type_to_string (eventType ),
79
+ e -> isFullscreen ,
80
+ e -> fullscreenEnabled ,
81
+ e -> nodeName ,
82
+ e -> id ,
83
+ e -> elementWidth ,
84
+ e -> elementHeight ,
85
+ e -> screenWidth ,
86
+ e -> screenHeight );
86
87
87
88
++ callCount ;
88
89
if (callCount == 1 ) { // Transitioned to fullscreen.
89
- if (!e -> isFullscreen ) {
90
- report_result (1 );
91
- }
90
+ assert (e -> isFullscreen );
92
91
} else if (callCount == 2 ) { // Transitioned to windowed, we must be back to the default pixel size 300x150.
93
- if (e -> isFullscreen || e -> elementWidth != 300 || e -> elementHeight != 150 ) {
94
- report_result (1 );
95
- } else {
96
- report_result (0 );
97
- }
92
+ assert (!e -> isFullscreen );
98
93
}
99
94
return 0 ;
100
95
}
@@ -122,7 +117,7 @@ bool on_canvassize_changed(int eventType, const void *reserved, void *userData)
122
117
int w , h ;
123
118
emscripten_get_canvas_element_size ("#canvas" , & w , & h );
124
119
double cssW , cssH ;
125
- emscripten_get_element_css_size (0 , & cssW , & cssH );
120
+ emscripten_get_element_css_size ("#canvas" , & cssW , & cssH );
126
121
printf ("Canvas resized: WebGL RTT size: %dx%d, canvas CSS size: %02gx%02g\n" , w , h , cssW , cssH );
127
122
return 0 ;
128
123
}
@@ -134,7 +129,7 @@ void requestFullscreen(int scaleMode, int canvasResolutionScaleMode, int filteri
134
129
s .canvasResolutionScaleMode = canvasResolutionScaleMode ;
135
130
s .filteringMode = filteringMode ;
136
131
s .canvasResizedCallback = on_canvassize_changed ;
137
- EMSCRIPTEN_RESULT ret = emscripten_request_fullscreen_strategy (0 , 1 , & s );
132
+ EMSCRIPTEN_RESULT ret = emscripten_request_fullscreen_strategy ("#canvas" , 1 , & s );
138
133
TEST_RESULT (requestFullscreen );
139
134
}
140
135
@@ -145,12 +140,13 @@ void enterSoftFullscreen(int scaleMode, int canvasResolutionScaleMode, int filte
145
140
s .canvasResolutionScaleMode = canvasResolutionScaleMode ;
146
141
s .filteringMode = filteringMode ;
147
142
s .canvasResizedCallback = on_canvassize_changed ;
148
- EMSCRIPTEN_RESULT ret = emscripten_enter_soft_fullscreen (0 , & s );
143
+ EMSCRIPTEN_RESULT ret = emscripten_enter_soft_fullscreen ("#canvas" , & s );
149
144
TEST_RESULT (enterSoftFullscreen );
150
145
}
151
146
152
- int on_button_click (int eventType , const EmscriptenMouseEvent * mouseEvent , void * userData ) {
153
- switch ((long )userData ) {
147
+ bool on_button_click (int eventType , const EmscriptenMouseEvent * mouseEvent , void * userData ) {
148
+ printf ("on_button_click: %ld\n" , (long )userData );
149
+ switch ((long )userData ) {
154
150
case 0 : requestFullscreen (EMSCRIPTEN_FULLSCREEN_SCALE_DEFAULT , EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE , EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT ); break ;
155
151
case 1 : requestFullscreen (EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH , EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF , EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT ); break ;
156
152
case 2 : requestFullscreen (EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH , EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF , EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT ); break ;
@@ -247,7 +243,6 @@ int main() {
247
243
emscripten_set_click_callback ("#b16" , (void * )16 , 1 , on_button_click );
248
244
249
245
printf ("To finish this test, press f to enter fullscreen mode, and then exit it.\n" );
250
- printf ("On IE, press a mouse key over the canvas after pressing f to activate the fullscreen request event.\n" );
251
246
252
247
emscripten_set_main_loop (draw , 0 , 0 );
253
248
return 0 ;
0 commit comments