Re: gdk_draw_string deprecated?
- From: Mathieu Lacage <mathieu_lacage myrealbox com>
- To: Andrej Prsa <andrej prsa guest arnes si>
- Cc: GTK Mailing list <gtk-list gnome org>
- Subject: Re: gdk_draw_string deprecated?
- Date: Tue, 14 Oct 2003 14:25:49 +0200
On Tue, 2003-10-14 at 14:13, Andrej Prsa wrote:
> Hello!
>
> > I am not sure what you are trying to do but you can get the platform's
> > default context object for a given layout with pango_layout_get_context.
>
> Well, it's just the other way around; I thought I have to create a context
> in order to create a layout in order to put some text on the drawable. I
> did all this with gdk_draw_string before and now I just want to
> "modernize" my program to GTK+2.* policy. O;)
well, I should have read my sample code better: here is something which
works (it draws a vertical scale). Sorry for the mistake.
This code might not build (I had to edit some stuff out of it) but it
worked at one point, that's for sure :)
{
PangoLayout *layout;
PangoContext *context;
gint max_width;
gint height, width;
/* vertical rule */
gdk_draw_line (draw, gc, x, 0, x, display_end);
/* horizontal rules + text */
gint32 y_step = display_end/n_steps;
gint32 y = 0;
gdouble real_y_step = ((gdouble )real_end)/((gdouble)n_steps);
gdouble real_y = 0;
context = gdk_pango_context_get ();
layout = pango_layout_new (context);
pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
max_width = 0;
for (RMuint8 i = 0; i < n_steps; i++) {
gdk_draw_line (draw, gc, x, y, x+10, y);
gchar *str = g_strdup_printf ("%u", (guint)real_y);
pango_layout_set_text (layout, str, -1);
g_free (str);
gdk_draw_layout (draw, gc, x, y, layout);
pango_layout_get_pixel_size (layout, &width, &height);
max_width = max (width, max_width);
y += y_step;
real_y += real_y_step;
}
g_assert (max_width >= 0);
return max_width;
}
Mathieu
--
Mathieu Lacage <mathieu gnu org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]