help drawing



        Hi,
        I want to draw a black square, which later I'll use
        as an oscilloscope, in my app but since I have not
        worked with drawables (so far), I decided to take a
        look at some code in a similar program ("pitchtune"
        was the chosen one).

        This is how I'm doing it:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* file1.c */
GdkGC   *black_gc;

void
set_colors( GdkWindow   *win )
{
        GdkColor        color;
        GdkColormap     *colormap;

        colormap = gdk_window_get_colormap( win );
        gdk_colormap_ref( colormap );

        black_gc = gdk_gc_new( win );
        color.red = color.green = color.blue = 0;
        gdk_color_alloc( colormap, &color );
        gdk_gc_set_foreground( black_gc, &color );

        gdk_window_set_background( win, &color );
        gdk_colormap_unref( colormap );
}

/* file2.c */
extern GtkWidget        *area;
extern GdkImage         *image;

gint
area_callback(  GtkWidget       *widget,
                GdkEventExpose  *event )
{
        gdk_draw_image( area, black_gc, image,
                        event->area.x, event->area.y,
                        event->area.x, event->area.y,
                        event->area.width, event->area.height );

        return TRUE;
}


/* file3.c */
#define IMAGE_WIDTH     350
#define IMAGE_HEIGHT    150

GtkWidget       *area;
GdkVisual       *visual;
GdkImage        *image;

[...]
area = gtk_drawing_area_new();
gtk_widget_set_usize( area, IMAGE_WIDTH, IMAGE_HEIGHT );
gtk_signal_connect( GTK_OBJECT(area), "expose_event",
                GTK_SIGNAL_FUNC(area_callback), NULL );
[...]
gtk_widget_realize( area );
visual = gdk_window_get_visual( area->window );
gdk_visual_ref( visual );

set_colors( area->window );

gdk_visual_unref( visual );
image = gdk_image_new(  GDK_IMAGE_FASTEST,
                        visual,
                        IMAGE_WIDTH,
                        IMAGE_HEIGHT );
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


        But the program runs (at the start) inmediately
        crashes and I get this message:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Gdk-ERROR **: BadValue (integer parameter out of range for operation)
serial 595 error_code 2 request_code 143 minor_code 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        If somebody could point me to what this error means...
        what am I missing?
        This is the first time I'm working with drawables and I
        have no clue on how to fix this?

        Thanks a lot in advance for your help.
        Regards,

                                         - Eduardo.





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