Bring over ctrQuake touch changes

This commit is contained in:
Ian 2023-10-23 10:05:09 -04:00
parent e1ef072c26
commit 1c38cda5aa
5 changed files with 153 additions and 116 deletions

View File

@ -102,7 +102,7 @@ COMMON_OBJS = chase.c \
snd_mix.c \
snd_mem.c \
snd_ctr.c \
in_null.c \
in_ctr.c \
cd_null.c \
gl_qmb.c \
gl_decal.c \

View File

@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// in_null.c -- for systems without a mouse
// in_ctr.c -- for the Nintendo 3DS
#include "quakedef.h"
#include <3ds.h>
@ -77,8 +77,25 @@ float IN_CalcInput(int axis, float speed, float tolerance, float acceleration) {
extern cvar_t scr_fov;
extern int original_fov, final_fov;
touchPosition oldtouch2, touch2;
extern uint8_t keyboardToggled;
void IN_Move (usercmd_t *cmd)
{
// Change look direction with stylus on touch screen
// From vanilla ctrQuake.
if(hidKeysDown() & KEY_TOUCH) {
hidTouchRead(&touch2);
oldtouch2 = touch2;
} else if(hidKeysHeld() & KEY_TOUCH && !keyboardToggled){
hidTouchRead(&touch2);
touch2.px = (touch2.px + oldtouch2.px) / 2.5;
touch2.py = (touch2.py + oldtouch2.py) / 2.5;
cl.viewangles[YAW] -= (touch2.px - oldtouch2.px) * sensitivity.value/2.5;
cl.viewangles[PITCH] += (touch2.py - oldtouch2.py) * sensitivity.value/2.5;
oldtouch2 = touch2;
V_StopPitchDrift ();
}
// TODO: Detect circle pad pro?
circlePosition left;
circlePosition right;

View File

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h"
#include "errno.h"
#include "touch_ctr.h"
#include <3ds.h>
@ -322,6 +323,7 @@ int main (int argc, char **argv)
Host_Init (&parms);
Touch_Init();
Touch_DrawOverlay();
oldtime = Sys_FloatTime();

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2017 Felipe Izzo
Copyright (C) 2015 Felipe Izzo
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -18,22 +18,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//FIX ME: load all hardcoded values from file
#include "quakedef.h"
#include <3ds.h>
#include "touch_ctr.h"
#include "keyboard_overlay_bin.h"
#include "touch_overlay_bin.h"
int keyboard_toggled;
static u16* touchpad_overlay;
static u16* keyboard_overlay;
static char last_key;
static int shift_toggled;
static u16* tfb;
static touchPosition touch;
//Keyboard is currently laid out on a 14*4 grid of 20px*20px boxes for easy(lazy) implementation
//Keyboard is currently laid out on a 14*4 grid of 20px*20px boxes for lazy implementation
char keymap[14 * 6] = {
K_ESCAPE , K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12, 0,
'`' , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', K_BACKSPACE,
@ -43,119 +35,129 @@ char keymap[14 * 6] = {
0, 0 , 0, 0, K_SPACE, K_SPACE, K_SPACE, K_SPACE, K_SPACE, K_SPACE, 0, K_LEFTARROW, K_DOWNARROW, K_RIGHTARROW
};
void Touch_DrawOverlay()
{
u16* overlay;
int x, y;
u16* touchOverlay;
u16* keyboardOverlay;
uint8_t keyboardToggled;
char lastKey = 0;
int tmode;
u16* tfb;
touchPosition oldtouch, touch;
u64 tick;
if(keyboard_toggled)
overlay = keyboard_overlay;
else
overlay = touchpad_overlay;
u64 lastTap = 0;
for(x = 0; x < 320; x++)
for(y = 0; y < 240; y++)
tfb[(x*240 + (239 - y))] = overlay[(y*320 + x)];
int shiftToggle = 0;
if(keyboard_toggled && shift_toggled)
{
for(x = 26; x < 29; x++)
for(y = 149; y < 152; y++)
tfb[(x*240 + (239 - y))] = RGB8_to_565(0,255,0);
}
void Touch_Init(){
tmode = TMODE_TOUCHPAD; //Start in touchpad Mode
tfb = (u16*)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
//Load overlay files from sdmc for easier testing
FILE *texture = fopen("touchOverlay.bin", "rb");
if(!texture)
Sys_Error("Could not open touchpadOverlay.bin\n");
fseek(texture, 0, SEEK_END);
int size = ftell(texture);
fseek(texture, 0, SEEK_SET);
touchOverlay = malloc(size);
fread(touchOverlay, 1, size, texture);
fclose(texture);
texture = fopen("keyboardOverlay.bin", "rb");
if(!texture)
Sys_Error("Could not open keyboardOverlay.bin\n");
fseek(texture, 0, SEEK_END);
size = ftell(texture);
fseek(texture, 0, SEEK_SET);
keyboardOverlay = malloc(size);
fread(keyboardOverlay, 1, size, texture);
fclose(texture);
}
void Touch_Init()
void Touch_DrawOverlay()
{
tfb = (u16*)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
touchpad_overlay = (u16*)touch_overlay_bin;
keyboard_overlay = (u16*)keyboard_overlay_bin;
shift_toggled = 0;
int x, y;
for(x=0; x<320; x++){
for(y=0; y<240;y++){
tfb[(x*240 + (239 - y))] = touchOverlay[(y*320 + x)];
}
}
if(keyboardToggled)
Touch_DrawKeyboard();
}
Touch_DrawOverlay();
void Touch_DrawKeyboard()
{
int x, y;
for(x=0; x<320; x++){
for(y=0; y<240;y++){
tfb[(x*240 + (239 - y))] = keyboardOverlay[(y*320 + x)];
}
}
if(shiftToggle)
{
for(x=26; x<29; x++){
for(y=149; y<152;y++){
tfb[((x)*240 + (239 - (y)))] = RGB8_to_565(0,255,0);
}
}
}
}
void Touch_Update(){
if(lastKey){
Key_Event(lastKey, false);
lastKey = 0;
}
if(hidKeysDown() & KEY_TOUCH){
hidTouchRead(&touch);
tick = Sys_FloatTime();
}
if(hidKeysUp() & KEY_TOUCH){
Touch_ProcessTap();
}
}
void Touch_KeyboardToggle()
{
if(keyboard_toggled)
{
shift_toggled = 0;
Key_Event(K_SHIFT, false);
}
if(keyboardToggled)
shiftToggle = 0;
Key_Event(K_SHIFT,false);
keyboard_toggled = !keyboard_toggled;
keyboardToggled = !keyboardToggled;
Touch_DrawOverlay();
}
void Touch_TouchpadUpdate()
void Touch_ProcessTap()
{
char key = 0;
if(touch.px > 268 && touch.py > 14 && touch.py < 226)
key = K_AUX9 + (touch.py - 14)/42;
if(key != last_key)
{
if(last_key)
Key_Event(last_key, false);
if(key)
Key_Event(key, true);
}
last_key = key;
}
void Touch_KeyboardUpdate()
{
char key = 0;
if(touch.py > 62 && touch.py < 188 && touch.px > 12 && touch.px < 308)
key = keymap[((touch.py - 62) / 21) * 14 + (touch.px - 12) / 21];
if(key == K_SHIFT && key != last_key)
{
shift_toggled = !shift_toggled;
Key_Event(K_SHIFT, shift_toggled);
Touch_DrawOverlay();
}
else if(key != last_key)
{
if(last_key && (last_key != K_SHIFT))
Key_Event(last_key, false);
if(key)
Key_Event(key, true);
}
last_key = key;
}
void Touch_Update()
{
if(hidKeysHeld() & KEY_TOUCH)
{
hidTouchRead(&touch);
if(!keyboard_toggled)
Touch_TouchpadUpdate();
else
Touch_KeyboardUpdate();
}
if(hidKeysDown() & KEY_TOUCH)
{
if (touch.py > 214 && touch.px > 142 && touch.px < 178)
if(touch.px > 268 && touch.py > 14 && touch.py < 226 && !keyboardToggled)
Touch_SideBarTap();
else if (touch.py > 62 && touch.py < 188 && touch.px > 12 && touch.px < 308 && keyboardToggled)
Touch_KeyboardTap();
else if (touch.py > 214 && touch.px > 142 && touch.px < 178)
Touch_KeyboardToggle();
}
}
if(hidKeysUp() & KEY_TOUCH)
{
if(last_key && (last_key != K_SHIFT))
{
Key_Event(last_key, false);
last_key = 0;
void Touch_SideBarTap()
{
uint16_t y = (touch.py - 14)/42;
lastKey = K_AUX9 + y;
Key_Event(lastKey, true);
}
void Touch_KeyboardTap()
{
char key = keymap[((touch.py - 62)/21) * 14 + (touch.px - 12)/21];
if(key == K_SHIFT){
shiftToggle = !shiftToggle;
Key_Event(K_SHIFT,shiftToggle);
Touch_DrawOverlay();
}
else {
Key_Event(key, true);
lastKey = key;
}
}

16
source/touch_ctr.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __TOUCH__
#define __TOUCH__
//Touchscreen mode identifiers
#define TMODE_TOUCHPAD 1
#define TMODE_KEYBOARD 2
#define TMODE_SETTINGS 3
void Touch_TouchpadTap();
void Touch_KeyboardTap();
void Touch_ProcessTap();
void Touch_DrawOverlay();
void Touch_Init();
void Touch_Update();
#endif