Image

Imagelrc wrote in Imagelinux

gtk is not my friend

I'm trying to draw a plot with various colors on a black background.

For my practice program, I'm basing my code off the plotter program in the SAMS gtk book.

I snarfed the colormap code from the piechart program.

The problem is that while gtk_gc_set_foreground() works just fine, gtk_gc_set_background has no apparent effect.

I've also tried futzing with my .gtkrc file and no matter what I do, the background of the plot comes out grey. It's driving me crazy



void line_plot( GtkMenuItem *was_clicked, GtkWidget *where_to_draw )
{
   static gint to_plot[NUM_PTS][2] = { {0, 0}, {15, 20}, {30, 80},
                              {45, 30}, {60, 25}, {75, 90}, {90, 120},
                              {105, 170}, {120, 100}, {135, 0} };
   /*static*/ GdkGC *plot_gc;
   static int first_time_in = 1;
   int pts;
                                                                                          
   GdkColor color[NCOLORS];
   GdkColormap *colormap=gdk_colormap_get_system();
   gboolean success_codes[NCOLORS];
                                                                                          
  GdkGCValues values;
                                                                                          
                                                                                          
   /* black */
   if (!gdk_color_parse("Black", &color[0]))
     g_error("couldn't parse black");
   /* white */
   if (!gdk_color_parse("White", &color[1]))
     g_error("couldn't parse white");
                                                                                          
                                                                                          
   if (!gdk_color_parse("Yellow", &color[2]))
     g_error("couldn't parse yellow");
   /* blue */
   if (!gdk_color_parse("RoyalBlue", &color[3]))
     g_error("couldn't parse blue");
   /* red */
   if (!gdk_color_parse("Red", &color[4]))
     g_error("couldn't parse red");
   /* green */
   if (!gdk_color_parse("ForestGreen", &color[5]))
     g_error("couldn't parse green");
                                                                                          
  if( first_time_in )
  {
    /* Initialize GC */
    plot_gc = gdk_gc_new( GTK_WIDGET(where_to_draw)->window );
  }
  if (gdk_colormap_alloc_colors( colormap, color, NCOLORS,
                                 FALSE, TRUE, success_codes ))
    g_error("couldn't allocate some of the colors");
                                                                                            gdk_gc_set_background( plot_gc, color + 2 );
  //plot_gc.background = 0;
  gdk_gc_set_foreground( plot_gc, color + 0 );
                                                                                          
  /* Draw Axis */
  gdk_draw_line( GTK_WIDGET(where_to_draw)->window, plot_gc,
                  XA_STARTX, XA_Y, XA_ENDX, XA_Y);
   gdk_draw_line( GTK_WIDGET(where_to_draw)->window, plot_gc,
                  YA_X, YA_STARTY, YA_X, YA_ENDY);