Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Started adding framework for Touchscreen API, based on and (consisten…

…t with) the existing Joystick API.
  • Loading branch information
Darren Alton committed Jun 23, 2008
1 parent 3782e51 commit 7a8d9fca74ad62849de05c21f674eaffe4dbda46
@@ -51,6 +51,9 @@ src/events/SDL_windowevents.c \
src/file/SDL_rwops.c \
src/joystick/nds/SDL_sysjoystick.c \
src/joystick/SDL_joystick.c \
src/touchscreen/nds/SDL_systouchscreen.c \
src/touchscreen/dummy/SDL_systouchscreen.c \
src/touchscreen/SDL_touchscreen.c \
src/stdlib/SDL_getenv.c \
src/stdlib/SDL_iconv.c \
src/stdlib/SDL_malloc.c \
@@ -67,6 +70,9 @@ src/timer/SDL_timer.c \
src/video/nds/SDL_ndsevents.c \
src/video/nds/SDL_ndsrender.c \
src/video/nds/SDL_ndsvideo.c \
src/video/dummy/SDL_nullevents.c \
src/video/dummy/SDL_nullrender.c \
src/video/dummy/SDL_nullvideo.c \
src/video/SDL_blit_0.c \
src/video/SDL_blit_1.c \
src/video/SDL_blit_A.c \
@@ -109,6 +109,7 @@ extern "C" {
#define SDL_INIT_VIDEO 0x00000020
#define SDL_INIT_CDROM 0x00000100
#define SDL_INIT_JOYSTICK 0x00000200
#define SDL_INIT_TOUCHSCREEN 0x00000400
#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */
#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */
#define SDL_INIT_EVERYTHING 0x0000FFFF
@@ -99,6 +99,9 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t;

/* Enable various input drivers */
#define SDL_JOYSTICK_NDS 1
/*#define SDL_JOYSTICK_DUMMY 1*/
#define SDL_TOUCHSCREEN_NDS 1
/*#define SDL_TOUCHSCREEN_DUMMY 1*/

/* DS has no dynamic linking afaik */
#define SDL_LOADSO_DISABLED 1
@@ -112,5 +115,6 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t;

/* Enable various video drivers */
#define SDL_VIDEO_DRIVER_NDS 1
#define SDL_VIDEO_DRIVER_DUMMY 1

#endif /* _SDL_config_nintendods_h */
@@ -35,6 +35,7 @@
#include "SDL_keyboard.h"
#include "SDL_mouse.h"
#include "SDL_joystick.h"
#include "SDL_touchscreen.h"
#include "SDL_quit.h"

#include "begin_code.h"
@@ -70,6 +71,9 @@ typedef enum
SDL_JOYHATMOTION, /**< Joystick hat position change */
SDL_JOYBUTTONDOWN, /**< Joystick button pressed */
SDL_JOYBUTTONUP, /**< Joystick button released */
SDL_TOUCHPRESSED, /**< Touchscreen pressed */
SDL_TOUCHRELEASED, /**< Touchscreen no longer pressed */
SDL_TOUCHMOTION, /**< Touchscreen point motion */
SDL_QUIT, /**< User-requested quit */
SDL_SYSWMEVENT, /**< System specific event */
SDL_EVENT_RESERVED1, /**< Reserved for future use... */
@@ -111,6 +115,11 @@ typedef enum
SDL_EVENTMASK(SDL_JOYBALLMOTION) |
SDL_EVENTMASK(SDL_JOYHATMOTION) |
SDL_EVENTMASK(SDL_JOYBUTTONDOWN) | SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_TOUCHPRESSEDMASK = SDL_EVENTMASK(SDL_TOUCHPRESSED),
SDL_TOUCHRELEASEDMASK = SDL_EVENTMASK(SDL_TOUCHRELEASED),
SDL_TOUCHMOTIONMASK = SDL_EVENTMASK(SDL_TOUCHMOTION),
SDL_TOUCHEVENTMASK = SDL_EVENTMASK(SDL_TOUCHPRESSED) |
SDL_EVENTMASK(SDL_TOUCHRELEASED) | SDL_EVENTMASK(SDL_TOUCHMOTION),
SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT),
SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT)
} SDL_EventMask;
@@ -263,6 +272,21 @@ typedef struct SDL_JoyButtonEvent
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
} SDL_JoyButtonEvent;

/**
* \struct SDL_TouchEvent
*
* \brief Touchscreen motion event structure (event.touch.*)
*/
typedef struct SDL_TouchEvent
{
Uint8 type; /**< SDL_TOUCHMOTION, SDL_TOUCHPRESS, SDL_TOUCHRELEASED */
Uint8 which; /**< The touchscreen device index */
int point; /**< The touch point index, relevant for multitouch. */
int xpos; /**< The X coordinate of the touch point. */
int ypos; /**< The Y coordinate of the touch point. */
int pressure; /**< The pressure of the touch */
} SDL_TouchEvent;

/**
* \struct SDL_QuitEvent
*
@@ -334,6 +358,7 @@ typedef union SDL_Event
SDL_JoyBallEvent jball; /**< Joystick ball event data */
SDL_JoyHatEvent jhat; /**< Joystick hat event data */
SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
SDL_TouchEvent touch; /**< Touchscreen event data */
SDL_QuitEvent quit; /**< Quit request event data */
SDL_UserEvent user; /**< Custom event data */
SDL_SysWMEvent syswm; /**< System dependent window event data */
@@ -0,0 +1,152 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/

/**
* \file SDL_touchscreen.h
*
* Include file for SDL touchscreen event handling
*/

#ifndef _SDL_touchscreen_h
#define _SDL_touchscreen_h

#include "SDL_stdinc.h"
#include "SDL_error.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

/* In order to use these functions, SDL_Init() must have been called
with the SDL_INIT_TOUCHSCREEN flag. This causes SDL to scan the system
for touchscreens, and load appropriate drivers.
*/

/* The touchscreen structure used to identify an SDL touchscreen */
struct _SDL_Touchscreen;
typedef struct _SDL_Touchscreen SDL_Touchscreen;


/* Function prototypes */
/*
* Count the number of touchscreens attached to the system
*/
extern DECLSPEC int SDLCALL SDL_NumTouchscreens(void);

/*
* Get the implementation dependent name of a touchscreen.
* This can be called before any touchscreens are opened.
* If no name can be found, this function returns NULL.
*/
extern DECLSPEC const char *SDLCALL SDL_TouchscreenName(int device_index);

/*
* Open a touchscreen for use - the index passed as an argument refers to
* the N'th touchscreen on the system. This index is the value which will
* identify this touchscreen in future touchscreen events.
*
* This function returns a touchscreen identifier, or NULL if an error occurred.
*/
extern DECLSPEC SDL_Touchscreen *SDLCALL SDL_TouchscreenOpen(int device_index);

/*
* Returns 1 if the touchscreen has been opened, or 0 if it has not.
*/
extern DECLSPEC int SDLCALL SDL_TouchscreenOpened(int device_index);

/*
* Get the device index of an opened touchscreen.
*/
extern DECLSPEC int SDLCALL SDL_TouchscreenIndex(SDL_Touchscreen * touchscreen);

/*
* Get the number of points a touchscreen can register at a time
* (single or multi-touch.)
*/
extern DECLSPEC int SDLCALL SDL_TouchscreenMaxPoints(SDL_Touchscreen * touchscreen);

/*
* Update the current state of the open touchscreens.
* This is called automatically by the event loop if any touchscreen
* events are enabled.
*/
extern DECLSPEC void SDLCALL SDL_TouchscreenUpdate(void);

/*
* Enable/disable touchscreen event polling.
* If touchscreen events are disabled, you must call SDL_TouchscreenUpdate()
* yourself and check the state of the touchscreen when you want touchscreen
* information.
* The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.
*/
extern DECLSPEC int SDLCALL SDL_TouchscreenEventState(int state);

/*
* Get the current X,Y position of the indicated point on the touchscreen.
*
* If not NULL, *x is set to an integer in the range [-32768,32767]
* where -32768 is the left edge, 0 is center, 32767 is right edge.
* Similarly with *y, for the top, center, and bottom, respectively.
* The returned value is an unsigned integer in the range [1,32767]
* that represents the pressure of the touch.
* If not being touched, 0 is returned and *x and *y are unmodified.
*
* The touch point indices start at index 0.
* If given a negative value for point, all the X,Y, and pressures
* for all the currently touched points on a multitouch device
* should be averaged and used for *x, *y, and the return value.
* If the value of point exceeds the number of points currently touched,
* 0 should be returned, and *x, *y should be left unmodified.
*
* On error, -1 is returned.
*/
extern DECLSPEC int SDLCALL SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen,
int point, int *x, int *y);

