gtkmm: Gtk::WidgetCustomDraw Class Reference

gtkmm 3.89.5.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | List of all members
Gtk::WidgetCustomDraw Class Reference
Widgets

Widget with signal_draw(). More...

`#include <gtkmm/widgetcustomdraw.h>`

Inheritance diagram for Gtk::WidgetCustomDraw:
[legend]

## Public Member Functions
| WidgetCustomDraw ()
Glib::SignalProxy< bool(const ::Cairo::RefPtr< ::Cairo::Context >&)> | signal_draw ()
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src)
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src)
void | remove_destroy_notify_callback (void *data) const

## Protected Member Functions
virtual bool | on_draw (const ::Cairo::RefPtr< ::Cairo::Context >& cr)
| This is a default handler for signal_draw(). More...
Protected Member Functions inherited from Glib::ExtraClassInit
| ExtraClassInit (GClassInitFunc class_init_func, void *class_data=nullptr, GInstanceInitFunc instance_init_func=nullptr)
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)

## Additional Inherited Members
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify

## Detailed Description

Widget with signal_draw().

Because of the way gtk+4 renders widgets, Gtk::Widget can't wrap the draw signal. If you make a custom widget that uses the draw signal, you must derive your custom widget from both WidgetCustomDraw and the relevant widget class. E.g. if you make a custom widget that you want to derive from Gtk::Widget, and you want to connect to signal_draw() or override the on_draw() default signal handler:

#include <gtkmm/widgetcustomdraw.h>
class MyWidget : public Gtk::WidgetCustomDraw, public Gtk::Widget
{
public:
MyWidget()
:
// The GType name will be gtkmm__CustomObject_MyMidget
Glib::ObjectBase("MyWidget"), // Unique class name
Gtk::WidgetCustomDraw(),
Gtk::Widget()
{
// ...
}
// ...
protected:
bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
// ...
};

WidgetCustomDraw must be listed before the widget class (Gtk::Widget in the example) in the list of base classes.

Do not use WidgetCustomDraw for drawing in a Gtk::DrawingArea. Gtk::DrawingArea uses a draw function instead of signal_draw(). See Gtk::DrawingArea::set_draw_func().

Don't derive from both WidgetCustomDraw and WidgetCustomSnapshot in the same class. It will compile, but probably at most one of signal_draw() and snapshot_vfunc() will work.

Since gtkmm 3.90:

## Constructor & Destructor Documentation

Gtk::WidgetCustomDraw::WidgetCustomDraw | ( |  | ) |

## Member Function Documentation

virtual bool Gtk::WidgetCustomDraw::on_draw | ( | const ::Cairo::RefPtr< ::Cairo::Context > & | cr | ) |
| protectedvirtual

This is a default handler for signal_draw().

Glib::SignalProxy<bool(const ::Cairo::RefPtr< ::Cairo::Context>&)> Gtk::WidgetCustomDraw::signal_draw | ( |  | ) |

Slot Prototype:
  `bool on_my_draw(const Cairo::RefPtr< ::Cairo::Context>& cr)`

This signal is emitted when a widget is supposed to render itself. The widget's top left corner must be painted at the origin of the passed in context and be sized to the values returned by Gtk::Widget::get_allocated_width() and Gtk::Widget::get_allocated_height().

Signal handlers connected to this signal can modify the cairo context passed as cr in any way they like and don't need to restore it. The signal emission takes care of calling cairo_save() before and cairo_restore() after invoking the handler.

The signal handler will get a cr with a clip region already set to the widget's dirty region, i.e. to the area that needs repainting. Complicated widgets that want to avoid redrawing themselves completely can get the full extents of the clip region with Cairo::Context::get_clip_extents(), or they can get a finer-grained representation of the dirty region with Cairo::Context::copy_clip_rectangle_list().

Parameters

  cr | The cairo context to draw to.

Returns
  `true` to stop other handlers from being invoked for the event. `false` to propagate the event further.