This commit is contained in:
rti 2010-07-14 16:52:34 +02:00
commit 5f9da63b41
10 changed files with 139 additions and 13 deletions

View file

@ -186,6 +186,9 @@ public:
/// Set the title of the NeL window
virtual void setWindowTitle(const ucstring &title)=0;
/// Set icon(s) of the NeL window
virtual void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)=0;
/// Set the position of the NeL window
virtual void setWindowPos(sint32 x, sint32 y)=0;

View file

@ -148,6 +148,9 @@ public:
/// Set the title of the NeL window
virtual void setWindowTitle(const ucstring &title);
/// Set icon(s) of the NeL window
virtual void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps);
/// Set the position of the NeL window
virtual void setWindowPos(sint32 x, sint32 y);

View file

@ -186,6 +186,9 @@ public:
/// Set the title of the NeL window
virtual void setWindowTitle(const ucstring &title)=0;
/// Set icon(s) of the NeL window
virtual void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)=0;
/// Set the position of the NeL window
virtual void setWindowPos(sint32 x, sint32 y)=0;

View file

@ -34,7 +34,7 @@ namespace NL3D
{
// ***************************************************************************
const uint32 IDriver::InterfaceVersion = 0x67; // changed window pos from uint32 to sint32
const uint32 IDriver::InterfaceVersion = 0x68; // added setWindowIcon
// ***************************************************************************
IDriver::IDriver() : _SyncTexDrvInfos( "IDriver::_SyncTexDrvInfos" )

View file

@ -1712,6 +1712,10 @@ bool CDriverD3D::release()
if (_HWnd)
{
// make sure window icons are deleted
std::vector<NLMISC::CBitmap> bitmaps;
setWindowIcon(bitmaps);
if (_DestroyWindow)
DestroyWindow (_HWnd);
_HWnd = NULL;
@ -2177,6 +2181,73 @@ void CDriverD3D::setWindowTitle(const ucstring &title)
SetWindowTextW(_HWnd,(WCHAR*)title.c_str());
}
// ***************************************************************************
void CDriverD3D::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
{
if (!_HWnd)
return;
static HICON winIconBig = NULL;
static HICON winIconSmall = NULL;
if (winIconBig)
{
DestroyIcon(winIconBig);
winIconBig = NULL;
}
if (winIconSmall)
{
DestroyIcon(winIconSmall);
winIconSmall = NULL;
}
sint smallIndex = -1;
uint smallWidth = GetSystemMetrics(SM_CXSMICON);
uint smallHeight = GetSystemMetrics(SM_CYSMICON);
sint bigIndex = -1;
uint bigWidth = GetSystemMetrics(SM_CXICON);
uint bigHeight = GetSystemMetrics(SM_CYICON);
// find icons with the exact size
for(uint i = 0; i < bitmaps.size(); ++i)
{
if (smallIndex == -1 && bitmaps[i].getWidth() == smallWidth && bitmaps[i].getHeight() == smallHeight)
smallIndex = i;
if (bigIndex == -1 && bitmaps[i].getWidth() == bigWidth && bitmaps[i].getHeight() == bigHeight)
bigIndex = i;
}
// find icons with taller size (we will resize them)
for(uint i = 0; i < bitmaps.size(); ++i)
{
if (smallIndex == -1 && bitmaps[i].getWidth() >= smallWidth && bitmaps[i].getHeight() >= smallHeight)
smallIndex = i;
if (bigIndex == -1 && bitmaps[i].getWidth() >= bigWidth && bitmaps[i].getHeight() >= bigHeight)
bigIndex = i;
}
if (smallIndex > -1)
winIconSmall = bitmaps[smallIndex].getHICON(smallWidth, smallHeight, 32);
if (bigIndex > -1)
winIconBig = bitmaps[bigIndex].getHICON(bigWidth, bigHeight, 32);
if (winIconBig)
{
SendMessage(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall);
SendMessage(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig);
}
else
{
SendMessage(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall);
SendMessage(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall);
}
}
// ***************************************************************************
void CDriverD3D::setWindowPos(sint32 x, sint32 y)
{

View file

@ -759,6 +759,9 @@ public:
/// Set the title of the NeL window
virtual void setWindowTitle(const ucstring &title);
/// Set icon(s) of the NeL window
virtual void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps);
/// Set the position of the NeL window
virtual void setWindowPos(sint32 x, sint32 y);

View file

@ -294,10 +294,13 @@ public:
virtual void beginDialogMode();
virtual void endDialogMode();
/// Set the title of the NeL window
/// Set title of the NeL window
virtual void setWindowTitle(const ucstring &title);
/// Set the position of the NeL window
/// Set icon(s) of the NeL window
virtual void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps);
/// Set position of the NeL window
virtual void setWindowPos(sint32 x, sint32 y);
/// Show or hide the NeL window
@ -850,8 +853,6 @@ private:
bool createWindow(const GfxMode& mode);
bool destroyWindow();
void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps);
enum EWindowStyle { EWSWindowed, EWSFullscreen };
void setWindowSize(uint32 width, uint32 height);

