Switch from Nz prefix to namespace Nz for linux
Former-commit-id: 64eeaf3c633254b04910ebd4576fd9e910002be0
This commit is contained in:
@@ -10,125 +10,128 @@
|
||||
#include <Nazara/Utility/X11/Display.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzIconImpl::NzIconImpl()
|
||||
namespace Nz
|
||||
{
|
||||
NzScopedXCBConnection connection;
|
||||
|
||||
m_iconPixmap.Connect(connection);
|
||||
m_maskPixmap.Connect(connection);
|
||||
}
|
||||
|
||||
bool NzIconImpl::Create(const NzImage& icon)
|
||||
{
|
||||
NzImage iconImage(icon); // Vive le COW
|
||||
if (!iconImage.Convert(nzPixelFormat_BGRA8))
|
||||
IconImpl::IconImpl()
|
||||
{
|
||||
NazaraError("Failed to convert icon to BGRA8");
|
||||
return false;
|
||||
ScopedXCBConnection connection;
|
||||
|
||||
m_iconPixmap.Connect(connection);
|
||||
m_maskPixmap.Connect(connection);
|
||||
}
|
||||
|
||||
auto width = iconImage.GetWidth();
|
||||
auto height = iconImage.GetHeight();
|
||||
|
||||
NzScopedXCBConnection connection;
|
||||
|
||||
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
|
||||
|
||||
if (!m_iconPixmap.Create(
|
||||
screen->root_depth,
|
||||
screen->root,
|
||||
width,
|
||||
height))
|
||||
bool IconImpl::Create(const Image& icon)
|
||||
{
|
||||
NazaraError("Failed to create icon pixmap");
|
||||
return false;
|
||||
}
|
||||
|
||||
NzCallOnExit onExit([this](){
|
||||
Destroy();
|
||||
});
|
||||
|
||||
NzXCBGContext iconGC(connection);
|
||||
|
||||
if (!iconGC.Create(
|
||||
m_iconPixmap,
|
||||
0,
|
||||
nullptr))
|
||||
{
|
||||
NazaraError("Failed to create icon gc");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!X11::CheckCookie(
|
||||
connection,
|
||||
xcb_put_image(
|
||||
connection,
|
||||
XCB_IMAGE_FORMAT_Z_PIXMAP,
|
||||
m_iconPixmap,
|
||||
iconGC,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
screen->root_depth,
|
||||
width * height * 4,
|
||||
iconImage.GetConstPixels()
|
||||
)))
|
||||
{
|
||||
NazaraError("Failed to put image for icon");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the mask pixmap (must have 1 bit depth)
|
||||
std::size_t pitch = (width + 7) / 8;
|
||||
static std::vector<nzUInt8> maskPixels(pitch * height, 0);
|
||||
for (std::size_t j = 0; j < height; ++j)
|
||||
{
|
||||
for (std::size_t i = 0; i < pitch; ++i)
|
||||
Image iconImage(icon); // Vive le COW
|
||||
if (!iconImage.Convert(Nz::PixelFormatType_BGRA8))
|
||||
{
|
||||
for (std::size_t k = 0; k < 8; ++k)
|
||||
NazaraError("Failed to convert icon to BGRA8");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto width = iconImage.GetWidth();
|
||||
auto height = iconImage.GetHeight();
|
||||
|
||||
ScopedXCBConnection connection;
|
||||
|
||||
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
|
||||
|
||||
if (!m_iconPixmap.Create(
|
||||
screen->root_depth,
|
||||
screen->root,
|
||||
width,
|
||||
height))
|
||||
{
|
||||
NazaraError("Failed to create icon pixmap");
|
||||
return false;
|
||||
}
|
||||
|
||||
CallOnExit onExit([this](){
|
||||
Destroy();
|
||||
});
|
||||
|
||||
XCBGContext iconGC(connection);
|
||||
|
||||
if (!iconGC.Create(
|
||||
m_iconPixmap,
|
||||
0,
|
||||
nullptr))
|
||||
{
|
||||
NazaraError("Failed to create icon gc");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!X11::CheckCookie(
|
||||
connection,
|
||||
xcb_put_image(
|
||||
connection,
|
||||
XCB_IMAGE_FORMAT_Z_PIXMAP,
|
||||
m_iconPixmap,
|
||||
iconGC,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
screen->root_depth,
|
||||
width * height * 4,
|
||||
iconImage.GetConstPixels()
|
||||
)))
|
||||
{
|
||||
NazaraError("Failed to put image for icon");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the mask pixmap (must have 1 bit depth)
|
||||
std::size_t pitch = (width + 7) / 8;
|
||||
static std::vector<UInt8> maskPixels(pitch * height, 0);
|
||||
for (std::size_t j = 0; j < height; ++j)
|
||||
{
|
||||
for (std::size_t i = 0; i < pitch; ++i)
|
||||
{
|
||||
if (i * 8 + k < width)
|
||||
for (std::size_t k = 0; k < 8; ++k)
|
||||
{
|
||||
nzUInt8 opacity = (iconImage.GetConstPixels()[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0;
|
||||
maskPixels[i + j * pitch] |= (opacity << k);
|
||||
if (i * 8 + k < width)
|
||||
{
|
||||
UInt8 opacity = (iconImage.GetConstPixels()[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0;
|
||||
maskPixels[i + j * pitch] |= (opacity << k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_maskPixmap.CreatePixmapFromBitmapData(
|
||||
X11::XCBDefaultRootWindow(connection),
|
||||
reinterpret_cast<uint8_t*>(&maskPixels[0]),
|
||||
width,
|
||||
height,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
nullptr))
|
||||
{
|
||||
NazaraError("Failed to create mask pixmap for icon");
|
||||
return false;
|
||||
}
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!m_maskPixmap.CreatePixmapFromBitmapData(
|
||||
X11::XCBDefaultRootWindow(connection),
|
||||
reinterpret_cast<uint8_t*>(&maskPixels[0]),
|
||||
width,
|
||||
height,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
nullptr))
|
||||
void IconImpl::Destroy()
|
||||
{
|
||||
NazaraError("Failed to create mask pixmap for icon");
|
||||
return false;
|
||||
m_iconPixmap.Destroy();
|
||||
m_maskPixmap.Destroy();
|
||||
}
|
||||
|
||||
onExit.Reset();
|
||||
xcb_pixmap_t IconImpl::GetIcon()
|
||||
{
|
||||
return m_iconPixmap;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzIconImpl::Destroy()
|
||||
{
|
||||
m_iconPixmap.Destroy();
|
||||
m_maskPixmap.Destroy();
|
||||
}
|
||||
|
||||
xcb_pixmap_t NzIconImpl::GetIcon()
|
||||
{
|
||||
return m_iconPixmap;
|
||||
}
|
||||
|
||||
xcb_pixmap_t NzIconImpl::GetMask()
|
||||
{
|
||||
return m_maskPixmap;
|
||||
xcb_pixmap_t IconImpl::GetMask()
|
||||
{
|
||||
return m_maskPixmap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user