@ -1062,6 +1062,8 @@ namespace olc
const bool IsMouseInsideWindow ( ) const ;
// Gets Actual Window pos
const olc : : vi2d & GetWindowPos ( ) const ;
// Gets the upper-left corner of the window to include window decorations/borders.
const olc : : vi2d & GetActualWindowPos ( ) const ;
// Gets Actual Window size
const olc : : vi2d & GetWindowSize ( ) const ;
// Gets pixel scale
@ -1310,6 +1312,7 @@ namespace olc
olc : : vi2d vMouseWindowPos = { 0 , 0 } ;
int32_t nMouseWheelDeltaCache = 0 ;
olc : : vi2d vWindowPos = { 0 , 0 } ;
olc : : vi2d vActualWindowPos = { 0 , 0 } ;
olc : : vi2d vWindowSize = { 0 , 0 } ;
olc : : vi2d vViewPos = { 0 , 0 } ;
olc : : vi2d vViewSize = { 0 , 0 } ;
@ -1382,6 +1385,7 @@ namespace olc
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_UpdateActualWindowPos ( int32_t x , int32_t y ) ;
void olc_UpdateWindowSize ( int32_t x , int32_t y ) ;
void olc_UpdateViewport ( ) ;
void olc_ConstructFontSheet ( ) ;
@ -2263,6 +2267,9 @@ namespace olc
const olc : : vi2d & PixelGameEngine : : GetWindowPos ( ) const
{ return vWindowPos ; }
const olc : : vi2d & PixelGameEngine : : GetActualWindowPos ( ) const
{ return vActualWindowPos ; }
const olc : : vi2d & PixelGameEngine : : GetWindowSize ( ) const
{ return vWindowSize ; }
@ -4521,6 +4528,11 @@ namespace olc
vWindowPos = { x , y } ;
}
void PixelGameEngine : : olc_UpdateActualWindowPos ( int32_t x , int32_t y ) {
vActualWindowPos = { x , y } ;
std : : cout < < vActualWindowPos < < std : : endl ;
}
void PixelGameEngine : : olc_UpdateMouseWheel ( int32_t delta )
{ nMouseWheelDeltaCache + = delta ; }
@ -6414,7 +6426,7 @@ namespace olc
RECT rWndRect = { 0 , 0 , ptrPGE - > GetWindowSize ( ) . x , ptrPGE - > GetWindowSize ( ) . y } ;
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE ;
DWORD dwStyle = WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_THICKFRAME ;
AdjustWindowRectEx ( & rWndRect , dwStyle , FALSE , dwExStyle ) ;
WINDOWPLACEMENT placement ;
int width = rWndRect . right - rWndRect . left ;
int height = rWndRect . bottom - rWndRect . top ;
MoveWindow ( olc_hWnd , pos . x , pos . y , width , height , true ) ;
@ -6427,9 +6439,10 @@ namespace olc
DWORD dwStyle = WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_THICKFRAME ;
WINDOWPLACEMENT placement ;
GetWindowPlacement ( olc_hWnd , & placement ) ;
AdjustWindowRectEx ( & rWndRect , dwStyle , FALSE , dwExStyle ) ;
int width = rWndRect . right - rWndRect . left ;
int height = rWndRect . bottom - rWndRect . top ;
MoveWindow ( olc_hWnd , placement . rcNormalPosition . left , placement . rcNormalPosition . top , width * ptrPGE - > GetPixelSize ( ) . x , height * ptrPGE - > GetPixelSize ( ) . y , true ) ;
MoveWindow ( olc_hWnd , placement . rcNormalPosition . left , placement . rcNormalPosition . top , width , height , true ) ;
}
}
@ -6448,6 +6461,7 @@ namespace olc
struct tagPOINT p { 0 , 0 } ;
//Update mouse positions and states outside the window.
GetCursorPos ( & p ) ;
ptrPGE - > olc_UpdateMouse ( p . x - ptrPGE - > GetWindowPos ( ) . x , p . y - ptrPGE - > GetWindowPos ( ) . y ) ;
ptrPGE - > olc_UpdateMouseState ( 0 , GetAsyncKeyState ( VK_LBUTTON ) > > 7 ) ;
ptrPGE - > olc_UpdateMouseState ( 1 , GetAsyncKeyState ( VK_RBUTTON ) > > 7 ) ;
@ -6475,6 +6489,12 @@ namespace olc
uint16_t x = lParam & 0xFFFF ; uint16_t y = ( lParam > > 16 ) & 0xFFFF ;
int16_t ix = * ( int16_t * ) & x ; int16_t iy = * ( int16_t * ) & y ;
ptrPGE - > olc_UpdateWindowPos ( ix , iy ) ;
//HACK ALERT! GetWindowPos() actually returns (0,0) for the canvas and not the window border, so to compensate we have to move down by the border amount.
WINDOWPLACEMENT placement ;
GetWindowPlacement ( hWnd , & placement ) ;
ptrPGE - > olc_UpdateActualWindowPos ( placement . rcNormalPosition . left , placement . rcNormalPosition . top ) ;
return 0 ;
}
case WM_SIZE : ptrPGE - > olc_UpdateWindowSize ( lParam & 0xFFFF , ( lParam > > 16 ) & 0xFFFF ) ; return 0 ;
@ -6706,7 +6726,7 @@ namespace olc
virtual void SetWindowSize ( vi2d size ) override {
if ( ! ptrPGE - > IsFullscreen ( ) ) {
XMapWindow ( olc_Display , olc_Window ) ;
XResizeWindow ( olc_Display , olc_Window , size . x * ptrPGE - > GetPixelSize ( ) . x , size . y * ptrPGE - > GetPixelSize ( ) . y ) ;
XResizeWindow ( olc_Display , olc_Window , size . x , size . y ) ;
}
}
@ -6765,12 +6785,14 @@ namespace olc
XWindowAttributes gwa ;
XGetWindowAttributes ( olc_Display , olc_Window , & gwa ) ;
ptrPGE - > olc_UpdateWindowPos ( gwa . x , gwa . y ) ;
ptrPGE - > olc_UpdateActualWindowPos ( 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_UpdateActualWindowPos ( xce . x , xce . y ) ;
ptrPGE - > olc_UpdateWindowSize ( xce . width , xce . height ) ;
}
else if ( xev . type = = KeyPress )
@ -7532,12 +7554,14 @@ namespace olc
virtual olc : : rcode StartSystemEventLoop ( ) override
{
ptrPGE - > olc_UpdateWindowPos ( EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . left } ) , EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . top } ) ) ;
ptrPGE - > olc_UpdateActualWindowPos ( EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . left } ) , EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . top } ) ) ;
return olc : : OK ;
}
virtual olc : : rcode HandleSystemEvent ( ) override
{
ptrPGE - > olc_UpdateWindowPos ( EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . left } ) , EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . top } ) ) ;
ptrPGE - > olc_UpdateActualWindowPos ( EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . left } ) , EM_ASM_INT ( { return Module . canvas . getBoundingClientRect ( ) . top } ) ) ;
return olc : : OK ;
}