@@ -26,167 +26,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2626#include <3ds.h>
2727#include "ctr.h"
2828
29- //Touchscreen mode identifiers
30- #define TMODE_TOUCHPAD 1
31- #define TMODE_KEYBOARD 2
32- #define TMODE_SETTINGS 3
33-
34- //Keyboard is currently laid out on a 14*4 grid of 20px*20px boxes for lazy implementation
35- char keymap [14 * 4 ] = {
36- '`' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' , '-' , '+' , K_BACKSPACE ,
37- K_TAB , 'q' , 'w' , 'e' , 'r' , 't' , 'y' , 'u' , 'i' , 'o' , 'p' , '[' , ']' , '|' ,
38- 0 , 'a' , 's' , 'd' , 'f' , 'g' , 'h' , 'j' , 'k' , 'l' , ';' , '\'' , K_ENTER , K_ENTER ,
39- K_SHIFT , 'z' , 'x' , 'c' , 'v' , 'b' , 'n' , 'm' , ',' , '.' , '/' , K_SHIFT , K_SHIFT , K_SHIFT
40- };
41-
42- u16 * touchpadOverlay ;
43- u16 * keyboardOverlay ;
44-
4529circlePosition cstick ;
4630circlePosition circlepad ;
4731touchPosition oldtouch , touch ;
48- char lastKey = 0 ;
49-
50- int tmode ;
51- u16 * tfb ;
52-
53- u64 lastTap = 0 ;
54- void ctrTouchpadTap (){
55- u64 thisTap = Sys_FloatTime ();
56- if (oldtouch .py > 195 && oldtouch .py < 240 && oldtouch .px > 0 && oldtouch .px < 45 ){
57- Key_Event ('`' , true);
58- lastKey = '`' ;
59- }
60- else if (oldtouch .py > 195 && oldtouch .py < 240 && oldtouch .px > 1 && oldtouch .px < 320 ){
61- tmode = 2 ;
62- ctrDrawTouchOverlay ();
63- }
64- else if ((thisTap - lastTap ) < 0.5 ){
65- Key_Event (K_SPACE , true);
66- lastKey = K_SPACE ;
67- }
68- lastTap = thisTap ;
69- }
70-
71- void ctrKeyboardTap (){
72- if (oldtouch .py > 20 && oldtouch .py < 100 && oldtouch .px > 15 && oldtouch .px < 295 ){
73- char key = keymap [((oldtouch .py - 20 ) / 20 ) * 14 + (oldtouch .px - 15 )/20 ];
74- Key_Event (key , true);
75- lastKey = key ;
76- }
77-
78- else if (oldtouch .py > 100 && oldtouch .py < 120 && oldtouch .px > 95 && oldtouch .px < 215 ){
79- Key_Event (K_SPACE , true);
80- lastKey = K_SPACE ;
81- }
82-
83- if (oldtouch .py > 195 && oldtouch .py < 240 && oldtouch .px > 1 && oldtouch .px < 320 ){
84- tmode = 1 ;
85- ctrDrawTouchOverlay ();
86- }
87- }
88-
89- void ctrProcessTap (){
90- if (tmode == TMODE_TOUCHPAD )
91- ctrTouchpadTap ();
92- else
93- ctrKeyboardTap ();
94- }
95-
96- void ctrDrawTouchOverlay (){
97- u16 * overlay = 0 ;
98- if (tmode == TMODE_TOUCHPAD )
99- overlay = touchpadOverlay ;
100- else
101- overlay = keyboardOverlay ;
102-
103- if (!overlay )
104- return ;
105- int x ,y ;
106-
107- for (x = 0 ; x < 320 ; x ++ ){
108- for (y = 0 ; y < 240 ;y ++ ){
109- tfb [(x * 240 + (239 - y ))] = overlay [(y * 320 + x )];
110- }
111- }
112-
113- }
11432
11533void IN_Init (void )
11634{
11735 if ( COM_CheckParm ("-nomouse" ) )
11836 return ;
119-
120- tmode = TMODE_TOUCHPAD ; //Start in touchpad Mode
121-
122- tfb = (u16 * )gfxGetFramebuffer (GFX_BOTTOM , GFX_LEFT , NULL , NULL );
123-
124- //Load overlay files from sdmc for easier testing
125- FILE * texture = fopen ("touchpadOverlay.bin" , "rb" );
126- if (!texture )
127- Sys_Error ("Could not open touchpadOverlay.bin\n" );
128- fseek (texture , 0 , SEEK_END );
129- int size = ftell (texture );
130- fseek (texture , 0 , SEEK_SET );
131- touchpadOverlay = malloc (size );
132- fread (touchpadOverlay , 1 , size , texture );
133- fclose (texture );
134-
135- texture = fopen ("keyboardOverlay.bin" , "rb" );
136- if (!texture )
137- Sys_Error ("Could not open keyboardOverlay.bin\n" );
138- fseek (texture , 0 , SEEK_END );
139- size = ftell (texture );
140- fseek (texture , 0 , SEEK_SET );
141- keyboardOverlay = malloc (size );
142- fread (keyboardOverlay , 1 , size , texture );
143- fclose (texture );
14437}
14538
14639void IN_Shutdown (void )
14740{
148- free (touchpadOverlay );
149- free (keyboardOverlay );
15041}
15142
15243void IN_Commands (void )
15344{
15445}
15546
156- u64 tick ;
157-
15847void IN_Move (usercmd_t * cmd )
15948{
160-
161- if (lastKey ){
162- Key_Event (lastKey , false);
163- lastKey = 0 ;
164- }
165-
166- if (hidKeysDown () & KEY_TOUCH ){
167- hidTouchRead (& oldtouch );
168- tick = Sys_FloatTime ();
169- }
170-
171- //If touchscreen is released in certain amount of time it's a tap
172- if (hidKeysUp () & KEY_TOUCH ){
173- if ((Sys_FloatTime () - tick ) < 1.0 ) //FIX ME: find optimal timeframe
174- ctrProcessTap ();
175- }
176-
177- else if (hidKeysHeld () & KEY_TOUCH ){
49+ if (hidKeysHeld () & KEY_TOUCH ){
17850 hidTouchRead (& touch );
179- touch .px = (touch .px + oldtouch .px ) / 2 ;
180- touch .py = (touch .py + oldtouch .py ) / 2 ;
51+ touch .px = (touch .px + oldtouch .px ) / 2 ;
52+ touch .py = (touch .py + oldtouch .py ) / 2 ;
18153 cl .viewangles [YAW ] -= (touch .px - oldtouch .px ) * sensitivity .value /2 ;
18254 if (in_mlook .state & 1 )
18355 cl .viewangles [PITCH ] += (touch .py - oldtouch .py ) * sensitivity .value /2 ;
18456 oldtouch = touch ;
18557 }
18658
18759 hidCircleRead (& circlepad );
188- cmd -> forwardmove += m_forward .value * circlepad .dy * 2 ; //FIX ME: allow circlepad sensitivity to be changed
189- cmd -> sidemove += m_side .value * circlepad .dx * 2 ; //FIX ME: allow player to choose between strafing or turning
60+ //CirclePad deadzone to fix ghost movements
61+ if (abs (circlepad .dy ) > 15 )
62+ cmd -> forwardmove += m_forward .value * circlepad .dy * 2 ; //FIX ME: allow circlepad sensitivity to be changed
63+ if (abs (circlepad .dx ) > 15 )
64+ cmd -> sidemove += m_side .value * circlepad .dx * 2 ; //FIX ME: allow player to choose between strafing or turning
19065
19166 //cStick is only available on N3DS... Until libctru implements support for circlePad Pro
19267 if (isN3DS ){
0 commit comments