You may have an app which needs to change the cursor when you interact with elements in the canvas. In the app I'm working on, I needed the cursor to change when you hover over drawn bars that allow for sizing. To do this I wrote a little javascript code to do the cursor change and then had the c++ call it.
The javascript code:
function changeMouseCursor( type ) {
if ( type == 0 ) {
$('canvas').css( 'cursor', 'default' );
}
else if ( type == 1 ) {
$('canvas').css('cursor', 'n-resize' );
}
else if ( type == 2 ) {
$('canvas').css('cursor', 's-resize' );
}
else if ( type == 4 ) {
$('canvas').css('cursor', 'e-resize' );
}
else if ( type == 5 ) {
$('canvas').css('cursor', 'se-resize' );
}
else if ( type == 6 ) {
$('canvas').css('cursor', 'ne-resize' );
}
else if ( type == 8 ) {
$('canvas').css('cursor', 'w-resize' );
}
else if ( type == 9 ) {
$('canvas').css('cursor', 'sw-resize' );
}
else if ( type == 10 ) {
$('canvas').css('cursor', 'nw-resize' );
}
}
Code in emscripten:
int sizeType = IsOverDraggableBorder( m_mouseX, m_mouseY );
if ( sizeType != m_sizingType )
{
//change the cursor
char call[200];
sprintf(call, "changeMouseCursor(%d)", sizeType );
emscripten_run_script(call);
m_sizingType = sizeType;
}
Here is what it looks like in my app :)
No comments:
Post a Comment