diff --git a/src/framework/WindowManager.cpp b/src/framework/WindowManager.cpp index e8df3038eaab375bc567d2ec770406f012f8c8f9..179d6530a7a3910cd28aff6bbad1f47566d9b9fd 100644 --- a/src/framework/WindowManager.cpp +++ b/src/framework/WindowManager.cpp @@ -371,6 +371,29 @@ void WindowManager::setWindowIcon(const string filename) const } } +void WindowManager::setWindowIcon(const unsigned char *data, const int size) const +{ + // prepare data buffer structure + SDL_RWops *buffer = SDL_RWFromMem((void*) data, size); + + if(buffer != NULL) { + // load BMP from prepared data buffer + SDL_Surface *surface = SDL_LoadBMP_RW(buffer, 1); + + if(surface != NULL) { + // set window icon + SDL_WM_SetIcon(surface, NULL); + SDL_FreeSurface(surface); + } + else { + cerr << "Could not create window icon surface: " << SDL_GetError() << endl; + } + } + else { + cerr << "Could not prepare window icon data: " << SDL_GetError() << endl; + } +} + void WindowManager::toggleFullscreen() { // toggle fullscreen bit and reset video mode diff --git a/src/framework/WindowManager.h b/src/framework/WindowManager.h index 2b80dffc87bd010e0f707226fcad4f114aefc855..32b4bdf33472c3e8b5095f40493dd7361f87685b 100644 --- a/src/framework/WindowManager.h +++ b/src/framework/WindowManager.h @@ -133,10 +133,28 @@ public: /** * \brief Set the main window's icon * + * This method uses the provided filename to load a bitmap (BMP) image + * from disk which in turn is displayed as the main window's icon. + * + * Note: The icon should have a size of 32x32 pixels! + * * \param filename The new icon's filename */ void setWindowIcon(const string filename) const; + /** + * \brief Set the main window's icon + * + * This method uses the provided raw data pointer to load a bitmap (BMP) image + * from memory which in turn is displayed as the main window's icon. + * + * Note: The icon should have a size of 32x32 pixels! + * + * \param data Pointer to the bitmap data buffer + * \param size Size of the bitmap data buffer + */ + void setWindowIcon(const unsigned char *data, const int size) const; + /** * \brief Toggles the fullscreen state of the main window * diff --git a/src/starsphere/EaH.bmp.res b/src/starsphere/EaH.bmp.res new file mode 100644 index 0000000000000000000000000000000000000000..3fd2c9f65dbcef70daf906ef885013fb30263403 Binary files /dev/null and b/src/starsphere/EaH.bmp.res differ diff --git a/src/starsphere/main.cpp b/src/starsphere/main.cpp index df13f6e8384d830a2b4e348ea55840939208d8a6..112becba5626518f25bf3e3bff93ed4b756b777c 100644 --- a/src/starsphere/main.cpp +++ b/src/starsphere/main.cpp @@ -72,8 +72,9 @@ int main(int argc, char **argv) exit(1); } - // create font resource instance + // create font and icon resource instances const Resource *fontResource = factory.createInstance("FontSansSerif"); + const Resource *iconResource = factory.createInstance("AppIconBMP"); if(fontResource == NULL) { cerr << "Font resource could not be loaded!" << endl; @@ -88,6 +89,14 @@ int main(int argc, char **argv) exit(1); } + if(iconResource != NULL && iconResource->data()->size() > 0) { + window.setWindowIcon(&iconResource->data()->at(0), iconResource->data()->size()); + delete iconResource; + } + else { + cerr << "Icon resource could not be loaded! Continuing anyway..." << endl; + } + window.setWindowCaption("Einstein@Home"); // register starsphere as event observer @@ -106,7 +115,7 @@ int main(int argc, char **argv) window.toggleFullscreen(); #ifdef __APPLE__ SetMacSSLevel(); -#endif +#endif } } diff --git a/src/starsphere/resources.orc b/src/starsphere/resources.orc index 82517aa2154e39f4dde3021ff5b31a4bcd96bd72..9c151b6eb7f44ce3a945520d3c9886d676b02948 100644 --- a/src/starsphere/resources.orc +++ b/src/starsphere/resources.orc @@ -21,3 +21,4 @@ # Resource specification of: Einstein@Home graphics application FontSansSerif|LiberationSans-Regular.ttf.res +AppIconBMP|EaH.bmp.res