mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-05 15:55:45 +00:00
Readded window icon
This commit is contained in:
parent
36e0cfbc9d
commit
0498e6e5f0
@ -3,8 +3,11 @@
|
||||
#include <stdexcept>
|
||||
#include <iomanip>
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
@ -14,6 +17,7 @@
|
||||
#include <components/vfs/registerarchives.hpp>
|
||||
|
||||
#include <components/sdlutil/sdlgraphicswindow.hpp>
|
||||
#include <components/sdlutil/imagetosurface.hpp>
|
||||
|
||||
#include <components/resource/resourcesystem.hpp>
|
||||
#include <components/resource/texturemanager.hpp>
|
||||
@ -346,7 +350,7 @@ void OMW::Engine::createWindow(Settings::Manager& settings)
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: set window icon
|
||||
setWindowIcon();
|
||||
|
||||
SDLUtil::setupWindowingSystemInterface();
|
||||
|
||||
@ -377,6 +381,26 @@ void OMW::Engine::createWindow(Settings::Manager& settings)
|
||||
mViewer->realize();
|
||||
}
|
||||
|
||||
void OMW::Engine::setWindowIcon()
|
||||
{
|
||||
boost::filesystem::ifstream windowIconStream;
|
||||
std::string windowIcon = (mResDir / "mygui" / "openmw.png").string();
|
||||
windowIconStream.open(windowIcon);
|
||||
if (windowIconStream.fail())
|
||||
std::cerr << "Failed to open " << windowIcon << std::endl;
|
||||
osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension("png");
|
||||
osgDB::ReaderWriter::ReadResult result = reader->readImage(windowIconStream);
|
||||
if (!result.success())
|
||||
std::cerr << "Failed to read " << windowIcon << ": " << result.message() << std::endl;
|
||||
else
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image = result.getImage();
|
||||
SDL_Surface* surface = SDLUtil::imageToSurface(image);
|
||||
SDL_SetWindowIcon(mWindow, surface);
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
}
|
||||
|
||||
void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
||||
{
|
||||
mEnvironment.setStateManager (
|
||||
|
@ -116,6 +116,7 @@ namespace OMW
|
||||
void prepareEngine (Settings::Manager & settings);
|
||||
|
||||
void createWindow(Settings::Manager& settings);
|
||||
void setWindowIcon();
|
||||
|
||||
public:
|
||||
Engine(Files::ConfigurationManager& configurationManager);
|
||||
|
@ -127,7 +127,7 @@ add_component_dir (fontloader
|
||||
)
|
||||
|
||||
add_component_dir (sdlutil
|
||||
sdlgraphicswindow
|
||||
sdlgraphicswindow imagetosurface
|
||||
)
|
||||
|
||||
add_component_dir (version
|
||||
|
28
components/sdlutil/imagetosurface.cpp
Normal file
28
components/sdlutil/imagetosurface.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "imagetosurface.hpp"
|
||||
|
||||
#include <osg/Image>
|
||||
#include <SDL_surface.h>
|
||||
|
||||
namespace SDLUtil
|
||||
{
|
||||
|
||||
SDL_Surface* imageToSurface(osg::Image *image)
|
||||
{
|
||||
int width = image->s();
|
||||
int height = image->t();
|
||||
SDL_Surface* surface = SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000,0x00FF0000,0x0000FF00,0x000000FF);
|
||||
|
||||
for(int x = 0; x < width; ++x)
|
||||
for(int y = 0; y < height; ++y)
|
||||
{
|
||||
osg::Vec4f clr = image->getColor(x, (height-1)-y);
|
||||
int bpp = surface->format->BytesPerPixel;
|
||||
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
|
||||
*(Uint32*)(p) = SDL_MapRGBA(surface->format, static_cast<Uint8>(clr.r() * 255),
|
||||
static_cast<Uint8>(clr.g() * 255), static_cast<Uint8>(clr.b() * 255), static_cast<Uint8>(clr.a() * 255));
|
||||
}
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
}
|
20
components/sdlutil/imagetosurface.hpp
Normal file
20
components/sdlutil/imagetosurface.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef OPENMW_COMPONENTS_SDLUTIL_IMAGETOSURFACE_H
|
||||
#define OPENMW_COMPONENTS_SDLUTIL_IMAGETOSURFACE_H
|
||||
|
||||
struct SDL_Surface;
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Image;
|
||||
}
|
||||
|
||||
namespace SDLUtil
|
||||
{
|
||||
|
||||
/// Convert an osg::Image to an SDL_Surface.
|
||||
/// @note The returned surface must be freed using SDL_FreeSurface.
|
||||
SDL_Surface* imageToSurface(osg::Image* image);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -269,4 +269,4 @@ void setupWindowingSystemInterface()
|
||||
osg::GraphicsContext::setWindowingSystemInterface(new SDL2WindowingSystemInterface);
|
||||
}
|
||||
|
||||
} // namespace TK
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public:
|
||||
/** Set mouse cursor to a specific shape.*/
|
||||
virtual void setCursor(MouseCursor cursor);
|
||||
|
||||
/** WindowData is used to pass in the SDL2 window handle attached the GraphicsContext::Traits structure. */
|
||||
/** WindowData is used to pass in the SDL2 window handle attached to the GraphicsContext::Traits structure. */
|
||||
struct WindowData : public osg::Referenced
|
||||
{
|
||||
WindowData(SDL_Window *window) : mWindow(window)
|
||||
@ -103,6 +103,6 @@ public:
|
||||
|
||||
void setupWindowingSystemInterface();
|
||||
|
||||
} // namespace TK
|
||||
}
|
||||
|
||||
#endif /* OSGGRAPHICSWINDOW_H */
|
||||
|
Loading…
Reference in New Issue
Block a user