Quick update to Area GTK+ drawing in an attempt fo figure out what's going on: we store the Area's width/height already; no need to get it back out from GTK+ itself.

This commit is contained in:
Pietro Gagliardi 2014-08-21 19:09:40 -04:00
parent 8feaa1c439
commit df8cbec7b8
1 changed files with 2 additions and 4 deletions

View File

@ -100,7 +100,6 @@ var areaCallbacks = []struct {
//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
var maxwid, maxht C.gint
a := (*area)(unsafe.Pointer(data))
// thanks to desrt in irc.gimp.net/#gtk+
@ -109,8 +108,7 @@ func our_area_draw_callback(widget *C.GtkWidget, cr *C.cairo_t, data C.gpointer)
// we do not need to clear the cliprect; GtkDrawingArea did it for us beforehand
cliprect := image.Rect(int(x0), int(y0), int(x1), int(y1))
// the cliprect can actually fall outside the size of the Area; clip it by intersecting the two rectangles
C.gtk_widget_get_size_request(widget, &maxwid, &maxht)
cliprect = image.Rect(0, 0, int(maxwid), int(maxht)).Intersect(cliprect)
cliprect = image.Rect(0, 0, a.width, a.height).Intersect(cliprect)
if cliprect.Empty() { // no intersection; nothing to paint
return C.FALSE // signals handled without stopping the event chain (thanks to desrt again)
}
@ -133,7 +131,7 @@ func our_area_draw_callback(widget *C.GtkWidget, cr *C.cairo_t, data C.gpointer)
0, 0) // origin of the surface
// that just set the brush that cairo uses: we have to actually draw now
// (via https://developer.gnome.org/gtkmm-tutorial/stable/sec-draw-images.html.en)
C.cairo_rectangle(cr, x0, y0, x1, y1) // breaking the nrom here since we have the coordinates as a C double already
C.cairo_rectangle(cr, x0, y0, x1, y1) // breaking the norm here since we have the coordinates as a C double already
C.cairo_fill(cr)
C.cairo_surface_destroy(surface) // free surface
return C.FALSE // signals handled without stopping the event chain (thanks to desrt again)