PDA

View Full Version : CL_DisplayWindow instance



Pap
06-10-2013, 07:36 PM
Hello ClanLib community,

Just starting using ClanLib, and I must say I am impressed by the amount of the features implemented. The only problem is the lack of extensive documentation. To the best of my knowledge, there are a few tutorials covering the basics, some examples in the ClanLib distribution, and of course the doxygen-generated documentation; unfortunately, the "SEARCHENGINE" flag in clanlib.doxygen must be turned off (well, it can be set to "YES" but the resulting javascript-powered search engine is very slow due to the huge amount of entries.) So it needs quite some time to get used to ClanLib; for example, it took me some time to figure out why set_alpha() in CL_Colorf didn't work (I had to set_subpixel(false) but such information was available in an example, not in the main ClanLib documentation.) I realize, of course, that writing an extensive documentation covering everything is extremely time-consuming and needs constant updating.

Anyway, here is my question (couldn't find an answer in the examples and doxygen documentation): For several practical reasons, I want to define a null instance of CL_DisplayWindow, say

CL_DisplayWindow window;
as a private variable in a class, then, in an initialization function, set window attributes, say

window.set_size(800,600,true);
window.set_title("ClanLib test");
window.set_small_icon(CL_ImageProviderFactory::loa d("icon_small.png",""));
window.set_large_icon(CL_ImageProviderFactory::loa d("icon_large.png",""));
then display the window as usual. For some reason, I get a segmentation fault when I try to do that (code compiles without any problem.) The reason I want such an implementation is to avoid passing the CL_DisplayWindow in all class functions that use it (for drawing text, graphics, etc.)
So, my question is, once I declare a null instance of a CL_DisplayWindow and set its attributes, what else do I need to do to display it?

An obvious workaround is to set up a temporary CL_DisplayWindow then copy it to the actual one, something like

CL_DisplayWindow window;
...
...
...
CL_DisplayWindowDescription window_desc;
window_desc.set_size(CL_Size(800,600),true);
window_desc.set_title("ClanLib test");
CL_DisplayWindow temp_window(window_desc);
temp_window.set_small_icon(CL_ImageProviderFactory ::load("icon_small.png",""));
temp_window.set_large_icon(CL_ImageProviderFactory ::load("icon_large.png",""));

window=temp_window;
but I'm not sure I can safely do window=temp_window in the end.

Judas
06-10-2013, 10:04 PM
Most classes in ClanLib are what I like to call handle classes. You can recognize a handle class in ClanLib if it has only a single private shared_ptr variable member. Handle classes usually have an empty constructor and a is_null() function. They are a (somewhat futile) attempt at improving code visuals for shared_ptr objects, where you still construct them with constructors and use . rather than -> to call functions.

Since CL_DisplayWindow is a handle class, when you construct it with the default constructor you get a null object (the std::shared_ptr member points at nothing). Except for calling is_null(), the object cannot be safely used until you assign it another handle:


CL_DisplayWindow my_window;

my_window.is_null(); // returns true

my_window = CL_DisplayWindow(description);

my_window.is_null(); // returns false

Because handle objects are effectively std::shared_ptr objects, you can safely assign it to as many variables as you want - they all point at the same handle in the end.

Pap
06-10-2013, 10:23 PM
Except for calling is_null(), the object cannot be safely used until you assign it another handle:
...
Because handle objects are effectively std::shared_ptr objects, you can safely assign it to as many variables as you want - they all point at the same handle in the end.
Thank you for the tip :)
Worked out of the box, so my code above is now

CL_DisplayWindow window;
...
...
...
CL_DisplayWindowDescription window_desc;
window_desc.set_size(CL_Size(800,600),true);
window_desc.set_title("ClanLib test");
window=CL_DisplayWindow(window_desc);
window.set_large_icon(CL_ImageProviderFactory::loa d("icon_large.png",""));
window.set_small_icon(CL_ImageProviderFactory::loa d("icon_small.png",""));

and works as expected... except small icon is not visible in window's title bar. I suspect it has to do with my Window Manager? (LXDE on a Debian Linux 64-bit box; at the moment I cannot test it on another window manager / operating system)

rombust
06-11-2013, 07:04 AM
Looking at the code, I don't think it has been implemented, since we have: (in Display/X11/x11_window.cpp)



void X11Window::set_small_icon(const PixelBuffer &image)
{
set_large_icon(image);
}

Pap
06-11-2013, 09:07 AM
According to this (http://www.rtsoft.com/forums/showthread.php?5738-Patch-X11-window-icons&highlight=set_large_icon) patch, set_large_icon() should work; I assume it has to do with the large icons one can see while changing window focus (via Alt+Tab or otherwise.) However, set_large_icon() doesn't have any effect as well. Having a look at the code, I see that both set_large_icon() and set_small_icon() are not really implemented in ClanLib-2.3.6/Sources/Display/X11/x11_window.cpp; they are both declared but implementation is empty. Not even the code below is present:
Looking at the code, I don't think it has been implemented, since we have: (in Display/X11/x11_window.cpp)

void X11Window::set_small_icon(const PixelBuffer &image)
{
set_large_icon(image);
}

rombust
06-12-2013, 11:11 AM
Ah, that's because we desperately need a ClanLib 2.3.7 release.

ClanLib 2.3 was patched after the last release.