diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 6428baab5..2a0d061fd 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -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 &bitmaps)=0; + /// Set the position of the NeL window virtual void setWindowPos(sint32 x, sint32 y)=0; diff --git a/code/nel/include/nel/3d/driver_user.h b/code/nel/include/nel/3d/driver_user.h index 1bda23c27..699691d89 100644 --- a/code/nel/include/nel/3d/driver_user.h +++ b/code/nel/include/nel/3d/driver_user.h @@ -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 &bitmaps); + /// Set the position of the NeL window virtual void setWindowPos(sint32 x, sint32 y); diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h index 4e7b2eb05..ce421b46d 100644 --- a/code/nel/include/nel/3d/u_driver.h +++ b/code/nel/include/nel/3d/u_driver.h @@ -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 &bitmaps)=0; + /// Set the position of the NeL window virtual void setWindowPos(sint32 x, sint32 y)=0; diff --git a/code/nel/src/3d/driver.cpp b/code/nel/src/3d/driver.cpp index d8a195c3a..39d72c7c3 100644 --- a/code/nel/src/3d/driver.cpp +++ b/code/nel/src/3d/driver.cpp @@ -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" ) diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp index 3986e8e26..e096a4d00 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -1712,6 +1712,10 @@ bool CDriverD3D::release() if (_HWnd) { + // make sure window icons are deleted + std::vector 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 &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) { diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index 52dca1dc5..ccd414782 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -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 &bitmaps); + /// Set the position of the NeL window virtual void setWindowPos(sint32 x, sint32 y); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index 2783c8bf3..18397d61b 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -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 &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 &bitmaps); - enum EWindowStyle { EWSWindowed, EWSFullscreen }; void setWindowSize(uint32 width, uint32 height); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp index d698285aa..3fecf8188 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -300,6 +300,9 @@ bool CDriverGL::unInit() void CDriverGL::setWindowIcon(const std::vector &bitmaps) { + if (_win == EmptyWindow) + return; + #if defined(NL_OS_WINDOWS) static HICON winIconBig = NULL; @@ -317,13 +320,39 @@ void CDriverGL::setWindowIcon(const std::vector &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 &bitmaps) #elif defined(NL_OS_MAC) - // TODO + // nothing to do #elif defined(NL_OS_UNIX) diff --git a/code/nel/src/3d/driver_user.cpp b/code/nel/src/3d/driver_user.cpp index ea8a44e83..523aaf4ba 100644 --- a/code/nel/src/3d/driver_user.cpp +++ b/code/nel/src/3d/driver_user.cpp @@ -332,6 +332,13 @@ void CDriverUser::setWindowTitle(const ucstring &title) _Driver->setWindowTitle(title); } +// *************************************************************************** +void CDriverUser::setWindowIcon(const std::vector &bitmaps) +{ + NL3D_HAUTO_UI_DRIVER; + _Driver->setWindowIcon(bitmaps); +} + // *************************************************************************** void CDriverUser::setWindowPos(sint32 x, sint32 y) { diff --git a/code/nel/src/misc/bitmap.cpp b/code/nel/src/misc/bitmap.cpp index 1a25da141..4a97a004d 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -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;