What happens if we do not check if cairo context exists and what happens if returning false, for example:
bool MyClass::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
if ( !cr) return false; // what realy happens when we return false?
// is the function called once again?
}
// approach 2
bool MyClass::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
// do stuff
return true; // works just fine without checking so why to check??
}
What is the benefit and why would one check there is a context?
What happens if returning false?
This has documentation for virtual bool Gtk::Widget::on_draw(const::Cairo::RefPtr<::Cairo::Context>& cr)
. I'm assuming, you're overriding that or something similar. The documentation doesn't say anything about the return value, but states it's the default handler of Gtk::Widget::signal_draw(). Here's a quote from that documentation:
Returns
true to stop other handlers from being invoked for the event. % false to propagate the event further.
If cr
doesn't point to anything, then there's probably no point in invoking further handlers of the draw event. Then again, all handlers that actually use cr
should probably check it anyway, so I don't think cheking here is necessary. If you have a lot of handlers, returning true when none of them can work may reduce a bit of overhead. I'm guessing that the stopping of events is more useful for controlling the event flow on user action rather than the draw event.
Returning false only if cr
doesn't point to anything seems weird to me. Returning true without checking should prevent other handlers, so that's a bit strange also.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments