Started adding framework for Touchscreen API, based on and (consistent with) the existing Joystick API. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Mon, 23 Jun 2008 11:55:26 +0000
branchgsoc2008_nds
changeset 2674f1d07ba2e275
parent 2673 24a6b3588eac
child 2675 5e4274591163
Started adding framework for Touchscreen API, based on and (consistent with) the existing Joystick API.
Makefile.ds
include/SDL.h
include/SDL_config_nintendods.h
include/SDL_events.h
include/SDL_touchscreen.h
src/SDL.c
src/events/SDL_events.c
src/file/SDL_rwops.c
src/touchscreen/SDL_systouchscreen.h
src/touchscreen/SDL_touchscreen.c
src/touchscreen/SDL_touchscreen_c.h
src/touchscreen/dummy/SDL_systouchscreen.c
src/touchscreen/nds/SDL_systouchscreen.c
     1.1 --- a/Makefile.ds	Thu Jun 19 07:11:35 2008 +0000
     1.2 +++ b/Makefile.ds	Mon Jun 23 11:55:26 2008 +0000
     1.3 @@ -51,6 +51,9 @@
     1.4  src/file/SDL_rwops.c \
     1.5  src/joystick/nds/SDL_sysjoystick.c \
     1.6  src/joystick/SDL_joystick.c \
     1.7 +src/touchscreen/nds/SDL_systouchscreen.c \
     1.8 +src/touchscreen/dummy/SDL_systouchscreen.c \
     1.9 +src/touchscreen/SDL_touchscreen.c \
    1.10  src/stdlib/SDL_getenv.c \
    1.11  src/stdlib/SDL_iconv.c \
    1.12  src/stdlib/SDL_malloc.c \
    1.13 @@ -67,6 +70,9 @@
    1.14  src/video/nds/SDL_ndsevents.c \
    1.15  src/video/nds/SDL_ndsrender.c \
    1.16  src/video/nds/SDL_ndsvideo.c \
    1.17 +src/video/dummy/SDL_nullevents.c \
    1.18 +src/video/dummy/SDL_nullrender.c \
    1.19 +src/video/dummy/SDL_nullvideo.c \
    1.20  src/video/SDL_blit_0.c \
    1.21  src/video/SDL_blit_1.c \
    1.22  src/video/SDL_blit_A.c \
     2.1 --- a/include/SDL.h	Thu Jun 19 07:11:35 2008 +0000
     2.2 +++ b/include/SDL.h	Mon Jun 23 11:55:26 2008 +0000
     2.3 @@ -109,6 +109,7 @@
     2.4  #define SDL_INIT_VIDEO		0x00000020
     2.5  #define SDL_INIT_CDROM		0x00000100
     2.6  #define SDL_INIT_JOYSTICK	0x00000200
     2.7 +#define SDL_INIT_TOUCHSCREEN	0x00000400
     2.8  #define SDL_INIT_NOPARACHUTE	0x00100000      /* Don't catch fatal signals */
     2.9  #define SDL_INIT_EVENTTHREAD	0x01000000      /* Not supported on all OS's */
    2.10  #define SDL_INIT_EVERYTHING	0x0000FFFF
     3.1 --- a/include/SDL_config_nintendods.h	Thu Jun 19 07:11:35 2008 +0000
     3.2 +++ b/include/SDL_config_nintendods.h	Mon Jun 23 11:55:26 2008 +0000
     3.3 @@ -99,6 +99,9 @@
     3.4  
     3.5  /* Enable various input drivers */
     3.6  #define SDL_JOYSTICK_NDS	1
     3.7 +/*#define SDL_JOYSTICK_DUMMY	1*/
     3.8 +#define SDL_TOUCHSCREEN_NDS	1
     3.9 +/*#define SDL_TOUCHSCREEN_DUMMY	1*/
    3.10  
    3.11  /* DS has no dynamic linking afaik */
    3.12  #define SDL_LOADSO_DISABLED	1
    3.13 @@ -112,5 +115,6 @@
    3.14  
    3.15  /* Enable various video drivers */
    3.16  #define SDL_VIDEO_DRIVER_NDS	1
    3.17 +#define SDL_VIDEO_DRIVER_DUMMY	1
    3.18  
    3.19  #endif /* _SDL_config_nintendods_h */
     4.1 --- a/include/SDL_events.h	Thu Jun 19 07:11:35 2008 +0000
     4.2 +++ b/include/SDL_events.h	Mon Jun 23 11:55:26 2008 +0000
     4.3 @@ -35,6 +35,7 @@
     4.4  #include "SDL_keyboard.h"
     4.5  #include "SDL_mouse.h"
     4.6  #include "SDL_joystick.h"
     4.7 +#include "SDL_touchscreen.h"
     4.8  #include "SDL_quit.h"
     4.9  
    4.10  #include "begin_code.h"
    4.11 @@ -70,6 +71,9 @@
    4.12      SDL_JOYHATMOTION,           /**< Joystick hat position change */
    4.13      SDL_JOYBUTTONDOWN,          /**< Joystick button pressed */
    4.14      SDL_JOYBUTTONUP,            /**< Joystick button released */
    4.15 +    SDL_TOUCHPRESSED,           /**< Touchscreen pressed */
    4.16 +    SDL_TOUCHRELEASED,          /**< Touchscreen no longer pressed */
    4.17 +    SDL_TOUCHMOTION,            /**< Touchscreen point motion */
    4.18      SDL_QUIT,                   /**< User-requested quit */
    4.19      SDL_SYSWMEVENT,             /**< System specific event */
    4.20      SDL_EVENT_RESERVED1,        /**< Reserved for future use... */
    4.21 @@ -111,6 +115,11 @@
    4.22          SDL_EVENTMASK(SDL_JOYBALLMOTION) |
    4.23          SDL_EVENTMASK(SDL_JOYHATMOTION) |
    4.24          SDL_EVENTMASK(SDL_JOYBUTTONDOWN) | SDL_EVENTMASK(SDL_JOYBUTTONUP),
    4.25 +    SDL_TOUCHPRESSEDMASK = SDL_EVENTMASK(SDL_TOUCHPRESSED),
    4.26 +    SDL_TOUCHRELEASEDMASK = SDL_EVENTMASK(SDL_TOUCHRELEASED),
    4.27 +    SDL_TOUCHMOTIONMASK = SDL_EVENTMASK(SDL_TOUCHMOTION),
    4.28 +    SDL_TOUCHEVENTMASK = SDL_EVENTMASK(SDL_TOUCHPRESSED) |
    4.29 +        SDL_EVENTMASK(SDL_TOUCHRELEASED) | SDL_EVENTMASK(SDL_TOUCHMOTION),
    4.30      SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT),
    4.31      SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT)
    4.32  } SDL_EventMask;
    4.33 @@ -264,6 +273,21 @@
    4.34  } SDL_JoyButtonEvent;
    4.35  
    4.36  /**
    4.37 + * \struct SDL_TouchEvent
    4.38 + *
    4.39 + * \brief Touchscreen motion event structure (event.touch.*)
    4.40 + */
    4.41 +typedef struct SDL_TouchEvent
    4.42 +{
    4.43 +    Uint8 type;         /**< SDL_TOUCHMOTION, SDL_TOUCHPRESS, SDL_TOUCHRELEASED */
    4.44 +    Uint8 which;        /**< The touchscreen device index */
    4.45 +    int point;          /**< The touch point index, relevant for multitouch. */
    4.46 +    int xpos;           /**< The X coordinate of the touch point. */
    4.47 +    int ypos;           /**< The Y coordinate of the touch point. */
    4.48 +    int pressure;       /**< The pressure of the touch */
    4.49 +} SDL_TouchEvent;
    4.50 +
    4.51 +/**
    4.52   * \struct SDL_QuitEvent
    4.53   *
    4.54   * \brief The "quit requested" event
    4.55 @@ -334,6 +358,7 @@
    4.56      SDL_JoyBallEvent jball;         /**< Joystick ball event data */
    4.57      SDL_JoyHatEvent jhat;           /**< Joystick hat event data */
    4.58      SDL_JoyButtonEvent jbutton;     /**< Joystick button event data */
    4.59 +    SDL_TouchEvent touch;           /**< Touchscreen event data */
    4.60      SDL_QuitEvent quit;             /**< Quit request event data */
    4.61      SDL_UserEvent user;             /**< Custom event data */
    4.62      SDL_SysWMEvent syswm;           /**< System dependent window event data */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/include/SDL_touchscreen.h	Mon Jun 23 11:55:26 2008 +0000
     5.3 @@ -0,0 +1,152 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2006 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +
    5.26 +/**
    5.27 + * \file SDL_touchscreen.h
    5.28 + *
    5.29 + * Include file for SDL touchscreen event handling
    5.30 + */
    5.31 +
    5.32 +#ifndef _SDL_touchscreen_h
    5.33 +#define _SDL_touchscreen_h
    5.34 +
    5.35 +#include "SDL_stdinc.h"
    5.36 +#include "SDL_error.h"
    5.37 +
    5.38 +#include "begin_code.h"
    5.39 +/* Set up for C function definitions, even when using C++ */
    5.40 +#ifdef __cplusplus
    5.41 +/* *INDENT-OFF* */
    5.42 +extern "C" {
    5.43 +/* *INDENT-ON* */
    5.44 +#endif
    5.45 +
    5.46 +/* In order to use these functions, SDL_Init() must have been called
    5.47 +   with the SDL_INIT_TOUCHSCREEN flag.  This causes SDL to scan the system
    5.48 +   for touchscreens, and load appropriate drivers.
    5.49 +*/
    5.50 +
    5.51 +/* The touchscreen structure used to identify an SDL touchscreen */
    5.52 +struct _SDL_Touchscreen;
    5.53 +typedef struct _SDL_Touchscreen SDL_Touchscreen;
    5.54 +
    5.55 +
    5.56 +/* Function prototypes */
    5.57 +/*
    5.58 + * Count the number of touchscreens attached to the system
    5.59 + */
    5.60 +extern DECLSPEC int SDLCALL SDL_NumTouchscreens(void);
    5.61 +
    5.62 +/*
    5.63 + * Get the implementation dependent name of a touchscreen.
    5.64 + * This can be called before any touchscreens are opened.
    5.65 + * If no name can be found, this function returns NULL.
    5.66 + */
    5.67 +extern DECLSPEC const char *SDLCALL SDL_TouchscreenName(int device_index);
    5.68 +
    5.69 +/*
    5.70 + * Open a touchscreen for use - the index passed as an argument refers to
    5.71 + * the N'th touchscreen on the system.  This index is the value which will
    5.72 + * identify this touchscreen in future touchscreen events.
    5.73 + *
    5.74 + * This function returns a touchscreen identifier, or NULL if an error occurred.
    5.75 + */
    5.76 +extern DECLSPEC SDL_Touchscreen *SDLCALL SDL_TouchscreenOpen(int device_index);
    5.77 +
    5.78 +/*
    5.79 + * Returns 1 if the touchscreen has been opened, or 0 if it has not.
    5.80 + */
    5.81 +extern DECLSPEC int SDLCALL SDL_TouchscreenOpened(int device_index);
    5.82 +
    5.83 +/*
    5.84 + * Get the device index of an opened touchscreen.
    5.85 + */
    5.86 +extern DECLSPEC int SDLCALL SDL_TouchscreenIndex(SDL_Touchscreen * touchscreen);
    5.87 +
    5.88 +/*
    5.89 + * Get the number of points a touchscreen can register at a time
    5.90 + * (single or multi-touch.)
    5.91 + */
    5.92 +extern DECLSPEC int SDLCALL SDL_TouchscreenMaxPoints(SDL_Touchscreen * touchscreen);
    5.93 +
    5.94 +/*
    5.95 + * Update the current state of the open touchscreens.
    5.96 + * This is called automatically by the event loop if any touchscreen
    5.97 + * events are enabled.
    5.98 + */
    5.99 +extern DECLSPEC void SDLCALL SDL_TouchscreenUpdate(void);
   5.100 +
   5.101 +/*
   5.102 + * Enable/disable touchscreen event polling.
   5.103 + * If touchscreen events are disabled, you must call SDL_TouchscreenUpdate()
   5.104 + * yourself and check the state of the touchscreen when you want touchscreen
   5.105 + * information.
   5.106 + * The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.
   5.107 + */
   5.108 +extern DECLSPEC int SDLCALL SDL_TouchscreenEventState(int state);
   5.109 +
   5.110 +/*
   5.111 + * Get the current X,Y position of the indicated point on the touchscreen.
   5.112 + *
   5.113 + * If not NULL, *x is set to an integer in the range [-32768,32767]
   5.114 + * where -32768 is the left edge, 0 is center, 32767 is right edge.
   5.115 + * Similarly with *y, for the top, center, and bottom, respectively.
   5.116 + * The returned value is an unsigned integer in the range [1,32767]
   5.117 + * that represents the pressure of the touch.
   5.118 + * If not being touched, 0 is returned and *x and *y are unmodified.
   5.119 + *
   5.120 + * The touch point indices start at index 0.
   5.121 + * If given a negative value for point, all the X,Y, and pressures
   5.122 + * for all the currently touched points on a multitouch device
   5.123 + * should be averaged and used for *x, *y, and the return value.
   5.124 + * If the value of point exceeds the number of points currently touched,
   5.125 + * 0 should be returned, and *x, *y should be left unmodified.
   5.126 + *
   5.127 + * On error, -1 is returned.
   5.128 + */
   5.129 +extern DECLSPEC int SDLCALL SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen,
   5.130 +                                                    int point, int *x, int *y);
   5.131 +
   5.132 +/*
   5.133 + * Get the number of currently touched points on a touchscreen.
   5.134 + * This is either 0 or 1 for a single-touch device.
   5.135 + * On error, -1 is returned.
   5.136 + */
   5.137 +extern DECLSPEC int SDLCALL SDL_TouchscreenGetPoints(SDL_Touchscreen * touchscreen);
   5.138 +
   5.139 +/*
   5.140 + * Close a touchscreen previously opened with SDL_TouchscreenOpen()
   5.141 + */
   5.142 +extern DECLSPEC void SDLCALL SDL_TouchscreenClose(SDL_Touchscreen * touchscreen);
   5.143 +
   5.144 +
   5.145 +/* Ends C function definitions when using C++ */
   5.146 +#ifdef __cplusplus
   5.147 +/* *INDENT-OFF* */
   5.148 +}
   5.149 +/* *INDENT-ON* */
   5.150 +#endif
   5.151 +#include "close_code.h"
   5.152 +
   5.153 +#endif /* _SDL_touchscreen_h */
   5.154 +
   5.155 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/SDL.c	Thu Jun 19 07:11:35 2008 +0000
     6.2 +++ b/src/SDL.c	Mon Jun 23 11:55:26 2008 +0000
     6.3 @@ -38,6 +38,10 @@
     6.4  extern int SDL_JoystickInit(void);
     6.5  extern void SDL_JoystickQuit(void);
     6.6  #endif
     6.7 +#if !SDL_TOUCHSCREEN_DISABLED
     6.8 +extern int SDL_TouchscreenInit(void);
     6.9 +extern void SDL_TouchscreenQuit(void);
    6.10 +#endif
    6.11  #if !SDL_CDROM_DISABLED
    6.12  extern int SDL_CDROMInit(void);
    6.13  extern void SDL_CDROMQuit(void);
    6.14 @@ -123,6 +127,21 @@
    6.15      }
    6.16  #endif
    6.17  
    6.18 +#if !SDL_TOUCHSCREEN_DISABLED
    6.19 +    /* Initialize the touchscreen subsystem */
    6.20 +    if ((flags & SDL_INIT_TOUCHSCREEN) && !(SDL_initialized & SDL_INIT_TOUCHSCREEN)) {
    6.21 +        if (SDL_TouchscreenInit() < 0) {
    6.22 +            return (-1);
    6.23 +        }
    6.24 +        SDL_initialized |= SDL_INIT_TOUCHSCREEN;
    6.25 +    }
    6.26 +#else
    6.27 +    if (flags & SDL_INIT_TOUCHSCREEN) {
    6.28 +        SDL_SetError("SDL not built with touchscreen support");
    6.29 +        return (-1);
    6.30 +    }
    6.31 +#endif
    6.32 +
    6.33  #if !SDL_CDROM_DISABLED
    6.34      /* Initialize the CD-ROM subsystem */
    6.35      if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
    6.36 @@ -180,6 +199,12 @@
    6.37          SDL_initialized &= ~SDL_INIT_JOYSTICK;
    6.38      }
    6.39  #endif
    6.40 +#if !SDL_TOUCHSCREEN_DISABLED
    6.41 +    if ((flags & SDL_initialized & SDL_INIT_TOUCHSCREEN)) {
    6.42 +        SDL_TouchscreenQuit();
    6.43 +        SDL_initialized &= ~SDL_INIT_TOUCHSCREEN;
    6.44 +    }
    6.45 +#endif
    6.46  #if !SDL_TIMERS_DISABLED
    6.47      if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
    6.48          SDL_TimerQuit();
     7.1 --- a/src/events/SDL_events.c	Thu Jun 19 07:11:35 2008 +0000
     7.2 +++ b/src/events/SDL_events.c	Mon Jun 23 11:55:26 2008 +0000
     7.3 @@ -31,6 +31,9 @@
     7.4  #if !SDL_JOYSTICK_DISABLED
     7.5  #include "../joystick/SDL_joystick_c.h"
     7.6  #endif
     7.7 +#if !SDL_TOUCHSCREEN_DISABLED
     7.8 +#include "../touchscreen/SDL_touchscreen_c.h"
     7.9 +#endif
    7.10  
    7.11  /* Public data -- the event filter */
    7.12  SDL_EventFilter SDL_EventOK = NULL;
    7.13 @@ -117,6 +120,12 @@
    7.14              SDL_JoystickUpdate();
    7.15          }
    7.16  #endif
    7.17 +#if !SDL_TOUCHSCREEN_DISABLED
    7.18 +        /* Similarly, check for touchscreen state change */
    7.19 +        if (SDL_numtouchscreens && (SDL_eventstate & SDL_TOUCHEVENTMASK)) {
    7.20 +            SDL_TouchscreenUpdate();
    7.21 +        }
    7.22 +#endif
    7.23  
    7.24          /* Give up the CPU for the rest of our timeslice */
    7.25          SDL_EventLock.safe = 1;
    7.26 @@ -388,6 +397,12 @@
    7.27              SDL_JoystickUpdate();
    7.28          }
    7.29  #endif
    7.30 +#if !SDL_TOUCHSCREEN_DISABLED
    7.31 +        /* Check for touchscreen state change */
    7.32 +        if (SDL_numtouchscreens && (SDL_eventstate & SDL_TOUCHEVENTMASK)) {
    7.33 +            SDL_TouchscreenUpdate();
    7.34 +        }
    7.35 +#endif
    7.36      }
    7.37  }
    7.38  
     8.1 --- a/src/file/SDL_rwops.c	Thu Jun 19 07:11:35 2008 +0000
     8.2 +++ b/src/file/SDL_rwops.c	Mon Jun 23 11:55:26 2008 +0000
     8.3 @@ -28,6 +28,10 @@
     8.4  #include "SDL_endian.h"
     8.5  #include "SDL_rwops.h"
     8.6  
     8.7 +#ifdef __NDS__
     8.8 +/* include libfat headers for fatInitDefault(). */
     8.9 +#include <fat.h>
    8.10 +#endif /* __NDS__ */
    8.11  
    8.12  #ifdef __WIN32__
    8.13  
    8.14 @@ -462,7 +466,10 @@
    8.15  SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
    8.16  {
    8.17      SDL_RWops *rwops = NULL;
    8.18 -
    8.19 +#ifdef __NDS__
    8.20 +    /* set it up so we can use stdio file function */
    8.21 +    fatInitDefault();
    8.22 +#endif /* __NDS__ */
    8.23      rwops = SDL_AllocRW();
    8.24      if (rwops != NULL) {
    8.25          rwops->seek = stdio_seek;
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/touchscreen/SDL_systouchscreen.h	Mon Jun 23 11:55:26 2008 +0000
     9.3 @@ -0,0 +1,78 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2006 Sam Lantinga
     9.7 +
     9.8 +    This library is SDL_free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Lesser General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2.1 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Lesser General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Lesser General Public
    9.19 +    License along with this library; if not, write to the Free Software
    9.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +#include "SDL_config.h"
    9.26 +
    9.27 +/* This is the system specific header for the SDL touchscreen API */
    9.28 +
    9.29 +#include "SDL_touchscreen.h"
    9.30 +
    9.31 +/* The SDL touchscreen structure */
    9.32 +struct _SDL_Touchscreen
    9.33 +{
    9.34 +    Uint8 index;                /* Device index */
    9.35 +    const char *name;           /* Touchscreen name - system dependent */
    9.36 +
    9.37 +    int maxpoints;              /* Max # multi-touch points, -1 if unlimited. */
    9.38 +    int npoints;                /* Number of points currently touched */
    9.39 +    struct touchpoint
    9.40 +    {
    9.41 +        int x;
    9.42 +        int y;
    9.43 +        int pressure;
    9.44 +    } *points;                   /* Current ball motion deltas */
    9.45 +
    9.46 +    struct touchscreen_hwdata *hwdata;     /* Driver dependent information */
    9.47 +
    9.48 +    int ref_count;              /* Reference count for multiple opens */
    9.49 +};
    9.50 +
    9.51 +/* Function to scan the system for touchscreens.
    9.52 + * Touchscreen 0 should be the system default touchscreen.
    9.53 + * This function should return the number of available touchscreens, or -1
    9.54 + * on an unrecoverable fatal error.
    9.55 + */
    9.56 +extern int SDL_SYS_TouchscreenInit(void);
    9.57 +
    9.58 +/* Function to get the device-dependent name of a touchscreen */
    9.59 +extern const char *SDL_SYS_TouchscreenName(int index);
    9.60 +
    9.61 +/* Function to open a touchscreen for use.
    9.62 +   The touchscreen to open is specified by the index field of the touchscreen.
    9.63 +   This should fill the maxpoints field of the touchscreen structure.
    9.64 +   It returns 0, or -1 if there is an error.
    9.65 + */
    9.66 +extern int SDL_SYS_TouchscreenOpen(SDL_Touchscreen * touchscreen);
    9.67 +
    9.68 +/* Function to update the state of a touchscreen - called as a device poll.
    9.69 + * This function shouldn't update the touchscreen structure directly,
    9.70 + * but instead should call SDL_PrivateTouchscreen*() to deliver events
    9.71 + * and update touchscreen device state.
    9.72 + */
    9.73 +extern void SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen);
    9.74 +
    9.75 +/* Function to close a touchscreen after use */
    9.76 +extern void SDL_SYS_TouchscreenClose(SDL_Touchscreen * touchscreen);
    9.77 +
    9.78 +/* Function to perform any system-specific touchscreen related cleanup */
    9.79 +extern void SDL_SYS_TouchscreenQuit(void);
    9.80 +
    9.81 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/touchscreen/SDL_touchscreen.c	Mon Jun 23 11:55:26 2008 +0000
    10.3 @@ -0,0 +1,482 @@
    10.4 +/*
    10.5 +    SDL - Simple DirectMedia Layer
    10.6 +    Copyright (C) 1997-2006 Sam Lantinga
    10.7 +
    10.8 +    This library is free software; you can redistribute it and/or
    10.9 +    modify it under the terms of the GNU Lesser General Public
   10.10 +    License as published by the Free Software Foundation; either
   10.11 +    version 2.1 of the License, or (at your option) any later version.
   10.12 +
   10.13 +    This library is distributed in the hope that it will be useful,
   10.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.16 +    Lesser General Public License for more details.
   10.17 +
   10.18 +    You should have received a copy of the GNU Lesser General Public
   10.19 +    License along with this library; if not, write to the Free Software
   10.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   10.21 +
   10.22 +    Sam Lantinga
   10.23 +    slouken@libsdl.org
   10.24 +*/
   10.25 +#include "SDL_config.h"
   10.26 +
   10.27 +/* This is the touchscreen API for Simple DirectMedia Layer */
   10.28 +
   10.29 +#include "SDL_events.h"
   10.30 +#include "SDL_systouchscreen.h"
   10.31 +#include "SDL_touchscreen_c.h"
   10.32 +#if !SDL_EVENTS_DISABLED
   10.33 +#include "../events/SDL_events_c.h"
   10.34 +#endif
   10.35 +
   10.36 +/* This is used for Quake III Arena */
   10.37 +#if SDL_EVENTS_DISABLED
   10.38 +#define SDL_Lock_EventThread()
   10.39 +#define SDL_Unlock_EventThread()
   10.40 +#endif
   10.41 +
   10.42 +Uint8 SDL_numtouchscreens = 0;
   10.43 +SDL_Touchscreen **SDL_touchscreens = NULL;
   10.44 +static SDL_Touchscreen *default_touchscreen = NULL;
   10.45 +
   10.46 +int
   10.47 +SDL_TouchscreenInit(void)
   10.48 +{
   10.49 +    int arraylen;
   10.50 +    int status;
   10.51 +
   10.52 +    SDL_numtouchscreens = 0;
   10.53 +    status = SDL_SYS_TouchscreenInit();
   10.54 +    if (status >= 0) {
   10.55 +        arraylen = (status + 1) * sizeof(*SDL_touchscreens);
   10.56 +        SDL_touchscreens = (SDL_Touchscreen **) SDL_malloc(arraylen);
   10.57 +        if (SDL_touchscreens == NULL) {
   10.58 +            SDL_numtouchscreens = 0;
   10.59 +        } else {
   10.60 +            SDL_memset(SDL_touchscreens, 0, arraylen);
   10.61 +            SDL_numtouchscreens = status;
   10.62 +        }
   10.63 +        status = 0;
   10.64 +    }
   10.65 +    default_touchscreen = NULL;
   10.66 +    return (status);
   10.67 +}
   10.68 +
   10.69 +/*
   10.70 + * Count the number of touchscreens attached to the system
   10.71 + */
   10.72 +int
   10.73 +SDL_NumTouchscreens(void)
   10.74 +{
   10.75 +    return SDL_numtouchscreens;
   10.76 +}
   10.77 +
   10.78 +/*
   10.79 + * Get the implementation dependent name of a touchscreen
   10.80 + */
   10.81 +const char *
   10.82 +SDL_TouchscreenName(int device_index)
   10.83 +{
   10.84 +    if ((device_index < 0) || (device_index >= SDL_numtouchscreens)) {
   10.85 +        SDL_SetError("There are %d touchscreens available", SDL_numtouchscreens);
   10.86 +        return (NULL);
   10.87 +    }
   10.88 +    return (SDL_SYS_TouchscreenName(device_index));
   10.89 +}
   10.90 +
   10.91 +/*
   10.92 + * Open a touchscreen for use - the index passed as an argument refers to
   10.93 + * the N'th touchscreen on the system.  This index is the value which will
   10.94 + * identify this touchscreen in future touchscreen events.
   10.95 + *
   10.96 + * This function returns a touchscreen identifier, or NULL if an error occurred.
   10.97 + */
   10.98 +SDL_Touchscreen *
   10.99 +SDL_TouchscreenOpen(int device_index)
  10.100 +{
  10.101 +    int i;
  10.102 +    SDL_Touchscreen *touchscreen;
  10.103 +
  10.104 +    if ((device_index < 0) || (device_index >= SDL_numtouchscreens)) {
  10.105 +        SDL_SetError("There are %d touchscreens available", SDL_numtouchscreens);
  10.106 +        return (NULL);
  10.107 +    }
  10.108 +
  10.109 +    /* If the touchscreen is already open, return it */
  10.110 +    for (i = 0; SDL_touchscreens[i]; ++i) {
  10.111 +        if (device_index == SDL_touchscreens[i]->index) {
  10.112 +            touchscreen = SDL_touchscreens[i];
  10.113 +            ++touchscreen->ref_count;
  10.114 +            return (touchscreen);
  10.115 +        }
  10.116 +    }
  10.117 +
  10.118 +    /* Create and initialize the touchscreen */
  10.119 +    touchscreen = (SDL_Touchscreen *) SDL_malloc((sizeof *touchscreen));
  10.120 +    if (touchscreen != NULL) {
  10.121 +        SDL_memset(touchscreen, 0, (sizeof *touchscreen));
  10.122 +        touchscreen->index = device_index;
  10.123 +        if (SDL_SYS_TouchscreenOpen(touchscreen) < 0) {
  10.124 +            SDL_free(touchscreen);
  10.125 +            touchscreen = NULL;
  10.126 +        } else {
  10.127 +            if (touchscreen->maxpoints > 0) {
  10.128 +                touchscreen->points = (struct touchpoint *) SDL_malloc
  10.129 +                    (touchscreen->maxpoints * sizeof(*touchscreen->points));
  10.130 +            }
  10.131 +            if ((touchscreen->maxpoints > 0) && !touchscreen->points) {
  10.132 +                SDL_OutOfMemory();
  10.133 +                SDL_TouchscreenClose(touchscreen);
  10.134 +                touchscreen = NULL;
  10.135 +            }
  10.136 +            if (touchscreen->points) {
  10.137 +                SDL_memset(touchscreen->points, 0,
  10.138 +                           touchscreen->maxpoints * sizeof(*touchscreen->points));
  10.139 +            }
  10.140 +        }
  10.141 +    }
  10.142 +    if (touchscreen) {
  10.143 +        /* Add touchscreen to list */
  10.144 +        ++touchscreen->ref_count;
  10.145 +        SDL_Lock_EventThread();
  10.146 +        for (i = 0; SDL_touchscreens[i]; ++i)
  10.147 +            /* Skip to next touchscreen */ ;
  10.148 +        SDL_touchscreens[i] = touchscreen;
  10.149 +        SDL_Unlock_EventThread();
  10.150 +    }
  10.151 +    return (touchscreen);
  10.152 +}
  10.153 +
  10.154 +/*
  10.155 + * Returns 1 if the touchscreen has been opened, or 0 if it has not.
  10.156 + */
  10.157 +int
  10.158 +SDL_TouchscreenOpened(int device_index)
  10.159 +{
  10.160 +    int i, opened;
  10.161 +
  10.162 +    opened = 0;
  10.163 +    for (i = 0; SDL_touchscreens[i]; ++i) {
  10.164 +        if (SDL_touchscreens[i]->index == (Uint8) device_index) {
  10.165 +            opened = 1;
  10.166 +            break;
  10.167 +        }
  10.168 +    }
  10.169 +    return (opened);
  10.170 +}
  10.171 +
  10.172 +static int
  10.173 +ValidTouchscreen(SDL_Touchscreen ** touchscreen)
  10.174 +{
  10.175 +    int valid;
  10.176 +
  10.177 +    if (*touchscreen == NULL) {
  10.178 +        *touchscreen = default_touchscreen;
  10.179 +    }
  10.180 +    if (*touchscreen == NULL) {
  10.181 +        SDL_SetError("Touchscreen hasn't been opened yet");
  10.182 +        valid = 0;
  10.183 +    } else {
  10.184 +        valid = 1;
  10.185 +    }
  10.186 +    return valid;
  10.187 +}
  10.188 +
  10.189 +/*
  10.190 + * Get the device index of an opened touchscreen.
  10.191 + */
  10.192 +int
  10.193 +SDL_TouchscreenIndex(SDL_Touchscreen * touchscreen)
  10.194 +{
  10.195 +    if (!ValidTouchscreen(&touchscreen)) {
  10.196 +        return (-1);
  10.197 +    }
  10.198 +    return (touchscreen->index);
  10.199 +}
  10.200 +
  10.201 +/*
  10.202 + * Get the max number of points on a multi-touch screen (or 1 on a single-touch)
  10.203 + */
  10.204 +int
  10.205 +SDL_TouchscreenMaxPoints(SDL_Touchscreen * touchscreen)
  10.206 +{
  10.207 +    if (!ValidTouchscreen(&touchscreen)) {
  10.208 +        return (-1);
  10.209 +    }
  10.210 +    return (touchscreen->maxpoints);
  10.211 +}
  10.212 +
  10.213 +/*
  10.214 + * Get the current X,Y position of the indicated point on the touchscreen
  10.215 + */
  10.216 +int
  10.217 +SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen, int point, int *x, int *y)
  10.218 +{
  10.219 +    int retval;
  10.220 +
  10.221 +    if (!ValidTouchscreen(&touchscreen)) {
  10.222 +        return (-1);
  10.223 +    }
  10.224 +
  10.225 +    retval = 0;
  10.226 +    if (point < 0) {
  10.227 +        int i; long avg;
  10.228 +        if(x) {
  10.229 +            avg = 0;
  10.230 +            for(i = 0; i < touchscreen->npoints; ++i) {
  10.231 +                avg += touchscreen->points[i].x;
  10.232 +            }
  10.233 +            *x = avg;
  10.234 +        }
  10.235 +        if(y) {
  10.236 +            avg = 0;
  10.237 +            for(i = 0; i < touchscreen->npoints; ++i) {
  10.238 +                avg += touchscreen->points[i].y;
  10.239 +            }
  10.240 +            *y = avg;
  10.241 +        }
  10.242 +        avg = 0;
  10.243 +        for(i = 0; i < touchscreen->npoints; ++i) {
  10.244 +            avg += touchscreen->points[i].pressure;
  10.245 +        }
  10.246 +        return (int)avg;
  10.247 +    } else if (point < touchscreen->maxpoints) {
  10.248 +        if (x) {
  10.249 +            *x = touchscreen->points[point].x;
  10.250 +        }
  10.251 +        if (y) {
  10.252 +            *y = touchscreen->points[point].y;
  10.253 +        }
  10.254 +        retval = touchscreen->points[point].pressure;
  10.255 +    } else {
  10.256 +        SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints);
  10.257 +        retval = -1;
  10.258 +    }
  10.259 +    return (retval);
  10.260 +}
  10.261 +
  10.262 +int
  10.263 +SDL_TouchscreenGetPoints(SDL_Touchscreen *touchscreen) {
  10.264 +    if (!ValidTouchscreen(&touchscreen)) {
  10.265 +        return (-1);
  10.266 +    }
  10.267 +
  10.268 +    return touchscreen->npoints;
  10.269 +}
  10.270 +
  10.271 +/*
  10.272 + * Close a touchscreen previously opened with SDL_TouchscreenOpen()
  10.273 + */
  10.274 +void
  10.275 +SDL_TouchscreenClose(SDL_Touchscreen * touchscreen)
  10.276 +{
  10.277 +    int i;
  10.278 +
  10.279 +    if (!ValidTouchscreen(&touchscreen)) {
  10.280 +        return;
  10.281 +    }
  10.282 +
  10.283 +    /* First decrement ref count */
  10.284 +    if (--touchscreen->ref_count > 0) {
  10.285 +        return;
  10.286 +    }
  10.287 +
  10.288 +    /* Lock the event queue - prevent touchscreen polling */
  10.289 +    SDL_Lock_EventThread();
  10.290 +
  10.291 +    if (touchscreen == default_touchscreen) {
  10.292 +        default_touchscreen = NULL;
  10.293 +    }
  10.294 +    SDL_SYS_TouchscreenClose(touchscreen);
  10.295 +
  10.296 +    /* Remove touchscreen from list */
  10.297 +    for (i = 0; SDL_touchscreens[i]; ++i) {
  10.298 +        if (touchscreen == SDL_touchscreens[i]) {
  10.299 +            SDL_memcpy(&SDL_touchscreens[i], &SDL_touchscreens[i + 1],
  10.300 +                       (SDL_numtouchscreens - i) * sizeof(touchscreen));
  10.301 +            break;
  10.302 +        }
  10.303 +    }
  10.304 +
  10.305 +    /* Let the event thread keep running */
  10.306 +    SDL_Unlock_EventThread();
  10.307 +
  10.308 +    /* Free the data associated with this touchscreen */
  10.309 +    if (touchscreen->points) {
  10.310 +        SDL_free(touchscreen->points);
  10.311 +    }
  10.312 +    SDL_free(touchscreen);
  10.313 +}
  10.314 +
  10.315 +void
  10.316 +SDL_TouchscreenQuit(void)
  10.317 +{
  10.318 +    /* Stop the event polling */
  10.319 +    SDL_Lock_EventThread();
  10.320 +    SDL_numtouchscreens = 0;
  10.321 +    SDL_Unlock_EventThread();
  10.322 +
  10.323 +    /* Quit the touchscreen setup */
  10.324 +    SDL_SYS_TouchscreenQuit();
  10.325 +    if (SDL_touchscreens) {
  10.326 +        SDL_free(SDL_touchscreens);
  10.327 +        SDL_touchscreens = NULL;
  10.328 +    }
  10.329 +}
  10.330 +
  10.331 +
  10.332 +/* These are global for SDL_systouchscreen.c and SDL_events.c */
  10.333 +int
  10.334 +SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point,
  10.335 +                                 int x, int y, int pressure) {
  10.336 +    int posted;
  10.337 +    int ev = SDL_TOUCHMOTION;
  10.338 +
  10.339 +    if (!ValidTouchscreen(&touchscreen)) {
  10.340 +        return -1;
  10.341 +    }
  10.342 +
  10.343 +    if(point >= touchscreen->maxpoints) {
  10.344 +        SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints);
  10.345 +        return -1;
  10.346 +    }
  10.347 +
  10.348 +    /* on neg. point, set the given args as the *only* point.
  10.349 +       so set the struct to have no points pressed, then continue as normal. */
  10.350 +    if(point < 0) {
  10.351 +        point = 0;
  10.352 +        touchscreen->npoints = 0;
  10.353 +        SDL_memset(touchscreen->points, 0,
  10.354 +                   touchscreen->maxpoints * sizeof(touchscreen->points[0]));
  10.355 +    }
  10.356 +
  10.357 +    /* new touch point!  that means a TOUCHPRESSED event is due. */
  10.358 +    if(point >= touchscreen->npoints) {
  10.359 +        ev = SDL_TOUCHPRESSED;
  10.360 +        point = touchscreen->npoints;
  10.361 +        ++touchscreen->npoints;
  10.362 +    }
  10.363 +
  10.364 +    /* no motion, no change, don't report an event. */
  10.365 +    if(touchscreen->points[point].x == x &&
  10.366 +       touchscreen->points[point].y == y &&
  10.367 +       touchscreen->points[point].pressure == pressure) {
  10.368 +        return 0;
  10.369 +    }
  10.370 +
  10.371 +    /* Update internal touchscreen point state */
  10.372 +    touchscreen->points[point].x = x;
  10.373 +    touchscreen->points[point].y = y;
  10.374 +    touchscreen->points[point].pressure = pressure;
  10.375 +
  10.376 +    /* Post the event, if desired */
  10.377 +    posted = 0;
  10.378 +#if !SDL_EVENTS_DISABLED
  10.379 +    if (SDL_ProcessEvents[ev] == SDL_ENABLE) {
  10.380 +        SDL_Event event;
  10.381 +        event.touch.type = ev;
  10.382 +        event.touch.which = touchscreen->index;
  10.383 +        event.touch.point = point;
  10.384 +        event.touch.xpos = x;
  10.385 +        event.touch.ypos = y;
  10.386 +        event.touch.pressure = pressure;
  10.387 +        if ((SDL_EventOK == NULL)
  10.388 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
  10.389 +            posted = 1;
  10.390 +            SDL_PushEvent(&event);
  10.391 +        }
  10.392 +    }
  10.393 +#endif /* !SDL_EVENTS_DISABLED */
  10.394 +    return (posted);
  10.395 +}
  10.396 +
  10.397 +int
  10.398 +SDL_PrivateTouchRelease(SDL_Touchscreen * touchscreen, int point) {
  10.399 +    int posted;
  10.400 +
  10.401 +    if (!ValidTouchscreen(&touchscreen)) {
  10.402 +        return -1;
  10.403 +    }
  10.404 +
  10.405 +    if(point >= touchscreen->maxpoints) {
  10.406 +        SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints);
  10.407 +        return -1;
  10.408 +    } else if(point >= touchscreen->npoints) {
  10.409 +        SDL_SetError("Point %d up when only %d were down", point, touchscreen->npoints);
  10.410 +        return -1;
  10.411 +    }
  10.412 +
  10.413 +    /* on neg. point, clear all points.  so set the struct to have one point
  10.414 +       pressed, then continue as normal. */
  10.415 +    if(point < 0) {
  10.416 +        point = 0;
  10.417 +        touchscreen->npoints = 1;
  10.418 +        SDL_memset(&(touchscreen->points[1]), 0,
  10.419 +                   (touchscreen->maxpoints-1) * sizeof(touchscreen->points[0]));
  10.420 +    }
  10.421 +
  10.422 +    /* Update internal touchscreen point state */
  10.423 +    touchscreen->points[point].pressure = 0;
  10.424 +    if(touchscreen->npoints >= 0) --touchscreen->npoints;
  10.425 +
  10.426 +    /* Post the event, if desired */
  10.427 +    posted = 0;
  10.428 +#if !SDL_EVENTS_DISABLED
  10.429 +    if (SDL_ProcessEvents[SDL_TOUCHRELEASED] == SDL_ENABLE) {
  10.430 +        SDL_Event event;
  10.431 +        event.touch.type = SDL_TOUCHRELEASED;
  10.432 +        event.touch.which = touchscreen->index;
  10.433 +        event.touch.point = point;
  10.434 +        if ((SDL_EventOK == NULL)
  10.435 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
  10.436 +            posted = 1;
  10.437 +            SDL_PushEvent(&event);
  10.438 +        }
  10.439 +    }
  10.440 +#endif /* !SDL_EVENTS_DISABLED */
  10.441 +    return (posted);
  10.442 +}
  10.443 +
  10.444 +void
  10.445 +SDL_TouchscreenUpdate(void)
  10.446 +{
  10.447 +    int i;
  10.448 +
  10.449 +    for (i = 0; SDL_touchscreens[i]; ++i) {
  10.450 +        SDL_SYS_TouchscreenUpdate(SDL_touchscreens[i]);
  10.451 +    }
  10.452 +}
  10.453 +
  10.454 +int
  10.455 +SDL_TouchscreenEventState(int state)
  10.456 +{
  10.457 +#if SDL_EVENTS_DISABLED
  10.458 +    return SDL_IGNORE;
  10.459 +#else
  10.460 +    const Uint8 event_list[] = {
  10.461 +        SDL_TOUCHPRESSED, SDL_TOUCHRELEASED, SDL_TOUCHMOTION
  10.462 +    };
  10.463 +    unsigned int i;
  10.464 +
  10.465 +    switch (state) {
  10.466 +    case SDL_QUERY:
  10.467 +        state = SDL_IGNORE;
  10.468 +        for (i = 0; i < SDL_arraysize(event_list); ++i) {
  10.469 +            state = SDL_EventState(event_list[i], SDL_QUERY);
  10.470 +            if (state == SDL_ENABLE) {
  10.471 +                break;
  10.472 +            }
  10.473 +        }
  10.474 +        break;
  10.475 +    default:
  10.476 +        for (i = 0; i < SDL_arraysize(event_list); ++i) {
  10.477 +            SDL_EventState(event_list[i], state);
  10.478 +        }
  10.479 +        break;
  10.480 +    }
  10.481 +    return (state);
  10.482 +#endif /* SDL_EVENTS_DISABLED */
  10.483 +}
  10.484 +
  10.485 +/* vi: set ts=4 sw=4 expandtab: */
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/touchscreen/SDL_touchscreen_c.h	Mon Jun 23 11:55:26 2008 +0000
    11.3 @@ -0,0 +1,42 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997-2006 Sam Lantinga
    11.7 +
    11.8 +    This library is free software; you can redistribute it and/or
    11.9 +    modify it under the terms of the GNU Lesser General Public
   11.10 +    License as published by the Free Software Foundation; either
   11.11 +    version 2.1 of the License, or (at your option) any later version.
   11.12 +
   11.13 +    This library is distributed in the hope that it will be useful,
   11.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 +    Lesser General Public License for more details.
   11.17 +
   11.18 +    You should have received a copy of the GNU Lesser General Public
   11.19 +    License along with this library; if not, write to the Free Software
   11.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   11.21 +
   11.22 +    Sam Lantinga
   11.23 +    slouken@libsdl.org
   11.24 +*/
   11.25 +#include "SDL_config.h"
   11.26 +
   11.27 +/* Useful functions and variables from SDL_touchscreen.c */
   11.28 +#include "SDL_touchscreen.h"
   11.29 +
   11.30 +/* The number of available touchscreens on the system */
   11.31 +extern Uint8 SDL_numtouchscreens;
   11.32 +
   11.33 +/* Internal event queueing functions */
   11.34 +
   11.35 +/* the point index starts at 0
   11.36 + * if point < 0, release all points and set this to be the first (only) point.
   11.37 + * if point >= touchscreen->maxpoints, error.
   11.38 + * otherwise, set or update the coordinates for the given point.
   11.39 + * return -1 if fatal error, 0 on success
   11.40 + */
   11.41 +extern int SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point,
   11.42 +                                 int x, int y, int pressure);
   11.43 +/* if point < 0, release all points. */
   11.44 +extern int SDL_PrivateTouchRelease(SDL_Touchscreen * touchscreen, int point);
   11.45 +/* vi: set ts=4 sw=4 expandtab: */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/touchscreen/dummy/SDL_systouchscreen.c	Mon Jun 23 11:55:26 2008 +0000
    12.3 @@ -0,0 +1,90 @@
    12.4 +/*
    12.5 +    SDL - Simple DirectMedia Layer
    12.6 +    Copyright (C) 1997-2006 Sam Lantinga
    12.7 +
    12.8 +    This library is free software; you can redistribute it and/or
    12.9 +    modify it under the terms of the GNU Lesser General Public
   12.10 +    License as published by the Free Software Foundation; either
   12.11 +    version 2.1 of the License, or (at your option) any later version.
   12.12 +
   12.13 +    This library is distributed in the hope that it will be useful,
   12.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 +    Lesser General Public License for more details.
   12.17 +
   12.18 +    You should have received a copy of the GNU Lesser General Public
   12.19 +    License along with this library; if not, write to the Free Software
   12.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   12.21 +
   12.22 +    Sam Lantinga
   12.23 +    slouken@libsdl.org
   12.24 +*/
   12.25 +#include "SDL_config.h"
   12.26 +
   12.27 +#if defined(SDL_TOUCHSCREEN_DUMMY) || defined(SDL_TOUCHSCREEN_DISABLED)
   12.28 +
   12.29 +/* This is the system specific header for the SDL touchscreen API */
   12.30 +
   12.31 +#include "SDL_touchscreen.h"
   12.32 +#include "../SDL_systouchscreen.h"
   12.33 +#include "../SDL_touchscreen_c.h"
   12.34 +
   12.35 +/* Function to scan the system for touchscreen.
   12.36 + * This function should set SDL_numtouchscreens to the number of available
   12.37 + * touchscreens.  Touchscreen 0 should be the system default touchscreen.
   12.38 + * It should return 0, or -1 on an unrecoverable fatal error.
   12.39 + */
   12.40 +int
   12.41 +SDL_SYS_TouchscreenInit(void)
   12.42 +{
   12.43 +    SDL_numtouchscreens = 0;
   12.44 +    return (0);
   12.45 +}
   12.46 +
   12.47 +/* Function to get the device-dependent name of a touchscreen */
   12.48 +const char *
   12.49 +SDL_SYS_TouchscreenName(int index)
   12.50 +{
   12.51 +    SDL_SetError("Logic error: No touchscreens available");
   12.52 +    return (NULL);
   12.53 +}
   12.54 +
   12.55 +/* Function to open a touchscreen for use.
   12.56 +   The touchscreen to open is specified by the index field of the touchscreen.
   12.57 +   This should fill the maxpoints field of the touchscreen structure.
   12.58 +   It returns 0, or -1 if there is an error.
   12.59 + */
   12.60 +int
   12.61 +SDL_SYS_TouchscreenOpen(SDL_Touchscreen * touchscreen)
   12.62 +{
   12.63 +    SDL_SetError("Logic error: No touchscreens available");
   12.64 +    return (-1);
   12.65 +}
   12.66 +
   12.67 +/* Function to update the state of a touchscreen - called as a device poll.
   12.68 + * This function shouldn't update the touchscreen structure directly,
   12.69 + * but instead should call SDL_PrivateTouchscreen*() to deliver events
   12.70 + * and update touchscreen device state.
   12.71 + */
   12.72 +void
   12.73 +SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen)
   12.74 +{
   12.75 +    return;
   12.76 +}
   12.77 +
   12.78 +/* Function to close a touchscreen after use */
   12.79 +void
   12.80 +SDL_SYS_TouchscreenClose(SDL_Touchscreen * touchscreen)
   12.81 +{
   12.82 +    return;
   12.83 +}
   12.84 +
   12.85 +/* Function to perform any system-specific touchscreen related cleanup */
   12.86 +void
   12.87 +SDL_SYS_TouchscreenQuit(void)
   12.88 +{
   12.89 +    return;
   12.90 +}
   12.91 +
   12.92 +#endif /* SDL_TOUCHSCREEN_DUMMY || SDL_TOUCHSCREEN_DISABLED */
   12.93 +/* vi: set ts=4 sw=4 expandtab: */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/touchscreen/nds/SDL_systouchscreen.c	Mon Jun 23 11:55:26 2008 +0000
    13.3 @@ -0,0 +1,115 @@
    13.4 +/*
    13.5 +    SDL - Simple DirectMedia Layer
    13.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    13.7 +
    13.8 +    This library is free software; you can redistribute it and/or
    13.9 +    modify it under the terms of the GNU Library General Public
   13.10 +    License as published by the Free Software Foundation; either
   13.11 +    version 2 of the License, or (at your option) any later version.
   13.12 +
   13.13 +    This library is distributed in the hope that it will be useful,
   13.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 +    Library General Public License for more details.
   13.17 +
   13.18 +    You should have received a copy of the GNU Library General Public
   13.19 +    License along with this library; if not, write to the Free
   13.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.21 +
   13.22 +    Sam Lantinga
   13.23 +    slouken@devolution.com
   13.24 +*/
   13.25 +
   13.26 +#include "SDL_config.h"
   13.27 +
   13.28 +#ifdef SDL_TOUCHSCREEN_NDS
   13.29 +
   13.30 +/* This is the system specific header for the SDL touchscreen API */
   13.31 +#include <nds.h>
   13.32 +#include <stdio.h>              /* For the definition of NULL */
   13.33 +
   13.34 +#include "SDL_error.h"
   13.35 +#include "SDL_events.h"
   13.36 +#include "SDL_touchscreen.h"
   13.37 +#include "../SDL_systouchscreen.h"
   13.38 +#include "../SDL_touchscreen_c.h"
   13.39 +
   13.40 +#include "../../video/nds/SDL_ndsevents_c.h"
   13.41 +
   13.42 +/* Function to scan the system for touchscreen.
   13.43 + * This function should set SDL_numtouchscreens to the number of available
   13.44 + * touchscreen.  Touchscreen 0 should be the system default touchscreen.
   13.45 + * It should return 0, or -1 on an unrecoverable fatal error.
   13.46 + */
   13.47 +int
   13.48 +SDL_SYS_TouchscreenInit(void)
   13.49 +{
   13.50 +    SDL_numtouchscreens = 1;
   13.51 +    return (1);
   13.52 +}
   13.53 +
   13.54 +/* Function to get the device-dependent name of a touchscreen */
   13.55 +const char *
   13.56 +SDL_SYS_TouchscreenName(int index)
   13.57 +{
   13.58 +    if (!index)
   13.59 +        return "NDS builtin touchscreen";
   13.60 +    SDL_SetError("No touchscreen available with that index");
   13.61 +    return (NULL);
   13.62 +}
   13.63 +
   13.64 +/* Function to open a touchscreen for use.
   13.65 +   The touchscreen to open is specified by the index field of the touchscreen.
   13.66 +   This should fill the maxpoints field of the touchscreen structure.
   13.67 +   It returns 0, or -1 if there is an error.
   13.68 + */
   13.69 +int
   13.70 +SDL_SYS_TouchscreenOpen(SDL_Touchscreen * touchscreen)
   13.71 +{
   13.72 +    touchscreen->maxpoints = 1;
   13.73 +    touchscreen->npoints = 0;
   13.74 +    /* do I call SDL_TouchscreenOpen here? */
   13.75 +    return 0;
   13.76 +}
   13.77 +
   13.78 +
   13.79 +/* Function to update the state of a touchscreen - called as a device poll.
   13.80 + * This function shouldn't update the touchscreen structure directly,
   13.81 + * but instead should call SDL_PrivateTouch*() to deliver events
   13.82 + * and update touchscreen device state.
   13.83 + */
   13.84 +void
   13.85 +SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen)
   13.86 +{
   13.87 +    u32 keysd, keysu, keysh;
   13.88 +    int xpos, ypos, pressure = 16384;
   13.89 +    touchPosition touch;
   13.90 +
   13.91 +    scanKeys();
   13.92 +    keysd = keysDown();
   13.93 +    keysh = keysHeld();
   13.94 +    keysu = keysUp();
   13.95 +    touch=touchReadXY();
   13.96 +    xpos = (touch.px-128)*256;
   13.97 +    ypos = (touch.py-96)*(65536/192);
   13.98 +
   13.99 +    if (((keysd|keysh) & KEY_TOUCH)) {
  13.100 +        SDL_PrivateTouchPress(touchscreen, 0, xpos, ypos, pressure);
  13.101 +    }
  13.102 +    if ((keysu & KEY_TOUCH)) {
  13.103 +        SDL_PrivateTouchRelease(touchscreen, 0);
  13.104 +    }
  13.105 }
  13.106 +
  13.107 +/* Function to close a touchscreen after use */
  13.108 +void
  13.109 +SDL_SYS_TouchscreenClose(SDL_Touchscreen * touchscreen)
  13.110 +{
  13.111 +}
  13.112 +
  13.113 +/* Function to perform any system-specific touchscreen related cleanup */
  13.114 +void
  13.115 +SDL_SYS_TouchscreenQuit(void)
  13.116 +{
  13.117 +}
  13.118 +#endif /* SDL_TOUCHSCREEN_NDS */
  13.119 +