[DEV] correct the icon setting
This commit is contained in:
parent
3653ba1761
commit
33c4783bac
@ -120,7 +120,8 @@ std::string gale::Application::getTitle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void gale::Application::setIcon(const std::string& _iconFile) {
|
void gale::Application::setIcon(const std::string& _iconFile) {
|
||||||
|
gale::Context& context = gale::getContext();
|
||||||
|
context.setIcon(_iconFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string gale::Application::getIcon() {
|
std::string gale::Application::getIcon() {
|
||||||
|
@ -96,7 +96,9 @@ extern "C" {
|
|||||||
} Hints;
|
} Hints;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : #include <egami/egami.h>
|
#ifdef GALE_BUILD_EGAMI
|
||||||
|
#include <egami/egami.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <X11/cursorfont.h>
|
#include <X11/cursorfont.h>
|
||||||
|
|
||||||
@ -1060,142 +1062,141 @@ class X11Interface : public gale::Context {
|
|||||||
}
|
}
|
||||||
/****************************************************************************************/
|
/****************************************************************************************/
|
||||||
void setIcon(const std::string& _inputFile) {
|
void setIcon(const std::string& _inputFile) {
|
||||||
// TODO : ...
|
#ifdef GALE_BUILD_EGAMI
|
||||||
#if 0
|
egami::Image dataImage;
|
||||||
egami::Image dataImage;
|
// load data
|
||||||
// load data
|
if (false == egami::load(dataImage, _inputFile)) {
|
||||||
if (false == egami::load(dataImage, _inputFile)) {
|
GALE_ERROR("Error when loading Icon");
|
||||||
GALE_ERROR("Error when loading Icon");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int32_t depth = DefaultDepth(m_display, DefaultScreen(m_display) );
|
|
||||||
GALE_DEBUG("X11 Create icon size=(" << dataImage.getWidth() << "," << dataImage.getHeight() << ") depth=" << depth);
|
|
||||||
switch(depth) {
|
|
||||||
case 8:
|
|
||||||
GALE_CRITICAL("Not manage pixmap in 8 bit... == > no icon ...");
|
|
||||||
return;
|
return;
|
||||||
case 16:
|
}
|
||||||
break;
|
int32_t depth = DefaultDepth(m_display, DefaultScreen(m_display) );
|
||||||
case 24:
|
GALE_DEBUG("X11 Create icon size=(" << dataImage.getWidth() << "," << dataImage.getHeight() << ") depth=" << depth);
|
||||||
break;
|
switch(depth) {
|
||||||
case 32:
|
case 8:
|
||||||
break;
|
GALE_CRITICAL("Not manage pixmap in 8 bit... == > no icon ...");
|
||||||
default:
|
return;
|
||||||
GALE_CRITICAL("Unknow thys type of bitDepth : " << depth);
|
case 16:
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
break;
|
||||||
|
case 32:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
GALE_CRITICAL("Unknow thys type of bitDepth : " << depth);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char* tmpVal = new char[4*dataImage.getWidth()*dataImage.getHeight()];
|
||||||
|
if (nullptr == tmpVal) {
|
||||||
|
GALE_CRITICAL("Allocation error ...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char* tmpVal = new char[4*dataImage.getWidth()*dataImage.getHeight()];
|
char* tmpPointer = tmpVal;
|
||||||
if (nullptr == tmpVal) {
|
switch(depth) {
|
||||||
GALE_CRITICAL("Allocation error ...");
|
case 16:
|
||||||
return;
|
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
|
||||||
}
|
for(pos.setX(0); pos.x()<dataImage.getHeight(); pos.setX(pos.x()+1)) {
|
||||||
char* tmpPointer = tmpVal;
|
etk::Color<> tmpColor = dataImage.get(pos);
|
||||||
switch(depth) {
|
int16_t tmpVal = (((uint16_t)((uint16_t)tmpColor.r()>>3))<<11)
|
||||||
case 16:
|
+ (((uint16_t)((uint16_t)tmpColor.g()>>2))<<5)
|
||||||
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
|
+ ((uint16_t)((uint16_t)tmpColor.b()>>3));
|
||||||
for(pos.setX(0); pos.x()<dataImage.getHeight(); pos.setX(pos.x()+1)) {
|
*tmpPointer++ = (uint8_t)(tmpVal>>8);
|
||||||
etk::Color<> tmpColor = dataImage.get(pos);
|
*tmpPointer++ = (uint8_t)(tmpVal&0x00FF);
|
||||||
int16_t tmpVal = (((uint16_t)((uint16_t)tmpColor.r()>>3))<<11)
|
}
|
||||||
+ (((uint16_t)((uint16_t)tmpColor.g()>>2))<<5)
|
|
||||||
+ ((uint16_t)((uint16_t)tmpColor.b()>>3));
|
|
||||||
*tmpPointer++ = (uint8_t)(tmpVal>>8);
|
|
||||||
*tmpPointer++ = (uint8_t)(tmpVal&0x00FF);
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case 24:
|
||||||
case 24:
|
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
|
||||||
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
|
for(pos.setX(0); pos.x()<dataImage.getHeight(); pos.setX(pos.x()+1)) {
|
||||||
for(pos.setX(0); pos.x()<dataImage.getHeight(); pos.setX(pos.x()+1)) {
|
etk::Color<> tmpColor = dataImage.get(pos);
|
||||||
etk::Color<> tmpColor = dataImage.get(pos);
|
*tmpPointer++ = tmpColor.b();
|
||||||
*tmpPointer++ = tmpColor.b();
|
*tmpPointer++ = tmpColor.g();
|
||||||
*tmpPointer++ = tmpColor.g();
|
*tmpPointer++ = tmpColor.r();
|
||||||
*tmpPointer++ = tmpColor.r();
|
tmpPointer++;
|
||||||
tmpPointer++;
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case 32:
|
||||||
case 32:
|
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
|
||||||
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
|
for(pos.setX(0); pos.x()<dataImage.getHeight(); pos.setX(pos.x()+1)) {
|
||||||
for(pos.setX(0); pos.x()<dataImage.getHeight(); pos.setX(pos.x()+1)) {
|
etk::Color<> tmpColor = dataImage.get(pos);
|
||||||
etk::Color<> tmpColor = dataImage.get(pos);
|
*tmpPointer++ = tmpColor.a();
|
||||||
*tmpPointer++ = tmpColor.a();
|
*tmpPointer++ = tmpColor.b();
|
||||||
*tmpPointer++ = tmpColor.b();
|
*tmpPointer++ = tmpColor.g();
|
||||||
*tmpPointer++ = tmpColor.g();
|
*tmpPointer++ = tmpColor.r();
|
||||||
*tmpPointer++ = tmpColor.r();
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
XImage* myImage = XCreateImage(m_display,
|
||||||
|
m_visual->visual,
|
||||||
|
depth,
|
||||||
|
ZPixmap,
|
||||||
|
0,
|
||||||
|
(char*)tmpVal,
|
||||||
|
dataImage.getWidth(),
|
||||||
|
dataImage.getHeight(),
|
||||||
|
32,
|
||||||
|
0);
|
||||||
|
|
||||||
|
Pixmap tmpPixmap = XCreatePixmap(m_display, m_WindowHandle, dataImage.getWidth(), dataImage.getHeight(), depth);
|
||||||
|
switch(tmpPixmap) {
|
||||||
|
case BadAlloc:
|
||||||
|
GALE_ERROR("X11: BadAlloc");
|
||||||
|
break;
|
||||||
|
case BadDrawable:
|
||||||
|
GALE_ERROR("X11: BadDrawable");
|
||||||
|
break;
|
||||||
|
case BadValue:
|
||||||
|
GALE_ERROR("X11: BadValue");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
GALE_DEBUG("Create Pixmap OK");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
GC tmpGC = DefaultGC(m_display, DefaultScreen(m_display) );
|
||||||
|
int error = XPutImage(m_display, tmpPixmap, tmpGC, myImage, 0, 0, 0, 0, dataImage.getWidth(), dataImage.getHeight());
|
||||||
|
switch(error) {
|
||||||
|
case BadDrawable:
|
||||||
|
GALE_ERROR("X11: BadDrawable");
|
||||||
|
break;
|
||||||
|
case BadGC:
|
||||||
|
GALE_ERROR("X11: BadGC");
|
||||||
|
break;
|
||||||
|
case BadMatch:
|
||||||
|
GALE_ERROR("X11: BadMatch");
|
||||||
|
break;
|
||||||
|
case BadValue:
|
||||||
|
GALE_ERROR("X11: BadValue");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
GALE_DEBUG("insert image OK");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// allocate a WM hints structure.
|
||||||
|
XWMHints* win_hints = XAllocWMHints();
|
||||||
|
if (!win_hints) {
|
||||||
|
GALE_ERROR("XAllocWMHints - out of memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// initialize the structure appropriately. first, specify which size hints we want to fill in. in our case - setting the icon's pixmap.
|
||||||
XImage* myImage = XCreateImage(m_display,
|
win_hints->flags = IconPixmapHint;
|
||||||
m_visual->visual,
|
// next, specify the desired hints data. in our case - supply the icon's desired pixmap.
|
||||||
depth,
|
win_hints->icon_pixmap = tmpPixmap;
|
||||||
ZPixmap,
|
// pass the hints to the window manager.
|
||||||
0,
|
XSetWMHints(m_display, m_WindowHandle, win_hints);
|
||||||
(char*)tmpVal,
|
GALE_INFO(" == > might be done ");
|
||||||
dataImage.getWidth(),
|
// finally, we can free the WM hints structure.
|
||||||
dataImage.getHeight(),
|
XFree(win_hints);
|
||||||
32,
|
|
||||||
0);
|
// Note when we free the pixmap ... the icon is removed ... == > this is a real memory leek ...
|
||||||
|
//XFreePixmap(m_display, tmpPixmap);
|
||||||
Pixmap tmpPixmap = XCreatePixmap(m_display, m_WindowHandle, dataImage.getWidth(), dataImage.getHeight(), depth);
|
|
||||||
switch(tmpPixmap) {
|
myImage->data = nullptr;
|
||||||
case BadAlloc:
|
XDestroyImage(myImage);
|
||||||
GALE_ERROR("X11: BadAlloc");
|
delete[] tmpVal;
|
||||||
break;
|
|
||||||
case BadDrawable:
|
|
||||||
GALE_ERROR("X11: BadDrawable");
|
|
||||||
break;
|
|
||||||
case BadValue:
|
|
||||||
GALE_ERROR("X11: BadValue");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GALE_DEBUG("Create Pixmap OK");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
GC tmpGC = DefaultGC(m_display, DefaultScreen(m_display) );
|
|
||||||
int error = XPutImage(m_display, tmpPixmap, tmpGC, myImage, 0, 0, 0, 0, dataImage.getWidth(), dataImage.getHeight());
|
|
||||||
switch(error) {
|
|
||||||
case BadDrawable:
|
|
||||||
GALE_ERROR("X11: BadDrawable");
|
|
||||||
break;
|
|
||||||
case BadGC:
|
|
||||||
GALE_ERROR("X11: BadGC");
|
|
||||||
break;
|
|
||||||
case BadMatch:
|
|
||||||
GALE_ERROR("X11: BadMatch");
|
|
||||||
break;
|
|
||||||
case BadValue:
|
|
||||||
GALE_ERROR("X11: BadValue");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GALE_DEBUG("insert image OK");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// allocate a WM hints structure.
|
|
||||||
XWMHints* win_hints = XAllocWMHints();
|
|
||||||
if (!win_hints) {
|
|
||||||
GALE_ERROR("XAllocWMHints - out of memory");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// initialize the structure appropriately. first, specify which size hints we want to fill in. in our case - setting the icon's pixmap.
|
|
||||||
win_hints->flags = IconPixmapHint;
|
|
||||||
// next, specify the desired hints data. in our case - supply the icon's desired pixmap.
|
|
||||||
win_hints->icon_pixmap = tmpPixmap;
|
|
||||||
// pass the hints to the window manager.
|
|
||||||
XSetWMHints(m_display, m_WindowHandle, win_hints);
|
|
||||||
GALE_INFO(" == > might be done ");
|
|
||||||
// finally, we can free the WM hints structure.
|
|
||||||
XFree(win_hints);
|
|
||||||
|
|
||||||
// Note when we free the pixmap ... the icon is removed ... == > this is a real memory leek ...
|
|
||||||
//XFreePixmap(m_display, tmpPixmap);
|
|
||||||
|
|
||||||
myImage->data = nullptr;
|
|
||||||
XDestroyImage(myImage);
|
|
||||||
delete[] tmpVal;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/****************************************************************************************/
|
/****************************************************************************************/
|
||||||
|
@ -36,6 +36,8 @@ def create(target):
|
|||||||
])
|
])
|
||||||
if target.name=="Linux":
|
if target.name=="Linux":
|
||||||
myModule.add_src_file('gale/context/X11/Context.cpp')
|
myModule.add_src_file('gale/context/X11/Context.cpp')
|
||||||
|
# check if egami is present in the worktree: this is for the icon parsing ...
|
||||||
|
myModule.add_optionnal_module_depend('egami', ["c++", "-DGALE_BUILD_EGAMI"])
|
||||||
elif target.name=="Windows":
|
elif target.name=="Windows":
|
||||||
myModule.add_src_file('gale/context/Windows/Context.cpp')
|
myModule.add_src_file('gale/context/Windows/Context.cpp')
|
||||||
elif target.name=="Android":
|
elif target.name=="Android":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user