Re: [gtkmm] Gdk::Colormap and Gdk::Color



Am 08.08.2002 06:42 schrieb(en) Michael A. Koziarski:
Hey guys, I've been asking on IRC for a while, but as I'm ~12hrs from everyone else I should probably use the list.

The application I'm writing needs to do a fair amount of drawing onto pixmaps etc. so I've been tinkering with Gdk::Drawables lately and I'm wondering whether I've understood the Gdk::Color situation wrt Gdk::Colormaps. Please point out any errors in the following:

In order to draw a line in a specified color, say red, I need to.

{
Glib::RefPtr<Gdk::Pixmap> pm = Gdk::Pixmap::create(x,y,d);
Glib::RefPrt<Gdk::GC> gc = Gdk::GC::create(gc);
Glib::RefPtr<Gdk::Colormap> cm = gc->get_colorap()
Gdk::Color red("red");

cm->alloc_color(red);
pm->draw_line(gc, 0, 0, 100, 100);
}

I've never used colormaps but from what I see I think that the following
solution should do the same:

{
Glib::RefPtr<Gdk::Pixmap> pm = Gdk::Pixmap::create(x,y,d);
Glib::RefPrt<Gdk::GC> gc = Gdk::GC::create(pm);
Gdk::Color red("red");

gc->set_foreground(red);
pm->draw_line(gc, 0, 0, 100, 100);
}

The foreground color of the GC is used to draw things, the background color
to fill geometric figures.

There is also a convinience function Gdk::GC::set_rgb_fg_color() that hides
some stuff necessary to map an rgb value to a color.

Regards,

  Martin



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