mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-10-14 01:49:05 +03:00
Treat 2-fingers touch as right click
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ EMFLAGS += -O2
|
||||
EMFLAGS += -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1
|
||||
|
||||
LFLAGS := $(EMFLAGS)
|
||||
LFLAGS += -s EXPORTED_FUNCTIONS="['_main','_ags_setAntialiasedStringMode','_sdl_rightButton', '_ald_getdata', '_ald_freedata']"
|
||||
LFLAGS += -s EXPORTED_FUNCTIONS="['_main','_ags_setAntialiasedStringMode', '_ald_getdata', '_ald_freedata']"
|
||||
|
||||
WASMFLAGS := -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s "BINARYEN_TRAP_MODE='allow'"
|
||||
ASMJSFLAGS := -s TOTAL_MEMORY=100663296
|
||||
|
||||
@@ -37,7 +37,6 @@ header {
|
||||
}
|
||||
|
||||
.contents {
|
||||
-webkit-user-select: none;
|
||||
max-width: 640px;
|
||||
margin: 2ex auto 0;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ namespace xsystem35 {
|
||||
Module.callMain();
|
||||
this.antialiasChanged();
|
||||
}, 0);
|
||||
this.addRightClickEmulation();
|
||||
}
|
||||
|
||||
setStatus(text: string) {
|
||||
@@ -140,22 +139,6 @@ namespace xsystem35 {
|
||||
localStorage.setItem('antialias', String(this.antialiasCheckbox.checked));
|
||||
_ags_setAntialiasedStringMode(this.antialiasCheckbox.checked ? 1 : 0);
|
||||
}
|
||||
|
||||
private addRightClickEmulation() {
|
||||
let emulatingRightClick = false;
|
||||
document.body.addEventListener('touchstart', (e) => {
|
||||
if (e.target !== document.body)
|
||||
return;
|
||||
_sdl_rightButton(1);
|
||||
emulatingRightClick = true;
|
||||
});
|
||||
document.body.addEventListener('touchend', (e) => {
|
||||
if (!emulatingRightClick)
|
||||
return;
|
||||
_sdl_rightButton(0);
|
||||
emulatingRightClick = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export let shell = new System35Shell();
|
||||
|
||||
@@ -23,7 +23,6 @@ declare var WebAssembly: any;
|
||||
// xsystem35 exported functions
|
||||
declare function _musfade_setvolval_all(vol: number): void;
|
||||
declare function _ags_setAntialiasedStringMode(on: number): void;
|
||||
declare function _sdl_rightButton(down: number): void;
|
||||
declare function _ald_getdata(type: number, no: number): number;
|
||||
declare function _ald_freedata(data: number): void;
|
||||
|
||||
|
||||
+18
-15
@@ -124,17 +124,27 @@ static void sdl_getEvent(void) {
|
||||
break;
|
||||
|
||||
case SDL_FINGERDOWN:
|
||||
mouseb |= 1 << SDL_BUTTON_LEFT;
|
||||
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = TRUE;
|
||||
mousex = e.tfinger.x * view_w;
|
||||
mousey = e.tfinger.y * view_h;
|
||||
if (SDL_GetNumTouchFingers(SDL_GetTouchDevice(0)) >= 2) {
|
||||
mouseb &= ~(1 << SDL_BUTTON_LEFT);
|
||||
mouseb |= 1 << SDL_BUTTON_RIGHT;
|
||||
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = FALSE;
|
||||
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_RIGHT)] = TRUE;
|
||||
} else {
|
||||
mouseb |= 1 << SDL_BUTTON_LEFT;
|
||||
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = TRUE;
|
||||
mousex = e.tfinger.x * view_w;
|
||||
mousey = e.tfinger.y * view_h;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_FINGERUP:
|
||||
mouseb &= ~(1 << SDL_BUTTON_LEFT);
|
||||
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = FALSE;
|
||||
mousex = e.tfinger.x * view_w;
|
||||
mousey = e.tfinger.y * view_h;
|
||||
if (SDL_GetNumTouchFingers(SDL_GetTouchDevice(0)) == 0) {
|
||||
mouseb &= ~(1 << SDL_BUTTON_LEFT | 1 << SDL_BUTTON_RIGHT);
|
||||
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = FALSE;
|
||||
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_RIGHT)] = FALSE;
|
||||
mousex = e.tfinger.x * view_w;
|
||||
mousey = e.tfinger.y * view_h;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_FINGERMOTION:
|
||||
@@ -252,10 +262,3 @@ int sdl_getjoyinfo(void) {
|
||||
return joyinfo;
|
||||
}
|
||||
#endif
|
||||
|
||||
void sdl_rightButton(int down) {
|
||||
SDL_Event sdlevent;
|
||||
sdlevent.type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
|
||||
sdlevent.button.button = SDL_BUTTON_RIGHT;
|
||||
SDL_PushEvent(&sdlevent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user