Skip to content

Commit

Permalink
Add support for setting mouse cursor on emscripten.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfpld committed Sep 20, 2024
1 parent 207605f commit 8b9da2e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions profiler/src/BackendEmscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static EGLSurface s_eglSurf;
static float s_prevScale;
static int s_width, s_height;
static uint64_t s_time;
static const char* s_prevCursor = nullptr;

static ImGuiKey TranslateKeyCode( const char* code )
{
Expand Down Expand Up @@ -272,6 +273,36 @@ void Backend::NewFrame( int& w, int& h )

ImGui_ImplOpenGL3_NewFrame();

ImGuiMouseCursor cursor = ImGui::GetMouseCursor();
const char* cursorName;
switch( cursor )
{
case ImGuiMouseCursor_None: cursorName = "none"; break;
case ImGuiMouseCursor_Arrow:
switch( s_isBusy() )
{
default:
case 0: cursorName = "default"; break;
case 1: cursorName = "progress"; break;
case 2: cursorName = "wait"; break;
}
break;
case ImGuiMouseCursor_TextInput: cursorName = "text"; break;
case ImGuiMouseCursor_ResizeAll: cursorName = "move"; break;
case ImGuiMouseCursor_ResizeNS: cursorName = "ns-resize"; break;
case ImGuiMouseCursor_ResizeEW: cursorName = "ew-resize"; break;
case ImGuiMouseCursor_ResizeNESW: cursorName = "nesw-resize"; break;
case ImGuiMouseCursor_ResizeNWSE: cursorName = "nwse-resize"; break;
case ImGuiMouseCursor_Hand: cursorName = "pointer"; break;
case ImGuiMouseCursor_NotAllowed: cursorName = "not-allowed"; break;
default: cursorName = "auto"; break;
};
if( s_prevCursor != cursorName )
{
s_prevCursor = cursorName;
EM_ASM_INT( { document.getElementById('canvas').style.cursor = UTF8ToString($0); }, cursorName );
}

uint64_t time = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
io.DeltaTime = std::min( 0.1f, ( time - s_time ) / 1000000.f );
s_time = time;
Expand Down

0 comments on commit 8b9da2e

Please sign in to comment.