From b46167f1e2bb00dc1dae5b466cd78e7ae817587d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 4 Aug 2014 23:48:04 -0400 Subject: [PATCH] Fixed up the implementation of Area on GTK+ and the Area test. Seems to be fine, though for some reason holding down a mouse button doesn't generate a drag in GTK+ 3.10... --- redo/area_unix.go | 22 +++++++++++++++++++++- redo/zz_test.go | 10 +++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/redo/area_unix.go b/redo/area_unix.go index eb9dde9..cc9fe73 100644 --- a/redo/area_unix.go +++ b/redo/area_unix.go @@ -53,7 +53,13 @@ func newArea(ab *areabase) Area { scroller: newScroller(widget, false), // not natively scrollable, clickCounter: new(clickCounter), } - // TODO connect signals + for _, c := range areaCallbacks { + g_signal_connect( + C.gpointer(unsafe.Pointer(a.drawingarea)), + c.name, + c.callback, + C.gpointer(unsafe.Pointer(a))) + } a.SetSize(a.width, a.height) return a } @@ -68,6 +74,20 @@ func (a *area) RepaintAll() { C.gtk_widget_queue_draw(a._widget) } +var areaCallbacks = []struct { + name string + callback C.GCallback +}{ + { "draw", area_draw_callback }, + { "button-press-event", area_button_press_event_callback }, + { "button-release-event", area_button_release_event_callback }, + { "motion-notify-event", area_motion_notify_event_callback }, + { "enter-notify-event", area_enterleave_notify_event_callback }, + { "leave-notify-event", area_enterleave_notify_event_callback }, + { "key-press-event", area_key_press_event_callback }, + { "key-release-event", area_key_release_event_callback }, +} + //export our_area_draw_callback func our_area_draw_callback(widget *C.GtkWidget, cr *C.cairo_t, data C.gpointer) C.gboolean { var x0, y0, x1, y1 C.double diff --git a/redo/zz_test.go b/redo/zz_test.go index 2c1a044..c54c614 100644 --- a/redo/zz_test.go +++ b/redo/zz_test.go @@ -10,6 +10,8 @@ import ( "reflect" "testing" "image" + "image/color" + "image/draw" ) var closeOnClick = flag.Bool("close", false, "close on click") @@ -43,10 +45,12 @@ type testwin struct { type areaHandler struct{} func (a *areaHandler) Paint(r image.Rectangle) *image.RGBA { - return image.NewRGBA(r) + i := image.NewRGBA(r) + draw.Draw(i, r, &image.Uniform{color.RGBA{128,0,128,255}}, image.ZP, draw.Src) + return i } -func (a *areaHandler) Mouse(me MouseEvent) bool { return false } -func (a *areaHandler) Key(ke KeyEvent) bool { return false } +func (a *areaHandler) Mouse(me MouseEvent) bool { fmt.Printf("%#v\n", me); return false } +func (a *areaHandler) Key(ke KeyEvent) bool { fmt.Printf("%#v\n", ke); return false } func (tw *testwin) make(done chan struct{}) { tw.t = NewTab()