Documented that the clip area in AreaHandler.Paint() more properly and indicate that it is cleared on each AreaHandler.Paint() call; (try to) implement that on Windows (GTK+ does it for us; noted that as well).
This commit is contained in:
parent
652797bd3e
commit
efdd60375a
4
area.go
4
area.go
|
@ -37,6 +37,8 @@ type Area struct {
|
||||||
// (Having to use this interface does not strike me as being particularly Go-like, but the nature of Paint makes channel-based event handling a non-option; in practice, deadlocks occur.)
|
// (Having to use this interface does not strike me as being particularly Go-like, but the nature of Paint makes channel-based event handling a non-option; in practice, deadlocks occur.)
|
||||||
type AreaHandler interface {
|
type AreaHandler interface {
|
||||||
// Paint is called when the Area needs to be redrawn.
|
// Paint is called when the Area needs to be redrawn.
|
||||||
|
// The part of the Area that needs to be redrawn is stored in cliprect.
|
||||||
|
// Before Paint() is called, this region is cleared with a system-defined background color.
|
||||||
// You MUST handle this event, and you MUST return a valid image, otherwise deadlocks and panicking will occur.
|
// You MUST handle this event, and you MUST return a valid image, otherwise deadlocks and panicking will occur.
|
||||||
// The image returned must have the same size as rect (but does not have to have the same origin points).
|
// The image returned must have the same size as rect (but does not have to have the same origin points).
|
||||||
// Example:
|
// Example:
|
||||||
|
@ -48,7 +50,7 @@ type AreaHandler interface {
|
||||||
// func (h *myAreaHandler) Paint(rect image.Rectangle) *image.NRGBA {
|
// func (h *myAreaHandler) Paint(rect image.Rectangle) *image.NRGBA {
|
||||||
// return img.SubImage(rect).(*image.NRGBA)
|
// return img.SubImage(rect).(*image.NRGBA)
|
||||||
// }
|
// }
|
||||||
Paint(rect image.Rectangle) *image.NRGBA
|
Paint(cliprect image.Rectangle) *image.NRGBA
|
||||||
|
|
||||||
// Mouse is called when the Area receives a mouse event.
|
// Mouse is called when the Area receives a mouse event.
|
||||||
// You are allowed to do nothing in this handler (to ignore mouse events).
|
// You are allowed to do nothing in this handler (to ignore mouse events).
|
||||||
|
|
|
@ -48,6 +48,7 @@ func our_area_draw_callback(widget *C.GtkWidget, cr *C.cairo_t, data C.gpointer)
|
||||||
s := (*sysData)(unsafe.Pointer(data))
|
s := (*sysData)(unsafe.Pointer(data))
|
||||||
// thanks to desrt in irc.gimp.net/#gtk+
|
// thanks to desrt in irc.gimp.net/#gtk+
|
||||||
C.cairo_clip_extents(cr, &x, &y, &w, &h)
|
C.cairo_clip_extents(cr, &x, &y, &w, &h)
|
||||||
|
// 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(x), int(y), int(w), int(h))
|
||||||
// the cliprect can actually fall outside the size of the Area; clip it by intersecting the two rectangles
|
// 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)
|
C.gtk_widget_get_size_request(widget, &maxwid, &maxht)
|
||||||
|
|
|
@ -78,11 +78,10 @@ func paintArea(s *sysData) {
|
||||||
var xrect _RECT
|
var xrect _RECT
|
||||||
var ps _PAINTSTRUCT
|
var ps _PAINTSTRUCT
|
||||||
|
|
||||||
// TODO send _TRUE if we want to erase the clip area
|
|
||||||
r1, _, _ := _getUpdateRect.Call(
|
r1, _, _ := _getUpdateRect.Call(
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
uintptr(unsafe.Pointer(&xrect)),
|
uintptr(unsafe.Pointer(&xrect)),
|
||||||
uintptr(_FALSE))
|
uintptr(_TRUE)) // erase the update rect with the background color
|
||||||
if r1 == 0 { // no update rect; do nothing
|
if r1 == 0 { // no update rect; do nothing
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -86,6 +86,7 @@ super ultra important things:
|
||||||
- for our two custom window classes, we should allocate extra space in the window class's info structure and then use SetWindowLongPtrW() during WM_CREATE to store the sysData and not have to make a new window class each time; this might also fix the s != nil && s.hwnd != 0 special cases in the Area WndProc if done right
|
- for our two custom window classes, we should allocate extra space in the window class's info structure and then use SetWindowLongPtrW() during WM_CREATE to store the sysData and not have to make a new window class each time; this might also fix the s != nil && s.hwnd != 0 special cases in the Area WndProc if done right
|
||||||
- references: https://github.com/glfw/glfw/blob/master/src/win32_window.c#L182, http://www.catch22.net/tuts/custom-controls
|
- references: https://github.com/glfw/glfw/blob/master/src/win32_window.c#L182, http://www.catch22.net/tuts/custom-controls
|
||||||
- Area redraw on Windows is still a bit flaky, especially after changing the Area size to something larger than the window size and then resizing the window(???)
|
- Area redraw on Windows is still a bit flaky, especially after changing the Area size to something larger than the window size and then resizing the window(???)
|
||||||
|
- despite us explicitly clearing the clip area on Windows, Area still doesn't seem to draw alpha bits correctly... it appears as if we are drawing over the existing image each time
|
||||||
|
|
||||||
important things:
|
important things:
|
||||||
- make specific wording in documentation consistent (make/create, etc.)
|
- make specific wording in documentation consistent (make/create, etc.)
|
||||||
|
|
Loading…
Reference in New Issue