Skip to content

Commit 7726f0e

Browse files
authored
Handling wasm orientation change in fullscreen (#2760)
1 parent 392d486 commit 7726f0e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

axmol/platform/desktop/RenderViewImpl.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ class GLFWEventHandler
145145
_view->onGLFWMouseMoveCallBack(window, x, y);
146146
}
147147
#if defined(__EMSCRIPTEN__)
148+
static EM_BOOL onWebOrientationChangeCallback(int eventType,
149+
const EmscriptenOrientationChangeEvent* e,
150+
void* /*userData*/)
151+
{
152+
if (_view)
153+
_view->onWebOrientationChangeCallback(eventType, e);
154+
return EM_TRUE;
155+
}
156+
148157
static EM_BOOL onWebFullscreenCallback(int eventType, const EmscriptenFullscreenChangeEvent* e, void* /*userData*/)
149158
{
150159
if (_view)
@@ -646,6 +655,7 @@ bool RenderViewImpl::initWithRect(std::string_view viewName,
646655
#if defined(__EMSCRIPTEN__)
647656
s_fullscreenState = std::make_unique<WebFullscreenState>();
648657
// clang-format off
658+
emscripten_set_orientationchange_callback(this, EM_TRUE, GLFWEventHandler::onWebOrientationChangeCallback);
649659
emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, this, EM_TRUE, GLFWEventHandler::onWebFullscreenCallback);
650660

651661
_isTouchDevice = !!EM_ASM_INT(return (('ontouchstart' in window) ||
@@ -1241,7 +1251,22 @@ void RenderViewImpl::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, doubl
12411251
}
12421252

12431253
#if defined(__EMSCRIPTEN__)
1244-
void RenderViewImpl::onWebFullscreenCallback(int eventType, const EmscriptenFullscreenChangeEvent* e)
1254+
void RenderViewImpl::onWebOrientationChangeCallback(int /*eventType*/, const EmscriptenOrientationChangeEvent* e)
1255+
{
1256+
AXLOGD("onWebOrientationChangeCallback: orientationIndex:{}, orientationAngle:{}", e->orientationIndex,
1257+
e->orientationAngle);
1258+
1259+
if (s_fullscreenState->isFullscreen)
1260+
{
1261+
int screenWidth = 0, screenHeight = 0;
1262+
emscripten_get_screen_size(&screenWidth, &screenHeight);
1263+
AXLOGD("Screen size after orientation change: ({}, {})", screenWidth, screenHeight);
1264+
glfwSetWindowSize(_mainWindow, screenWidth, screenHeight);
1265+
}
1266+
// else: browser handling canvas size
1267+
}
1268+
1269+
void RenderViewImpl::onWebFullscreenCallback(int /*eventType*/, const EmscriptenFullscreenChangeEvent* e)
12451270
{
12461271
if (e->isFullscreen == s_fullscreenState->isFullscreen)
12471272
return;
@@ -1382,6 +1407,8 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc
13821407
director->getScheduler()->schedule([director](float) { director->pause(); }, director, 0, 0, 0, false,
13831408
"step");
13841409
break;
1410+
default:
1411+
break;
13851412
}
13861413
}
13871414
#endif

axmol/platform/desktop/RenderViewImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ THE SOFTWARE.
3636
struct EmscriptenMouseEvent;
3737
struct EmscriptenTouchEvent;
3838
struct EmscriptenFullscreenChangeEvent;
39+
struct EmscriptenOrientationChangeEvent;
3940
#endif
4041

4142
namespace ax
@@ -144,6 +145,7 @@ class AX_DLL RenderViewImpl : public RenderView
144145
void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify);
145146
void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
146147
#if defined(__EMSCRIPTEN__)
148+
void onWebOrientationChangeCallback(int eventType, const EmscriptenOrientationChangeEvent* e);
147149
void onWebFullscreenCallback(int eventType, const EmscriptenFullscreenChangeEvent* e);
148150
void onWebTouchCallback(int eventType, const EmscriptenTouchEvent* touchEvent);
149151
void onWebClickCallback();

0 commit comments

Comments
 (0)