1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
#define EVENT_METHOD(i, x) GTK_WIDGET_GET_CLASS(i)->x
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
#define XSIZE 600
|
|
|
|
#define YSIZE 400
|
|
|
|
|
1998-12-10 17:31:04 +00:00
|
|
|
/* This routine gets control when the close button is clicked */
|
2005-01-03 19:26:36 +00:00
|
|
|
static gboolean close_application( GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data )
|
1999-11-13 23:06:46 +00:00
|
|
|
{
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_main_quit ();
|
2002-02-16 23:52:30 +00:00
|
|
|
return FALSE;
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|
|
|
|
|
1998-12-10 17:31:04 +00:00
|
|
|
/* The main routine */
|
1999-11-13 23:06:46 +00:00
|
|
|
int main( int argc,
|
|
|
|
char *argv[] ) {
|
1998-03-31 23:43:49 +00:00
|
|
|
GtkWidget *window, *table, *area, *hrule, *vrule;
|
|
|
|
|
1998-12-10 17:31:04 +00:00
|
|
|
/* Initialize GTK and create the main window */
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_init (&argc, &argv);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2008-08-11 18:36:07 +00:00
|
|
|
g_signal_connect (window, "delete-event",
|
2002-02-19 19:47:16 +00:00
|
|
|
G_CALLBACK (close_application), NULL);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
1998-12-10 17:31:04 +00:00
|
|
|
/* Create a table for placing the ruler and the drawing area */
|
2002-02-19 01:25:26 +00:00
|
|
|
table = gtk_table_new (3, 2, FALSE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), table);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
area = gtk_drawing_area_new ();
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (area), XSIZE, YSIZE);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach (GTK_TABLE (table), area, 1, 2, 1, 2,
|
|
|
|
GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_set_events (area, GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* The horizontal ruler goes on top. As the mouse moves across the
|
|
|
|
* drawing area, a motion_notify_event is passed to the
|
|
|
|
* appropriate event handler for the ruler. */
|
2010-10-29 23:41:55 +00:00
|
|
|
hrule = gtk_ruler_new (GTK_ORIENTATION_HORIZONTAL);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_ruler_set_metric (GTK_RULER (hrule), GTK_PIXELS);
|
|
|
|
gtk_ruler_set_range (GTK_RULER (hrule), 7, 13, 0, 20);
|
2008-08-11 18:36:07 +00:00
|
|
|
g_signal_connect_swapped (area, "motion-notify-event",
|
|
|
|
G_CALLBACK (EVENT_METHOD (hrule,
|
|
|
|
motion_notify_event)),
|
|
|
|
hrule);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach (GTK_TABLE (table), hrule, 1, 2, 0, 1,
|
|
|
|
GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0);
|
2008-08-11 18:36:07 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* The vertical ruler goes on the left. As the mouse moves across
|
|
|
|
* the drawing area, a motion_notify_event is passed to the
|
|
|
|
* appropriate event handler for the ruler. */
|
2010-10-29 23:41:55 +00:00
|
|
|
vrule = gtk_ruler_new (GTK_ORIENTATION_VERTICAL);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_ruler_set_metric (GTK_RULER (vrule), GTK_PIXELS);
|
|
|
|
gtk_ruler_set_range (GTK_RULER (vrule), 0, YSIZE, 10, YSIZE );
|
2008-08-11 18:36:07 +00:00
|
|
|
g_signal_connect_swapped (area, "motion-notify-event",
|
|
|
|
G_CALLBACK (EVENT_METHOD (vrule,
|
|
|
|
motion_notify_event)),
|
|
|
|
vrule);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach (GTK_TABLE (table), vrule, 0, 1, 1, 2,
|
|
|
|
GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
1998-12-10 17:31:04 +00:00
|
|
|
/* Now show everything */
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_widget_show (area);
|
|
|
|
gtk_widget_show (hrule);
|
|
|
|
gtk_widget_show (vrule);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
gtk_widget_show (window);
|
|
|
|
gtk_main ();
|
1998-03-31 23:43:49 +00:00
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
return 0;
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|