|
|
@ -998,6 +998,12 @@ namespace olc |
|
|
|
const olc::vi2d& GetWindowMouse() const; |
|
|
|
const olc::vi2d& GetWindowMouse() const; |
|
|
|
// Gets the mouse as a vector to keep Tarriest happy
|
|
|
|
// Gets the mouse as a vector to keep Tarriest happy
|
|
|
|
const olc::vi2d& GetMousePos() const; |
|
|
|
const olc::vi2d& GetMousePos() const; |
|
|
|
|
|
|
|
// Get Mouse X coordinate in "screen" space
|
|
|
|
|
|
|
|
int32_t GetMouseScreenX() const; |
|
|
|
|
|
|
|
// Get Mouse Y coordinate in "screen" space
|
|
|
|
|
|
|
|
int32_t GetMouseScreenY() const; |
|
|
|
|
|
|
|
// Gets the mouse as a vector in screen space, this will still keep Tarriest happy
|
|
|
|
|
|
|
|
const olc::vi2d& GetMouseScreenPos() const; |
|
|
|
|
|
|
|
|
|
|
|
static const std::map<size_t, uint8_t>& GetKeyMap() { return mapKeys; } |
|
|
|
static const std::map<size_t, uint8_t>& GetKeyMap() { return mapKeys; } |
|
|
|
|
|
|
|
|
|
|
@ -1021,6 +1027,8 @@ namespace olc |
|
|
|
uint32_t GetFPS() const; |
|
|
|
uint32_t GetFPS() const; |
|
|
|
// Gets last update of elapsed time
|
|
|
|
// Gets last update of elapsed time
|
|
|
|
float GetElapsedTime() const; |
|
|
|
float GetElapsedTime() const; |
|
|
|
|
|
|
|
// Gets Actual Window pos
|
|
|
|
|
|
|
|
const olc::vi2d& GetWindowPos() const; |
|
|
|
// Gets Actual Window size
|
|
|
|
// Gets Actual Window size
|
|
|
|
const olc::vi2d& GetWindowSize() const; |
|
|
|
const olc::vi2d& GetWindowSize() const; |
|
|
|
// Gets pixel scale
|
|
|
|
// Gets pixel scale
|
|
|
@ -1218,10 +1226,13 @@ namespace olc |
|
|
|
olc::vi2d vPixelSize = { 4, 4 }; |
|
|
|
olc::vi2d vPixelSize = { 4, 4 }; |
|
|
|
olc::vi2d vScreenPixelSize = { 4, 4 }; |
|
|
|
olc::vi2d vScreenPixelSize = { 4, 4 }; |
|
|
|
olc::vi2d vMousePos = { 0, 0 }; |
|
|
|
olc::vi2d vMousePos = { 0, 0 }; |
|
|
|
|
|
|
|
olc::vi2d vMouseScreenPos = { 0, 0 }; |
|
|
|
int32_t nMouseWheelDelta = 0; |
|
|
|
int32_t nMouseWheelDelta = 0; |
|
|
|
olc::vi2d vMousePosCache = { 0, 0 }; |
|
|
|
olc::vi2d vMousePosCache = { 0, 0 }; |
|
|
|
|
|
|
|
olc::vi2d vMouseScreenPosCache = { 0, 0 }; |
|
|
|
olc::vi2d vMouseWindowPos = { 0, 0 }; |
|
|
|
olc::vi2d vMouseWindowPos = { 0, 0 }; |
|
|
|
int32_t nMouseWheelDeltaCache = 0; |
|
|
|
int32_t nMouseWheelDeltaCache = 0; |
|
|
|
|
|
|
|
olc::vi2d vWindowPos = { 0, 0 }; |
|
|
|
olc::vi2d vWindowSize = { 0, 0 }; |
|
|
|
olc::vi2d vWindowSize = { 0, 0 }; |
|
|
|
olc::vi2d vViewPos = { 0, 0 }; |
|
|
|
olc::vi2d vViewPos = { 0, 0 }; |
|
|
|
olc::vi2d vViewSize = { 0,0 }; |
|
|
|
olc::vi2d vViewSize = { 0,0 }; |
|
|
@ -1291,7 +1302,9 @@ namespace olc |
|
|
|
public: |
|
|
|
public: |
|
|
|
// "Break In" Functions
|
|
|
|
// "Break In" Functions
|
|
|
|
void olc_UpdateMouse(int32_t x, int32_t y); |
|
|
|
void olc_UpdateMouse(int32_t x, int32_t y); |
|
|
|
|
|
|
|
void olc_UpdateScreenMouse(int32_t x, int32_t y); |
|
|
|
void olc_UpdateMouseWheel(int32_t delta); |
|
|
|
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_UpdateWindowSize(int32_t x, int32_t y); |
|
|
|
void olc_UpdateViewport(); |
|
|
|
void olc_UpdateViewport(); |
|
|
|
void olc_ConstructFontSheet(); |
|
|
|
void olc_ConstructFontSheet(); |
|
|
@ -2001,6 +2014,7 @@ namespace olc |
|
|
|
|
|
|
|
|
|
|
|
// Construct the window
|
|
|
|
// Construct the window
|
|
|
|
if (platform->CreateWindowPane({ 30,30 }, vWindowSize, bFullScreen) != olc::OK) return olc::FAIL; |
|
|
|
if (platform->CreateWindowPane({ 30,30 }, vWindowSize, bFullScreen) != olc::OK) return olc::FAIL; |
|
|
|
|
|
|
|
olc_UpdateWindowPos(30,30); |
|
|
|
olc_UpdateWindowSize(vWindowSize.x, vWindowSize.y); |
|
|
|
olc_UpdateWindowSize(vWindowSize.x, vWindowSize.y); |
|
|
|
|
|
|
|
|
|
|
|
// Start the thread
|
|
|
|
// Start the thread
|
|
|
@ -2114,6 +2128,15 @@ namespace olc |
|
|
|
const olc::vi2d& PixelGameEngine::GetMousePos() const |
|
|
|
const olc::vi2d& PixelGameEngine::GetMousePos() const |
|
|
|
{ return vMousePos; } |
|
|
|
{ return vMousePos; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t PixelGameEngine::GetMouseScreenX() const |
|
|
|
|
|
|
|
{ return vMouseScreenPos.x; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t PixelGameEngine::GetMouseScreenY() const |
|
|
|
|
|
|
|
{ return vMouseScreenPos.y; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const olc::vi2d& PixelGameEngine::GetMouseScreenPos() const |
|
|
|
|
|
|
|
{ return vMouseScreenPos; } |
|
|
|
|
|
|
|
|
|
|
|
int32_t PixelGameEngine::GetMouseWheel() const |
|
|
|
int32_t PixelGameEngine::GetMouseWheel() const |
|
|
|
{ return nMouseWheelDelta; } |
|
|
|
{ return nMouseWheelDelta; } |
|
|
|
|
|
|
|
|
|
|
@ -2126,6 +2149,9 @@ namespace olc |
|
|
|
float PixelGameEngine::GetElapsedTime() const |
|
|
|
float PixelGameEngine::GetElapsedTime() const |
|
|
|
{ return fLastElapsed; } |
|
|
|
{ return fLastElapsed; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const olc::vi2d& PixelGameEngine::GetWindowPos() const |
|
|
|
|
|
|
|
{ return vWindowPos; } |
|
|
|
|
|
|
|
|
|
|
|
const olc::vi2d& PixelGameEngine::GetWindowSize() const |
|
|
|
const olc::vi2d& PixelGameEngine::GetWindowSize() const |
|
|
|
{ return vWindowSize; } |
|
|
|
{ return vWindowSize; } |
|
|
|
|
|
|
|
|
|
|
@ -3760,6 +3786,11 @@ namespace olc |
|
|
|
vViewPos = (vWindowSize - vViewSize) / 2; |
|
|
|
vViewPos = (vWindowSize - vViewSize) / 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PixelGameEngine::olc_UpdateWindowPos(int32_t x, int32_t y) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
vWindowPos = { x, y }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PixelGameEngine::olc_UpdateWindowSize(int32_t x, int32_t y) |
|
|
|
void PixelGameEngine::olc_UpdateWindowSize(int32_t x, int32_t y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
vWindowSize = { x, y }; |
|
|
|
vWindowSize = { x, y }; |
|
|
@ -3786,6 +3817,12 @@ namespace olc |
|
|
|
if (vMousePosCache.y < 0) vMousePosCache.y = 0; |
|
|
|
if (vMousePosCache.y < 0) vMousePosCache.y = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PixelGameEngine::olc_UpdateScreenMouse(int32_t x, int32_t y) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
vMouseScreenPos={x,y}; |
|
|
|
|
|
|
|
vMouseScreenPosCache={x,y}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PixelGameEngine::olc_UpdateMouseState(int32_t button, bool state) |
|
|
|
void PixelGameEngine::olc_UpdateMouseState(int32_t button, bool state) |
|
|
|
{ pMouseNewState[button] = state; } |
|
|
|
{ pMouseNewState[button] = state; } |
|
|
|
|
|
|
|
|
|
|
@ -3932,6 +3969,11 @@ namespace olc |
|
|
|
for (auto& ext : vExtensions) bExtensionBlockFrame |= ext->OnBeforeUserUpdate(fElapsedTime); |
|
|
|
for (auto& ext : vExtensions) bExtensionBlockFrame |= ext->OnBeforeUserUpdate(fElapsedTime); |
|
|
|
if (!bExtensionBlockFrame) |
|
|
|
if (!bExtensionBlockFrame) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
#if defined(OLC_PLATFORM_WINAPI) |
|
|
|
|
|
|
|
struct tagPOINT p{0,0}; |
|
|
|
|
|
|
|
GetCursorPos(&p); |
|
|
|
|
|
|
|
olc_UpdateScreenMouse(p.x,p.y); |
|
|
|
|
|
|
|
#endif |
|
|
|
if (!OnUserUpdate(fElapsedTime)) bAtomActive = false; |
|
|
|
if (!OnUserUpdate(fElapsedTime)) bAtomActive = false; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -5594,6 +5636,7 @@ namespace olc |
|
|
|
ptrPGE->olc_UpdateMouse(ix, iy); |
|
|
|
ptrPGE->olc_UpdateMouse(ix, iy); |
|
|
|
return 0; |
|
|
|
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_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_MOUSEWHEEL: ptrPGE->olc_UpdateMouseWheel(GET_WHEEL_DELTA_WPARAM(wParam)); return 0; |
|
|
|
case WM_MOUSELEAVE: ptrPGE->olc_UpdateMouseFocus(false); return 0; |
|
|
|
case WM_MOUSELEAVE: ptrPGE->olc_UpdateMouseFocus(false); return 0; |
|
|
@ -5839,11 +5882,13 @@ namespace olc |
|
|
|
{ |
|
|
|
{ |
|
|
|
XWindowAttributes gwa; |
|
|
|
XWindowAttributes gwa; |
|
|
|
XGetWindowAttributes(olc_Display, olc_Window, &gwa); |
|
|
|
XGetWindowAttributes(olc_Display, olc_Window, &gwa); |
|
|
|
|
|
|
|
ptrPGE->olc_UpdateWindowPos(gwa.x, gwa.y); |
|
|
|
ptrPGE->olc_UpdateWindowSize(gwa.width, gwa.height); |
|
|
|
ptrPGE->olc_UpdateWindowSize(gwa.width, gwa.height); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xev.type == ConfigureNotify) |
|
|
|
else if (xev.type == ConfigureNotify) |
|
|
|
{ |
|
|
|
{ |
|
|
|
XConfigureEvent xce = xev.xconfigure; |
|
|
|
XConfigureEvent xce = xev.xconfigure; |
|
|
|
|
|
|
|
ptrPGE->olc_UpdateWindowPos(xce.x, xce.y); |
|
|
|
ptrPGE->olc_UpdateWindowSize(xce.width, xce.height); |
|
|
|
ptrPGE->olc_UpdateWindowSize(xce.width, xce.height); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xev.type == KeyPress) |
|
|
|
else if (xev.type == KeyPress) |
|
|
@ -6340,7 +6385,7 @@ namespace olc |
|
|
|
emscripten_set_focus_callback("#canvas", 0, 1, focus_callback); |
|
|
|
emscripten_set_focus_callback("#canvas", 0, 1, focus_callback); |
|
|
|
|
|
|
|
|
|
|
|
#pragma warning disable format |
|
|
|
#pragma warning disable format |
|
|
|
EM_ASM( window.onunload = Module._olc_OnPageUnload; ); |
|
|
|
EM_ASM( window.onunload = Module._olc_OnPageUnload;); |
|
|
|
|
|
|
|
|
|
|
|
// IMPORTANT! - Sorry About This...
|
|
|
|
// IMPORTANT! - Sorry About This...
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -6363,6 +6408,7 @@ namespace olc |
|
|
|
// dimensions of the canvas container's element.
|
|
|
|
// dimensions of the canvas container's element.
|
|
|
|
Module.olc_AspectRatio = $0 / $1; |
|
|
|
Module.olc_AspectRatio = $0 / $1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onmousemove = function(e){Module.olc_MOUSEX=e.clientX;Module.olc_MOUSEY=e.clientY;}; |
|
|
|
// HACK ALERT!
|
|
|
|
// HACK ALERT!
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Here we assume any html shell that uses 3 or more instance of the class "emscripten"
|
|
|
|
// Here we assume any html shell that uses 3 or more instance of the class "emscripten"
|
|
|
@ -6414,8 +6460,6 @@ namespace olc |
|
|
|
Module.canvas.focus(); |
|
|
|
Module.canvas.focus(); |
|
|
|
}, 200); |
|
|
|
}, 200); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// olc_Init
|
|
|
|
// olc_Init
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// set up resize observer and fullscreenchange event handler
|
|
|
|
// set up resize observer and fullscreenchange event handler
|
|
|
@ -6451,10 +6495,17 @@ namespace olc |
|
|
|
Module.olc_Init(); |
|
|
|
Module.olc_Init(); |
|
|
|
|
|
|
|
|
|
|
|
}, vWindowSize.x, vWindowSize.y); // Fullscreen and Resize Observers
|
|
|
|
}, vWindowSize.x, vWindowSize.y); // Fullscreen and Resize Observers
|
|
|
|
|
|
|
|
|
|
|
|
#pragma warning restore format |
|
|
|
#pragma warning restore format |
|
|
|
return olc::rcode::OK; |
|
|
|
return olc::rcode::OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateScreenMouse(int x, int y) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ptrPGE->olc_UpdateScreenMouse(x, y); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Interface PGE's UpdateWindowSize, for use in Javascript
|
|
|
|
// Interface PGE's UpdateWindowSize, for use in Javascript
|
|
|
|
void UpdateWindowSize(int width, int height) |
|
|
|
void UpdateWindowSize(int width, int height) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -6508,12 +6559,14 @@ namespace olc |
|
|
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) |
|
|
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ptrPGE->olc_UpdateMouse(e->touches->targetX, e->touches->targetY); |
|
|
|
ptrPGE->olc_UpdateMouse(e->touches->targetX, e->touches->targetY); |
|
|
|
|
|
|
|
ptrPGE->olc_UpdateScreenMouse(e->touches->targetX, e->touches->targetY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Start
|
|
|
|
// Start
|
|
|
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) |
|
|
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ptrPGE->olc_UpdateMouse(e->touches->targetX, e->touches->targetY); |
|
|
|
ptrPGE->olc_UpdateMouse(e->touches->targetX, e->touches->targetY); |
|
|
|
|
|
|
|
ptrPGE->olc_UpdateScreenMouse(e->touches->targetX, e->touches->targetY); |
|
|
|
ptrPGE->olc_UpdateMouseState(0, true); |
|
|
|
ptrPGE->olc_UpdateMouseState(0, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -6530,8 +6583,10 @@ namespace olc |
|
|
|
static EM_BOOL mouse_callback(int eventType, const EmscriptenMouseEvent* e, void* userData) |
|
|
|
static EM_BOOL mouse_callback(int eventType, const EmscriptenMouseEvent* e, void* userData) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//Mouse Movement
|
|
|
|
//Mouse Movement
|
|
|
|
if (eventType == EMSCRIPTEN_EVENT_MOUSEMOVE) |
|
|
|
if (eventType == EMSCRIPTEN_EVENT_MOUSEMOVE){ |
|
|
|
ptrPGE->olc_UpdateMouse(e->targetX, e->targetY); |
|
|
|
ptrPGE->olc_UpdateMouse(e->targetX, e->targetY); |
|
|
|
|
|
|
|
ptrPGE->olc_UpdateScreenMouse(e->targetX, e->targetY); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Mouse button press
|
|
|
|
//Mouse button press
|
|
|
@ -6578,6 +6633,10 @@ namespace olc |
|
|
|
|
|
|
|
|
|
|
|
static void MainLoop() |
|
|
|
static void MainLoop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ptrPGE->olc_UpdateWindowPos(EM_ASM_INT({return Module.canvas.getBoundingClientRect().left}),EM_ASM_INT({return Module.canvas.getBoundingClientRect().top})); |
|
|
|
|
|
|
|
vi2d screenMousePos = {EM_ASM_INT({return Module.olc_MOUSEX;}),EM_ASM_INT({return Module.olc_MOUSEY;})}; |
|
|
|
|
|
|
|
ptrPGE->olc_UpdateScreenMouse(screenMousePos.x,screenMousePos.y); |
|
|
|
olc::Platform::ptrPGE->olc_CoreUpdate(); |
|
|
|
olc::Platform::ptrPGE->olc_CoreUpdate(); |
|
|
|
if (!ptrPGE->olc_IsRunning()) |
|
|
|
if (!ptrPGE->olc_IsRunning()) |
|
|
|
{ |
|
|
|
{ |
|
|
|