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



commit 93b14255495f29efef6767370905bfa6ec90204d
Author: Luca Bacci <luca bacci982 gmail com>
Date:   Fri Aug 3 19:31:11 2018 +0200

    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

 include/DrawingAreaVisualDisk.h |  2 +-
 src/DrawingAreaVisualDisk.cc    | 16 ++--------------
 2 files changed, 3 insertions(+), 15 deletions(-)
---
diff --git a/include/DrawingAreaVisualDisk.h b/include/DrawingAreaVisualDisk.h
index d7f6ee49..226051dd 100644
--- a/include/DrawingAreaVisualDisk.h
+++ b/include/DrawingAreaVisualDisk.h
@@ -65,7 +65,7 @@ private:
        int spreadout_leftover_px( std::vector<visual_partition> & visual_partitions, int pixels ) ;
        
        //overridden signalhandlers
-       bool on_expose_event( GdkEventExpose * event ) ;
+       bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
        bool on_button_press_event( GdkEventButton * event ) ;
        void on_size_allocate( Gtk::Allocation & allocation ) ;
 
diff --git a/src/DrawingAreaVisualDisk.cc b/src/DrawingAreaVisualDisk.cc
index 2b0069ff..6589a842 100644
--- a/src/DrawingAreaVisualDisk.cc
+++ b/src/DrawingAreaVisualDisk.cc
@@ -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 ) ;
-       
-       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();
+       bool ret_val = Gtk::DrawingArea::on_draw(cr);
 
        cr->set_line_width(2.0);
        cr->set_line_join(Cairo::LINE_JOIN_MITER);  // default


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]