Skip to content

Commit

Permalink
Fix resize canvas for Emscripten Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Aug 22, 2024
1 parent 239a6a3 commit 0957b80
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Projects/Irrlicht/Include/IrrlichtDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ namespace irr
used. */
virtual E_DEVICE_TYPE getType() const = 0;

//! Add event resize - fix for SDL2 Emscripten
virtual void onWindowResize(u32 w, u32 h) = 0;

//! Check if a driver type is supported by the engine.
/** Even if true is returned the driver may not be available
for a configuration requested when creating the device. */
Expand Down
17 changes: 16 additions & 1 deletion Projects/Irrlicht/Source/CIrrDeviceSDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,9 @@ namespace irr
{
// FIXME: Implement more precise window control
case SDL_WINDOWEVENT_SIZE_CHANGED:
#ifndef EMSCRIPTEN
// SKYLICHT: Need post an event to application, I will fix it later...
// FIXME: Check if the window is game window
// FIXME: Check if the window is game window
if ((SDL_event.window.data1 != (int)Width) || (SDL_event.window.data2 != (int)Height))
{
Width = SDL_event.window.data1;
Expand All @@ -495,6 +496,7 @@ namespace irr
irrevent.UserEvent.UserData2 = (s32)Height;
postEventFromUser(irrevent);
}
#endif
break;
case SDL_WINDOWEVENT_ENTER:
case SDL_WINDOWEVENT_FOCUS_GAINED:
Expand Down Expand Up @@ -977,6 +979,15 @@ namespace irr
KeyMap.sort();
}

void CIrrDeviceSDL2::onWindowResize(u32 w, u32 h)
{
#ifdef EMSCRIPTEN
Width = w;
Height = h;
resizeWindow(w, h);
#endif
}

void CIrrDeviceSDL2::resizeWindow(u32 x, u32 y)
{
if (ScreenWindow)
Expand All @@ -994,6 +1005,10 @@ namespace irr
{
ScreenTexture = SDL_CreateTexture(ScreenRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Width, Height);
}

char log[512];
sprintf(log, "[CIrrDeviceSDL2] resizeWindow %d %d - %d %d", x, y, Width, Height);
os::Printer::log(log);
}

CIrrDeviceSDL2::CCursorControl::CCursorControl(CIrrDeviceSDL2* dev)
Expand Down
2 changes: 2 additions & 0 deletions Projects/Irrlicht/Source/CIrrDeviceSDL2.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ namespace irr
return EIDT_SDL;
}

virtual void onWindowResize(u32 w, u32 h) _IRR_OVERRIDE_;

//! Implementation of the linux cursor control
class CCursorControl : public gui::ICursorControl
{
Expand Down
5 changes: 5 additions & 0 deletions Projects/Irrlicht/Source/CIrrDeviceStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ void CIrrDeviceStub::setRandomizer(IRandomizer* r)
}
}

void CIrrDeviceStub::onWindowResize(u32 w, u32 h)
{

}

namespace
{
struct SDefaultRandomizer : public IRandomizer
Expand Down
2 changes: 2 additions & 0 deletions Projects/Irrlicht/Source/CIrrDeviceStub.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ namespace irr
return &CreationParams;
}

virtual void onWindowResize(u32 w, u32 h);

protected:

void createGUIAndScene();
Expand Down
7 changes: 6 additions & 1 deletion Projects/Skylicht/Client/Source/CApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,16 @@ namespace Skylicht
m_width = w;
m_height = h;

IrrlichtDevice* dev = getIrrlichtDevice();

#ifdef __EMSCRIPTEN__
dev->onWindowResize((u32)w, (u32)h);
#endif
// resize window
m_driver->OnResize(core::dimension2du((u32)w, (u32)h));

// resize mouse
if (getIrrlichtDevice()->isFullscreen())
if (dev->isFullscreen())
{
core::rect<s32> winRect(0, 0, w, h);
m_device->getCursorControl()->setReferenceRect(&winRect);
Expand Down
10 changes: 5 additions & 5 deletions Projects/ThirdParty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ setup_project_group("${bzip2_source}" ${CMAKE_CURRENT_SOURCE_DIR})
#curl
if (BUILD_CURL)
file(GLOB_RECURSE curl_source
./source/curl/**.cpp
./source/curl/**.hpp
./source/curl/**.cpp
./source/curl/**.hpp
./source/curl/**.c
./source/curl/**.h)
setup_project_group("${curl_source}" ${CMAKE_CURRENT_SOURCE_DIR})
endif()

#json
file(GLOB_RECURSE json_source
./source/json/**.cpp
./source/json/**.hpp
./source/json/**.cpp
./source/json/**.hpp
./source/json/**.c
./source/json/**.h)
setup_project_group("${json_source}" ${CMAKE_CURRENT_SOURCE_DIR})
endif()

#jpeglib
file(GLOB_RECURSE jpeglib_source
Expand Down

0 comments on commit 0957b80

Please sign in to comment.