@ -1021,6 +1021,8 @@ namespace olc
uint32_t GetFPS ( ) const ;
// Gets last update of elapsed time
float GetElapsedTime ( ) const ;
// Gets Actual Window pos
const olc : : vi2d & GetWindowPos ( ) const ;
// Gets Actual Window size
const olc : : vi2d & GetWindowSize ( ) const ;
// Gets pixel scale
@ -1222,6 +1224,7 @@ namespace olc
olc : : vi2d vMousePosCache = { 0 , 0 } ;
olc : : vi2d vMouseWindowPos = { 0 , 0 } ;
int32_t nMouseWheelDeltaCache = 0 ;
olc : : vi2d vWindowPos = { 0 , 0 } ;
olc : : vi2d vWindowSize = { 0 , 0 } ;
olc : : vi2d vViewPos = { 0 , 0 } ;
olc : : vi2d vViewSize = { 0 , 0 } ;
@ -1292,6 +1295,7 @@ namespace olc
// "Break In" Functions
void olc_UpdateMouse ( int32_t x , int32_t y ) ;
void olc_UpdateMouseWheel ( int32_t delta ) ;
void olc_UpdateWindowPos ( int32_t x , int32_t y ) ;
void olc_UpdateWindowSize ( int32_t x , int32_t y ) ;
void olc_UpdateViewport ( ) ;
void olc_ConstructFontSheet ( ) ;
@ -2001,6 +2005,7 @@ namespace olc
// Construct the window
if ( platform - > CreateWindowPane ( { 30 , 30 } , vWindowSize , bFullScreen ) ! = olc : : OK ) return olc : : FAIL ;
olc_UpdateWindowPos ( 30 , 30 ) ;
olc_UpdateWindowSize ( vWindowSize . x , vWindowSize . y ) ;
// Start the thread
@ -2126,6 +2131,9 @@ namespace olc
float PixelGameEngine : : GetElapsedTime ( ) const
{ return fLastElapsed ; }
const olc : : vi2d & PixelGameEngine : : GetWindowPos ( ) const
{ return vWindowPos ; }
const olc : : vi2d & PixelGameEngine : : GetWindowSize ( ) const
{ return vWindowSize ; }
@ -3761,6 +3769,11 @@ namespace olc
olc_UpdateViewport ( ) ;
}
void PixelGameEngine : : olc_UpdateWindowPos ( int32_t x , int32_t y )
{
vWindowPos = { x , y } ;
}
void PixelGameEngine : : olc_UpdateMouseWheel ( int32_t delta )
{ nMouseWheelDeltaCache + = delta ; }
@ -5589,6 +5602,7 @@ namespace olc
ptrPGE - > olc_UpdateMouse ( ix , iy ) ;
return 0 ;
}
case WM_MOVE : ptrPGE - > olc_UpdateWindowPos ( lParam & 0xFFFF , ( lParam > > 16 ) & 0xFFFF ) ; return 0 ;
case WM_SIZE : ptrPGE - > olc_UpdateWindowSize ( lParam & 0xFFFF , ( lParam > > 16 ) & 0xFFFF ) ; return 0 ;
case WM_MOUSEWHEEL : ptrPGE - > olc_UpdateMouseWheel ( GET_WHEEL_DELTA_WPARAM ( wParam ) ) ; return 0 ;
case WM_MOUSELEAVE : ptrPGE - > olc_UpdateMouseFocus ( false ) ; return 0 ;
@ -5834,11 +5848,13 @@ namespace olc
{
XWindowAttributes gwa ;
XGetWindowAttributes ( olc_Display , olc_Window , & gwa ) ;
ptrPGE - > olc_UpdateWindowPos ( gwa . x , gwa . y ) ;
ptrPGE - > olc_UpdateWindowSize ( gwa . width , gwa . height ) ;
}
else if ( xev . type = = ConfigureNotify )
{
XConfigureEvent xce = xev . xconfigure ;
ptrPGE - > olc_UpdateWindowPos ( xce . x , xce . y ) ;
ptrPGE - > olc_UpdateWindowSize ( xce . width , xce . height ) ;
}
else if ( xev . type = = KeyPress )
@ -6316,19 +6332,19 @@ namespace olc
mapKeys [ DOM_PK_QUOTE ] = Key : : OEM_7 ; mapKeys [ DOM_PK_BACKSLASH ] = Key : : OEM_8 ;
// Keyboard Callbacks
emscripten_set_keydown_callback ( " #canvas " , 0 , 1 , keyboard_callback ) ;
emscripten_set_keyup_callback ( " #canvas " , 0 , 1 , keyboard_callback ) ;
emscripten_set_keydown_callback ( " body " , 0 , 1 , keyboard_callback ) ;
emscripten_set_keyup_callback ( " body " , 0 , 1 , keyboard_callback ) ;
// Mouse Callbacks
emscripten_set_wheel_callback ( " #canvas " , 0 , 1 , wheel_callback ) ;
emscripten_set_mousedown_callback ( " #canvas " , 0 , 1 , mouse_callback ) ;
emscripten_set_mouseup_callback ( " #canvas " , 0 , 1 , mouse_callback ) ;
emscripten_set_mousemove_callback ( " #canvas " , 0 , 1 , mouse_callback ) ;
emscripten_set_mousedown_callback ( " body " , 0 , 1 , mouse_callback ) ;
emscripten_set_mouseup_callback ( " body " , 0 , 1 , mouse_callback ) ;
emscripten_set_mousemove_callback ( " body " , 0 , 1 , mouse_callback ) ;
// Touch Callbacks
emscripten_set_touchstart_callback ( " #canvas " , 0 , 1 , touch_callback ) ;
emscripten_set_touchmove_callback ( " #canvas " , 0 , 1 , touch_callback ) ;
emscripten_set_touchend_callback ( " #canvas " , 0 , 1 , touch_callback ) ;
emscripten_set_touchstart_callback ( " body " , 0 , 1 , touch_callback ) ;
emscripten_set_touchmove_callback ( " body " , 0 , 1 , touch_callback ) ;
emscripten_set_touchend_callback ( " body " , 0 , 1 , touch_callback ) ;
// Canvas Focus Callbacks
emscripten_set_blur_callback ( " #canvas " , 0 , 1 , focus_callback ) ;
@ -6569,7 +6585,22 @@ namespace olc
{ return olc : : OK ; }
virtual olc : : rcode HandleSystemEvent ( ) override
{ return olc : : OK ; }
{
ptrPGE - > olc_UpdateWindowPos ( EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . left } ) , EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . top } ) ) ;
int mouseDown = EM_ASM_INT ( { return Module . olc_MOUSEDOWN } ) ;
int mouseUp = EM_ASM_INT ( { return Module . olc_MOUSEUP } ) ;
if ( mouseDown ! = - 1 ) {
if ( mouseDown = = 2 ) { mouseDown = 1 ; } //Javascript uses button 2 as right click while PGE uses button 1. This translates it back.
ptrPGE - > olc_UpdateMouseState ( mouseDown , true ) ;
EM_ASM ( { Module . olc_MOUSEDOWN = - 1 } ) ;
}
if ( mouseUp ! = - 1 ) {
if ( mouseUp = = 2 ) { mouseUp = 1 ; } //Javascript uses button 2 as right click while PGE uses button 1. This translates it back.
ptrPGE - > olc_UpdateMouseState ( mouseUp , false ) ;
EM_ASM ( { Module . olc_MOUSEUP = - 1 } ) ;
}
return olc : : OK ;
}
static void MainLoop ( )
{