port-to-gtk3: Use draw signal in the partition visualizer (#7)

In Gtk2 widgets draw themselves in response to the expose event signal.
In Gtk3 widgets draw themselves in response to the GtkWidget::draw
signal, and the signal handler gets a Cairo context as an argument.

Convert Gtk::DrawingArea rendering code to respond to the
GtkWidget::draw signal.

This commit is specific to the drawing area contained in the main
application window (also called the DrawingAreaVisualDisk).

Reference:

[1] Migrating from GTK+ 2.x to GTK+ 3 - "The GtkWidget::draw signal":
    https://developer.gnome.org/gtk3/stable/ch26s02.html#id-1.6.3.4.11

Closes #7 - Port to Gtk3
This commit is contained in:
Luca Bacci 2018-08-03 19:31:11 +02:00 committed by Mike Fleetwood
parent 4c1fe3bf7a
commit 93b1425549
2 changed files with 3 additions and 15 deletions

View File

@ -65,7 +65,7 @@ private:
int spreadout_leftover_px( std::vector<visual_partition> & visual_partitions, int pixels ) ; int spreadout_leftover_px( std::vector<visual_partition> & visual_partitions, int pixels ) ;
//overridden signalhandlers //overridden signalhandlers
bool on_expose_event( GdkEventExpose * event ) ; bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
bool on_button_press_event( GdkEventButton * event ) ; bool on_button_press_event( GdkEventButton * event ) ;
void on_size_allocate( Gtk::Allocation & allocation ) ; void on_size_allocate( Gtk::Allocation & allocation ) ;

View File

@ -314,21 +314,9 @@ void DrawingAreaVisualDisk::set_selected( const std::vector<visual_partition> &
} }
bool DrawingAreaVisualDisk::on_expose_event( GdkEventExpose * event ) bool DrawingAreaVisualDisk::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{ {
bool ret_val = Gtk::DrawingArea::on_expose_event( event ) ; bool ret_val = Gtk::DrawingArea::on_draw(cr);
Glib::RefPtr<Gdk::Window> window = get_window();
if (!window)
return true;
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
// Clip to the area indicated by the expose event so that we only redraw
// the portion of the window that needs to be redrawn.
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
cr->clip();
cr->set_line_width(2.0); cr->set_line_width(2.0);
cr->set_line_join(Cairo::LINE_JOIN_MITER); // default cr->set_line_join(Cairo::LINE_JOIN_MITER); // default