Removed old touchscreen system, starting to implement mouse-based touchscreen. Also, more work on a non-software-rendering video driver gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Thu, 10 Jul 2008 23:35:01 +0000
branchgsoc2008_nds
changeset 26783895761db26a
parent 2677 6386764eb222
child 2679 bc3e3e889f6d
Removed old touchscreen system, starting to implement mouse-based touchscreen. Also, more work on a non-software-rendering video driver
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/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
src/video/nds/SDL_ndsevents.c
src/video/nds/SDL_ndsrender.c
     1.1 --- a/Makefile.ds	Wed Jul 02 13:59:30 2008 +0000
     1.2 +++ b/Makefile.ds	Thu Jul 10 23:35:01 2008 +0000
     1.3 @@ -51,9 +51,6 @@
     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 \
     2.1 --- a/include/SDL.h	Wed Jul 02 13:59:30 2008 +0000
     2.2 +++ b/include/SDL.h	Thu Jul 10 23:35:01 2008 +0000
     2.3 @@ -109,7 +109,6 @@
     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	Wed Jul 02 13:59:30 2008 +0000
     3.2 +++ b/include/SDL_config_nintendods.h	Thu Jul 10 23:35:01 2008 +0000
     3.3 @@ -100,8 +100,6 @@
     3.4  /* Enable various input drivers */
     3.5  #define SDL_JOYSTICK_NDS	1
     3.6  /*#define SDL_JOYSTICK_DUMMY	1*/
     3.7 -#define SDL_TOUCHSCREEN_NDS	1
     3.8 -/*#define SDL_TOUCHSCREEN_DUMMY	1*/
     3.9  
    3.10  /* DS has no dynamic linking afaik */
    3.11  #define SDL_LOADSO_DISABLED	1
     4.1 --- a/include/SDL_events.h	Wed Jul 02 13:59:30 2008 +0000
     4.2 +++ b/include/SDL_events.h	Thu Jul 10 23:35:01 2008 +0000
     4.3 @@ -35,7 +35,6 @@
     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 @@ -71,9 +70,6 @@
    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 @@ -115,11 +111,6 @@
    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 @@ -273,21 +264,6 @@
    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 @@ -358,7 +334,6 @@
    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 --- a/include/SDL_touchscreen.h	Wed Jul 02 13:59:30 2008 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,153 +0,0 @@
     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 unsigned integer in the range [1,65535]
   5.114 - * where 1 is the left edge, 32768 is roughly center, 65535 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,65535],
   5.117 - * which represents the pressure of the touch.  This should be 32767 in
   5.118 - * non-pressure-sensitive driver implementations.
   5.119 - * If not being touched, 0 is returned and *x and *y are unmodified.
   5.120 - *
   5.121 - * The touch point indices start at index 0.
   5.122 - * If given a negative value for point, all the X,Y, and pressures
   5.123 - * for all the currently touched points on a multitouch device
   5.124 - * should be averaged and used for *x, *y, and the return value.
   5.125 - * If the value of point exceeds the number of points currently touched,
   5.126 - * 0 should be returned, and *x, *y should be left unmodified.
   5.127 - *
   5.128 - * On error, -1 is returned.
   5.129 - */
   5.130 -extern DECLSPEC Uint16 SDLCALL SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen,
   5.131 -                                                    int point, Uint16 *x, Uint16 *y);
   5.132 -
   5.133 -/*
   5.134 - * Get the number of currently touched points on a touchscreen.
   5.135 - * This is either 0 or 1 for a single-touch device.
   5.136 - * On error, -1 is returned.
   5.137 - */
   5.138 -extern DECLSPEC int SDLCALL SDL_TouchscreenGetPoints(SDL_Touchscreen * touchscreen);
   5.139 -
   5.140 -/*
   5.141 - * Close a touchscreen previously opened with SDL_TouchscreenOpen()
   5.142 - */
   5.143 -extern DECLSPEC void SDLCALL SDL_TouchscreenClose(SDL_Touchscreen * touchscreen);
   5.144 -
   5.145 -
   5.146 -/* Ends C function definitions when using C++ */
   5.147 -#ifdef __cplusplus
   5.148 -/* *INDENT-OFF* */
   5.149 -}
   5.150 -/* *INDENT-ON* */
   5.151 -#endif
   5.152 -#include "close_code.h"
   5.153 -
   5.154 -#endif /* _SDL_touchscreen_h */
   5.155 -
   5.156 -/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/SDL.c	Wed Jul 02 13:59:30 2008 +0000
     6.2 +++ b/src/SDL.c	Thu Jul 10 23:35:01 2008 +0000
     6.3 @@ -38,10 +38,6 @@
     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 @@ -127,21 +123,6 @@
    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 @@ -199,12 +180,6 @@
    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	Wed Jul 02 13:59:30 2008 +0000
     7.2 +++ b/src/events/SDL_events.c	Thu Jul 10 23:35:01 2008 +0000
     7.3 @@ -31,9 +31,6 @@
     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 @@ -120,12 +117,6 @@
    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 @@ -397,12 +388,6 @@
    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/touchscreen/SDL_systouchscreen.h	Wed Jul 02 13:59:30 2008 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,78 +0,0 @@
     8.4 -/*
     8.5 -    SDL - Simple DirectMedia Layer
     8.6 -    Copyright (C) 1997-2006 Sam Lantinga
     8.7 -
     8.8 -    This library is SDL_free software; you can redistribute it and/or
     8.9 -    modify it under the terms of the GNU Lesser General Public
    8.10 -    License as published by the Free Software Foundation; either
    8.11 -    version 2.1 of the License, or (at your option) any later version.
    8.12 -
    8.13 -    This library is distributed in the hope that it will be useful,
    8.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 -    Lesser General Public License for more details.
    8.17 -
    8.18 -    You should have received a copy of the GNU Lesser General Public
    8.19 -    License along with this library; if not, write to the Free Software
    8.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 -
    8.22 -    Sam Lantinga
    8.23 -    slouken@libsdl.org
    8.24 -*/
    8.25 -#include "SDL_config.h"
    8.26 -
    8.27 -/* This is the system specific header for the SDL touchscreen API */
    8.28 -
    8.29 -#include "SDL_touchscreen.h"
    8.30 -
    8.31 -/* The SDL touchscreen structure */
    8.32 -struct _SDL_Touchscreen
    8.33 -{
    8.34 -    Uint8 index;                /* Device index */
    8.35 -    const char *name;           /* Touchscreen name - system dependent */
    8.36 -
    8.37 -    int maxpoints;              /* Max # multi-touch points, -1 if unlimited. */
    8.38 -    int npoints;                /* Number of points currently touched */
    8.39 -    struct touchpoint
    8.40 -    {
    8.41 -        Uint16 x;
    8.42 -        Uint16 y;
    8.43 -        Uint16 pressure;
    8.44 -    } *points;                   /* Current ball motion deltas */
    8.45 -
    8.46 -    struct touchscreen_hwdata *hwdata;     /* Driver dependent information */
    8.47 -
    8.48 -    int ref_count;              /* Reference count for multiple opens */
    8.49 -};
    8.50 -
    8.51 -/* Function to scan the system for touchscreens.
    8.52 - * Touchscreen 0 should be the system default touchscreen.
    8.53 - * This function should return the number of available touchscreens, or -1
    8.54 - * on an unrecoverable fatal error.
    8.55 - */
    8.56 -extern int SDL_SYS_TouchscreenInit(void);
    8.57 -
    8.58 -/* Function to get the device-dependent name of a touchscreen */
    8.59 -extern const char *SDL_SYS_TouchscreenName(int index);
    8.60 -
    8.61 -/* Function to open a touchscreen for use.
    8.62 -   The touchscreen to open is specified by the index field of the touchscreen.
    8.63 -   This should fill the maxpoints field of the touchscreen structure.
    8.64 -   It returns 0, or -1 if there is an error.
    8.65 - */
    8.66 -extern int SDL_SYS_TouchscreenOpen(SDL_Touchscreen * touchscreen);
    8.67 -
    8.68 -/* Function to update the state of a touchscreen - called as a device poll.
    8.69 - * This function shouldn't update the touchscreen structure directly,
    8.70 - * but instead should call SDL_PrivateTouchscreen*() to deliver events
    8.71 - * and update touchscreen device state.
    8.72 - */
    8.73 -extern void SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen);
    8.74 -
    8.75 -/* Function to close a touchscreen after use */
    8.76 -extern void SDL_SYS_TouchscreenClose(SDL_Touchscreen * touchscreen);
    8.77 -
    8.78 -/* Function to perform any system-specific touchscreen related cleanup */
    8.79 -extern void SDL_SYS_TouchscreenQuit(void);
    8.80 -
    8.81 -/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/touchscreen/SDL_touchscreen.c	Wed Jul 02 13:59:30 2008 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,546 +0,0 @@
     9.4 -/*
     9.5 -    SDL - Simple DirectMedia Layer
     9.6 -    Copyright (C) 1997-2006 Sam Lantinga
     9.7 -
     9.8 -    This library is 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 touchscreen API for Simple DirectMedia Layer */
    9.28 -
    9.29 -#include "SDL_events.h"
    9.30 -#include "SDL_systouchscreen.h"
    9.31 -#include "SDL_touchscreen_c.h"
    9.32 -#if !SDL_EVENTS_DISABLED
    9.33 -#include "../events/SDL_events_c.h"
    9.34 -#endif
    9.35 -
    9.36 -/* This is used for Quake III Arena */
    9.37 -#if SDL_EVENTS_DISABLED
    9.38 -#define SDL_Lock_EventThread()
    9.39 -#define SDL_Unlock_EventThread()
    9.40 -#endif
    9.41 -
    9.42 -Uint8 SDL_numtouchscreens = 0;
    9.43 -SDL_Touchscreen **SDL_touchscreens = NULL;
    9.44 -static SDL_Touchscreen *default_touchscreen = NULL;
    9.45 -
    9.46 -int
    9.47 -SDL_TouchscreenInit(void)
    9.48 -{
    9.49 -    int arraylen;
    9.50 -    int status;
    9.51 -
    9.52 -    SDL_numtouchscreens = 0;
    9.53 -    status = SDL_SYS_TouchscreenInit();
    9.54 -    if (status >= 0) {
    9.55 -        arraylen = (status + 1) * sizeof(*SDL_touchscreens);
    9.56 -        SDL_touchscreens = (SDL_Touchscreen **) SDL_malloc(arraylen);
    9.57 -        if (SDL_touchscreens == NULL) {
    9.58 -            SDL_numtouchscreens = 0;
    9.59 -        } else {
    9.60 -            SDL_memset(SDL_touchscreens, 0, arraylen);
    9.61 -            SDL_numtouchscreens = status;
    9.62 -        }
    9.63 -        status = 0;
    9.64 -    }
    9.65 -    default_touchscreen = NULL;
    9.66 -    return (status);
    9.67 -}
    9.68 -
    9.69 -/*
    9.70 - * Count the number of touchscreens attached to the system
    9.71 - */
    9.72 -int
    9.73 -SDL_NumTouchscreens(void)
    9.74 -{
    9.75 -    return SDL_numtouchscreens;
    9.76 -}
    9.77 -
    9.78 -/*
    9.79 - * Get the implementation dependent name of a touchscreen
    9.80 - */
    9.81 -const char *
    9.82 -SDL_TouchscreenName(int device_index)
    9.83 -{
    9.84 -    if ((device_index < 0) || (device_index >= SDL_numtouchscreens)) {
    9.85 -        SDL_SetError("There are %d touchscreens available", SDL_numtouchscreens);
    9.86 -        return (NULL);
    9.87 -    }
    9.88 -    return (SDL_SYS_TouchscreenName(device_index));
    9.89 -}
    9.90 -
    9.91 -/*
    9.92 - * Open a touchscreen for use - the index passed as an argument refers to
    9.93 - * the N'th touchscreen on the system.  This index is the value which will
    9.94 - * identify this touchscreen in future touchscreen events.
    9.95 - *
    9.96 - * This function returns a touchscreen identifier, or NULL if an error occurred.
    9.97 - */
    9.98 -SDL_Touchscreen *
    9.99 -SDL_TouchscreenOpen(int device_index)
   9.100 -{
   9.101 -    int i;
   9.102 -    SDL_Touchscreen *touchscreen;
   9.103 -
   9.104 -    if ((device_index < 0) || (device_index >= SDL_numtouchscreens)) {
   9.105 -        SDL_SetError("There are %d touchscreens available", SDL_numtouchscreens);
   9.106 -        return (NULL);
   9.107 -    }
   9.108 -
   9.109 -    /* If the touchscreen is already open, return it */
   9.110 -    for (i = 0; SDL_touchscreens[i]; ++i) {
   9.111 -        if (device_index == SDL_touchscreens[i]->index) {
   9.112 -            touchscreen = SDL_touchscreens[i];
   9.113 -            ++touchscreen->ref_count;
   9.114 -            return (touchscreen);
   9.115 -        }
   9.116 -    }
   9.117 -
   9.118 -    /* Create and initialize the touchscreen */
   9.119 -    touchscreen = (SDL_Touchscreen *) SDL_malloc((sizeof *touchscreen));
   9.120 -    if (touchscreen != NULL) {
   9.121 -        SDL_memset(touchscreen, 0, (sizeof *touchscreen));
   9.122 -        touchscreen->index = device_index;
   9.123 -        if (SDL_SYS_TouchscreenOpen(touchscreen) < 0) {
   9.124 -            SDL_free(touchscreen);
   9.125 -            touchscreen = NULL;
   9.126 -        } else {
   9.127 -            if (touchscreen->maxpoints > 0) {
   9.128 -                touchscreen->points = (struct touchpoint *) SDL_malloc
   9.129 -                    (touchscreen->maxpoints * sizeof(*touchscreen->points));
   9.130 -            }
   9.131 -            if ((touchscreen->maxpoints > 0) && !touchscreen->points) {
   9.132 -                SDL_OutOfMemory();
   9.133 -                SDL_TouchscreenClose(touchscreen);
   9.134 -                touchscreen = NULL;
   9.135 -            }
   9.136 -            if (touchscreen->points) {
   9.137 -                SDL_memset(touchscreen->points, 0,
   9.138 -                           touchscreen->maxpoints * sizeof(*touchscreen->points));
   9.139 -            }
   9.140 -        }
   9.141 -    }
   9.142 -    if (touchscreen) {
   9.143 -        /* Add touchscreen to list */
   9.144 -        ++touchscreen->ref_count;
   9.145 -        SDL_Lock_EventThread();
   9.146 -        for (i = 0; SDL_touchscreens[i]; ++i)
   9.147 -            /* Skip to next touchscreen */ ;
   9.148 -        SDL_touchscreens[i] = touchscreen;
   9.149 -        SDL_Unlock_EventThread();
   9.150 -    }
   9.151 -    return (touchscreen);
   9.152 -}
   9.153 -
   9.154 -/*
   9.155 - * Returns 1 if the touchscreen has been opened, or 0 if it has not.
   9.156 - */
   9.157 -int
   9.158 -SDL_TouchscreenOpened(int device_index)
   9.159 -{
   9.160 -    int i, opened;
   9.161 -
   9.162 -    opened = 0;
   9.163 -    for (i = 0; SDL_touchscreens[i]; ++i) {
   9.164 -        if (SDL_touchscreens[i]->index == (Uint8) device_index) {
   9.165 -            opened = 1;
   9.166 -            break;
   9.167 -        }
   9.168 -    }
   9.169 -    return (opened);
   9.170 -}
   9.171 -
   9.172 -static int
   9.173 -ValidTouchscreen(SDL_Touchscreen ** touchscreen)
   9.174 -{
   9.175 -    int valid;
   9.176 -
   9.177 -    if (*touchscreen == NULL) {
   9.178 -        *touchscreen = default_touchscreen;
   9.179 -    }
   9.180 -    if (*touchscreen == NULL) {
   9.181 -        SDL_SetError("Touchscreen hasn't been opened yet");
   9.182 -        valid = 0;
   9.183 -    } else {
   9.184 -        valid = 1;
   9.185 -    }
   9.186 -    return valid;
   9.187 -}
   9.188 -
   9.189 -/*
   9.190 - * Get the device index of an opened touchscreen.
   9.191 - */
   9.192 -int
   9.193 -SDL_TouchscreenIndex(SDL_Touchscreen * touchscreen)
   9.194 -{
   9.195 -    if (!ValidTouchscreen(&touchscreen)) {
   9.196 -        return (-1);
   9.197 -    }
   9.198 -    return (touchscreen->index);
   9.199 -}
   9.200 -
   9.201 -/*
   9.202 - * Get the max number of points on a multi-touch screen (or 1 on a single-touch)
   9.203 - */
   9.204 -int
   9.205 -SDL_TouchscreenMaxPoints(SDL_Touchscreen * touchscreen)
   9.206 -{
   9.207 -    if (!ValidTouchscreen(&touchscreen)) {
   9.208 -        return (-1);
   9.209 -    }
   9.210 -    return (touchscreen->maxpoints);
   9.211 -}
   9.212 -
   9.213 -/*
   9.214 - * Get the current X,Y position of the indicated point on the touchscreen
   9.215 - */
   9.216 -Uint16
   9.217 -SDL_TouchscreenGetXY(SDL_Touchscreen *touchscreen, int point, Uint16 *x, Uint16 *y)
   9.218 -{
   9.219 -    int retval;
   9.220 -
   9.221 -    if (!ValidTouchscreen(&touchscreen)) {
   9.222 -        return (-1);
   9.223 -    }
   9.224 -
   9.225 -    retval = 0;
   9.226 -    if (point < 0) {
   9.227 -        int i; long avg;
   9.228 -        if(x) {
   9.229 -            avg = 0;
   9.230 -            for(i = 0; i < touchscreen->npoints; ++i) {
   9.231 -                avg += touchscreen->points[i].x;
   9.232 -            }
   9.233 -            *x = avg;
   9.234 -        }
   9.235 -        if(y) {
   9.236 -            avg = 0;
   9.237 -            for(i = 0; i < touchscreen->npoints; ++i) {
   9.238 -                avg += touchscreen->points[i].y;
   9.239 -            }
   9.240 -            *y = avg;
   9.241 -        }
   9.242 -        avg = 0;
   9.243 -        for(i = 0; i < touchscreen->npoints; ++i) {
   9.244 -            avg += touchscreen->points[i].pressure;
   9.245 -        }
   9.246 -        return (int)avg;
   9.247 -    } else if (point < touchscreen->maxpoints) {
   9.248 -        if (x) {
   9.249 -            *x = touchscreen->points[point].x;
   9.250 -        }
   9.251 -        if (y) {
   9.252 -            *y = touchscreen->points[point].y;
   9.253 -        }
   9.254 -        retval = touchscreen->points[point].pressure;
   9.255 -    } else {
   9.256 -        SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints);
   9.257 -        retval = -1;
   9.258 -    }
   9.259 -    return (retval);
   9.260 -}
   9.261 -
   9.262 -int
   9.263 -SDL_TouchscreenGetPoints(SDL_Touchscreen *touchscreen) {
   9.264 -    if (!ValidTouchscreen(&touchscreen)) {
   9.265 -        return (-1);
   9.266 -    }
   9.267 -
   9.268 -    return touchscreen->npoints;
   9.269 -}
   9.270 -
   9.271 -/*
   9.272 - * Close a touchscreen previously opened with SDL_TouchscreenOpen()
   9.273 - */
   9.274 -void
   9.275 -SDL_TouchscreenClose(SDL_Touchscreen * touchscreen)
   9.276 -{
   9.277 -    int i;
   9.278 -
   9.279 -    if (!ValidTouchscreen(&touchscreen)) {
   9.280 -        return;
   9.281 -    }
   9.282 -
   9.283 -    /* First decrement ref count */
   9.284 -    if (--touchscreen->ref_count > 0) {
   9.285 -        return;
   9.286 -    }
   9.287 -
   9.288 -    /* Lock the event queue - prevent touchscreen polling */
   9.289 -    SDL_Lock_EventThread();
   9.290 -
   9.291 -    if (touchscreen == default_touchscreen) {
   9.292 -        default_touchscreen = NULL;
   9.293 -    }
   9.294 -    SDL_SYS_TouchscreenClose(touchscreen);
   9.295 -
   9.296 -    /* Remove touchscreen from list */
   9.297 -    for (i = 0; SDL_touchscreens[i]; ++i) {
   9.298 -        if (touchscreen == SDL_touchscreens[i]) {
   9.299 -            SDL_memcpy(&SDL_touchscreens[i], &SDL_touchscreens[i + 1],
   9.300 -                       (SDL_numtouchscreens - i) * sizeof(touchscreen));
   9.301 -            break;
   9.302 -        }
   9.303 -    }
   9.304 -
   9.305 -    /* Let the event thread keep running */
   9.306 -    SDL_Unlock_EventThread();
   9.307 -
   9.308 -    /* Free the data associated with this touchscreen */
   9.309 -    if (touchscreen->points) {
   9.310 -        SDL_free(touchscreen->points);
   9.311 -    }
   9.312 -    SDL_free(touchscreen);
   9.313 -}
   9.314 -
   9.315 -void
   9.316 -SDL_TouchscreenQuit(void)
   9.317 -{
   9.318 -    /* Stop the event polling */
   9.319 -    SDL_Lock_EventThread();
   9.320 -    SDL_numtouchscreens = 0;
   9.321 -    SDL_Unlock_EventThread();
   9.322 -
   9.323 -    /* Quit the touchscreen setup */
   9.324 -    SDL_SYS_TouchscreenQuit();
   9.325 -    if (SDL_touchscreens) {
   9.326 -        SDL_free(SDL_touchscreens);
   9.327 -        SDL_touchscreens = NULL;
   9.328 -    }
   9.329 -}
   9.330 -
   9.331 -
   9.332 -/* These are global for SDL_systouchscreen.c and SDL_events.c */
   9.333 -int
   9.334 -SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point, Uint16 x, Uint16 y, Uint16 pressure) {
   9.335 -    int posted;
   9.336 -
   9.337 -    if (!ValidTouchscreen(&touchscreen)) {
   9.338 -        return -1;
   9.339 -    }
   9.340 -
   9.341 -    if(point >= touchscreen->maxpoints) {
   9.342 -        SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints);
   9.343 -        return -1;
   9.344 -    }
   9.345 -
   9.346 -    /* on neg. point, set the given args as the *only* point.
   9.347 -       so set the struct to have no points pressed, then continue as normal. */
   9.348 -    if(point < 0) {
   9.349 -        point = 0;
   9.350 -        touchscreen->npoints = 0;
   9.351 -        SDL_memset(touchscreen->points, 0,
   9.352 -                   touchscreen->maxpoints * sizeof(touchscreen->points[0]));
   9.353 -    }
   9.354 -
   9.355 -    /* new touch point!  that means a TOUCHPRESSED event is due. */
   9.356 -    if(point >= touchscreen->npoints) {
   9.357 -        point = touchscreen->npoints;
   9.358 -        ++touchscreen->npoints;
   9.359 -    }
   9.360 -
   9.361 -    /* no motion, no change, don't report an event. */
   9.362 -    if(touchscreen->points[point].pressure > 0) {
   9.363 -        SDL_SetError("Warning: touch point %d was already pressed", point);
   9.364 -        return -1;
   9.365 -    }
   9.366 -
   9.367 -    /* Update internal touchscreen point state */
   9.368 -    touchscreen->points[point].x = x;
   9.369 -    touchscreen->points[point].y = y;
   9.370 -    touchscreen->points[point].pressure = pressure;
   9.371 -
   9.372 -    /* Post the event, if desired */
   9.373 -    posted = 0;
   9.374 -#if !SDL_EVENTS_DISABLED
   9.375 -    if (SDL_ProcessEvents[SDL_TOUCHPRESSED] == SDL_ENABLE) {
   9.376 -        SDL_Event event;
   9.377 -        event.touch.type = SDL_TOUCHPRESSED;
   9.378 -        event.touch.which = touchscreen->index;
   9.379 -        event.touch.point = point;
   9.380 -        event.touch.xpos = x;
   9.381 -        event.touch.ypos = y;
   9.382 -        event.touch.pressure = pressure;
   9.383 -        if ((SDL_EventOK == NULL)
   9.384 -            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   9.385 -            posted = 1;
   9.386 -            SDL_PushEvent(&event);
   9.387 -        }
   9.388 -    }
   9.389 -#endif /* !SDL_EVENTS_DISABLED */
   9.390 -    return (posted);
   9.391 -}
   9.392 -
   9.393 -int
   9.394 -SDL_PrivateTouchMove(SDL_Touchscreen * touchscreen, int point,
   9.395 -                                 Uint16 x, Uint16 y, Uint16 pressure) {
   9.396 -    int posted;
   9.397 -
   9.398 -    if (!ValidTouchscreen(&touchscreen)) {
   9.399 -        return -1;
   9.400 -    }
   9.401 -
   9.402 -    if(point >= touchscreen->maxpoints) {
   9.403 -        SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints);
   9.404 -        return -1;
   9.405 -    }
   9.406 -
   9.407 -    /* on neg. point, set the given args as the *only* point.
   9.408 -       so set the struct to have no points pressed, then continue as normal. */
   9.409 -    if(point < 0) {
   9.410 -        point = 0;
   9.411 -        touchscreen->npoints = 0;
   9.412 -        SDL_memset(touchscreen->points, 0,
   9.413 -                   touchscreen->maxpoints * sizeof(touchscreen->points[0]));
   9.414 -    }
   9.415 -
   9.416 -    /* new touch point!  that means a TOUCHPRESSED event is due. */
   9.417 -    if(point >= touchscreen->npoints || touchscreen->points[point].pressure == 0) {
   9.418 -        SDL_SetError("Touch point %d shouldn't move before it's pressed.", point);
   9.419 -        return -1;
   9.420 -    }
   9.421 -
   9.422 -    /* no motion, no change, don't report an event. */
   9.423 -    if(touchscreen->points[point].x == x &&
   9.424 -       touchscreen->points[point].y == y &&
   9.425 -       touchscreen->points[point].pressure == pressure) {
   9.426 -        return 0;
   9.427 -    }
   9.428 -
   9.429 -    /* Update internal touchscreen point state */
   9.430 -    touchscreen->points[point].x = x;
   9.431 -    touchscreen->points[point].y = y;
   9.432 -    touchscreen->points[point].pressure = pressure;
   9.433 -
   9.434 -    /* Post the event, if desired */
   9.435 -    posted = 0;
   9.436 -#if !SDL_EVENTS_DISABLED
   9.437 -    if (SDL_ProcessEvents[SDL_TOUCHMOTION] == SDL_ENABLE) {
   9.438 -        SDL_Event event;
   9.439 -        event.touch.type = SDL_TOUCHMOTION;
   9.440 -        event.touch.which = touchscreen->index;
   9.441 -        event.touch.point = point;
   9.442 -        event.touch.xpos = x;
   9.443 -        event.touch.ypos = y;
   9.444 -        event.touch.pressure = pressure;
   9.445 -        if ((SDL_EventOK == NULL)
   9.446 -            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   9.447 -            posted = 1;
   9.448 -            SDL_PushEvent(&event);
   9.449 -        }
   9.450 -    }
   9.451 -#endif /* !SDL_EVENTS_DISABLED */
   9.452 -    return (posted);
   9.453 -}
   9.454 -
   9.455 -int
   9.456 -SDL_PrivateTouchRelease(SDL_Touchscreen * touchscreen, int point) {
   9.457 -    int posted;
   9.458 -    int i;
   9.459 -
   9.460 -    if (!ValidTouchscreen(&touchscreen)) {
   9.461 -        return -1;
   9.462 -    }
   9.463 -
   9.464 -    if(point >= touchscreen->maxpoints) {
   9.465 -        SDL_SetError("Touchscreen only can have %d points", touchscreen->maxpoints);
   9.466 -        return -1;
   9.467 -    } else if(point >= touchscreen->npoints) {
   9.468 -        SDL_SetError("Point %d up when only %d were down", point, touchscreen->npoints);
   9.469 -        return -1;
   9.470 -    }
   9.471 -
   9.472 -    /* on neg. point, clear all points.  so set the struct to have one point
   9.473 -       pressed, then continue as normal. */
   9.474 -    if(point < 0) {
   9.475 -        point = 0;
   9.476 -        touchscreen->npoints = 1;
   9.477 -        SDL_memset(&(touchscreen->points[1]), 0,
   9.478 -                   (touchscreen->maxpoints-1) * sizeof(touchscreen->points[0]));
   9.479 -    }
   9.480 -
   9.481 -    /* Update internal touchscreen point state */
   9.482 -    touchscreen->points[point].pressure = 0;
   9.483 -    touchscreen->points[point].x = 0;
   9.484 -    touchscreen->points[point].y = 0;
   9.485 -    if(touchscreen->npoints >= 0) --touchscreen->npoints;
   9.486 -    for(i = point; i < touchscreen->npoints; ++i) {
   9.487 -        touchscreen->points[i] = touchscreen->points[i+1];
   9.488 -    }
   9.489 -
   9.490 -    /* Post the event, if desired */
   9.491 -    posted = 0;
   9.492 -#if !SDL_EVENTS_DISABLED
   9.493 -    if (SDL_ProcessEvents[SDL_TOUCHRELEASED] == SDL_ENABLE) {
   9.494 -        SDL_Event event;
   9.495 -        event.touch.type = SDL_TOUCHRELEASED;
   9.496 -        event.touch.which = touchscreen->index;
   9.497 -        event.touch.point = point;
   9.498 -        if ((SDL_EventOK == NULL)
   9.499 -            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   9.500 -            posted = 1;
   9.501 -            SDL_PushEvent(&event);
   9.502 -        }
   9.503 -    }
   9.504 -#endif /* !SDL_EVENTS_DISABLED */
   9.505 -    return (posted);
   9.506 -}
   9.507 -
   9.508 -void
   9.509 -SDL_TouchscreenUpdate(void)
   9.510 -{
   9.511 -    int i;
   9.512 -
   9.513 -    for (i = 0; SDL_touchscreens[i]; ++i) {
   9.514 -        SDL_SYS_TouchscreenUpdate(SDL_touchscreens[i]);
   9.515 -    }
   9.516 -}
   9.517 -
   9.518 -int
   9.519 -SDL_TouchscreenEventState(int state)
   9.520 -{
   9.521 -#if SDL_EVENTS_DISABLED
   9.522 -    return SDL_IGNORE;
   9.523 -#else
   9.524 -    const Uint8 event_list[] = {
   9.525 -        SDL_TOUCHPRESSED, SDL_TOUCHRELEASED, SDL_TOUCHMOTION
   9.526 -    };
   9.527 -    unsigned int i;
   9.528 -
   9.529 -    switch (state) {
   9.530 -    case SDL_QUERY:
   9.531 -        state = SDL_IGNORE;
   9.532 -        for (i = 0; i < SDL_arraysize(event_list); ++i) {
   9.533 -            state = SDL_EventState(event_list[i], SDL_QUERY);
   9.534 -            if (state == SDL_ENABLE) {
   9.535 -                break;
   9.536 -            }
   9.537 -        }
   9.538 -        break;
   9.539 -    default:
   9.540 -        for (i = 0; i < SDL_arraysize(event_list); ++i) {
   9.541 -            SDL_EventState(event_list[i], state);
   9.542 -        }
   9.543 -        break;
   9.544 -    }
   9.545 -    return (state);
   9.546 -#endif /* SDL_EVENTS_DISABLED */
   9.547 -}
   9.548 -
   9.549 -/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/touchscreen/SDL_touchscreen_c.h	Wed Jul 02 13:59:30 2008 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,53 +0,0 @@
    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 -/* Useful functions and variables from SDL_touchscreen.c */
   10.28 -#include "SDL_touchscreen.h"
   10.29 -
   10.30 -/* The number of available touchscreens on the system */
   10.31 -extern Uint8 SDL_numtouchscreens;
   10.32 -
   10.33 -/* Internal event queueing functions */
   10.34 -
   10.35 -/* the point index starts at 0
   10.36 - * if point < 0, release all points and set this to be the first (only) point.
   10.37 - * if point >= touchscreen->maxpoints, error.
   10.38 - * otherwise, add a point with the given coordinates.
   10.39 - * return < 0 if fatal error, >= 0 on success
   10.40 - */
   10.41 -extern int SDL_PrivateTouchPress(SDL_Touchscreen * touchscreen, int point,
   10.42 -                                  Uint16 x, Uint16 y, Uint16 pressure);
   10.43 -/* if point < 0, release all points and set this to be the first (only) point.
   10.44 - * if point >= touchscreen->maxpoints, error.
   10.45 - * otherwise, update the coordinates for the given point.
   10.46 - * return < 0 if fatal error, >= 0 on success
   10.47 - */
   10.48 -extern int SDL_PrivateTouchMove(SDL_Touchscreen * touchscreen, int point,
   10.49 -                                 Uint16 x, Uint16 y, Uint16 pressure);
   10.50 -/* if point < 0, release all points.
   10.51 - * if point >= touchscreen->npoints, error.
   10.52 - * otherwise, remove the given point.
   10.53 - * return < 0 if fatal error, >= 0 on success
   10.54 - */
   10.55 -extern int SDL_PrivateTouchRelease(SDL_Touchscreen * touchscreen, int point);
   10.56 -/* vi: set ts=4 sw=4 expandtab: */
    11.1 --- a/src/touchscreen/dummy/SDL_systouchscreen.c	Wed Jul 02 13:59:30 2008 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,90 +0,0 @@
    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 -#if defined(SDL_TOUCHSCREEN_DUMMY) || defined(SDL_TOUCHSCREEN_DISABLED)
   11.28 -
   11.29 -/* This is the system specific header for the SDL touchscreen API */
   11.30 -
   11.31 -#include "SDL_touchscreen.h"
   11.32 -#include "../SDL_systouchscreen.h"
   11.33 -#include "../SDL_touchscreen_c.h"
   11.34 -
   11.35 -/* Function to scan the system for touchscreen.
   11.36 - * This function should set SDL_numtouchscreens to the number of available
   11.37 - * touchscreens.  Touchscreen 0 should be the system default touchscreen.
   11.38 - * It should return 0, or -1 on an unrecoverable fatal error.
   11.39 - */
   11.40 -int
   11.41 -SDL_SYS_TouchscreenInit(void)
   11.42 -{
   11.43 -    SDL_numtouchscreens = 0;
   11.44 -    return (0);
   11.45 -}
   11.46 -
   11.47 -/* Function to get the device-dependent name of a touchscreen */
   11.48 -const char *
   11.49 -SDL_SYS_TouchscreenName(int index)
   11.50 -{
   11.51 -    SDL_SetError("Logic error: No touchscreens available");
   11.52 -    return (NULL);
   11.53 -}
   11.54 -
   11.55 -/* Function to open a touchscreen for use.
   11.56 -   The touchscreen to open is specified by the index field of the touchscreen.
   11.57 -   This should fill the maxpoints field of the touchscreen structure.
   11.58 -   It returns 0, or -1 if there is an error.
   11.59 - */
   11.60 -int
   11.61 -SDL_SYS_TouchscreenOpen(SDL_Touchscreen * touchscreen)
   11.62 -{
   11.63 -    SDL_SetError("Logic error: No touchscreens available");
   11.64 -    return (-1);
   11.65 -}
   11.66 -
   11.67 -/* Function to update the state of a touchscreen - called as a device poll.
   11.68 - * This function shouldn't update the touchscreen structure directly,
   11.69 - * but instead should call SDL_PrivateTouchscreen*() to deliver events
   11.70 - * and update touchscreen device state.
   11.71 - */
   11.72 -void
   11.73 -SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen)
   11.74 -{
   11.75 -    return;
   11.76 -}
   11.77 -
   11.78 -/* Function to close a touchscreen after use */
   11.79 -void
   11.80 -SDL_SYS_TouchscreenClose(SDL_Touchscreen * touchscreen)
   11.81 -{
   11.82 -    return;
   11.83 -}
   11.84 -
   11.85 -/* Function to perform any system-specific touchscreen related cleanup */
   11.86 -void
   11.87 -SDL_SYS_TouchscreenQuit(void)
   11.88 -{
   11.89 -    return;
   11.90 -}
   11.91 -
   11.92 -#endif /* SDL_TOUCHSCREEN_DUMMY || SDL_TOUCHSCREEN_DISABLED */
   11.93 -/* vi: set ts=4 sw=4 expandtab: */
    12.1 --- a/src/touchscreen/nds/SDL_systouchscreen.c	Wed Jul 02 13:59:30 2008 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,126 +0,0 @@
    12.4 -/*
    12.5 -    SDL - Simple DirectMedia Layer
    12.6 -    Copyright (C) 1997, 1998, 1999, 2000, 2001  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 Library General Public
   12.10 -    License as published by the Free Software Foundation; either
   12.11 -    version 2 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 -    Library General Public License for more details.
   12.17 -
   12.18 -    You should have received a copy of the GNU Library General Public
   12.19 -    License along with this library; if not, write to the Free
   12.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.21 -
   12.22 -    Sam Lantinga
   12.23 -    slouken@devolution.com
   12.24 -*/
   12.25 -
   12.26 -#include "SDL_config.h"
   12.27 -
   12.28 -#ifdef SDL_TOUCHSCREEN_NDS
   12.29 -
   12.30 -/* This is the system specific header for the SDL touchscreen API */
   12.31 -#include <nds.h>
   12.32 -#include <stdio.h>              /* For the definition of NULL */
   12.33 -
   12.34 -#include "SDL_error.h"
   12.35 -#include "SDL_events.h"
   12.36 -#include "SDL_touchscreen.h"
   12.37 -#include "../SDL_systouchscreen.h"
   12.38 -#include "../SDL_touchscreen_c.h"
   12.39 -
   12.40 -#include "../../video/nds/SDL_ndsevents_c.h"
   12.41 -
   12.42 -/* Function to scan the system for touchscreen.
   12.43 - * This function should set SDL_numtouchscreens to the number of available
   12.44 - * touchscreen.  Touchscreen 0 should be the system default touchscreen.
   12.45 - * It should return 0, or -1 on an unrecoverable fatal error.
   12.46 - */
   12.47 -int
   12.48 -SDL_SYS_TouchscreenInit(void)
   12.49 -{
   12.50 -    SDL_numtouchscreens = 1;
   12.51 -    return (1);
   12.52 -}
   12.53 -
   12.54 -/* Function to get the device-dependent name of a touchscreen */
   12.55 -const char *
   12.56 -SDL_SYS_TouchscreenName(int index)
   12.57 -{
   12.58 -    if (!index)
   12.59 -        return "NDS builtin touchscreen";
   12.60 -    SDL_SetError("No touchscreen available with that index");
   12.61 -    return (NULL);
   12.62 -}
   12.63 -
   12.64 -/* Function to open a touchscreen for use.
   12.65 -   The touchscreen to open is specified by the index field of the touchscreen.
   12.66 -   This should fill the maxpoints field of the touchscreen structure.
   12.67 -   It returns 0, or -1 if there is an error.
   12.68 - */
   12.69 -int
   12.70 -SDL_SYS_TouchscreenOpen(SDL_Touchscreen * touchscreen)
   12.71 -{
   12.72 -    touchscreen->maxpoints = 1;
   12.73 -    touchscreen->npoints = 0;
   12.74 -    /* do I call SDL_TouchscreenOpen here? */
   12.75 -    return 0;
   12.76 -}
   12.77 -
   12.78 -
   12.79 -/* Function to update the state of a touchscreen - called as a device poll.
   12.80 - * This function shouldn't update the touchscreen structure directly,
   12.81 - * but instead should call SDL_PrivateTouch*() to deliver events
   12.82 - * and update touchscreen device state.
   12.83 - */
   12.84 -void
   12.85 -SDL_SYS_TouchscreenUpdate(SDL_Touchscreen * touchscreen)
   12.86 -{
   12.87 -    u32 keysd, keysu, keysh;
   12.88 -    Uint16 xpos=0, ypos=0, pressure = 32767;
   12.89 -    touchPosition touch;
   12.90 -
   12.91 -    /*scanKeys();*/
   12.92 -    keysd = keysDown();
   12.93 -    keysh = keysHeld();
   12.94 -    keysu = keysUp();
   12.95 -    touch=touchReadXY();
   12.96 -    xpos = (touch.px << 8) + 1;
   12.97 -    ypos = (touch.py << 16) / 192 + 1;
   12.98 -    /* TODO uses touch.x and touch.y for something.
   12.99 -       we discussed in the mailing list having both "hardware x/y" and
  12.100 -       "screen x/y" coordinates.  maybe modify structs for that too
  12.101 -       also, find out how Colors! gets pressure and see if it's practical here
  12.102 -     */
  12.103 -
  12.104 -    if ((keysd & KEY_TOUCH)) {
  12.105 -        SDL_PrivateTouchPress(touchscreen, 0, xpos, ypos, pressure);
  12.106 -    }
  12.107 -    if ((keysh & KEY_TOUCH)) {
  12.108 -    	/* sometimes the touch jumps to y=1 before it reports as keysUp */
  12.109 -    	if(ypos > 1) {
  12.110 -	    SDL_PrivateTouchMove(touchscreen, 0, xpos, ypos, pressure);
  12.111 -	}
  12.112 -    }
  12.113 -    if ((keysu & KEY_TOUCH)) {
  12.114 -        SDL_PrivateTouchRelease(touchscreen, 0);
  12.115 -    }
  12.116 }
  12.117 -
  12.118 -/* Function to close a touchscreen after use */
  12.119 -void
  12.120 -SDL_SYS_TouchscreenClose(SDL_Touchscreen * touchscreen)
  12.121 -{
  12.122 -}
  12.123 -
  12.124 -/* Function to perform any system-specific touchscreen related cleanup */
  12.125 -void
  12.126 -SDL_SYS_TouchscreenQuit(void)
  12.127 -{
  12.128 -}
  12.129 -#endif /* SDL_TOUCHSCREEN_NDS */
  12.130 -
    13.1 --- a/src/video/nds/SDL_ndsevents.c	Wed Jul 02 13:59:30 2008 +0000
    13.2 +++ b/src/video/nds/SDL_ndsevents.c	Thu Jul 10 23:35:01 2008 +0000
    13.3 @@ -39,6 +39,16 @@
    13.4  NDS_PumpEvents(_THIS)
    13.5  {
    13.6      scanKeys();
    13.7 +    /* TODO: defer click-age */
    13.8 +    if(keysDown() & KEY_TOUCH) {
    13.9 +        SDL_SendMouseButton(0, SDL_PRESSED, 0);
   13.10 +    } else if(keysUp() & KEY_TOUCH) {
   13.11 +        SDL_SendMouseButton(0, SDL_RELEASED, 0);
   13.12 +    }
   13.13 +    if(keysHeld() & KEY_TOUCH) {
   13.14 +        touchPosition t = touchReadXY();
   13.15 +        SDL_SendMouseMotion(0, 0, t.px, t.py);
   13.16 +    }
   13.17  }
   13.18  
   13.19  /* vi: set ts=4 sw=4 expandtab: */
    14.1 --- a/src/video/nds/SDL_ndsrender.c	Wed Jul 02 13:59:30 2008 +0000
    14.2 +++ b/src/video/nds/SDL_ndsrender.c	Thu Jul 10 23:35:01 2008 +0000
    14.3 @@ -79,10 +79,16 @@
    14.4  
    14.5  SDL_RenderDriver NDS_RenderDriver = {
    14.6      NDS_CreateRenderer,
    14.7 -    {"nds", SDL_RENDERER_PRESENTCOPY}
    14.8 -/*   (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
    14.9 -      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
   14.10 -      SDL_RENDERER_PRESENTDISCARD),*/
   14.11 +    {"nds", SDL_RENDERER_SINGLEBUFFER}
   14.12 +/*SDL_RENDERER_ values
   14.13 +SINGLEBUFFER   Render directly to the window, if possible
   14.14 +PRESENTCOPY    Present uses a copy from back buffer to the front buffer
   14.15 +PRESENTFLIP2   Present uses a flip, swapping back buffer and front buffer
   14.16 +PRESENTFLIP3   Present uses a flip, rotating two back buf.s and a front buf.
   14.17 +PRESENTDISCARD Present leaves the contents of the backbuffer undefined
   14.18 +PRESENTVSYNC   Present is synchronized with the refresh rate
   14.19 +ACCELERATED    The renderer uses hardware acceleration
   14.20 +*/
   14.21  };
   14.22  
   14.23  typedef struct
   14.24 @@ -91,6 +97,12 @@
   14.25      u16* fb;
   14.26  } NDS_RenderData;
   14.27  
   14.28 +typedef struct
   14.29 +{
   14.30 +    enum { NDSTX_BG, NDSTX_SPR } type;
   14.31 +    struct { int w, h, pitch, bpp; } dim;
   14.32 +    u16 *vram;
   14.33 +} NDS_TextureData;
   14.34  
   14.35  
   14.36  /* this is mainly hackish testing/debugging stuff to get cleaned up soon
   14.37 @@ -143,7 +155,7 @@
   14.38      sdlds_print_pixfmt_info(s->format);
   14.39  }
   14.40  
   14.41 -
   14.42 +/* again the above shouldn't make it into the stable version */
   14.43  
   14.44  SDL_Renderer *
   14.45  NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
   14.46 @@ -199,7 +211,8 @@
   14.47      } else {
   14.48          renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
   14.49          n = 1;
   14.50 -    }/*
   14.51 +    }
   14.52 +    /*
   14.53      for (i = 0; i < n; ++i) {
   14.54          data->screens[i] =
   14.55              SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
   14.56 @@ -218,6 +231,182 @@
   14.57  }
   14.58  
   14.59  static int
   14.60 +NDS_ActivateRenderer(SDL_Renderer * renderer)
   14.61 +{
   14.62 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   14.63 +    /* stub. TODO: figure out what needs to be done, if anything. */
   14.64 +    return 0;
   14.65 +}
   14.66 +
   14.67 +static int
   14.68 +NDS_DisplayModeChanged(SDL_Renderer * renderer)
   14.69 +{
   14.70 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   14.71 +    /* stub. TODO: figure out what needs to be done */
   14.72 +    return 0;
   14.73 +}
   14.74 +
   14.75 +static int
   14.76 +NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   14.77 +{
   14.78 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   14.79 +
   14.80 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   14.81 +        SDL_SetError("Unsupported texture format");
   14.82 +        return -1;
   14.83 +    } else {
   14.84 +        int bpp;
   14.85 +        Uint32 Rmask, Gmask, Bmask, Amask;
   14.86 +
   14.87 +        if (!SDL_PixelFormatEnumToMasks
   14.88 +            (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   14.89 +            SDL_SetError("Unknown texture format");
   14.90 +            return -1;
   14.91 +        }
   14.92 +        /* TODO: appropriate checks for ABGR1555 */
   14.93 +        texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
   14.94 +        /* TODO: conditional statements on w/h to place it as bg/sprite */
   14.95 +    }
   14.96 +
   14.97 +    if (!texture->driverdata) {
   14.98 +        return -1;
   14.99 +    }
  14.100 +    return 0;
  14.101 +}
  14.102 +
  14.103 +static int
  14.104 +NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
  14.105 +                      void **pixels, int *pitch)
  14.106 +{
  14.107 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  14.108 +        SDL_SetError("Unsupported texture format");
  14.109 +        return -1;
  14.110 +    } else {
  14.111 +        NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  14.112 +
  14.113 +        *pixels = txdat->vram;
  14.114 +        *pitch = txdat->dim.pitch;
  14.115 +        return 0;
  14.116 +    }
  14.117 +}
  14.118 +
  14.119 +static int
  14.120 +NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
  14.121 +                     const SDL_Color * colors, int firstcolor, int ncolors)
  14.122 +{
  14.123 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  14.124 +        SDL_SetError("YUV textures don't have a palette");
  14.125 +        return -1;
  14.126 +    } else {
  14.127 +        NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  14.128 +        /* TODO: mess with 8-bit modes and/or 16-color palette modes */
  14.129 +        return 0;
  14.130 +    }
  14.131 +}
  14.132 +
  14.133 +static int
  14.134 +NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
  14.135 +                     SDL_Color * colors, int firstcolor, int ncolors)
  14.136 +{
  14.137 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  14.138 +        SDL_SetError("YUV textures don't have a palette");
  14.139 +        return -1;
  14.140 +    } else {
  14.141 +        NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  14.142 +        /* TODO: mess with 8-bit modes and/or 16-color palette modes */
  14.143 +        return 0;
  14.144 +    }
  14.145 +}
  14.146 +
  14.147 +static int
  14.148 +NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
  14.149 +{
  14.150 +    /* stub. TODO: figure out what needs to be done, if anything */
  14.151 +    return 0;
  14.152 +}
  14.153 +
  14.154 +static int
  14.155 +NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
  14.156 +{
  14.157 +    /* stub. TODO: figure out what needs to be done, if anything */
  14.158 +    return 0;
  14.159 +}
  14.160 +
  14.161 +static int
  14.162 +NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
  14.163 +{
  14.164 +    /* stub. TODO: figure out what needs to be done, if anything */
  14.165 +    return 0;
  14.166 +}
  14.167 +
  14.168 +static int
  14.169 +NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
  14.170 +{
  14.171 +    /* stub. TODO: figure out what needs to be done.
  14.172 +       (NDS hardware scaling is nearest neighbor.) */
  14.173 +    return 0;
  14.174 +}
  14.175 +
  14.176 +static int
  14.177 +NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  14.178 +                 const SDL_Rect * rect, const void *pixels, int pitch)
  14.179 +{
  14.180 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  14.181 +        SDL_SetError("Unsupported texture format");
  14.182 +        return -1;
  14.183 +    } else {
  14.184 +        NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  14.185 +        Uint8 *src, *dst;
  14.186 +        int row;
  14.187 +        size_t length;
  14.188 +        /* IMPORTANT! copy the new pixels into the sprite or bg. */
  14.189 +        src = (Uint8 *) pixels;
  14.190 +        dst =
  14.191 +            (Uint8 *) txdat->vram + rect->y * txdat->dim.pitch +
  14.192 +            rect->x * (txdat->dim.bpp/8);
  14.193 +        length = rect->w * (txdat->dim.bpp/8);
  14.194 +        for (row = 0; row < rect->h; ++row) {
  14.195 +            SDL_memcpy(dst, src, length);
  14.196 +            src += pitch;
  14.197 +            dst += surface->pitch;
  14.198 +        }
  14.199 +        return 0;
  14.200 +    }
  14.201 +}
  14.202 +
  14.203 +static int
  14.204 +NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  14.205 +               const SDL_Rect * rect, int markDirty, void **pixels,
  14.206 +               int *pitch)
  14.207 +{
  14.208 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  14.209 +        SDL_SetError("Unsupported texture format");
  14.210 +        return -1;
  14.211 +    } else {
  14.212 +        NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  14.213 +
  14.214 +        *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
  14.215 +                            + rect->x * (txdat->dim.bpp/8));
  14.216 +        *pitch = txdat->dim.pitch;
  14.217 +        return 0;
  14.218 +    }
  14.219 +}
  14.220 +
  14.221 +static void
  14.222 +NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  14.223 +{
  14.224 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  14.225 +        SDL_SetError("Unsupported texture format");
  14.226 +    }
  14.227 +}
  14.228 +
  14.229 +static void
  14.230 +NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  14.231 +                int numrects, const SDL_Rect * rects)
  14.232 +{ /* stub */
  14.233 +}
  14.234 +
  14.235 +static int
  14.236  NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
  14.237                     Uint8 a, const SDL_Rect * rect)
  14.238  {
  14.239 @@ -235,6 +424,7 @@
  14.240      }
  14.241      return 0;
  14.242  }
  14.243 +
  14.244  static int
  14.245  NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  14.246                     const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  14.247 @@ -297,19 +487,40 @@
  14.248  }
  14.249  
  14.250  static void
  14.251 +NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  14.252 +{
  14.253 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  14.254 +        SDL_SetError("Unsupported texture format");
  14.255 +    } else {
  14.256 +        /* TODO: free anything allocated for texture */
  14.257 +        /*SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  14.258 +        SDL_FreeSurface(surface);*/
  14.259 +    }
  14.260 +}
  14.261 +
  14.262 +static void
  14.263  NDS_DestroyRenderer(SDL_Renderer * renderer)
  14.264  {
  14.265      NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
  14.266 +    /*SDL_Window *window = SDL_GetWindowFromID(renderer->window);
  14.267 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/
  14.268      int i;
  14.269  
  14.270 -    printf("NDS_DestroyRenderer(renderer)\n");
  14.271 -    printf(" renderer: %s\n", renderer->info.name);
  14.272      if (data) {
  14.273 -        /*for (i = 0; i < SDL_arraysize(data->screens); ++i) {
  14.274 -            if (data->screens[i]) {
  14.275 -                SDL_FreeSurface(data->screens[i]);
  14.276 +        for (i = 0; i < SDL_arraysize(data->texture); ++i) {
  14.277 +            if (data->texture[i]) {
  14.278 +                DestroyTexture(data->renderer, data->texture[i]);
  14.279              }
  14.280 -        }*/
  14.281 +        }
  14.282 +        if (data->surface.format) {
  14.283 +            SDL_SetSurfacePalette(&data->surface, NULL);
  14.284 +            SDL_FreeFormat(data->surface.format);
  14.285 +        }
  14.286 +        if (display->palette) {
  14.287 +            SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged,
  14.288 +                                data);
  14.289 +        }
  14.290 +        SDL_FreeDirtyRects(&data->dirty);
  14.291          SDL_free(data);
  14.292      }
  14.293      SDL_free(renderer);