Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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 9c59129
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 26 deletions.
10 changes: 5 additions & 5 deletions WhatsNew
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions include/SDL_audio.h
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions include/SDL_video.h
Expand Up @@ -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().
Expand All @@ -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.
Expand Down
20 changes: 16 additions & 4 deletions src/audio/SDL_audio.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 15 additions & 4 deletions src/video/SDL_video.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 17 additions & 2 deletions test/loopwave.c
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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);

Expand Down
22 changes: 19 additions & 3 deletions test/testvidinfo.c
Expand Up @@ -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();
Expand Down

0 comments on commit 9c59129

Please sign in to comment.