Skip to content
Snippets Groups Projects
Commit e58d6d7b authored by Oliver Bock's avatar Oliver Bock
Browse files

Added window icon

parent 42ceda94
No related branches found
No related tags found
No related merge requests found
...@@ -371,6 +371,29 @@ void WindowManager::setWindowIcon(const string filename) const ...@@ -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() void WindowManager::toggleFullscreen()
{ {
// toggle fullscreen bit and reset video mode // toggle fullscreen bit and reset video mode
......
...@@ -133,10 +133,28 @@ public: ...@@ -133,10 +133,28 @@ public:
/** /**
* \brief Set the main window's icon * \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 * \param filename The new icon's filename
*/ */
void setWindowIcon(const string filename) const; 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 * \brief Toggles the fullscreen state of the main window
* *
......
File added
...@@ -72,8 +72,9 @@ int main(int argc, char **argv) ...@@ -72,8 +72,9 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
// create font resource instance // create font and icon resource instances
const Resource *fontResource = factory.createInstance("FontSansSerif"); const Resource *fontResource = factory.createInstance("FontSansSerif");
const Resource *iconResource = factory.createInstance("AppIconBMP");
if(fontResource == NULL) { if(fontResource == NULL) {
cerr << "Font resource could not be loaded!" << endl; cerr << "Font resource could not be loaded!" << endl;
...@@ -88,6 +89,14 @@ int main(int argc, char **argv) ...@@ -88,6 +89,14 @@ int main(int argc, char **argv)
exit(1); 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"); window.setWindowCaption("Einstein@Home");
// register starsphere as event observer // register starsphere as event observer
......
...@@ -21,3 +21,4 @@ ...@@ -21,3 +21,4 @@
# Resource specification of: Einstein@Home graphics application # Resource specification of: Einstein@Home graphics application
FontSansSerif|LiberationSans-Regular.ttf.res FontSansSerif|LiberationSans-Regular.ttf.res
AppIconBMP|EaH.bmp.res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment