Fixed variable names in Area drawing code on Unix to reflect that image.Rectangle is point-to-point, not origin/size like on Mac OS X. Windows was already fine; it just uses "left, top, right, and bottom" instead of "x0, y0, x1, and y1".

This commit is contained in:
Pietro Gagliardi 2014-05-17 17:01:52 -04:00
parent 352c60bf68
commit ce14390eff
2 changed files with 6 additions and 5 deletions

View File

@ -29,7 +29,6 @@ func areaView_drawRect(self C.id, rect C.struct_xrect) {
s := getSysData(self)
// TODO clear clip rect
// rectangles in Cocoa are origin/size, not point0/point1; if we don't watch for this, weird things will happen when scrolling
// TODO change names EVERYWHERE ELSE to match
cliprect := image.Rect(int(rect.x), int(rect.y), int(rect.x + rect.width), int(rect.y + rect.height))
max := C.frame(self)
cliprect = image.Rect(0, 0, int(max.width), int(max.height)).Intersect(cliprect)

View File

@ -42,14 +42,15 @@ func gtkAreaGetControl(scrollarea *C.GtkWidget) *C.GtkWidget {
//export our_area_draw_callback
func our_area_draw_callback(widget *C.GtkWidget, cr *C.cairo_t, data C.gpointer) C.gboolean {
var x, y, w, h C.double
var x0, y0, x1, y1 C.double
var maxwid, maxht C.gint
s := (*sysData)(unsafe.Pointer(data))
// thanks to desrt in irc.gimp.net/#gtk+
C.cairo_clip_extents(cr, &x, &y, &w, &h)
// TODO these are in "user coordinates"; is that what we want?
C.cairo_clip_extents(cr, &x0, &y0, &x1, &y1)
// we do not need to clear the cliprect; GtkDrawingArea did it for us beforehand
cliprect := image.Rect(int(x), int(y), int(w), int(h))
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)
@ -75,7 +76,8 @@ 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, x, y, w, h) // breaking the nrom here since we have the double data already
// TODO see above about user coordinates; if we do change to device coordinates the following line will need to change or be added to
C.cairo_rectangle(cr, x0, y0, x1, y1) // breaking the nrom 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)