Re: canvas question



On Wed, 30 May 2001, Eicke Godehardt wrote:
> I'm writing a music editing program for gnome but I'm very new to work
> with the gnome canvas.
> I use the canvas to display all the notes etc. by writing my own items.
> But there is a problem.  I had to put a large rectangle in the back to
> get 2 things:
> 1. to color the background -- how can I set the background color for the
>    canvas and the bigger problem

Here is a short method from one of my programs to set the canvas
background color:

void set_background_color_ref(GtkWidget *canvas, GdkColor *color)
{
  /* try to alloc color */
  if(gdk_color_alloc(gdk_colormap_get_system(), color))
  {
    GtkStyle *style;
    style = gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(canvas)));

    /* set new style */
    style->bg[GTK_STATE_NORMAL] = *color;
    gtk_widget_set_style(GTK_WIDGET(canvas), style);
  }
}


> 2. only with the rectangle I get mouse (pressing) events -- how can I make
>    the whole canvas `sensible'?

Just connect to one of the GtkWidget events (cos the canvas is also a
GtkWidget). Eg. you can use:

        gtk_signal_connect_after (GTK_OBJECT (canvas),
                                  "button-press-event",
                                  (GtkSignalFunc) handle_canvas_click,
                                  my_data);

Maybe you must set the event mask poperly before with:

	gtk_widget_set_events (GTK_WIDGET (canvas), GDK_ALL_EVENTS_MASK);

This describes which events will reach the widget.

Hope that helps.

   Jens





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