Commit 841a8776 authored by Sam Lantinga's avatar Sam Lantinga

Now returns an error if unable to open audio on BeOS

Fixed bugs in fullscreen/windowed mode changes, removed duplicated code.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40115
parent 890d0337
...@@ -16,6 +16,7 @@ be found at the <A HREF="http://www.libsdl.org/"> main SDL page</A>. ...@@ -16,6 +16,7 @@ be found at the <A HREF="http://www.libsdl.org/"> main SDL page</A>.
Major changes since SDL 1.0.0: Major changes since SDL 1.0.0:
</H2> </H2>
<UL> <UL>
<LI> 1.2.2: Now returns an error if unable to open audio on BeOS
<LI> 1.2.2: Now gets correct keyboard state when starting up on X11 <LI> 1.2.2: Now gets correct keyboard state when starting up on X11
<LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers <LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers
<LI> 1.2.2: Improved the OpenBSD port (native audio default, etc.) <LI> 1.2.2: Improved the OpenBSD port (native audio default, etc.)
......
...@@ -201,8 +201,12 @@ int BE_OpenAudio(_THIS, SDL_AudioSpec *spec) ...@@ -201,8 +201,12 @@ int BE_OpenAudio(_THIS, SDL_AudioSpec *spec)
NULL, _this); NULL, _this);
SDL_UnmaskSignals(&omask); SDL_UnmaskSignals(&omask);
} }
audio_obj->Start(); if ( audio_obj->Start() == B_NO_ERROR ) {
audio_obj->SetHasData(true); audio_obj->SetHasData(true);
} else {
SDL_SetError("Unable to start Be audio");
return(-1);
}
/* We're running! */ /* We're running! */
return(1); return(1);
......
...@@ -85,7 +85,7 @@ public: ...@@ -85,7 +85,7 @@ public:
dest.top = updateRect.top + yoff; dest.top = updateRect.top + yoff;
dest.left = updateRect.left + xoff; dest.left = updateRect.left + xoff;
dest.bottom = updateRect.bottom + yoff; dest.bottom = updateRect.bottom + yoff;
dest.right = updateRect.right + xoff;; dest.right = updateRect.right + xoff;
DrawBitmap(image, updateRect, dest); DrawBitmap(image, updateRect, dest);
} else { } else {
DrawBitmap(image, updateRect, updateRect); DrawBitmap(image, updateRect, updateRect);
......
...@@ -357,32 +357,26 @@ static bool BE_FindClosestFSMode(_THIS, int width, int height, int bpp, ...@@ -357,32 +357,26 @@ static bool BE_FindClosestFSMode(_THIS, int width, int height, int bpp,
} }
} }
static int BE_ToggleFullScreen(_THIS, int fullscreen) static int BE_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen)
{ {
bool needs_unlock, is_fullscreen; int was_fullscreen;
bool needs_unlock;
BScreen bscreen; BScreen bscreen;
BRect bounds; BRect bounds;
display_mode mode; display_mode mode;
int width, height, bpp; int width, height, bpp;
/* Set the fullscreen mode */
was_fullscreen = SDL_Win->IsFullScreen();
SDL_Win->SetFullScreen(fullscreen); SDL_Win->SetFullScreen(fullscreen);
is_fullscreen = SDL_Win->IsFullScreen(); fullscreen = SDL_Win->IsFullScreen();
if(!((is_fullscreen && fullscreen) ||
(!is_fullscreen && !fullscreen))) {
/* Modeswitch failed */
return 0;
}
if(is_fullscreen) _this->screen->flags |= SDL_FULLSCREEN;
else _this->screen->flags &= ~SDL_FULLSCREEN;
width = _this->screen->w; width = screen->w;
height = _this->screen->h; height = screen->h;
/* Set the appropriate video mode */ /* Set the appropriate video mode */
if ( fullscreen ) { if ( fullscreen ) {
bpp = _this->screen->format->BitsPerPixel; bpp = screen->format->BitsPerPixel;
bscreen.GetMode(&mode); bscreen.GetMode(&mode);
if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) || if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) ||
(width != mode.virtual_width) || (width != mode.virtual_width) ||
...@@ -394,14 +388,15 @@ static int BE_ToggleFullScreen(_THIS, int fullscreen) ...@@ -394,14 +388,15 @@ static int BE_ToggleFullScreen(_THIS, int fullscreen)
*/ */
SDL_Win->InhibitResize(); SDL_Win->InhibitResize();
} else { } else {
_this->screen->flags &= ~SDL_FULLSCREEN; fullscreen = 0;
SDL_Win->SetFullScreen(fullscreen);
} }
} }
}
} else { if ( ! fullscreen ) {
bscreen.SetMode(&saved_mode); bscreen.SetMode(&saved_mode);
} }
if ( SDL_Win->Lock() ) { if ( SDL_Win->Lock() ) {
int xoff, yoff; int xoff, yoff;
if ( SDL_Win->Shown() ) { if ( SDL_Win->Shown() ) {
...@@ -410,82 +405,68 @@ static int BE_ToggleFullScreen(_THIS, int fullscreen) ...@@ -410,82 +405,68 @@ static int BE_ToggleFullScreen(_THIS, int fullscreen)
} else { } else {
needs_unlock = 0; needs_unlock = 0;
} }
/* This resizes the window and view area, but inhibits resizing of /* This resizes the window and view area, but inhibits resizing
* the BBitmap due to the InhibitResize call above. Thus the bitmap * of the BBitmap due to the InhibitResize call above. Thus the
* (pixel data) never changes. * bitmap (pixel data) never changes.
*/ */
SDL_Win->ResizeTo(width, height); SDL_Win->ResizeTo(width, height);
bounds = bscreen.Frame(); bounds = bscreen.Frame();
/* Calculate offsets - used either to center window (windowed mode) /* Calculate offsets - used either to center window
* or to set drawing offsets (fullscreen mode) * (windowed mode) or to set drawing offsets (fullscreen mode)
*/ */
xoff = (bounds.IntegerWidth() - _this->screen->w)/2; xoff = (bounds.IntegerWidth() - width)/2;
yoff = (bounds.IntegerHeight() - _this->screen->h)/2; yoff = (bounds.IntegerHeight() - height)/2;
if(fullscreen) { printf("Setting X/Y offset: %d/%d\n", xoff, yoff);
if ( fullscreen ) {
/* Set offset for drawing */ /* Set offset for drawing */
SDL_Win->SetXYOffset(xoff, yoff); SDL_Win->SetXYOffset(xoff, yoff);
} else { } else {
/* Center window and reset the drawing offset */ /* Center window and reset the drawing offset */
SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0,
yoff > 0 ? (float)yoff : 0.0);
SDL_Win->SetXYOffset(0, 0); SDL_Win->SetXYOffset(0, 0);
} }
if ( ! needs_unlock || was_fullscreen ) {
/* Center the window the first time */
SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0f,
yoff > 0 ? (float)yoff : 0.0f);
}
SDL_Win->Show(); SDL_Win->Show();
/* Unlock the window manually after the first Show() */ /* Unlock the window manually after the first Show() */
if ( needs_unlock ) { SDL_Win->Unlock(); } if ( needs_unlock ) {
SDL_Win->Unlock();
}
}
/* Set the fullscreen flag in the screen surface */
if ( fullscreen ) {
screen->flags |= SDL_FULLSCREEN;
} else {
screen->flags &= ~SDL_FULLSCREEN;
} }
return(1); return(1);
} }
static int BE_ToggleFullScreen(_THIS, int fullscreen)
{
return BE_SetFullScreen(_this, _this->screen, fullscreen);
}
/* FIXME: check return values and cleanup here */ /* FIXME: check return values and cleanup here */
SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags) int width, int height, int bpp, Uint32 flags)
{ {
BScreen bscreen; BScreen bscreen;
display_mode mode;
BBitmap *bbitmap; BBitmap *bbitmap;
BRect bounds; BRect bounds;
int needs_unlock;
int xoff = 0, yoff = 0;
/* Set the appropriate video mode */
if ( flags & SDL_FULLSCREEN ) {
bscreen.GetMode(&mode);
if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) ||
(width != mode.virtual_width) ||
(height != mode.virtual_height) ) {
if(BE_FindClosestFSMode(_this, width, height, bpp, &mode)) {
bscreen.SetMode(&mode);
xoff = (mode.virtual_width - width)/2;
yoff = (mode.virtual_height - height)/2;
} else {
flags &= ~SDL_FULLSCREEN;
}
}
} else {
if ( current->flags & SDL_FULLSCREEN ) {
bscreen.SetMode(&saved_mode);
}
}
/* Create the view for this window */ /* Create the view for this window */
if ( SDL_Win->CreateView(flags) < 0 ) { if ( SDL_Win->CreateView(flags) < 0 ) {
return(NULL); return(NULL);
} }
/* Set offsets */
SDL_Win->SetXYOffset(xoff, yoff);
current->flags = 0; /* Clear flags */ current->flags = 0; /* Clear flags */
current->w = width; current->w = width;
current->h = height; current->h = height;
if ( flags & SDL_FULLSCREEN ) {
SDL_Win->SetFullScreen(1);
current->flags |= SDL_FULLSCREEN;
} else {
SDL_Win->SetFullScreen(0);
}
SDL_Win->SetType(B_TITLED_WINDOW); SDL_Win->SetType(B_TITLED_WINDOW);
if ( flags & SDL_NOFRAME ) { if ( flags & SDL_NOFRAME ) {
current->flags |= SDL_NOFRAME; current->flags |= SDL_NOFRAME;
...@@ -523,33 +504,8 @@ SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -523,33 +504,8 @@ SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current,
_this->UpdateRects = BE_NormalUpdate; _this->UpdateRects = BE_NormalUpdate;
} }
/* Hide the window for resizing */ /* Set the correct fullscreen mode */
if ( SDL_Win->Lock() ) { BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0);
if ( SDL_Win->Shown() ) {
needs_unlock = 1;
SDL_Win->Hide();
} else {
needs_unlock = 0;
}
/* Resize, but only if the window is different size than
* before. Otherwise it jumps funnily when the user resizes.
*/
bounds = SDL_Win->Bounds();
if((int)bounds.Width() != width ||
(int)bounds.Height() != height) {
SDL_Win->ResizeTo(width, height);
bounds = bscreen.Frame();
SDL_Win->MoveTo((bounds.Width()-width)/2,
(bounds.Height()-height)/2);
}
SDL_Win->Show();
/* Unlock the window manually after the first Show() */
if ( needs_unlock ) {
SDL_Win->Unlock();
}
}
/* We're done */ /* We're done */
return(current); return(current);
......
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