mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-09-30 19:07:59 +03:00
Treat touches outside the viewport as right-clicks
The old method to simulate right click (two-finger touch) still works.
This commit is contained in:
+30
-10
@@ -13,8 +13,15 @@
|
||||
#include "ags.h"
|
||||
#include "texthook.h"
|
||||
|
||||
enum TouchState {
|
||||
TOUCH_NONE,
|
||||
TOUCH_LBUTTON,
|
||||
TOUCH_RBUTTON,
|
||||
};
|
||||
|
||||
extern SDL_Window* g_window;
|
||||
static int mousex, mousey, fingers;
|
||||
static int mousex, mousey;
|
||||
static TouchState touch_state = TOUCH_NONE;
|
||||
|
||||
void NACT::pump_events()
|
||||
{
|
||||
@@ -47,7 +54,25 @@ void NACT::pump_events()
|
||||
case SDL_FINGERMOTION:
|
||||
mousex = e.tfinger.x * 640;
|
||||
mousey = e.tfinger.y * ags->screen_height;
|
||||
fingers = SDL_GetNumTouchFingers(e.tfinger.touchId);
|
||||
switch (SDL_GetNumTouchFingers(e.tfinger.touchId)) {
|
||||
case 0:
|
||||
touch_state = TOUCH_NONE;
|
||||
break;
|
||||
case 1:
|
||||
// A touch outside of the viewport (SDL clamps it to 0.0-1.0) is
|
||||
// a right-click.
|
||||
if (e.tfinger.x == 0.0f || e.tfinger.x == 1.0f ||
|
||||
e.tfinger.y == 0.0f || e.tfinger.y == 1.0f) {
|
||||
touch_state = TOUCH_RBUTTON;
|
||||
} else {
|
||||
touch_state = TOUCH_LBUTTON;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// Two-finger touch is a right-click.
|
||||
touch_state = TOUCH_RBUTTON;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_APP_DIDENTERFOREGROUND:
|
||||
@@ -67,19 +92,14 @@ uint8 NACT::get_key()
|
||||
|
||||
// キーボード&マウス
|
||||
const Uint8* key = SDL_GetKeyboardState(NULL);
|
||||
Uint32 mouse;
|
||||
if (fingers) {
|
||||
mouse = fingers == 1 ? SDL_BUTTON_LMASK : SDL_BUTTON_RMASK;
|
||||
} else {
|
||||
mouse = SDL_GetMouseState(NULL, NULL);
|
||||
}
|
||||
Uint32 mouse = SDL_GetMouseState(NULL, NULL);
|
||||
|
||||
if(key[SDL_SCANCODE_UP ] || key[SDL_SCANCODE_KP_8 ] ) val |= 0x01;
|
||||
if(key[SDL_SCANCODE_DOWN ] || key[SDL_SCANCODE_KP_2 ] ) val |= 0x02;
|
||||
if(key[SDL_SCANCODE_LEFT ] || key[SDL_SCANCODE_KP_4 ] ) val |= 0x04;
|
||||
if(key[SDL_SCANCODE_RIGHT ] || key[SDL_SCANCODE_KP_6 ] ) val |= 0x08;
|
||||
if(key[SDL_SCANCODE_RETURN] || mouse & SDL_BUTTON_LMASK) val |= 0x10;
|
||||
if(key[SDL_SCANCODE_SPACE ] || mouse & SDL_BUTTON_RMASK) val |= 0x20;
|
||||
if(key[SDL_SCANCODE_RETURN] || mouse & SDL_BUTTON_LMASK || touch_state == TOUCH_LBUTTON) val |= 0x10;
|
||||
if(key[SDL_SCANCODE_SPACE ] || mouse & SDL_BUTTON_RMASK || touch_state == TOUCH_RBUTTON) val |= 0x20;
|
||||
if(key[SDL_SCANCODE_ESCAPE] ) val |= 0x40;
|
||||
if(key[SDL_SCANCODE_TAB ] ) val |= 0x80;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user