diff --git a/WindowManager.cpp b/WindowManager.cpp index 416426d43a2d8732d145ffd246e88e4c0f5b4735..47ccd57f8511122025e3564d4e58d59e2264ca1c 100644 --- a/WindowManager.cpp +++ b/WindowManager.cpp @@ -8,11 +8,8 @@ WindowManager::~WindowManager() { } -bool WindowManager::initialize(const bool fullscreen, const int width, const int height) +bool WindowManager::initialize(const int width, const int height) { - // be sure there's at least one observer! - assert(eventObservers.size() > 0); - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { cerr << "Window system could not be initalized: " << SDL_GetError() << endl; return false; @@ -117,11 +114,6 @@ bool WindowManager::initialize(const bool fullscreen, const int width, const int m_DesktopBitsPerPixel, m_VideoModeFlags); - // switch to fullscreen if requested - if(fullscreen && m_FullscreenModeAvailable) { - toggleFullscreen(); - } - if (m_DisplaySurface == NULL) { cerr << "Could not acquire rendering surface: " << SDL_GetError() << endl; return false; @@ -323,12 +315,12 @@ int WindowManager::windowHeight() const return m_CurrentHeight; } -void WindowManager::setWindowCaption(const string caption) +void WindowManager::setWindowCaption(const string caption) const { SDL_WM_SetCaption(caption.c_str(), NULL); } -void WindowManager::setWindowIcon(const string filename) +void WindowManager::setWindowIcon(const string filename) const { if (filename.length() > 0) { SDL_WM_SetIcon(SDL_LoadBMP(filename.c_str()), NULL); diff --git a/WindowManager.h b/WindowManager.h index a64b3627c9c6f4b4be50f48de769df4ea8da41e0..af954b881d9126ed1b21dc76e123ce4af2ba007e 100644 --- a/WindowManager.h +++ b/WindowManager.h @@ -18,7 +18,7 @@ public: WindowManager(); virtual ~WindowManager(); - bool initialize(const bool fullscreen, const int width = 1024, const int height = 768); + bool initialize(const int width = 1024, const int height = 768); void registerEventObserver(AbstractGraphicsEngine *engine); void unregisterEventObserver(AbstractGraphicsEngine *engine); void eventLoop(); @@ -26,14 +26,14 @@ public: int windowWidth() const; int windowHeight() const; - void setWindowCaption(const string caption); - void setWindowIcon(const string filename); + void setWindowCaption(const string caption) const; + void setWindowIcon(const string filename) const; void toggleFullscreen(); private: // FIXME: work around static, otherwise event conflict when more than one instance - static Uint32 timerCallbackRenderEvent( Uint32 interval, void *param ); - static Uint32 timerCallbackBOINCUpdateEvent( Uint32 interval, void *param ); + static Uint32 timerCallbackRenderEvent(Uint32 interval, void *param); + static Uint32 timerCallbackBOINCUpdateEvent(Uint32 interval, void *param); int m_DesktopWidth; int m_DesktopHeight; diff --git a/main.C b/main.C index 5897a723f709af96e329965f954118f9f51d8947..18da4354afa1f9c7ef9b6cd4897ef292a2560620 100644 --- a/main.C +++ b/main.C @@ -38,44 +38,40 @@ using namespace std; int main(int argc, char **argv) { - Starsphere graphics; - WindowManager window; - - // register starsphere as event observer - window.registerEventObserver(&graphics); - -#ifdef NDEBUG - const bool fullscreen = true; -#else - const bool fullscreen = false; -#endif + // prepare main objects + WindowManager window; + ResourceFactory factory; + Starsphere graphics; // initialize window manager - if(!window.initialize(fullscreen)) { - window.unregisterEventObserver(&graphics); + if(!window.initialize()) { exit(1); } - window.setWindowCaption("Einstein@Home"); - - // prepare resource factory - ResourceFactory factory; - // create font resource instance const Resource *fontResource = factory.createInstance("FontSansSerif"); if(fontResource == NULL) { cerr << "Font resource could not be loaded!" << endl; - window.unregisterEventObserver(&graphics); exit(1); } if(fontResource->data()->size() == 0) { cerr << "Font resource could not be loaded!" << endl; - window.unregisterEventObserver(&graphics); + delete fontResource; exit(1); } + + window.setWindowCaption("Einstein@Home"); + // register starsphere as event observer + window.registerEventObserver(&graphics); + +#ifdef NDEBUG + // switch to fullscreen when in release mode + window.toggleFullscreen(); +#endif + // pepare rendering graphics.initialize(window.windowWidth(), window.windowHeight(), fontResource);