Date: Mon, 3 May 2004 03:15:01 +0100
authorSam Lantinga <slouken@libsdl.org>
Sun, 18 Jul 2004 22:57:40 +0000
changeset 91104a403e4ccf5
parent 910 4ab6d1fd028f
child 912 bc0b95b02235
Date: Mon, 3 May 2004 03:15:01 +0100
From: David Symmonds
Subject: SDL Typedef Structs

Hi, Thanks for the SDL libraries, I have been using them for about a year
now and they are really brilliant. One thing that I have just found whilst
using them through C++ (and needing forward declarations) is that when you
typedef structs you sometimes use

typedef struct Name
{
...
}Name;

e.g. SDL_Surface


and other times use

typedef struct
{
...
}Name;


e.g. SDL_Rect

The first type works fine, when I define a header file I can just put
'struct Name;' at the top and use the Name throughout. However, the second
type is harder to use in a header, and I haven't found a way yet, other than
to include 'SDL.h' in the header file (undesirable). Would there be any harm
in changing the definition of SDL_Rect and such like to the second form?
include/SDL_audio.h
include/SDL_cdrom.h
include/SDL_events.h
include/SDL_keyboard.h
include/SDL_mouse.h
include/SDL_syswm.h
include/SDL_version.h
include/SDL_video.h
src/SDL_error_c.h
     1.1 --- a/include/SDL_audio.h	Sun Jul 18 19:46:38 2004 +0000
     1.2 +++ b/include/SDL_audio.h	Sun Jul 18 22:57:40 2004 +0000
     1.3 @@ -45,7 +45,7 @@
     1.4  #endif
     1.5  
     1.6  /* The calculated values in this structure are calculated by SDL_OpenAudio() */
     1.7 -typedef struct {
     1.8 +typedef struct SDL_AudioSpec {
     1.9  	int freq;		/* DSP frequency -- samples per second */
    1.10  	Uint16 format;		/* Audio data format */
    1.11  	Uint8  channels;	/* Number of channels: 1 mono, 2 stereo */
     2.1 --- a/include/SDL_cdrom.h	Sun Jul 18 19:46:38 2004 +0000
     2.2 +++ b/include/SDL_cdrom.h	Sun Jul 18 22:57:40 2004 +0000
     2.3 @@ -62,7 +62,7 @@
     2.4  /* Given a status, returns true if there's a disk in the drive */
     2.5  #define CD_INDRIVE(status)	((int)status > 0)
     2.6  
     2.7 -typedef struct {
     2.8 +typedef struct SDL_CDtrack {
     2.9  	Uint8 id;		/* Track number */
    2.10  	Uint8 type;		/* Data or audio track */
    2.11  	Uint16 unused;
     3.1 --- a/include/SDL_events.h	Sun Jul 18 19:46:38 2004 +0000
     3.2 +++ b/include/SDL_events.h	Sun Jul 18 22:57:40 2004 +0000
     3.3 @@ -106,14 +106,14 @@
     3.4  #define SDL_ALLEVENTS		0xFFFFFFFF
     3.5  
     3.6  /* Application visibility event structure */
     3.7 -typedef struct {
     3.8 +typedef struct SDL_ActiveEvent {
     3.9  	Uint8 type;	/* SDL_ACTIVEEVENT */
    3.10  	Uint8 gain;	/* Whether given states were gained or lost (1/0) */
    3.11  	Uint8 state;	/* A mask of the focus states */
    3.12  } SDL_ActiveEvent;
    3.13  
    3.14  /* Keyboard event structure */
    3.15 -typedef struct {
    3.16 +typedef struct SDL_KeyboardEvent {
    3.17  	Uint8 type;	/* SDL_KEYDOWN or SDL_KEYUP */
    3.18  	Uint8 which;	/* The keyboard device index */
    3.19  	Uint8 state;	/* SDL_PRESSED or SDL_RELEASED */
    3.20 @@ -121,7 +121,7 @@
    3.21  } SDL_KeyboardEvent;
    3.22  
    3.23  /* Mouse motion event structure */
    3.24 -typedef struct {
    3.25 +typedef struct SDL_MouseMotionEvent {
    3.26  	Uint8 type;	/* SDL_MOUSEMOTION */
    3.27  	Uint8 which;	/* The mouse device index */
    3.28  	Uint8 state;	/* The current button state */
    3.29 @@ -131,7 +131,7 @@
    3.30  } SDL_MouseMotionEvent;
    3.31  
    3.32  /* Mouse button event structure */
    3.33 -typedef struct {
    3.34 +typedef struct SDL_MouseButtonEvent {
    3.35  	Uint8 type;	/* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
    3.36  	Uint8 which;	/* The mouse device index */
    3.37  	Uint8 button;	/* The mouse button index */
    3.38 @@ -140,7 +140,7 @@
    3.39  } SDL_MouseButtonEvent;
    3.40  
    3.41  /* Joystick axis motion event structure */
    3.42 -typedef struct {
    3.43 +typedef struct SDL_JoyAxisEvent {
    3.44  	Uint8 type;	/* SDL_JOYAXISMOTION */
    3.45  	Uint8 which;	/* The joystick device index */
    3.46  	Uint8 axis;	/* The joystick axis index */
    3.47 @@ -148,7 +148,7 @@
    3.48  } SDL_JoyAxisEvent;
    3.49  
    3.50  /* Joystick trackball motion event structure */
    3.51 -typedef struct {
    3.52 +typedef struct SDL_JoyBallEvent {
    3.53  	Uint8 type;	/* SDL_JOYBALLMOTION */
    3.54  	Uint8 which;	/* The joystick device index */
    3.55  	Uint8 ball;	/* The joystick trackball index */
    3.56 @@ -157,7 +157,7 @@
    3.57  } SDL_JoyBallEvent;
    3.58  
    3.59  /* Joystick hat position change event structure */
    3.60 -typedef struct {
    3.61 +typedef struct SDL_JoyHatEvent {
    3.62  	Uint8 type;	/* SDL_JOYHATMOTION */
    3.63  	Uint8 which;	/* The joystick device index */
    3.64  	Uint8 hat;	/* The joystick hat index */
    3.65 @@ -170,7 +170,7 @@
    3.66  } SDL_JoyHatEvent;
    3.67  
    3.68  /* Joystick button event structure */
    3.69 -typedef struct {
    3.70 +typedef struct SDL_JoyButtonEvent {
    3.71  	Uint8 type;	/* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
    3.72  	Uint8 which;	/* The joystick device index */
    3.73  	Uint8 button;	/* The joystick button index */
    3.74 @@ -181,24 +181,24 @@
    3.75     When you get this event, you are responsible for setting a new video
    3.76     mode with the new width and height.
    3.77   */
    3.78 -typedef struct {
    3.79 +typedef struct SDL_ResizeEvent {
    3.80  	Uint8 type;	/* SDL_VIDEORESIZE */
    3.81  	int w;		/* New width */
    3.82  	int h;		/* New height */
    3.83  } SDL_ResizeEvent;
    3.84  
    3.85  /* The "screen redraw" event */
    3.86 -typedef struct {
    3.87 +typedef struct SDL_ExposeEvent {
    3.88  	Uint8 type;	/* SDL_VIDEOEXPOSE */
    3.89  } SDL_ExposeEvent;
    3.90  
    3.91  /* The "quit requested" event */
    3.92 -typedef struct {
    3.93 +typedef struct SDL_QuitEvent {
    3.94  	Uint8 type;	/* SDL_QUIT */
    3.95  } SDL_QuitEvent;
    3.96  
    3.97  /* A user-defined event type */
    3.98 -typedef struct {
    3.99 +typedef struct SDL_UserEvent {
   3.100  	Uint8 type;	/* SDL_USEREVENT through SDL_NUMEVENTS-1 */
   3.101  	int code;	/* User defined event code */
   3.102  	void *data1;	/* User defined data pointer */
   3.103 @@ -208,7 +208,7 @@
   3.104  /* If you want to use this event, you should include SDL_syswm.h */
   3.105  struct SDL_SysWMmsg;
   3.106  typedef struct SDL_SysWMmsg SDL_SysWMmsg;
   3.107 -typedef struct {
   3.108 +typedef struct SDL_SysWMEvent {
   3.109  	Uint8 type;
   3.110  	SDL_SysWMmsg *msg;
   3.111  } SDL_SysWMEvent;
     4.1 --- a/include/SDL_keyboard.h	Sun Jul 18 19:46:38 2004 +0000
     4.2 +++ b/include/SDL_keyboard.h	Sun Jul 18 22:57:40 2004 +0000
     4.3 @@ -55,7 +55,7 @@
     4.4  		An international character..
     4.5  	}
     4.6   */
     4.7 -typedef struct {
     4.8 +typedef struct SDL_keysym {
     4.9  	Uint8 scancode;			/* hardware specific scancode */
    4.10  	SDLKey sym;			/* SDL virtual keysym */
    4.11  	SDLMod mod;			/* current key modifiers */
     5.1 --- a/include/SDL_mouse.h	Sun Jul 18 19:46:38 2004 +0000
     5.2 +++ b/include/SDL_mouse.h	Sun Jul 18 22:57:40 2004 +0000
     5.3 @@ -40,7 +40,7 @@
     5.4  #endif
     5.5  
     5.6  typedef struct WMcursor WMcursor;	/* Implementation dependent */
     5.7 -typedef struct {
     5.8 +typedef struct SDL_Cursor {
     5.9  	SDL_Rect area;			/* The area of the mouse cursor */
    5.10  	Sint16 hot_x, hot_y;		/* The "tip" of the cursor */
    5.11  	Uint8 *data;			/* B/W cursor data */
     6.1 --- a/include/SDL_syswm.h	Sun Jul 18 19:46:38 2004 +0000
     6.2 +++ b/include/SDL_syswm.h	Sun Jul 18 22:57:40 2004 +0000
     6.3 @@ -74,7 +74,7 @@
     6.4     When this structure is returned, it holds information about which
     6.5     low level system it is using, and will be one of SDL_SYSWM_TYPE.
     6.6   */
     6.7 -typedef struct {
     6.8 +typedef struct SDL_SysWMinfo {
     6.9  	SDL_version version;
    6.10  	SDL_SYSWM_TYPE subsystem;
    6.11  	union {
    6.12 @@ -106,7 +106,7 @@
    6.13  };
    6.14  
    6.15  /* The windows custom window manager information structure */
    6.16 -typedef struct {
    6.17 +typedef struct SDL_SysWMinfo {
    6.18  	SDL_version version ;
    6.19  	GR_WINDOW_ID window ;	/* The display window */
    6.20  } SDL_SysWMinfo;
    6.21 @@ -125,7 +125,7 @@
    6.22  };
    6.23  
    6.24  /* The windows custom window manager information structure */
    6.25 -typedef struct {
    6.26 +typedef struct SDL_SysWMinfo {
    6.27  	SDL_version version;
    6.28  	HWND window;			/* The Win32 display window */
    6.29  	HGLRC hglrc;			/* The OpenGL context, if any */
    6.30 @@ -141,7 +141,7 @@
    6.31  };
    6.32  
    6.33  /* The RISCOS custom window manager information structure */
    6.34 -typedef struct {
    6.35 +typedef struct SDL_SysWMinfo {
    6.36  	SDL_version version;
    6.37  	int wimpVersion;    /* Wimp version running under */
    6.38  	int taskHandle;     /* The RISCOS task handle */
    6.39 @@ -159,7 +159,7 @@
    6.40  };
    6.41  
    6.42  /* The QNX custom window manager information structure */
    6.43 -typedef struct {
    6.44 +typedef struct SDL_SysWMinfo {
    6.45  	SDL_version version;
    6.46  	int data;
    6.47  } SDL_SysWMinfo;
    6.48 @@ -173,7 +173,7 @@
    6.49  };
    6.50  
    6.51  /* The generic custom window manager information structure */
    6.52 -typedef struct {
    6.53 +typedef struct SDL_SysWMinfo {
    6.54  	SDL_version version;
    6.55  	int data;
    6.56  } SDL_SysWMinfo;
     7.1 --- a/include/SDL_version.h	Sun Jul 18 19:46:38 2004 +0000
     7.2 +++ b/include/SDL_version.h	Sun Jul 18 22:57:40 2004 +0000
     7.3 @@ -44,7 +44,7 @@
     7.4  #define SDL_MINOR_VERSION	2
     7.5  #define SDL_PATCHLEVEL		8
     7.6  
     7.7 -typedef struct {
     7.8 +typedef struct SDL_version {
     7.9  	Uint8 major;
    7.10  	Uint8 minor;
    7.11  	Uint8 patch;
     8.1 --- a/include/SDL_video.h	Sun Jul 18 19:46:38 2004 +0000
     8.2 +++ b/include/SDL_video.h	Sun Jul 18 22:57:40 2004 +0000
     8.3 @@ -47,12 +47,12 @@
     8.4  #define SDL_ALPHA_TRANSPARENT 0
     8.5  
     8.6  /* Useful data types */
     8.7 -typedef struct {
     8.8 +typedef struct SDL_Rect {
     8.9  	Sint16 x, y;
    8.10  	Uint16 w, h;
    8.11  } SDL_Rect;
    8.12  
    8.13 -typedef struct {
    8.14 +typedef struct SDL_Color {
    8.15  	Uint8 r;
    8.16  	Uint8 g;
    8.17  	Uint8 b;
    8.18 @@ -60,7 +60,7 @@
    8.19  } SDL_Color;
    8.20  #define SDL_Colour SDL_Color
    8.21  
    8.22 -typedef struct {
    8.23 +typedef struct SDL_Palette {
    8.24  	int       ncolors;
    8.25  	SDL_Color *colors;
    8.26  } SDL_Palette;
    8.27 @@ -154,7 +154,7 @@
    8.28  
    8.29  
    8.30  /* Useful for determining the video hardware capabilities */
    8.31 -typedef struct {
    8.32 +typedef struct SDL_VideoInfo {
    8.33  	Uint32 hw_available :1;	/* Flag: Can you create hardware surfaces? */
    8.34  	Uint32 wm_available :1;	/* Flag: Can you talk to a window manager? */
    8.35  	Uint32 UnusedBits1  :6;
     9.1 --- a/src/SDL_error_c.h	Sun Jul 18 19:46:38 2004 +0000
     9.2 +++ b/src/SDL_error_c.h	Sun Jul 18 22:57:40 2004 +0000
     9.3 @@ -35,7 +35,7 @@
     9.4  #define ERR_MAX_STRLEN	128
     9.5  #define ERR_MAX_ARGS	5
     9.6  
     9.7 -typedef struct {
     9.8 +typedef struct SDL_error {
     9.9  	/* This is a numeric value corresponding to the current error */
    9.10  	int error;
    9.11