[gtkmm-documentation] custom_widget example: Correct the coordinates in on_draw()



commit fe6a4f3dd1a7eb4b44fb5f7e494420942cf89070
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Tue Jan 24 16:23:01 2017 +0100

    custom_widget example: Correct the coordinates in on_draw()
    
    Use both clip and allocation as in gtkwidget.c. Otherwise the background
    is correctly painted only if the widget is located in the upper lefthand
    corner of the window.

 examples/book/custom/custom_widget/mywidget.cc |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index 71afcce..bcdaf25 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -172,14 +172,16 @@ void MyWidget::on_unrealize()
 bool MyWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
 {
   const Gtk::Allocation allocation = get_allocation();
-  const double scale_x = (double)allocation.get_width() / m_scale;
-  const double scale_y = (double)allocation.get_height() / m_scale;
+  Gtk::Allocation clip = get_clip();
+  clip.set_x(clip.get_x() - allocation.get_x());
+  clip.set_y(clip.get_y() - allocation.get_y());
+  const double scale_x = (double)clip.get_width() / m_scale;
+  const double scale_y = (double)clip.get_height() / m_scale;
   auto refStyleContext = get_style_context();
 
   // paint the background
   refStyleContext->render_background(cr,
-    allocation.get_x(), allocation.get_y(),
-    allocation.get_width(), allocation.get_height());
+    clip.get_x(), clip.get_y(), clip.get_width(), clip.get_height());
 
   // draw the foreground
   Gdk::Cairo::set_source_rgba(cr, refStyleContext->get_color());


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