mirror of
https://github.com/nzp-team/glquake.git
synced 2025-03-15 07:00:57 +00:00
Merge pull request #6 from nzp-team/swkbd
Replace Quake keyboard with libctru swkbd
This commit is contained in:
commit
74b3a294ff
6 changed files with 55 additions and 91 deletions
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
// in_ctr.c -- for the Nintendo 3DS
|
||||
|
||||
#include "quakedef.h"
|
||||
#include <GL/picaGL.h>
|
||||
#include <3ds.h>
|
||||
|
||||
extern int bind_grab;
|
||||
|
@ -77,23 +78,33 @@ 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;
|
||||
touchPosition old_touch, cur_touch;
|
||||
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 ();
|
||||
// Touch based viewangles based on Quake2CTR
|
||||
// This was originally based on ctrQuake, however
|
||||
// that implementation was less elegant and had
|
||||
// a weird jerk bug when tapping the screen.
|
||||
if(hidKeysDown() & KEY_TOUCH)
|
||||
hidTouchRead(&old_touch);
|
||||
|
||||
if((hidKeysHeld() & KEY_TOUCH))
|
||||
{
|
||||
hidTouchRead(&cur_touch);
|
||||
|
||||
if(cur_touch.px < 268)
|
||||
{
|
||||
int tx = cur_touch.px - old_touch.px;
|
||||
int ty = cur_touch.py - old_touch.py;
|
||||
|
||||
if(m_pitch.value < 0)
|
||||
ty = -ty;
|
||||
|
||||
cl.viewangles[YAW] -= abs(tx) > 1 ? tx * sensitivity.value * 0.33f : 0;
|
||||
cl.viewangles[PITCH] += abs(ty) > 1 ? ty * sensitivity.value * 0.33f : 0;
|
||||
}
|
||||
|
||||
old_touch = cur_touch;
|
||||
}
|
||||
|
||||
// TODO: Detect circle pad pro?
|
||||
|
@ -147,7 +158,7 @@ void IN_Move (usercmd_t *cmd)
|
|||
|
||||
// Set the pitch.
|
||||
const bool invertPitch = m_pitch.value < 0;
|
||||
const float pitchScale = yawScale * (invertPitch ? -1 : 1);
|
||||
const float pitchScale = yawScale * (invertPitch ? 1 : -1);
|
||||
|
||||
cl.viewangles[PITCH] += pitchScale * look_y * host_frametime;
|
||||
|
||||
|
@ -192,3 +203,20 @@ void IN_Move (usercmd_t *cmd)
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ctr software keyboard courtesy of libctru samples
|
||||
//
|
||||
void IN_SwitchKeyboard(void)
|
||||
{
|
||||
static SwkbdState swkbd;
|
||||
static char console_buffer[64];
|
||||
SwkbdButton button = SWKBD_BUTTON_NONE;
|
||||
|
||||
swkbdInit(&swkbd, SWKBD_TYPE_QWERTY, 2, -1);
|
||||
swkbdSetInitialText(&swkbd, console_buffer);
|
||||
swkbdSetHintText(&swkbd, "Enter Quake console command");
|
||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Send", true);
|
||||
button = swkbdInputText(&swkbd, console_buffer, sizeof(console_buffer));
|
||||
|
||||
Cbuf_AddText(va("%s\n", console_buffer));
|
||||
}
|
|
@ -32,3 +32,4 @@ void IN_Move (usercmd_t *cmd);
|
|||
void IN_ClearStates (void);
|
||||
// restores all button and position states to defaults
|
||||
|
||||
void IN_SwitchKeyboard (void);
|
|
@ -208,6 +208,12 @@ extern qboolean console_enabled;
|
|||
void Key_Console (int key)
|
||||
{
|
||||
char *cmd;
|
||||
|
||||
if (key == K_SELECT)
|
||||
{
|
||||
IN_SwitchKeyboard();
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_JOY3 || key == K_ENTER)
|
||||
{
|
||||
|
@ -690,6 +696,7 @@ void Key_Init (void)
|
|||
consolekeys[K_SHIFT] = true;
|
||||
consolekeys[K_MWHEELUP] = true;
|
||||
consolekeys[K_MWHEELDOWN] = true;
|
||||
consolekeys[K_SELECT] = true;
|
||||
consolekeys['`'] = false;
|
||||
consolekeys['~'] = false;
|
||||
|
||||
|
|
|
@ -1426,6 +1426,7 @@ void M_Options_Key (int k)
|
|||
case 1:
|
||||
console_enabled = true;
|
||||
m_state = m_none;
|
||||
Con_Printf("\nPress SELECT to open keyboard.\n\n");
|
||||
Con_ToggleConsole_f ();
|
||||
break;
|
||||
case 2:
|
||||
|
|
|
@ -25,19 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include <3ds.h>
|
||||
#include "touch_ctr.h"
|
||||
|
||||
//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,
|
||||
K_TAB, 'q' , 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '|',
|
||||
0, 'a' , 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', K_ENTER, K_ENTER,
|
||||
K_SHIFT, 'z' , 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, K_UPARROW, 0,
|
||||
0, 0 , 0, 0, K_SPACE, K_SPACE, K_SPACE, K_SPACE, K_SPACE, K_SPACE, 0, K_LEFTARROW, K_DOWNARROW, K_RIGHTARROW
|
||||
};
|
||||
|
||||
u16* touchOverlay;
|
||||
u16* keyboardOverlay;
|
||||
uint8_t keyboardToggled;
|
||||
char lastKey = 0;
|
||||
int tmode;
|
||||
u16* tfb;
|
||||
|
@ -62,16 +50,6 @@ void Touch_Init(){
|
|||
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_DrawOverlay()
|
||||
|
@ -82,26 +60,6 @@ void Touch_DrawOverlay()
|
|||
tfb[(x*240 + (239 - y))] = touchOverlay[(y*320 + x)];
|
||||
}
|
||||
}
|
||||
if(keyboardToggled)
|
||||
Touch_DrawKeyboard();
|
||||
}
|
||||
|
||||
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(){
|
||||
|
@ -120,25 +78,10 @@ void Touch_Update(){
|
|||
}
|
||||
}
|
||||
|
||||
void Touch_KeyboardToggle()
|
||||
{
|
||||
if(keyboardToggled)
|
||||
shiftToggle = 0;
|
||||
Key_Event(K_SHIFT,false);
|
||||
|
||||
keyboardToggled = !keyboardToggled;
|
||||
|
||||
Touch_DrawOverlay();
|
||||
}
|
||||
|
||||
void Touch_ProcessTap()
|
||||
{
|
||||
if(touch.px > 268 && touch.py > 14 && touch.py < 226 && !keyboardToggled)
|
||||
if(touch.px > 268 && touch.py > 14 && touch.py < 226)
|
||||
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();
|
||||
}
|
||||
|
||||
void Touch_SideBarTap()
|
||||
|
@ -146,18 +89,4 @@ 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;
|
||||
}
|
||||
}
|
|
@ -3,11 +3,9 @@
|
|||
|
||||
//Touchscreen mode identifiers
|
||||
#define TMODE_TOUCHPAD 1
|
||||
#define TMODE_KEYBOARD 2
|
||||
#define TMODE_SETTINGS 3
|
||||
#define TMODE_SETTINGS 2
|
||||
|
||||
void Touch_TouchpadTap();
|
||||
void Touch_KeyboardTap();
|
||||
void Touch_ProcessTap();
|
||||
void Touch_DrawOverlay();
|
||||
void Touch_Init();
|
||||
|
|
Loading…
Reference in a new issue