forked from Mirrorlandia_minetest/irrlicht
SDL: Implement getDisplayDensity() and setWindowIcon()
This commit is contained in:
parent
acbc90a000
commit
49b6ccde72
@ -9,6 +9,8 @@
|
|||||||
#include "IEventReceiver.h"
|
#include "IEventReceiver.h"
|
||||||
#include "IGUIElement.h"
|
#include "IGUIElement.h"
|
||||||
#include "IGUIEnvironment.h"
|
#include "IGUIEnvironment.h"
|
||||||
|
#include "IImageLoader.h"
|
||||||
|
#include "IFileSystem.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "CTimer.h"
|
#include "CTimer.h"
|
||||||
#include "irrString.h"
|
#include "irrString.h"
|
||||||
@ -243,7 +245,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
|||||||
#endif
|
#endif
|
||||||
if (SDL_Init(flags) < 0)
|
if (SDL_Init(flags) < 0)
|
||||||
{
|
{
|
||||||
os::Printer::log("Unable to initialize SDL!", SDL_GetError());
|
os::Printer::log("Unable to initialize SDL", SDL_GetError(), ELL_ERROR);
|
||||||
Close = true;
|
Close = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -871,6 +873,29 @@ bool CIrrDeviceSDL::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Get the display density in dots per inch.
|
||||||
|
float CIrrDeviceSDL::getDisplayDensity() const
|
||||||
|
{
|
||||||
|
if (!Window)
|
||||||
|
return 0.0f;
|
||||||
|
|
||||||
|
int window_w;
|
||||||
|
int window_h;
|
||||||
|
SDL_GetWindowSize(Window, &window_w, &window_h);
|
||||||
|
|
||||||
|
int drawable_w;
|
||||||
|
int drawable_h;
|
||||||
|
SDL_GL_GetDrawableSize(Window, &drawable_w, &drawable_h);
|
||||||
|
|
||||||
|
// assume 96 dpi
|
||||||
|
float dpi_w = (float)drawable_w / (float)window_w * 96.0f;
|
||||||
|
float dpi_h = (float)drawable_h / (float)window_h * 96.0f;
|
||||||
|
|
||||||
|
return std::max(dpi_w, dpi_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CIrrDeviceSDL::SwapWindow()
|
void CIrrDeviceSDL::SwapWindow()
|
||||||
{
|
{
|
||||||
SDL_GL_SwapWindow(Window);
|
SDL_GL_SwapWindow(Window);
|
||||||
@ -908,6 +933,41 @@ void CIrrDeviceSDL::setWindowCaption(const wchar_t* text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Sets the window icon.
|
||||||
|
bool CIrrDeviceSDL::setWindowIcon(const video::IImage *img)
|
||||||
|
{
|
||||||
|
if (!Window)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
u32 height = img->getDimension().Height;
|
||||||
|
u32 width = img->getDimension().Width;
|
||||||
|
|
||||||
|
SDL_Surface *surface = SDL_CreateRGBSurface(0, width, height, 32,
|
||||||
|
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
|
||||||
|
|
||||||
|
if (!surface) {
|
||||||
|
os::Printer::log("Failed to create SDL suface", ELL_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_LockSurface(surface);
|
||||||
|
bool succ = img->copyToNoScaling(surface->pixels, width, height, video::ECF_A8R8G8B8, surface->pitch);
|
||||||
|
SDL_UnlockSurface(surface);
|
||||||
|
|
||||||
|
if (!succ) {
|
||||||
|
os::Printer::log("Could not copy icon image. Is the format not ECF_A8R8G8B8?", ELL_ERROR);
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetWindowIcon(Window, surface);
|
||||||
|
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! notifies the device that it should close itself
|
//! notifies the device that it should close itself
|
||||||
void CIrrDeviceSDL::closeDevice()
|
void CIrrDeviceSDL::closeDevice()
|
||||||
{
|
{
|
||||||
|
@ -48,6 +48,9 @@ namespace irr
|
|||||||
//! sets the caption of the window
|
//! sets the caption of the window
|
||||||
void setWindowCaption(const wchar_t* text) override;
|
void setWindowCaption(const wchar_t* text) override;
|
||||||
|
|
||||||
|
//! Sets the window icon.
|
||||||
|
bool setWindowIcon(const video::IImage *img) override;
|
||||||
|
|
||||||
//! returns if window is active. if not, nothing need to be drawn
|
//! returns if window is active. if not, nothing need to be drawn
|
||||||
bool isWindowActive() const override;
|
bool isWindowActive() const override;
|
||||||
|
|
||||||
@ -94,6 +97,9 @@ namespace irr
|
|||||||
return EIDT_SDL;
|
return EIDT_SDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Get the display density in dots per inch.
|
||||||
|
float getDisplayDensity() const override;
|
||||||
|
|
||||||
void SwapWindow();
|
void SwapWindow();
|
||||||
|
|
||||||
//! Implementation of the linux cursor control
|
//! Implementation of the linux cursor control
|
||||||
|
Loading…
Reference in New Issue
Block a user