[gtkmm] Drawing text on a DrawingArea Widget
- From: Markus Meier <m meier unibas ch>
- To: gtkmm-list gnome org
- Subject: [gtkmm] Drawing text on a DrawingArea Widget
- Date: Thu, 06 Feb 2003 16:21:22 +0100
Dear all
I have to port my gtkmm-1.2 application to gtkmm-2.0. However, I have
troubles to draw text on a Gtk::DrawingArea Widget with this new
toolkit.
I can draw text in the widget, but not in the font I want (courier).
I figured out the following sequence from the gtkmm reference:
...
Glib::RefPtr<Gdk::GC> gc;
Glib::RefPtr<Pango::Context> pango_context;
Glib::RefPtr<Pango::Layout> pango_layout;
Glib::RefPtr<Pango::Font> font;
Pango::FontDescription font_description;
Gtk::DrawingArea *da;
//create GC
gc=Gdk::GC::create(da->get_window());
//get pango_context of the DrawingArea and set font
pango_context=da->get_pango_context();
font_description.set_family("courier");
//"-*-courier-bold-r-normal--14-*-*-*-m-*-iso8859-1");
font_description.set_style(Pango::STYLE_NORMAL);
font_description.set_variant(Pango::VARIANT_NORMAL);
font_description.set_weight(Pango::WEIGHT_BOLD);
font_description.set_stretch(Pango::STRETCH_NORMAL);
font_description.set_size(14);
pango_context->set_font_description(font_description);
font=pango_context->load_font(font_description);
if(font==0)
cerr << "Could not load font courier 14\n";
//yes the font did load
//now create the pango layout for the DrawingArea
pango_layout=da->create_pango_layout("");
gc->set_foreground(blue); //Gdk::Color blue
pango_layout->set_text("abcdefg");
da->get_window()->draw_layout(gc, 10, 10, pango_layout);
...
However, no text appears on the screen. If I use
create_pango_context() instead of get_pango_context() the text is
drawn, even in the right colour. However my font settings are ignored.
What am I doing wrong? Any help is appreciated.
Best regards,
Markus
Markus Meier
M. E. Müller Institut
Biozentrum der Universität Basel
Klingelbergstrasse 70
CH-4056 Basel
Tel.: +41 61 267 20 91
Fax: +41 61 267 21 09
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]