Skip to content

Commit

Permalink
libgui|GLWindow: Setting window icon
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent d9cc9f0 commit a9b0245
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doomsday/libs/gui/include/de/graphics/glwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
namespace de {

class GLTimer;
class Image;

/**
* Top-level window that contains an OpenGL drawing surface. @ingroup gui
Expand Down Expand Up @@ -83,6 +84,7 @@ class LIBGUI_PUBLIC GLWindow : public Asset
GLWindow();

void setTitle(const String &title);
void setIcon(const Image &image);
void setMinimumSize(const Size &minSize);
void setGeometry(const Rectanglei &rect);
inline void setGeometry(dint x, dint y, duint width, duint height)
Expand Down
12 changes: 12 additions & 0 deletions doomsday/libs/gui/src/graphics/glwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "de/ElapsedTimer"
#include "de/EventLoop"
#include "de/CoreEvent"
#include "de/Image"

#include <de/GLBuffer>
#include <de/GLState>
Expand Down Expand Up @@ -372,6 +373,17 @@ void GLWindow::setTitle(const String &title)
SDL_SetWindowTitle(d->window, title);
}

void GLWindow::setIcon(const Image &image)
{
const Image rgba = image.convertToFormat(Image::RGBA_8888);
SDL_Surface *icon = SDL_CreateRGBSurfaceWithFormatFrom(const_cast<dbyte *>(image.bits()),
image.width(), image.height(),
32, image.stride(),
SDL_PIXELFORMAT_ABGR8888);
SDL_SetWindowIcon(d->window, icon);
SDL_FreeSurface(icon);
}

void GLWindow::setMinimumSize(const Size &minSize)
{
SDL_SetWindowMinimumSize(d->window, minSize.x, minSize.y);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/gui/src/graphics/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ bool Image::hasAlphaChannel() const
Image Image::convertToFormat(Format toFormat) const
{
if (d->format == toFormat)
{
{
// No conversion necessary.
return *this;
}
Expand Down

0 comments on commit a9b0245

Please sign in to comment.