[cl-gtk2-devel] GtkDrawingArea

Doug South doug.south at gmail.com
Thu Feb 24 04:02:00 UTC 2011


Hi,

New to Lisp and Gtk...

I'm trying to use a GtkDrawingArea with cl-gtk2 and am wondering if it
is possible. I didn't have much luck with:

(asdf:operate 'asdf:load-op :cl-gtk2-gtk)

(defun draw-test ()
  (gtk:within-main-loop
    (let ((drawing-area (make-instance 'gtk:drawing-area :width 1500
:height 300))
	  (window (make-instance 'gtk:gtk-window :type :toplevel :title
"Drawing Test")))
      (gtk:container-add window drawing-area)
      (gobject:g-signal-connect drawing-area "expose" #'expose-event)
      (gobject:g-signal-connect window "expose" #'expose-event)
      (gtk:widget-show window :all t))))

(let ((output *standard-output*))
  (defun expose-event (&rest b)
    (format output "~a" b))

  (defun what-is-object (object)
    (describe object output)))

I'm not concerned with the expose events (though they are not being
called in either case). I'd expect the window to have a 1500 x 300
widget in it, but it appears as if there is no widget in it (and is
only 200 x 200).

As a sanity check, I tried doing the same thing in C:

#include <gtk/gtk.h>

gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event,
gpointer data) {
	gdk_draw_arc (widget->window,
		      widget->style->fg_gc[gtk_widget_get_state(widget)],
		      TRUE,
		      0, 0, widget->allocation.width, widget->allocation.height,
		      0, 64 * 360);
	return TRUE;
}

int main(int argc, char *argv[]) {
	GtkWidget *window;
	GtkWidget *drawing_area;

	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	drawing_area = gtk_drawing_area_new();
	gtk_widget_set_size_request(drawing_area, 1500, 300);
	gtk_container_add(GTK_CONTAINER(window), drawing_area);

	g_signal_connect(drawing_area, "expose-event",
		G_CALLBACK(on_expose_event), NULL);

	gtk_widget_show_all(window);
	gtk_main();
	return 0;
}

This time the expose event does something a bit more useful, but the
main point is that the window _IS_ 1500 x 300 (with a nice ellipse in
it). I even tried commenting out the signal connect just to check my
logic, and I still get the size of window I'd expect.

So, the questions regarding cl-gtk2-gtk are:

1) Am I setting the drawing area size correctly?
2) Am I adding the drawing area correctly? (I've added labels and
buttons successfully with cl-gtk2-gtk while going through the C Gtk
tutorial)
3) Is there another package I need to install beyond cl-gtk2-gtk?
4) Something obvious that I'm not aware of?

Thanks in advance,
Doug South




More information about the cl-gtk2-devel mailing list