View file

@ -300,6 +300,9 @@ bool CDriverGL::unInit()
void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
{
if (_win == EmptyWindow)
return;
#if defined(NL_OS_WINDOWS)
static HICON winIconBig = NULL;
@ -317,13 +320,39 @@ void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
winIconSmall = NULL;
}
// first bitmap is the small icon
if (bitmaps.size() > 0)
winIconSmall = bitmaps[0].getHICON(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 32);
sint smallIndex = -1;
uint smallWidth = GetSystemMetrics(SM_CXSMICON);
uint smallHeight = GetSystemMetrics(SM_CYSMICON);
// second bitmap is the big icon
if (bitmaps.size() > 1)
winIconBig = bitmaps[1].getHICON(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 32);
sint bigIndex = -1;
uint bigWidth = GetSystemMetrics(SM_CXICON);
uint bigHeight = GetSystemMetrics(SM_CYICON);
// find icons with the exact size
for(uint i = 0; i < bitmaps.size(); ++i)
{
if (smallIndex == -1 && bitmaps[i].getWidth() == smallWidth && bitmaps[i].getHeight() == smallHeight)
smallIndex = i;
if (bigIndex == -1 && bitmaps[i].getWidth() == bigWidth && bitmaps[i].getHeight() == bigHeight)
bigIndex = i;
}
// find icons with taller size (we will resize them)
for(uint i = 0; i < bitmaps.size(); ++i)
{
if (smallIndex == -1 && bitmaps[i].getWidth() >= smallWidth && bitmaps[i].getHeight() >= smallHeight)
smallIndex = i;
if (bigIndex == -1 && bitmaps[i].getWidth() >= bigWidth && bitmaps[i].getHeight() >= bigHeight)
bigIndex = i;
}
if (smallIndex > -1)
winIconSmall = bitmaps[smallIndex].getHICON(smallWidth, smallHeight, 32);
if (bigIndex > -1)
winIconBig = bitmaps[bigIndex].getHICON(bigWidth, bigHeight, 32);
if (winIconBig)
{
@ -338,7 +367,7 @@ void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
#elif defined(NL_OS_MAC)
// TODO
// nothing to do
#elif defined(NL_OS_UNIX)

View file

@ -332,6 +332,13 @@ void CDriverUser::setWindowTitle(const ucstring &title)
_Driver->setWindowTitle(title);
}
// ***************************************************************************
void CDriverUser::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
{
NL3D_HAUTO_UI_DRIVER;
_Driver->setWindowIcon(bitmaps);
}
// ***************************************************************************
void CDriverUser::setWindowPos(sint32 x, sint32 y)
{

View file

@ -4112,9 +4112,15 @@ void CBitmap::getDibData(uint8*& extractData)
HICON CBitmap::getHICON(sint iconWidth, sint iconHeight, sint iconDepth, const NLMISC::CRGBA &col, sint hotSpotX, sint hotSpotY, bool cursor) const
{
HICON result = NULL;
CBitmap src = *this;
// resample bitmap if necessary
if (_Width != iconWidth || _Height != iconHeight)
{
src.resample(iconWidth, iconHeight);
}
CBitmap colorBm;
colorBm.resize(iconWidth, iconHeight, CBitmap::RGBA);
const CRGBA *srcColorPtr = (CRGBA *) &(getPixels()[0]);
const CRGBA *srcColorPtr = (CRGBA *) &(src.getPixels()[0]);
const CRGBA *srcColorPtrLast = srcColorPtr + (iconWidth * iconHeight);
CRGBA *destColorPtr = (CRGBA *) &(colorBm.getPixels()[0]);
static volatile uint8 alphaThreshold = 127;