Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
116 lines (97 loc) · 3.29 KB

SDL_systouchscreen.c

File metadata and controls

116 lines (97 loc) · 3.29 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
#include "SDL_config.h"
#ifdef SDL_TOUCHSCREEN_NDS
/* This is the system specific header for the SDL touchscreen API */
#include <nds.h>
#include <stdio.h> /* For the definition of NULL */
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_touchscreen.h"
#include "../SDL_systouchscreen.h"
#include "../SDL_touchscreen_c.h"
#include "../../video/nds/SDL_ndsevents_c.h"
/* Function to scan the system for touchscreen.
* This function should set SDL_numtouchscreens to the number of available
* touchscreen. Touchscreen 0 should be the system default touchscreen.
* It should return 0, or -1 on an unrecoverable fatal error.
*/
int
SDL_SYS_TouchscreenInit(void)
{
SDL_numtouchscreens = 1;
return (1);
}
/* Function to get the device-dependent name of a touchscreen */
const char *
SDL_SYS_TouchscreenName(int index)
{
if (!index)
return "NDS builtin touchscreen";
SDL_SetError("No touchscreen available with that index");
return (NULL);
}
/* Function to open a touchscreen for use.
The touchscreen to open is specified by the index field of the touchscreen.
This should fill the maxpoints field of the touchscreen structure.
It returns 0, or -1 if there is an error.
*/
int
SDL_SYS_TouchscreenOpen(SDL_Touchscreen * touchscreen)
{
touchscreen->maxpoints = 1;
touchscreen->npoints = 0;
/* do I call SDL_TouchscreenOpen here? */
return 0;
}
/* Function to update the state of a touchscreen - called as a device poll.
* This function shouldn't update the touchscreen structure directly,
* but instead should call SDL_PrivateTouch*() to deliver events
* and update touchscreen device state.
*/
void
SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen)
{
u32 keysd, keysu, keysh;
int xpos, ypos, pressure = 16384;
touchPosition touch;
scanKeys();
keysd = keysDown();
keysh = keysHeld();
keysu = keysUp();
touch=touchReadXY();
xpos = (touch.px-128)*256;
ypos = (touch.py-96)*(65536/192);
if (((keysd|keysh) & KEY_TOUCH)) {
SDL_PrivateTouchPress(touchscreen, 0, xpos, ypos, pressure);
}
if ((keysu & KEY_TOUCH)) {
SDL_PrivateTouchRelease(touchscreen, 0);
}}
/* Function to close a touchscreen after use */
void
SDL_SYS_TouchscreenClose(SDL_Touchscreen * touchscreen)
{
}
/* Function to perform any system-specific touchscreen related cleanup */
void
SDL_SYS_TouchscreenQuit(void)
{
}
#endif /* SDL_TOUCHSCREEN_NDS */