Re: Please, Give me advise about my first line draw program.
- From: Paolo Costabel <paolo imageworks com>
- To: doogie78 hanmir com
- Cc: GTK+ App Devel Mail List <gtk-app-devel-list gnome org>
- Subject: Re: Please, Give me advise about my first line draw program.
- Date: Fri, 17 May 2002 14:41:30 -0700
Donggyoo Lee wrote:
Sorry, Oh my misktake. Here is source.
Please give me advise.
------------------------------------------------------------------------
myline.cName: myline.c
Type: text/x-csrc
GtkDrawingArea is a widget. You can't just draw directly into it.
Instead, you have to provide a callback for expose events. Tis will be
called
every time the widget needs refreshing.
I have attached a modified version that works.
However, in general you will want to use a back buffer pixmap for your
drawing operations
and copy it in the drawing area inside the expose callback. See
scribble-simple in
the example directory of gtk source tree.
--
---------------------------------------------------------------------
Paolo Costabel Visit The Internet Comic Books Database
Sony Imageworks http://www.comicsdb.com
#include <gtk/gtk.h>
#define XSIZE 600
#define YSIZE 400
/* This routine gets control when the close button is clicked */
gint close_application( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
gtk_main_quit ();
return FALSE;
}
/* Redraw the screen from the backing pixmap */
static gint
expose_event (GtkWidget *widget, GdkEventExpose *event)
{
gdk_draw_line(widget->window, widget->style->black_gc, 0, 0, 300, 300);
return FALSE;
}
/* The main routine */
int main( int argc, char *argv[] )
{
GtkWidget *window, *drawing_area;
/* Initialize GTK and create the main window */
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (close_application), NULL);
drawing_area = gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
GTK_SIGNAL_FUNC (expose_event), NULL);
gtk_drawing_area_size (drawing_area, XSIZE, YSIZE);
gtk_widget_show (drawing_area);
gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK);
/* Now show everything */
gtk_widget_show (window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]