mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
DPI scale mouse coordinates in web client
This commit is contained in:
parent
e608660785
commit
298d497c55
18
src/Window.c
18
src/Window.c
@ -2763,6 +2763,8 @@ void GLContext_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <emscripten/html5.h>
|
||||
#include <emscripten/key_codes.h>
|
||||
static float dpiScale;
|
||||
#define DPI_SCALE(x) ((int)(x * dpiScale))
|
||||
|
||||
static void Window_RefreshBounds(void) {
|
||||
emscripten_get_canvas_element_size(NULL, &Window_Width, &Window_Height);
|
||||
@ -2802,7 +2804,7 @@ static EM_BOOL Window_MouseMove(int type, const EmscriptenMouseEvent* ev, void*
|
||||
Input_SetPressed(KEY_RMOUSE, (ev->buttons & 0x02) != 0);
|
||||
Input_SetPressed(KEY_MMOUSE, (ev->buttons & 0x04) != 0);
|
||||
|
||||
Pointer_SetPosition(0, ev->canvasX, ev->canvasY);
|
||||
Pointer_SetPosition(0, DPI_SCALE(ev->canvasX), DPI_SCALE(ev->canvasY));
|
||||
if (Input_RawMode) Event_RaiseMove(&PointerEvents.RawMoved, 0, ev->movementX, ev->movementY);
|
||||
return true;
|
||||
}
|
||||
@ -2812,7 +2814,9 @@ static EM_BOOL Window_TouchStart(int type, const EmscriptenTouchEvent* ev, void*
|
||||
int i;
|
||||
for (i = 0; i < ev->numTouches; ++i) {
|
||||
t = &ev->touches[i];
|
||||
if (t->isChanged) Input_AddTouch(t->identifier, t->canvasX, t->canvasY);
|
||||
if (!t->isChanged) continue;
|
||||
|
||||
Input_AddTouch(t->identifier, DPI_SCALE(t->canvasX), DPI_SCALE(t->canvasY));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -2822,7 +2826,9 @@ static EM_BOOL Window_TouchMove(int type, const EmscriptenTouchEvent* ev, void*
|
||||
int i;
|
||||
for (i = 0; i < ev->numTouches; ++i) {
|
||||
t = &ev->touches[i];
|
||||
if (t->isChanged) Input_UpdateTouch(t->identifier, t->canvasX, t->canvasY);
|
||||
if (!t->isChanged) continue;
|
||||
|
||||
Input_UpdateTouch(t->identifier, DPI_SCALE(t->canvasX), DPI_SCALE(t->canvasY));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -2832,7 +2838,9 @@ static EM_BOOL Window_TouchEnd(int type, const EmscriptenTouchEvent* ev, void* d
|
||||
int i;
|
||||
for (i = 0; i < ev->numTouches; ++i) {
|
||||
t = &ev->touches[i];
|
||||
if (t->isChanged) Input_RemoveTouch(t->identifier, t->canvasX, t->canvasY);
|
||||
if (!t->isChanged) continue;
|
||||
|
||||
Input_RemoveTouch(t->identifier, DPI_SCALE(t->canvasX), DPI_SCALE(t->canvasY));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -3013,6 +3021,8 @@ void Window_Init(void) {
|
||||
Display_Bounds.Height = EM_ASM_INT_V({ return screen.height; });
|
||||
Display_BitsPerPixel = 24;
|
||||
|
||||
dpiScale = EM_ASM_DOUBLE_V({ return window.devicePixelRatio || 1.0; });
|
||||
|
||||
/* copy text, but only if user isn't selecting something else on the webpage */
|
||||
EM_ASM(window.addEventListener('copy',
|
||||
function(e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user