rombust
12-18-2008, 04:42 PM
While copying objects in ClanLib 0.9, we can use the following method:
CL_GraphicContext gc = display_window.get_gc();
CL_Font old_font = gc.get_font();
This has virtually no overhead, as all it does internally is copy the implementation pointer (ie the implementation itself is not copied)
This is useful. We can construct objects using the following method:
CL_Font my_font
my_font = CL_Font(gc, "Tahoma", 12);
...But...
We cannot do:
CL_PushButton button;
button = CL_PushButton(&gui_window);
As an appropriate constructor does not exist.
Is this intentional?
Any thoughts?
Note:
We have to be careful using the first method, as we can fall into the following trap:
void myfunction(const CL_DisplayWindowDescription &desc)
{
CL_DisplayWindowDescription copy_desc = desc;
copy_desc.set_width(100);
}
This would also change "desc". The compiler would not warn that we are modifying a const. (See http://en.wikipedia.org/wiki/Const_correctness#Loopholes_to_const-correctness )
This is why copy() was added to CL_FontDescription API
CL_GraphicContext gc = display_window.get_gc();
CL_Font old_font = gc.get_font();
This has virtually no overhead, as all it does internally is copy the implementation pointer (ie the implementation itself is not copied)
This is useful. We can construct objects using the following method:
CL_Font my_font
my_font = CL_Font(gc, "Tahoma", 12);
...But...
We cannot do:
CL_PushButton button;
button = CL_PushButton(&gui_window);
As an appropriate constructor does not exist.
Is this intentional?
Any thoughts?
Note:
We have to be careful using the first method, as we can fall into the following trap:
void myfunction(const CL_DisplayWindowDescription &desc)
{
CL_DisplayWindowDescription copy_desc = desc;
copy_desc.set_width(100);
}
This would also change "desc". The compiler would not warn that we are modifying a const. (See http://en.wikipedia.org/wiki/Const_correctness#Loopholes_to_const-correctness )
This is why copy() was added to CL_FontDescription API