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

Added API requested in bug #43:

        Added SDL_GetNumVideoDrivers() and SDL_GetVideoDriver().
        Replaced SDL_VideoDriverName() with SDL_GetCurrentVideoDriver()
        Added SDL_GetNumAudioDrivers() and SDL_GetAudioDriver().
        Replaced SDL_AudioDriverName() with SDL_GetCurrentAudioDriver()
  • Loading branch information
slouken committed May 20, 2006
1 parent 73b7e9b commit 9c591299856d3817b5035ef78d49e1fb24061952
Showing with 90 additions and 26 deletions.
  1. +5 −5 WhatsNew
  2. +9 −4 include/SDL_audio.h
  3. +9 −4 include/SDL_video.h
  4. +16 −4 src/audio/SDL_audio.c
  5. +15 −4 src/video/SDL_video.c
  6. +17 −2 test/loopwave.c
  7. +19 −3 test/testvidinfo.c
@@ -1,7 +1,11 @@

This is a list of API changes in SDL's version history.

Version 1.0:
1.3.0:
Added SDL_GetNumVideoDrivers() and SDL_GetVideoDriver().
Replaced SDL_VideoDriverName() with SDL_GetCurrentVideoDriver()
Added SDL_GetNumAudioDrivers() and SDL_GetAudioDriver().
Replaced SDL_AudioDriverName() with SDL_GetCurrentAudioDriver()

1.2.10:
If SDL_OpenAudio() is passed zero for the desired format
@@ -416,8 +420,6 @@ Version 1.0:
1.0.0:
New public release

Version 0.11:

0.11.5:
A new function SDL_GetVideoSurface() has been added, and returns
a pointer to the current display surface.
@@ -436,8 +438,6 @@ Version 0.11:
installing fatal signal handlers on operating systems that support
them.

Version 0.9:

0.9.15:
SDL_CreateColorCursor() has been removed. Color cursors should
be implemented as sprites, blitted by the application when the
@@ -95,18 +95,23 @@ typedef struct SDL_AudioCVT {

/* Function prototypes */

/* These functions return the list of built in video drivers, in the
* order that they are normally initialized by default.
*/
extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
extern DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index);

/* These functions are used internally, and should not be used unless you
* have a specific need to specify the audio driver you want to use.
* You should normally use SDL_Init() or SDL_InitSubSystem().
*/
extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
extern DECLSPEC void SDLCALL SDL_AudioQuit(void);

/* This function fills the given character buffer with the name of the
* current audio driver, and returns a pointer to it if the audio driver has
* been initialized. It returns NULL if no driver has been initialized.
/* This function returns the name of the current audio driver, or NULL
* if no driver has been initialized.
*/
extern DECLSPEC char * SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen);
extern DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void);

/*
* This function opens the audio device with the desired parameters, and
@@ -224,6 +224,12 @@ typedef enum {

/* Function prototypes */

/* These functions return the list of built in video drivers, in the
* order that they are normally initialized by default.
*/
extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void);
extern DECLSPEC const char * SDLCALL SDL_GetVideoDriver(int index);

/* These functions are used internally, and should not be used unless you
* have a specific need to specify the video driver you want to use.
* You should normally use SDL_Init() or SDL_InitSubSystem().
@@ -240,11 +246,10 @@ typedef enum {
extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, Uint32 flags);
extern DECLSPEC void SDLCALL SDL_VideoQuit(void);

/* This function fills the given character buffer with the name of the
* video driver, and returns a pointer to it if the video driver has
* been initialized. It returns NULL if no driver has been initialized.
/* This function returns the name of the current video driver, or NULL
* if no driver has been initialized.
*/
extern DECLSPEC char * SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen);
extern DECLSPEC const char * SDLCALL SDL_GetCurrentVideoDriver(void);

/*
* This function returns a pointer to the current display surface.
@@ -330,6 +330,19 @@ static Uint16 SDL_ParseAudioFormat(const char *string)
return format;
}

int SDL_GetNumAudioDrivers(void)
{
return(SDL_arraysize(bootstrap)-1);
}

const char *SDL_GetAudioDriver(int index)
{
if ( index >= 0 && index < SDL_GetNumAudioDrivers() ) {
return(bootstrap[index]->name);
}
return(NULL);
}

int SDL_AudioInit(const char *driver_name)
{
SDL_AudioDevice *audio;
@@ -419,11 +432,10 @@ int SDL_AudioInit(const char *driver_name)
return(0);
}

char *SDL_AudioDriverName(char *namebuf, int maxlen)
const char *SDL_GetCurrentAudioDriver()
{
if ( current_audio != NULL ) {
SDL_strlcpy(namebuf, current_audio->name, maxlen);
return(namebuf);
if ( current_audio ) {
return current_audio->name;
}
return(NULL);
}
@@ -137,6 +137,18 @@ void SDL_VideoQuit(void);

static SDL_GrabMode SDL_WM_GrabInputOff(void);

int SDL_GetNumVideoDrivers(void)
{
return(SDL_arraysize(bootstrap)-1);
}

const char *SDL_GetVideoDriver(int index)
{
if ( index >= 0 && index < SDL_GetNumVideoDrivers() ) {
return(bootstrap[index]->name);
}
return(NULL);
}

/*
* Initialize the video and event subsystems -- determine native pixel format
@@ -278,11 +290,10 @@ int SDL_VideoInit (const char *driver_name, Uint32 flags)
return(0);
}

char *SDL_VideoDriverName(char *namebuf, int maxlen)
const char *SDL_GetCurrentVideoDriver()
{
if ( current_video != NULL ) {
SDL_strlcpy(namebuf, current_video->name, maxlen);
return(namebuf);
if ( current_video ) {
return current_video->name;
}
return(NULL);
}
@@ -62,7 +62,22 @@ void poked(int sig)

int main(int argc, char *argv[])
{
char name[32];
int i, n;

/* Print available audio drivers */
n = SDL_GetNumAudioDrivers();
if ( n == 0 ) {
printf("No built-in audio drivers\n");
} else {
printf("Built-in audio drivers:");
for ( i = 0; i < n; ++i ) {
if ( i > 0 ) {
printf(",");
}
printf(" %s", SDL_GetAudioDriver(i));
}
printf("\n");
}

/* Load the SDL library */
if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
@@ -102,7 +117,7 @@ int main(int argc, char *argv[])
SDL_PauseAudio(0);

/* Let the audio run */
printf("Using audio driver: %s\n", SDL_AudioDriverName(name, 32));
printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
while ( ! done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) )
SDL_Delay(1000);

@@ -386,16 +386,32 @@ void RunVideoTests()
int main(int argc, char *argv[])
{
const SDL_VideoInfo *info;
int i;
int i, n;
SDL_Rect **modes;
char driver[128];
const char *driver;

/* Print available video drivers */
n = SDL_GetNumVideoDrivers();
if ( n == 0 ) {
printf("No built-in video drivers\n");
} else {
printf("Built-in video drivers:");
for ( i = 0; i < n; ++i ) {
if ( i > 0 ) {
printf(",");
}
printf(" %s", SDL_GetVideoDriver(i));
}
printf("\n");
}

if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
driver = SDL_GetCurrentVideoDriver();
if ( driver ) {
printf("Video driver: %s\n", driver);
}
info = SDL_GetVideoInfo();

0 comments on commit 9c59129

Please sign in to comment.