Commit f70b972d authored by Sam Lantinga's avatar Sam Lantinga

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?

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40912
parent 1ac1efb0
...@@ -45,7 +45,7 @@ extern "C" { ...@@ -45,7 +45,7 @@ extern "C" {
#endif #endif
/* The calculated values in this structure are calculated by SDL_OpenAudio() */ /* The calculated values in this structure are calculated by SDL_OpenAudio() */
typedef struct { typedef struct SDL_AudioSpec {
int freq; /* DSP frequency -- samples per second */ int freq; /* DSP frequency -- samples per second */
Uint16 format; /* Audio data format */ Uint16 format; /* Audio data format */
Uint8 channels; /* Number of channels: 1 mono, 2 stereo */ Uint8 channels; /* Number of channels: 1 mono, 2 stereo */
......
...@@ -62,7 +62,7 @@ typedef enum { ...@@ -62,7 +62,7 @@ typedef enum {
/* Given a status, returns true if there's a disk in the drive */ /* Given a status, returns true if there's a disk in the drive */
#define CD_INDRIVE(status) ((int)status > 0) #define CD_INDRIVE(status) ((int)status > 0)
typedef struct { typedef struct SDL_CDtrack {
Uint8 id; /* Track number */ Uint8 id; /* Track number */
Uint8 type; /* Data or audio track */ Uint8 type; /* Data or audio track */
Uint16 unused; Uint16 unused;
......
...@@ -106,14 +106,14 @@ enum { ...@@ -106,14 +106,14 @@ enum {
#define SDL_ALLEVENTS 0xFFFFFFFF #define SDL_ALLEVENTS 0xFFFFFFFF
/* Application visibility event structure */ /* Application visibility event structure */
typedef struct { typedef struct SDL_ActiveEvent {
Uint8 type; /* SDL_ACTIVEEVENT */ Uint8 type; /* SDL_ACTIVEEVENT */
Uint8 gain; /* Whether given states were gained or lost (1/0) */ Uint8 gain; /* Whether given states were gained or lost (1/0) */
Uint8 state; /* A mask of the focus states */ Uint8 state; /* A mask of the focus states */
} SDL_ActiveEvent; } SDL_ActiveEvent;
/* Keyboard event structure */ /* Keyboard event structure */
typedef struct { typedef struct SDL_KeyboardEvent {
Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */ Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */
Uint8 which; /* The keyboard device index */ Uint8 which; /* The keyboard device index */
Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ Uint8 state; /* SDL_PRESSED or SDL_RELEASED */
...@@ -121,7 +121,7 @@ typedef struct { ...@@ -121,7 +121,7 @@ typedef struct {
} SDL_KeyboardEvent; } SDL_KeyboardEvent;
/* Mouse motion event structure */ /* Mouse motion event structure */
typedef struct { typedef struct SDL_MouseMotionEvent {
Uint8 type; /* SDL_MOUSEMOTION */ Uint8 type; /* SDL_MOUSEMOTION */
Uint8 which; /* The mouse device index */ Uint8 which; /* The mouse device index */
Uint8 state; /* The current button state */ Uint8 state; /* The current button state */
...@@ -131,7 +131,7 @@ typedef struct { ...@@ -131,7 +131,7 @@ typedef struct {
} SDL_MouseMotionEvent; } SDL_MouseMotionEvent;
/* Mouse button event structure */ /* Mouse button event structure */
typedef struct { typedef struct SDL_MouseButtonEvent {
Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */ Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
Uint8 which; /* The mouse device index */ Uint8 which; /* The mouse device index */
Uint8 button; /* The mouse button index */ Uint8 button; /* The mouse button index */
...@@ -140,7 +140,7 @@ typedef struct { ...@@ -140,7 +140,7 @@ typedef struct {
} SDL_MouseButtonEvent; } SDL_MouseButtonEvent;
/* Joystick axis motion event structure */ /* Joystick axis motion event structure */
typedef struct { typedef struct SDL_JoyAxisEvent {
Uint8 type; /* SDL_JOYAXISMOTION */ Uint8 type; /* SDL_JOYAXISMOTION */
Uint8 which; /* The joystick device index */ Uint8 which; /* The joystick device index */
Uint8 axis; /* The joystick axis index */ Uint8 axis; /* The joystick axis index */
...@@ -148,7 +148,7 @@ typedef struct { ...@@ -148,7 +148,7 @@ typedef struct {
} SDL_JoyAxisEvent; } SDL_JoyAxisEvent;
/* Joystick trackball motion event structure */ /* Joystick trackball motion event structure */
typedef struct { typedef struct SDL_JoyBallEvent {
Uint8 type; /* SDL_JOYBALLMOTION */ Uint8 type; /* SDL_JOYBALLMOTION */
Uint8 which; /* The joystick device index */ Uint8 which; /* The joystick device index */
Uint8 ball; /* The joystick trackball index */ Uint8 ball; /* The joystick trackball index */
...@@ -157,7 +157,7 @@ typedef struct { ...@@ -157,7 +157,7 @@ typedef struct {
} SDL_JoyBallEvent; } SDL_JoyBallEvent;
/* Joystick hat position change event structure */ /* Joystick hat position change event structure */
typedef struct { typedef struct SDL_JoyHatEvent {
Uint8 type; /* SDL_JOYHATMOTION */ Uint8 type; /* SDL_JOYHATMOTION */
Uint8 which; /* The joystick device index */ Uint8 which; /* The joystick device index */
Uint8 hat; /* The joystick hat index */ Uint8 hat; /* The joystick hat index */
...@@ -170,7 +170,7 @@ typedef struct { ...@@ -170,7 +170,7 @@ typedef struct {
} SDL_JoyHatEvent; } SDL_JoyHatEvent;
/* Joystick button event structure */ /* Joystick button event structure */
typedef struct { typedef struct SDL_JoyButtonEvent {
Uint8 type; /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */ Uint8 type; /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
Uint8 which; /* The joystick device index */ Uint8 which; /* The joystick device index */
Uint8 button; /* The joystick button index */ Uint8 button; /* The joystick button index */
...@@ -181,24 +181,24 @@ typedef struct { ...@@ -181,24 +181,24 @@ typedef struct {
When you get this event, you are responsible for setting a new video When you get this event, you are responsible for setting a new video
mode with the new width and height. mode with the new width and height.
*/ */
typedef struct { typedef struct SDL_ResizeEvent {
Uint8 type; /* SDL_VIDEORESIZE */ Uint8 type; /* SDL_VIDEORESIZE */
int w; /* New width */ int w; /* New width */
int h; /* New height */ int h; /* New height */
} SDL_ResizeEvent; } SDL_ResizeEvent;
/* The "screen redraw" event */ /* The "screen redraw" event */
typedef struct { typedef struct SDL_ExposeEvent {
Uint8 type; /* SDL_VIDEOEXPOSE */ Uint8 type; /* SDL_VIDEOEXPOSE */
} SDL_ExposeEvent; } SDL_ExposeEvent;
/* The "quit requested" event */ /* The "quit requested" event */
typedef struct { typedef struct SDL_QuitEvent {
Uint8 type; /* SDL_QUIT */ Uint8 type; /* SDL_QUIT */
} SDL_QuitEvent; } SDL_QuitEvent;
/* A user-defined event type */ /* A user-defined event type */
typedef struct { typedef struct SDL_UserEvent {
Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */ Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */
int code; /* User defined event code */ int code; /* User defined event code */
void *data1; /* User defined data pointer */ void *data1; /* User defined data pointer */
...@@ -208,7 +208,7 @@ typedef struct { ...@@ -208,7 +208,7 @@ typedef struct {
/* If you want to use this event, you should include SDL_syswm.h */ /* If you want to use this event, you should include SDL_syswm.h */
struct SDL_SysWMmsg; struct SDL_SysWMmsg;
typedef struct SDL_SysWMmsg SDL_SysWMmsg; typedef struct SDL_SysWMmsg SDL_SysWMmsg;
typedef struct { typedef struct SDL_SysWMEvent {
Uint8 type; Uint8 type;
SDL_SysWMmsg *msg; SDL_SysWMmsg *msg;
} SDL_SysWMEvent; } SDL_SysWMEvent;
......
...@@ -55,7 +55,7 @@ extern "C" { ...@@ -55,7 +55,7 @@ extern "C" {
An international character.. An international character..
} }
*/ */
typedef struct { typedef struct SDL_keysym {
Uint8 scancode; /* hardware specific scancode */ Uint8 scancode; /* hardware specific scancode */
SDLKey sym; /* SDL virtual keysym */ SDLKey sym; /* SDL virtual keysym */
SDLMod mod; /* current key modifiers */ SDLMod mod; /* current key modifiers */
......
...@@ -40,7 +40,7 @@ extern "C" { ...@@ -40,7 +40,7 @@ extern "C" {
#endif #endif
typedef struct WMcursor WMcursor; /* Implementation dependent */ typedef struct WMcursor WMcursor; /* Implementation dependent */
typedef struct { typedef struct SDL_Cursor {
SDL_Rect area; /* The area of the mouse cursor */ SDL_Rect area; /* The area of the mouse cursor */
Sint16 hot_x, hot_y; /* The "tip" of the cursor */ Sint16 hot_x, hot_y; /* The "tip" of the cursor */
Uint8 *data; /* B/W cursor data */ Uint8 *data; /* B/W cursor data */
......
...@@ -74,7 +74,7 @@ struct SDL_SysWMmsg { ...@@ -74,7 +74,7 @@ struct SDL_SysWMmsg {
When this structure is returned, it holds information about which When this structure is returned, it holds information about which
low level system it is using, and will be one of SDL_SYSWM_TYPE. low level system it is using, and will be one of SDL_SYSWM_TYPE.
*/ */
typedef struct { typedef struct SDL_SysWMinfo {
SDL_version version; SDL_version version;
SDL_SYSWM_TYPE subsystem; SDL_SYSWM_TYPE subsystem;
union { union {
...@@ -106,7 +106,7 @@ struct SDL_SysWMmsg { ...@@ -106,7 +106,7 @@ struct SDL_SysWMmsg {
}; };
/* The windows custom window manager information structure */ /* The windows custom window manager information structure */
typedef struct { typedef struct SDL_SysWMinfo {
SDL_version version ; SDL_version version ;
GR_WINDOW_ID window ; /* The display window */ GR_WINDOW_ID window ; /* The display window */
} SDL_SysWMinfo; } SDL_SysWMinfo;
...@@ -125,7 +125,7 @@ struct SDL_SysWMmsg { ...@@ -125,7 +125,7 @@ struct SDL_SysWMmsg {
}; };
/* The windows custom window manager information structure */ /* The windows custom window manager information structure */
typedef struct { typedef struct SDL_SysWMinfo {
SDL_version version; SDL_version version;
HWND window; /* The Win32 display window */ HWND window; /* The Win32 display window */
HGLRC hglrc; /* The OpenGL context, if any */ HGLRC hglrc; /* The OpenGL context, if any */
...@@ -141,7 +141,7 @@ struct SDL_SysWMmsg { ...@@ -141,7 +141,7 @@ struct SDL_SysWMmsg {
}; };
/* The RISCOS custom window manager information structure */ /* The RISCOS custom window manager information structure */
typedef struct { typedef struct SDL_SysWMinfo {
SDL_version version; SDL_version version;
int wimpVersion; /* Wimp version running under */ int wimpVersion; /* Wimp version running under */
int taskHandle; /* The RISCOS task handle */ int taskHandle; /* The RISCOS task handle */
...@@ -159,7 +159,7 @@ struct SDL_SysWMmsg { ...@@ -159,7 +159,7 @@ struct SDL_SysWMmsg {
}; };
/* The QNX custom window manager information structure */ /* The QNX custom window manager information structure */
typedef struct { typedef struct SDL_SysWMinfo {
SDL_version version; SDL_version version;
int data; int data;
} SDL_SysWMinfo; } SDL_SysWMinfo;
...@@ -173,7 +173,7 @@ struct SDL_SysWMmsg { ...@@ -173,7 +173,7 @@ struct SDL_SysWMmsg {
}; };
/* The generic custom window manager information structure */ /* The generic custom window manager information structure */
typedef struct { typedef struct SDL_SysWMinfo {
SDL_version version; SDL_version version;
int data; int data;
} SDL_SysWMinfo; } SDL_SysWMinfo;
......
...@@ -44,7 +44,7 @@ extern "C" { ...@@ -44,7 +44,7 @@ extern "C" {
#define SDL_MINOR_VERSION 2 #define SDL_MINOR_VERSION 2
#define SDL_PATCHLEVEL 8 #define SDL_PATCHLEVEL 8
typedef struct { typedef struct SDL_version {
Uint8 major; Uint8 major;
Uint8 minor; Uint8 minor;
Uint8 patch; Uint8 patch;
......
...@@ -47,12 +47,12 @@ extern "C" { ...@@ -47,12 +47,12 @@ extern "C" {
#define SDL_ALPHA_TRANSPARENT 0 #define SDL_ALPHA_TRANSPARENT 0
/* Useful data types */ /* Useful data types */
typedef struct { typedef struct SDL_Rect {
Sint16 x, y; Sint16 x, y;
Uint16 w, h; Uint16 w, h;
} SDL_Rect; } SDL_Rect;
typedef struct { typedef struct SDL_Color {
Uint8 r; Uint8 r;
Uint8 g; Uint8 g;
Uint8 b; Uint8 b;
...@@ -60,7 +60,7 @@ typedef struct { ...@@ -60,7 +60,7 @@ typedef struct {
} SDL_Color; } SDL_Color;
#define SDL_Colour SDL_Color #define SDL_Colour SDL_Color
typedef struct { typedef struct SDL_Palette {
int ncolors; int ncolors;
SDL_Color *colors; SDL_Color *colors;
} SDL_Palette; } SDL_Palette;
...@@ -154,7 +154,7 @@ typedef struct SDL_Surface { ...@@ -154,7 +154,7 @@ typedef struct SDL_Surface {
/* Useful for determining the video hardware capabilities */ /* Useful for determining the video hardware capabilities */
typedef struct { typedef struct SDL_VideoInfo {
Uint32 hw_available :1; /* Flag: Can you create hardware surfaces? */ Uint32 hw_available :1; /* Flag: Can you create hardware surfaces? */
Uint32 wm_available :1; /* Flag: Can you talk to a window manager? */ Uint32 wm_available :1; /* Flag: Can you talk to a window manager? */
Uint32 UnusedBits1 :6; Uint32 UnusedBits1 :6;
......
...@@ -35,7 +35,7 @@ static char rcsid = ...@@ -35,7 +35,7 @@ static char rcsid =
#define ERR_MAX_STRLEN 128 #define ERR_MAX_STRLEN 128
#define ERR_MAX_ARGS 5 #define ERR_MAX_ARGS 5
typedef struct { typedef struct SDL_error {
/* This is a numeric value corresponding to the current error */ /* This is a numeric value corresponding to the current error */
int error; int error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment