Skip to content

Commit

Permalink
implement touch control for on-screen keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Apr 4, 2020
1 parent a4a1492 commit 6a6c661
Show file tree
Hide file tree
Showing 26 changed files with 176 additions and 19 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
set(CMAKE_VERBOSE_MAKEFILE OFF)

set(VERSION_MAJOR 1)
set(VERSION_MINOR 98)
set(VERSION_MINOR 99)

if(BUILD_PSP2)
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
Expand Down Expand Up @@ -143,7 +143,7 @@ if(BUILD_PSP2)
-DUSE_UAE4ALL_VKBD
-DUSE_ARMV7
-DUSE_ARMNEON
-marm -mfpu=neon -mcpu=cortex-a9 -march=armv7-a -mfloat-abi=hard -ffast-math
-marm -mfpu=neon -mtune=cortex-a9 -mfloat-abi=hard -ffast-math
-fno-asynchronous-unwind-tables -funroll-loops
-mword-relocations -fno-unwind-tables -fno-optimize-sibling-calls
-mvectorize-with-neon-quad -funsafe-math-optimizations
Expand Down
23 changes: 9 additions & 14 deletions README.MD
Expand Up @@ -4,19 +4,9 @@ On the Switch, since v1.84, please use nsp injection to start uae4all2, otherwis

Recent Changes
======
1.98 (Switch only)

- recompile to add support for 9.0.0 firmware

1.97 (Switch only)

- add option to main menu that displays online instruction manual (opens web browser)
1.99

1.96

- increase maximum displayed lines from 270 to 286, useful for overscan games like Babeanoid
- fix cia overlay in AGA mode, fixes Reshoot-R hang at title screen
- add instruction manual to Vita livearea screen
- allow touch input to control on-screen keyboard in addition to dpad

Description
=====
Expand All @@ -40,7 +30,7 @@ Thanks to CrashMidnick for the French virtual keyboard.

Thanks to the original authors Chui, john4p, TomB, notaz, Bernd Schneider, Toni Wilen, Pickle, smoku, AnotherGuest, Anonymous engineer, finkel, Lubomyr, pelya and many more.

Thanks to my supporters on Patreon: Andyways, CountDuckula, Jason Crawford, Greg Gibson, Jesse Harlin, Özgür Karter, Matthew Machnee, Milenko, Ibrahim Fazel Poor, and RadicalR.
Thanks to my supporters on Patreon: Andyways, Count Duckula, Jesse Harlin, Özgür Karter, Matthew Machnee, Mored4u, Ibrahim Fazel Poor, and RadicalR.

Installation
======
Expand Down Expand Up @@ -96,6 +86,7 @@ Vita/Switch-exclusive Features
- Config file management (load, save as, etc.)
- Thumbnail previews for savestates
- Four different on-screen keyboard styles: original, warm, cool, and dark
- On-screen keyboard keys can be pressed via touch input in addition to dpad navigation

Controls
=====
Expand Down Expand Up @@ -267,7 +258,7 @@ Games with no fixes (or unknown fixes)

- IK+
Issue: no sound fx
Fix: unknown, but can play PlayStation 1 version in Retroarch instead. This requires cycle exact, which is not supported.
Fix: unknown, but can play PlayStation 1 version in Retroarch instead. The Retroarch PUAE core can play this game correctly on Vita.

- Nebulus 2
Issue: doors are not showing
Expand Down Expand Up @@ -326,6 +317,10 @@ Compiling

CHANGELOG
=====
1.99

- allow touch input to control on-screen keyboard, in addition to dpad

1.98 (Switch only)

- recompile to add support for 9.0.0 firmware
Expand Down
Binary file modified psp2data/sce_sys/manual/001.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/002.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/003.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/004.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/005.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/006.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/007.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/008.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/009.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/010.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/011.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/012.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/013.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/014.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/015.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified psp2data/sce_sys/manual/016.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psp2data/sce_sys/manual/017.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/gp2x/menu/menu_main.cpp
Expand Up @@ -945,7 +945,7 @@ SDL_ANDROID_SetScreenKeyboardShown(1);
{
// This works on all CFW
WebWifiConfig conf;
webWifiCreate(&conf, NULL, "https://github.com/rsn8887/uae4all2/releases/latest", 0, 0);
webWifiCreate(&conf, NULL, "https://github.com/rsn8887/uae4all2/releases/latest", (Uuid){0}, 0);
webWifiShow(&conf, NULL);
// The following would be better, but crashes on SX OS
//WebCommonConfig config;
Expand Down
7 changes: 5 additions & 2 deletions src/od-joy.cpp
Expand Up @@ -762,9 +762,12 @@ void read_joystick(int nr, unsigned int *dir, int *button)
}
#endif
else { //button release, pressing sticky keys is possible again.
for (int i=0; i<NUM_STICKY; i++)
if (vkbd_touch_x == -1 && vkbd_touch_y == -1)
{
vkbd_sticky_key[i].can_switch=true;
for (int i=0; i<NUM_STICKY; i++)
{
vkbd_sticky_key[i].can_switch=true;
}
}
}
// TODO: add vkbd_button2 mapped to button2
Expand Down
22 changes: 22 additions & 0 deletions src/psp2/psp2_touch.c
Expand Up @@ -11,6 +11,8 @@ typedef int bool;
#define false 0;
#define true 1;

