mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-27 01:06:19 +00:00
Fixed: #1019 Add public setWindowIcon method to UDriver
This commit is contained in:
parent
5b2600003b
commit
4775af45e2
10 changed files with 139 additions and 13 deletions
|
@ -186,6 +186,9 @@ public:
|
||||||
/// Set the title of the NeL window
|
/// Set the title of the NeL window
|
||||||
virtual void setWindowTitle(const ucstring &title)=0;
|
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
|
/// Set the position of the NeL window
|
||||||
virtual void setWindowPos(sint32 x, sint32 y)=0;
|
virtual void setWindowPos(sint32 x, sint32 y)=0;
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,9 @@ public:
|
||||||
/// Set the title of the NeL window
|
/// Set the title of the NeL window
|
||||||
virtual void setWindowTitle(const ucstring &title);
|
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
|
/// Set the position of the NeL window
|
||||||
virtual void setWindowPos(sint32 x, sint32 y);
|
virtual void setWindowPos(sint32 x, sint32 y);
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,9 @@ public:
|
||||||
/// Set the title of the NeL window
|
/// Set the title of the NeL window
|
||||||
virtual void setWindowTitle(const ucstring &title)=0;
|
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
|
/// Set the position of the NeL window
|
||||||
virtual void setWindowPos(sint32 x, sint32 y)=0;
|
virtual void setWindowPos(sint32 x, sint32 y)=0;
|
||||||
|
|
||||||
|
|
|
@ -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" )
|
IDriver::IDriver() : _SyncTexDrvInfos( "IDriver::_SyncTexDrvInfos" )
|
||||||
|
|
|
@ -1712,6 +1712,10 @@ bool CDriverD3D::release()
|
||||||
|
|
||||||
if (_HWnd)
|
if (_HWnd)
|
||||||
{
|
{
|
||||||
|
// make sure window icons are deleted
|
||||||
|
std::vector<NLMISC::CBitmap> bitmaps;
|
||||||
|
setWindowIcon(bitmaps);
|
||||||
|
|
||||||
if (_DestroyWindow)
|
if (_DestroyWindow)
|
||||||
DestroyWindow (_HWnd);
|
DestroyWindow (_HWnd);
|
||||||
_HWnd = NULL;
|
_HWnd = NULL;
|
||||||
|
@ -2177,6 +2181,73 @@ void CDriverD3D::setWindowTitle(const ucstring &title)
|
||||||
SetWindowTextW(_HWnd,(WCHAR*)title.c_str());
|
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)
|
void CDriverD3D::setWindowPos(sint32 x, sint32 y)
|
||||||
{
|
{
|
||||||
|
|
|
@ -759,6 +759,9 @@ public:
|
||||||
/// Set the title of the NeL window
|
/// Set the title of the NeL window
|
||||||
virtual void setWindowTitle(const ucstring &title);
|
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
|
/// Set the position of the NeL window
|
||||||
virtual void setWindowPos(sint32 x, sint32 y);
|
virtual void setWindowPos(sint32 x, sint32 y);
|
||||||
|
|
||||||
|
|
|
@ -294,10 +294,13 @@ public:
|
||||||
virtual void beginDialogMode();
|
virtual void beginDialogMode();
|
||||||
virtual void endDialogMode();
|
virtual void endDialogMode();
|
||||||
|
|
||||||
/// Set the title of the NeL window
|
/// Set title of the NeL window
|
||||||
virtual void setWindowTitle(const ucstring &title);
|
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);
|
virtual void setWindowPos(sint32 x, sint32 y);
|
||||||
|
|
||||||
/// Show or hide the NeL window
|
/// Show or hide the NeL window
|
||||||
|
@ -850,8 +853,6 @@ private:
|
||||||
bool createWindow(const GfxMode& mode);
|
bool createWindow(const GfxMode& mode);
|
||||||
bool destroyWindow();
|
bool destroyWindow();
|
||||||
|
|
||||||
void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps);
|
|
||||||
|
|
||||||
enum EWindowStyle { EWSWindowed, EWSFullscreen };
|
enum EWindowStyle { EWSWindowed, EWSFullscreen };
|
||||||
|
|
||||||
void setWindowSize(uint32 width, uint32 height);
|
void setWindowSize(uint32 width, uint32 height);
|
||||||
|
|
|
@ -300,6 +300,9 @@ bool CDriverGL::unInit()
|
||||||
|
|
||||||
void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
|
void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
|
||||||
{
|
{
|
||||||
|
if (_win == EmptyWindow)
|
||||||
|
return;
|
||||||
|
|
||||||
#if defined(NL_OS_WINDOWS)
|
#if defined(NL_OS_WINDOWS)
|
||||||
|
|
||||||
static HICON winIconBig = NULL;
|
static HICON winIconBig = NULL;
|
||||||
|
@ -317,13 +320,39 @@ void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
|
||||||
winIconSmall = NULL;
|
winIconSmall = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// first bitmap is the small icon
|
sint smallIndex = -1;
|
||||||
if (bitmaps.size() > 0)
|
uint smallWidth = GetSystemMetrics(SM_CXSMICON);
|
||||||
winIconSmall = bitmaps[0].getHICON(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 32);
|
uint smallHeight = GetSystemMetrics(SM_CYSMICON);
|
||||||
|
|
||||||
// second bitmap is the big icon
|
sint bigIndex = -1;
|
||||||
if (bitmaps.size() > 1)
|
uint bigWidth = GetSystemMetrics(SM_CXICON);
|
||||||
winIconBig = bitmaps[1].getHICON(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 32);
|
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)
|
if (winIconBig)
|
||||||
{
|
{
|
||||||
|
@ -338,7 +367,7 @@ void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
|
||||||
|
|
||||||
#elif defined(NL_OS_MAC)
|
#elif defined(NL_OS_MAC)
|
||||||
|
|
||||||
// TODO
|
// nothing to do
|
||||||
|
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
|
|
||||||
|
|
|
@ -332,6 +332,13 @@ void CDriverUser::setWindowTitle(const ucstring &title)
|
||||||
_Driver->setWindowTitle(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)
|
void CDriverUser::setWindowPos(sint32 x, sint32 y)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 CBitmap::getHICON(sint iconWidth, sint iconHeight, sint iconDepth, const NLMISC::CRGBA &col, sint hotSpotX, sint hotSpotY, bool cursor) const
|
||||||
{
|
{
|
||||||
HICON result = NULL;
|
HICON result = NULL;
|
||||||
|
CBitmap src = *this;
|
||||||
|
// resample bitmap if necessary
|
||||||
|
if (_Width != iconWidth || _Height != iconHeight)
|
||||||
|
{
|
||||||
|
src.resample(iconWidth, iconHeight);
|
||||||
|
}
|
||||||
CBitmap colorBm;
|
CBitmap colorBm;
|
||||||
colorBm.resize(iconWidth, iconHeight, CBitmap::RGBA);
|
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);
|
const CRGBA *srcColorPtrLast = srcColorPtr + (iconWidth * iconHeight);
|
||||||
CRGBA *destColorPtr = (CRGBA *) &(colorBm.getPixels()[0]);
|
CRGBA *destColorPtr = (CRGBA *) &(colorBm.getPixels()[0]);
|
||||||
static volatile uint8 alphaThreshold = 127;
|
static volatile uint8 alphaThreshold = 127;
|
||||||
|
|
Loading…
Reference in a new issue