Added screenWidth() and screenHeight() methods to the SDL framebuffer.

This will allow to figure out exactly how big a window can be on the current
screen.  Also, it will mean I can finally change the 'gl_fsmax' option to do
what I originally meant it to do; maximize to the desktop resolution when
doing fullscreen OpenGL.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@352 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-01-04 19:59:13 +00:00
parent 3c0e0af714
commit 5993383be6
4 changed files with 81 additions and 37 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferGL.cxx,v 1.8 2005-01-04 02:29:28 stephena Exp $
// $Id: FrameBufferGL.cxx,v 1.9 2005-01-04 19:59:12 stephena Exp $
//============================================================================
#include <SDL.h>
@ -120,13 +120,10 @@ bool FrameBufferGL::init()
return false;
// Check which system we are running under
x11Available = false;
#if UNIX && (!__APPLE__)
// Get the system-specific WM information
SDL_VERSION(&myWMInfo.version);
if(SDL_GetWMInfo(&myWMInfo) > 0)
if(myWMInfo.subsystem == SDL_SYSWM_X11)
x11Available = true;
#endif
myWMAvailable = true;
// Get the maximum size of a window for THIS screen
theMaxZoomLevel = maxWindowSizeForScreen();

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSDL.cxx,v 1.1 2004-05-24 17:18:22 stephena Exp $
// $Id: FrameBufferSDL.cxx,v 1.2 2005-01-04 19:59:13 stephena Exp $
//============================================================================
#include <SDL.h>
@ -30,7 +30,7 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBufferSDL::FrameBufferSDL()
: x11Available(false),
: myWMAvailable(false),
theZoomLevel(1),
theMaxZoomLevel(1),
theAspectRatio(1.0),
@ -167,28 +167,22 @@ bool FrameBufferSDL::fullScreen()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 FrameBufferSDL::maxWindowSizeForScreen()
{
if(!x11Available)
return 4;
uInt32 sWidth = screenWidth();
uInt32 sHeight = screenHeight();
uInt32 multiplier = sWidth / myWidth;
#ifdef UNIX
// Otherwise, lock the screen and get the width and height
myWMInfo.info.x11.lock_func();
Display* theX11Display = myWMInfo.info.x11.display;
myWMInfo.info.x11.unlock_func();
// If screenwidth or height could not be found, use default zoom value
if(sWidth == 0 || sHeight == 0)
return 2;
int screenWidth = DisplayWidth(theX11Display, DefaultScreen(theX11Display));
int screenHeight = DisplayHeight(theX11Display, DefaultScreen(theX11Display));
uInt32 multiplier = screenWidth / myWidth;
bool found = false;
while(!found && (multiplier > 0))
{
// Figure out the desired size of the window
int width = (int) (myWidth * multiplier * theAspectRatio);
int height = myHeight * multiplier;
uInt32 width = (uInt32) (myWidth * multiplier * theAspectRatio);
uInt32 height = myHeight * multiplier;
if((width < screenWidth) && (height < screenHeight))
if((width < sWidth) && (height < sHeight))
found = true;
else
multiplier--;
@ -198,9 +192,56 @@ uInt32 FrameBufferSDL::maxWindowSizeForScreen()
return multiplier;
else
return 1;
#endif
}
return 4;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 FrameBufferSDL::screenWidth()
{
uInt32 width = 0;
if(myWMAvailable)
{
#if defined(UNIX)
if(myWMInfo.subsystem == SDL_SYSWM_X11)
{
myWMInfo.info.x11.lock_func();
width = DisplayWidth(myWMInfo.info.x11.display,
DefaultScreen(myWMInfo.info.x11.display));
myWMInfo.info.x11.unlock_func();
}
#elif defined(WIN32)
width = (uInt32) GetSystemMetrics(SM_CXSCREEN);
#elif defined(MAC_OSX)
// FIXME - add OSX Desktop code here (I don't think SDL supports it yet)
#endif
}
return width;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 FrameBufferSDL::screenHeight()
{
uInt32 height = 0;
if(myWMAvailable)
{
#if defined(UNIX)
if(myWMInfo.subsystem == SDL_SYSWM_X11)
{
myWMInfo.info.x11.lock_func();
height = DisplayHeight(myWMInfo.info.x11.display,
DefaultScreen(myWMInfo.info.x11.display));
myWMInfo.info.x11.unlock_func();
}
#elif defined(WIN32)
height = (uInt32) GetSystemMetrics(SM_CYSCREEN);
#elif defined(MAC_OSX)
// FIXME - add OSX Desktop code here (I don't think SDL supports it yet)
#endif
}
return height;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSDL.hxx,v 1.3 2004-06-23 00:15:32 stephena Exp $
// $Id: FrameBufferSDL.hxx,v 1.4 2005-01-04 19:59:13 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_SDL_HXX
@ -35,7 +35,7 @@
the core FrameBuffer.
@author Stephen Anthony
@version $Id: FrameBufferSDL.hxx,v 1.3 2004-06-23 00:15:32 stephena Exp $
@version $Id: FrameBufferSDL.hxx,v 1.4 2005-01-04 19:59:13 stephena Exp $
*/
class FrameBufferSDL : public FrameBuffer
{
@ -102,6 +102,16 @@ class FrameBufferSDL : public FrameBuffer
*/
uInt32 imageHeight() { return myDimensions.h; }
/**
This routine is called to get the width of the system desktop.
*/
uInt32 screenWidth();
/**
This routine is called to get the height of the system desktop.
*/
uInt32 screenHeight();
/**
Set the title and icon for the main SDL window.
*/
@ -157,8 +167,8 @@ class FrameBufferSDL : public FrameBuffer
// (these may be different than the screen/window dimensions)
SDL_Rect myDimensions;
// Indicates if we are running under X11
bool x11Available;
// Indicates if the system-specific WM information is available
bool myWMAvailable;
// Indicates the current zoom level of the SDL screen
uInt32 theZoomLevel;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSoft.cxx,v 1.4 2005-01-03 19:16:09 stephena Exp $
// $Id: FrameBufferSoft.cxx,v 1.5 2005-01-04 19:59:13 stephena Exp $
//============================================================================
#include <SDL.h>
@ -69,16 +69,12 @@ bool FrameBufferSoft::init()
if(SDL_Init(initflags) < 0)
return false;
// Check which system we are running under
x11Available = false;
#if UNIX && (!__APPLE__)
// Get the system-specific WM information
SDL_VERSION(&myWMInfo.version);
if(SDL_GetWMInfo(&myWMInfo) > 0)
if(myWMInfo.subsystem == SDL_SYSWM_X11)
x11Available = true;
#endif
myWMAvailable = true;
// Get the maximum size of a window for THIS screen
// Get the maximum size of a window for the desktop
theMaxZoomLevel = maxWindowSizeForScreen();
// Check to see if window size will fit in the screen