[gtkmm] Gdk::Color/Gdk::GC question
- From: Carl Nygard <cjnygard fast net>
- To: gtkmm-list gnome org
- Subject: [gtkmm] Gdk::Color/Gdk::GC question
- Date: Tue, 27 Jul 2004 15:58:52 -0400
Can someone tell me why GC::set_rgb_fg_color does not work? I'm using
the radar.cc example from the .rpm install, here's the code I modified:
(setting NOTRGB=1 works fine, otherwise black screen)
PPI::PPI()
{
// get_window() would return 0 because the Gdk::Window has not yet been realized
// So we can only allocate the colors here - the rest will happen in on_realize().
Glib::RefPtr<Gdk::Screen> screen =
Gdk::Visual::get_best(Gdk::VISUAL_TRUE_COLOR)->get_screen();
// Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
Glib::RefPtr<Gdk::Colormap> colormap = screen->get_rgb_colormap();
blue_ = Gdk::Color("blue");
red_ = Gdk::Color("red");
// ....
}
void PPI::on_realize()
{
// We need to call the base on_realize()
Gtk::DrawingArea::on_realize();
// Now we can allocate any additional resources we need
Glib::RefPtr<Gdk::Window> window = get_window();
gc_ = Gdk::GC::create(window);
window->set_background(black_);
window->clear();
// Make sure the same colormap is set in the gc_
Glib::RefPtr<Gdk::Screen> screen =
Gdk::Visual::get_best(Gdk::VISUAL_TRUE_COLOR)->get_screen();
gc_->set_colormap(screen->get_rgb_colormap());
// gc_->set_foreground(green_);
}
bool PPI::on_expose_event(GdkEventExpose*)
{
// we need a ref to the gdkmm window
Glib::RefPtr<Gdk::Window> window = get_window();
// window geometry: x, y, width, height, depth
int winx, winy, winw, winh, wind;
window->get_geometry(winx, winy, winw, winh, wind);
window->clear();
// 4 white points
#if NOTRGB
gc_->set_foreground(white_);
#else
{
Gdk::Color c;
c.set_rgb(255, 255, 255);
gc_->set_rgb_fg_color(c);
}
#endif
window->draw_point(gc_, 5, 5);
window->draw_point(gc_, 5, winh-5);
window->draw_point(gc_, winw-5, winh-5);
window->draw_point(gc_, winw-5, 5);
// a thick solid grey line
#if NOTRGB
gc_->set_foreground(grey_);
#else
{
Gdk::Color c;
c.set_rgb(128, 128, 128);
gc_->set_rgb_fg_color(c);
}
#endif
gc_->set_line_attributes(/*line_width*/7, /*LineStyle*/Gdk::LINE_SOLID,/*CapStyle*/Gdk::CAP_NOT_LAST,/*JoinStyle*/Gdk::JOIN_MITER);
// LineStyle: LINE_SOLID, LINE_ON_OFF_DASH, LINE_DOUBLE_DASH
// CapStyle: CAP_NOT_LAST, CAP_BUTT, CAP_ROUND, CAP_PROJECTING
// JoinStyle: JOIN_MITER, JOIN_ROUND, JOIN_BEVEL
window->draw_line(gc_, 10, 10, winw-10, winh-10);
// ...
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]