[gtkmm-documentation] Custom widget example: Avoid some warnings
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Custom widget example: Avoid some warnings
- Date: Tue, 26 Jan 2016 19:11:15 +0000 (UTC)
commit a359bd4f64afde97dad0b7bee9097876b5c524db
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Tue Jan 26 20:08:30 2016 +0100
Custom widget example: Avoid some warnings
When drawing the foreground, get the color for the current widget state.
Trying to get the color for another state triggers a warning from
gtk_style_context_get_property().
examples/book/custom/custom_widget/mywidget.cc | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index 02f71a1..0a263f6 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -185,14 +185,16 @@ 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;
+ auto refStyleContext = get_style_context();
// paint the background
- get_style_context()->render_background(cr,
+ refStyleContext->render_background(cr,
allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height());
// draw the foreground
- Gdk::Cairo::set_source_rgba(cr, get_style_context()->get_color());
+ const auto state = refStyleContext->get_state();
+ Gdk::Cairo::set_source_rgba(cr, refStyleContext->get_color(state));
cr->move_to(155.*scale_x, 165.*scale_y);
cr->line_to(155.*scale_x, 838.*scale_y);
cr->line_to(265.*scale_x, 900.*scale_y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]