/*
* Get the number of currently touched points on a touchscreen.
* This is either 0 or 1 for a single-touch device.
* On error, -1 is returned.
*/
extern DECLSPEC int SDLCALL SDL_TouchscreenGetPoints(SDL_Touchscreen * touchscreen);

/*
* Close a touchscreen previously opened with SDL_TouchscreenOpen()
*/
extern DECLSPEC void SDLCALL SDL_TouchscreenClose(SDL_Touchscreen * touchscreen);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"

#endif /* _SDL_touchscreen_h */

/* vi: set ts=4 sw=4 expandtab: */
@@ -38,6 +38,10 @@
extern int SDL_JoystickInit(void);
extern void SDL_JoystickQuit(void);
#endif
#if !SDL_TOUCHSCREEN_DISABLED
extern int SDL_TouchscreenInit(void);
extern void SDL_TouchscreenQuit(void);
#endif
#if !SDL_CDROM_DISABLED
extern int SDL_CDROMInit(void);
extern void SDL_CDROMQuit(void);
@@ -123,6 +127,21 @@ SDL_InitSubSystem(Uint32 flags)
}
#endif

#if !SDL_TOUCHSCREEN_DISABLED
/* Initialize the touchscreen subsystem */
if ((flags & SDL_INIT_TOUCHSCREEN) && !(SDL_initialized & SDL_INIT_TOUCHSCREEN)) {
if (SDL_TouchscreenInit() < 0) {
return (-1);
}
SDL_initialized |= SDL_INIT_TOUCHSCREEN;
}
#else
if (flags & SDL_INIT_TOUCHSCREEN) {
SDL_SetError("SDL not built with touchscreen support");
return (-1);
}
#endif

#if !SDL_CDROM_DISABLED
/* Initialize the CD-ROM subsystem */
if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
@@ -180,6 +199,12 @@ SDL_QuitSubSystem(Uint32 flags)
SDL_initialized &= ~SDL_INIT_JOYSTICK;
}
#endif
#if !SDL_TOUCHSCREEN_DISABLED
if ((flags & SDL_initialized & SDL_INIT_TOUCHSCREEN)) {
SDL_TouchscreenQuit();
SDL_initialized &= ~SDL_INIT_TOUCHSCREEN;
}
#endif
#if !SDL_TIMERS_DISABLED
if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
SDL_TimerQuit();
@@ -31,6 +31,9 @@
#if !SDL_JOYSTICK_DISABLED
#include "../joystick/SDL_joystick_c.h"
#endif
#if !SDL_TOUCHSCREEN_DISABLED
#include "../touchscreen/SDL_touchscreen_c.h"
#endif

/* Public data -- the event filter */
SDL_EventFilter SDL_EventOK = NULL;
@@ -117,6 +120,12 @@ SDL_GobbleEvents(void *unused)
SDL_JoystickUpdate();
}
#endif
#if !SDL_TOUCHSCREEN_DISABLED
/* Similarly, check for touchscreen state change */
if (SDL_numtouchscreens && (SDL_eventstate & SDL_TOUCHEVENTMASK)) {
SDL_TouchscreenUpdate();
}
#endif

/* Give up the CPU for the rest of our timeslice */
SDL_EventLock.safe = 1;
@@ -387,6 +396,12 @@ SDL_PumpEvents(void)
if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
SDL_JoystickUpdate();
}
#endif
#if !SDL_TOUCHSCREEN_DISABLED
/* Check for touchscreen state change */
if (SDL_numtouchscreens && (SDL_eventstate & SDL_TOUCHEVENTMASK)) {
SDL_TouchscreenUpdate();
}
#endif
}
}
@@ -28,6 +28,10 @@
#include "SDL_endian.h"
#include "SDL_rwops.h"

#ifdef __NDS__
/* include libfat headers for fatInitDefault(). */
#include <fat.h>
#endif /* __NDS__ */

#ifdef __WIN32__

@@ -462,7 +466,10 @@ SDL_RWops *
SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
{
SDL_RWops *rwops = NULL;

#ifdef __NDS__
/* set it up so we can use stdio file function */
fatInitDefault();
#endif /* __NDS__ */
rwops = SDL_AllocRW();
if (rwops != NULL) {
rwops->seek = stdio_seek;

0 comments on commit 7a8d9fc

Please sign in to comment.