#include "vkbd.h"

SceTouchData touch_old[SCE_TOUCH_PORT_MAX_NUM];
SceTouchData touch[SCE_TOUCH_PORT_MAX_NUM];

Expand Down Expand Up @@ -237,6 +239,14 @@ void psp2ProcessFingerDown(TouchEvent *event) {
// id (for multitouch)
int id = event->tfinger.fingerId;

if (vkbd_mode) {
if (port == 0) {
vkbd_touch_x = event->tfinger.x;
vkbd_touch_y = event->tfinger.y;
}
return;
}

int x = lastmx;
int y = lastmy;

Expand Down Expand Up @@ -267,6 +277,15 @@ void psp2ProcessFingerUp(TouchEvent *event) {
// id (for multitouch)
int id = event->tfinger.fingerId;

if (vkbd_mode) {
if (port == 0) {
vkbd_touch_x = -1;
vkbd_touch_y = -1;
vkbd_move &= ~VKBD_BUTTON;
}
return;
}

// find out how many fingers were down before this event
int numFingersDown = 0;
for (int i = 0; i < MAX_NUM_FINGERS; i++) {
Expand Down Expand Up @@ -331,6 +350,9 @@ void psp2ProcessFingerUp(TouchEvent *event) {
}

void psp2ProcessFingerMotion(TouchEvent *event) {
if (vkbd_mode)
return;

// front (0) or back (1) panel
int port = event->tfinger.touchId;
// id (for multitouch)
Expand Down
Binary file modified src/psp2/vita2d_fbo/lib/libvita2d.a
Binary file not shown.
23 changes: 23 additions & 0 deletions src/switch/switch_touch.c
Expand Up @@ -17,6 +17,9 @@

#include "math.h"

typedef int bool;
#include "vkbd.h"

static void initTouch();
static void preprocessEvents(SDL_Event *event);
static void preprocessFingerDown(SDL_Event *event);
Expand Down Expand Up @@ -124,6 +127,14 @@ static void preprocessFingerDown(SDL_Event *event) {
// id (for multitouch)
SDL_FingerID id = event->tfinger.fingerId;

if (vkbd_mode) {
if (port == 0) {
vkbd_touch_x = event->tfinger.x;
vkbd_touch_y = event->tfinger.y;
}
return;
}

int x = lastmx;
int y = lastmy;

Expand Down Expand Up @@ -156,6 +167,15 @@ static void preprocessFingerUp(SDL_Event *event) {
// id (for multitouch)
SDL_FingerID id = event->tfinger.fingerId;

if (vkbd_mode) {
if (port == 0) {
vkbd_touch_x = -1;
vkbd_touch_y = -1;
vkbd_move &= ~VKBD_BUTTON;
}
return;
}

// find out how many fingers were down before this event
int numFingersDown = 0;
for (int i = 0; i < MAX_NUM_FINGERS; i++) {
Expand Down Expand Up @@ -218,6 +238,9 @@ static void preprocessFingerUp(SDL_Event *event) {
}

static void preprocessFingerMotion(SDL_Event *event) {
if (vkbd_mode)
return;

// front (0) or back (1) panel
SDL_TouchID port = event->tfinger.touchId;
// id (for multitouch)
Expand Down
112 changes: 112 additions & 0 deletions src/vkbd/vkbd.cpp
Expand Up @@ -10,12 +10,17 @@

#include "keyboard.h"

#define MIN(a,b) ((a) < (b) ? (a) : (b))

#define VKBD_MIN_HOLDING_TIME 200
#define VKBD_MOVE_DELAY 50

extern int keycode2amiga(SDL_keysym *prKeySym);

extern int mainMenu_displayHires;
extern int mainMenu_displayedLines;
extern int mainMenu_shader;
extern int visibleAreaWidth;
extern int mainMenu_vkbdLanguage;
extern int mainMenu_vkbdStyle;

Expand All @@ -41,6 +46,8 @@ t_vkbd_sticky_key vkbd_sticky_key[] =
int vkbd_let_go_of_direction=0;
int vkbd_mode=0;
int vkbd_move=0;
float vkbd_touch_x=-1;
float vkbd_touch_y=-1;
int vkbd_key=KEYCODE_NOTHING;
SDLKey vkbd_button2=(SDLKey)0; //not implemented
int vkbd_keysave=KEYCODE_NOTHING;
Expand Down Expand Up @@ -182,6 +189,8 @@ static t_vkbd_rect vkbd_rect_US[]=
{{211, 61, 14, 11 }, 81,12,89,91, AK_LF}, // 90
{{226, 61, 14, 11 }, 82,12,90,92, AK_DN}, // 91
{{241, 61, 14, 11 }, 83,13,91,69, AK_RT}, // 92
{{0, 0, 0, 0 }, 0,0,0,0, 0}, // 93
{{0, 0, 0, 0 }, 0,0,0,0, 0}, // 94
};

//UK KEYBOARD
Expand Down Expand Up @@ -287,6 +296,7 @@ static t_vkbd_rect vkbd_rect_UK[]=
{{241, 61, 14, 11 }, 83,13,91,69, AK_RT}, // 92
// UK extra keys
{{31, 49, 14, 11 }, 55,86,70,71, AK_LTGT}, // 93 *
{{0, 0, 0, 0 }, 0,0,0,0, 0}, // 94
};

//GERMAN KEYBOARD
Expand Down Expand Up @@ -827,12 +837,114 @@ void vkbd_displace_down(void)
vkbd_y=prSDLScreen->h-ksur->h;
}

int vkbd_touch_xy_to_actual(float touch_x, float touch_y)
{
int x = 0;
int y = 0;
int x_offset = 0;
int y_offset = 0;
float scaled_width = 0;
float scaled_height = 0;
#ifdef __PSP2__
int display_width = 960;
int display_height = 544;
//is a shader active?
if (mainMenu_shader != 0)
{
scaled_height = display_height;
if (mainMenu_displayHires)
scaled_width = (0.5f*(float)visibleAreaWidth*((float)544/(float)mainMenu_displayedLines));
else
scaled_width = ((float)visibleAreaWidth*((float)544/(float)mainMenu_displayedLines));
x_offset = (display_width - scaled_width) / 2;
y_offset = (display_height - scaled_height) / 2;
}
else //otherwise do regular integer 2* scaling without filtering to ensure good picture quality
{
scaled_height = (float) (2 * mainMenu_displayedLines);
if (mainMenu_displayHires)
scaled_width = (float) (1 * visibleAreaWidth);
else
scaled_width = (float) (2 * visibleAreaWidth);
x_offset = (display_width - scaled_width) / 2;
y_offset = (display_height - scaled_height) / 2;
}
#else
int display_width = 1280;
int display_height = 720;
if (mainMenu_shader == 0) {
// integer scaling
int screen_width;
int screen_height;
screen_width = visibleAreaWidth;
if (mainMenu_displayHires)
screen_height = 2 * mainMenu_displayedLines;
else
screen_height = mainMenu_displayedLines;
int scale_factor = MIN(display_height / screen_height, display_width / screen_width);
scaled_height = scale_factor * screen_height;
scaled_width = scale_factor * screen_width;
} else {
// scale to fit, preserve aspect ratio
scaled_height = display_height;
if (mainMenu_displayHires)
scaled_width = ((visibleAreaWidth * display_height) / (float) (2 * mainMenu_displayedLines));
else
scaled_width = ((visibleAreaWidth * display_height) / (float) (mainMenu_displayedLines));
}
// centering
x_offset = (display_width - scaled_width) / 2;
y_offset = (display_height - scaled_height) / 2;
#endif
x = (((touch_x * display_width) - x_offset) * visibleAreaWidth) / scaled_width;
y = (((touch_y * display_height) - y_offset) * mainMenu_displayedLines) / scaled_height;
x -= vkbd_x;
y -= vkbd_y;
if (mainMenu_displayHires)
x /= 2;

for (int i = 0; i < 95; i++)
{
int x_min = vkbd_rect[i].rect.x;
int y_min = vkbd_rect[i].rect.y;
int x_max = x_min + vkbd_rect[i].rect.w;
int y_max = y_min + vkbd_rect[i].rect.h;
if (x_min != 0 && y_min != 0 && x >= x_min-1 && x <= x_max && y >= y_min-1 && y <= y_max)
return i;
}
return -1;
}

int vkbd_process(void)
{
Uint32 now=SDL_GetTicks();
SDL_Rect r;

vkbd_redraw();

if (vkbd_touch_x != -1 && vkbd_touch_y != -1) {
int new_vkbd_actual = vkbd_touch_xy_to_actual(vkbd_touch_x, vkbd_touch_y);
if (new_vkbd_actual != -1)
{
vkbd_actual = new_vkbd_actual;
vkbd_move = VKBD_BUTTON;
// draw key dark while touched
if (mainMenu_displayHires)
{
r.x=vkbd_x+2*vkbd_rect[vkbd_actual].rect.x;
r.w=2*vkbd_rect[vkbd_actual].rect.w;
}
else
{
r.x=vkbd_x+vkbd_rect[vkbd_actual].rect.x;
r.w=vkbd_rect[vkbd_actual].rect.w;
}
r.y=vkbd_y+vkbd_rect[vkbd_actual].rect.y;
r.h=vkbd_rect[vkbd_actual].rect.h;
SDL_FillRect(prSDLScreen,&r,vkbd_color);
}
}

if (vkbd_move&VKBD_BUTTON)
{
vkbd_move=0;
Expand Down
2 changes: 2 additions & 0 deletions src/vkbd/vkbd.h
Expand Up @@ -38,6 +38,8 @@ void vkbd_reset_sticky_keys(void);

extern int vkbd_mode;
extern int vkbd_move;
extern float vkbd_touch_x;
extern float vkbd_touch_y;
typedef struct
{
int code; // amiga-side keycode
Expand Down

0 comments on commit 6a6c661

Please sign in to comment.