Initialized check + toggle fullscreen fix

This commit is contained in:
James Turk 2003-01-27 04:33:34 +00:00
parent cfd50e58f8
commit 4365e8ae26
2 changed files with 71 additions and 32 deletions

View File

@ -13,7 +13,7 @@
File: ZE_ZEngine.h <br>
Description: Header file for ZEngine class, the core of the ZEngine. <br>
Author(s): James Turk <br>
$Id: ZE_ZEngine.h,v 1.17 2003/01/25 19:55:13 cozman Exp $<br>
$Id: ZE_ZEngine.h,v 1.18 2003/01/27 04:33:34 cozman Exp $<br>
\file ZE_ZEngine.h
\brief Definition file for core ZEngine class.
@ -98,6 +98,8 @@ class ZEngine
int mBPP;
//! Fullscreen setting of Display
bool mFullscreen;
//! If ZEngine display has been setup.
bool mInitialized;
#ifdef USE_SDL_MIXER
//! Sound Bitrate
@ -163,6 +165,15 @@ class ZEngine
**/
void ToggleFullscreen();
/*!
\brief Check state of ZEngine.
Checks if ZEngine display has been properly setup.
\since 0.8.2
\return Boolean status of ZEngine, true if CreateDisplay has been successfully called, false if ZEngine has no display.
**/
bool Initialized();
/////////////////
//Screen Access//
/////////////////

View File

@ -13,7 +13,7 @@
File: ZE_ZEngine.cpp <br>
Description: Implementation source file for ZEngine library main singleton class. <br>
Author(s): James Turk <br>
$Id: ZE_ZEngine.cpp,v 1.24 2003/01/26 00:55:52 cozman Exp $<br>
$Id: ZE_ZEngine.cpp,v 1.25 2003/01/27 04:33:34 cozman Exp $<br>
\file ZE_ZEngine.cpp
\brief Central source file for ZEngine.
@ -30,6 +30,7 @@ ZEngine *ZEngine::sInstance=NULL;
ZEngine::ZEngine()
{
mInitialized = false;
mWidth = 640;
mHeight = 480;
mBPP = 16;
@ -105,27 +106,34 @@ bool ZEngine::CreateDisplay(string title, string icon)
{
Uint32 flags=0;
SDL_Surface *iconImg;
bool status=true; //status of setup
bool status=true; //status of setup, only true if everything went flawless
int bpp;
int rgb_size[3];
if(!mInitialized)
{
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0)
{
ReportError(ZERR_SDL_INIT,SDL_GetError());
return false; //return now, nothing else should be called
}
}
#ifdef USE_SDL_MIXER
if(!mInitialized)
{
if(Mix_OpenAudio(mRate, AUDIO_S16SYS, mStereo?2:1, 4096) < 0) //Open Audio (Stereo?2:1 is conditional for number of channels)
{
ReportError(ZERR_MIX_INIT,SDL_GetError());
status = false; //continue setup without sound
}
}
#endif //USE_SDL_MIXER
//set flags and bpp//
if(mFullscreen)
flags |= SDL_FULLSCREEN;
if(mBPP != -1 && mBPP != 8 && mBPP != 15 && mBPP != 16 && mBPP != 24 && mBPP !=32)
{
ReportError(ZERR_VIDMODE,FormatStr("%d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",mBPP));
@ -173,7 +181,7 @@ bool ZEngine::CreateDisplay(string title, string icon)
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, mBPP==32 ? 24 : mBPP);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, mBPP==32 ? 24 : mBPP); //use 24 if BPP is 32
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0);
@ -182,7 +190,9 @@ bool ZEngine::CreateDisplay(string title, string icon)
flags |= SDL_OPENGL;
//Window Manager settings//
if(!mInitialized) //only set these settings the first time
{
//Default window manager settings//
SDL_EnableKeyRepeat(30,30);
if(!icon.length())
SDL_WM_SetCaption(title.c_str(),NULL);
@ -193,6 +203,7 @@ bool ZEngine::CreateDisplay(string title, string icon)
SDL_WM_SetIcon(iconImg,NULL);
FreeImage(iconImg);
}
}
//create SDL screen and update settings based on returned screen//
mScreen = SDL_SetVideoMode(mWidth, mHeight, mBPP, flags);
@ -218,21 +229,28 @@ bool ZEngine::CreateDisplay(string title, string icon)
mKeyIsPressed = SDL_GetKeyState(NULL);
#ifdef USE_SDL_TTF
if(!mInitialized)
{
if(TTF_Init() < 0)
{
ReportError(ZERR_TTF_INIT,TTF_GetError());
status = false; //possible to go on without SDL_TTF
}
}
#endif //USE_SDL_TTF
if(!mInitialized)
mLastTime = mPausedTime = SDL_GetTicks();
mActive = true;
mInitialized = true; //if it makes it to the end it has been initialized
return status; //return true (false will be returned if TTF or Mixer fail)
}
void ZEngine::CloseDisplay()
{
if(mInitialized)
{
#ifdef USE_SDL_TTF
TTF_Quit();
#endif
@ -249,6 +267,9 @@ void ZEngine::CloseDisplay()
if(mErrlog != stderr && mErrlog != stdin)
fclose(mErrlog);
mInitialized = false;
}
}
void ZEngine::ToggleFullscreen()
@ -259,10 +280,17 @@ void ZEngine::ToggleFullscreen()
#else
SetupDisplay(mWidth,mHeight,mBPP,!mFullscreen);
SDL_WM_GetCaption(&title,&icon);
if(icon)
CreateDisplay(title,icon);
else
CreateDisplay(title);
#endif
SetReloadNeed(true);
mActive = true;
}
bool ZEngine::Initialized()
{
return mInitialized;
}
SDL_Surface *ZEngine::Display()