From 2b48f7cabfbf269ac5d5ff292a7c788715ecd411 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 25 Mar 2014 09:10:06 -0400 Subject: [PATCH] Wrote the code to actually scroll Areas on Windows. --- area_windows.go | 26 ++++++++++++++++++++++++-- controls_windows.go | 1 - todo.md | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/area_windows.go b/area_windows.go index 4b4eedc..01080e5 100644 --- a/area_windows.go +++ b/area_windows.go @@ -51,6 +51,7 @@ func paintArea(s *sysData) { var xrect _RECT var ps _PAINTSTRUCT + var si _SCROLLINFO // TODO send _TRUE if we want to erase the clip area r1, _, _ := _getUpdateRect.Call( @@ -61,15 +62,36 @@ func paintArea(s *sysData) { return } + si.cbSize = uint32(unsafe.Sizeof(si)) + si.fMask = _SIF_POS | _SIF_TRACKPOS + r1, _, err := _getScrollInfo.Call( + uintptr(s.hwnd), + uintptr(_SB_HORZ), + uintptr(unsafe.Pointer(&si))) + if r1 == 0 { // failure + panic(fmt.Errorf("error getting horizontal scroll position for Area repaint: %v", err)) + } + hscroll := int(si.nPos) + si.cbSize = uint32(unsafe.Sizeof(si)) // MSDN example code reinitializes this each time, so we'll do it too just to be safe + si.fMask = _SIF_POS | _SIF_TRACKPOS + r1, _, err = _getScrollInfo.Call( + uintptr(s.hwnd), + uintptr(_SB_VERT), + uintptr(unsafe.Pointer(&si))) + if r1 == 0 { // failure + panic(fmt.Errorf("error getting vertical scroll position for Area repaint: %v", err)) + } + vscroll := int(si.nPos) + cliprect := image.Rect(int(xrect.Left), int(xrect.Top), int(xrect.Right), int(xrect.Bottom)) - // TODO offset cliprect by scroll position + cliprect = cliprect.Add(image.Pt(hscroll, vscroll)) // adjust by scroll position // make sure the cliprect doesn't fall outside the size of the Area cliprect = cliprect.Intersect(image.Rect(0, 0, 320, 240)) // TODO change when adding resizing if cliprect.Empty() { // still no update rect return } - r1, _, err := _beginPaint.Call( + r1, _, err = _beginPaint.Call( uintptr(s.hwnd), uintptr(unsafe.Pointer(&ps))) if r1 == 0 { // failure diff --git a/controls_windows.go b/controls_windows.go index ab227ee..e7a72c9 100644 --- a/controls_windows.go +++ b/controls_windows.go @@ -501,7 +501,6 @@ const ( var ( _getScrollInfo = user32.NewProc("GetScrollInfo") - _getScrollPos = user32.NewProc("GetScrollPos") _setScrollInfo = user32.NewProc("SetScrollInfo") _scrollWindowEx = user32.NewProc("ScrollWindowEx") ) diff --git a/todo.md b/todo.md index aeaedaf..4a81bae 100644 --- a/todo.md +++ b/todo.md @@ -79,6 +79,7 @@ super ultra important things: - see update 18 March 2014 in README - resizing seems to be completely and totally broken in the Wayland backend - scrolling Areas in wine by clicking in the page scroll area often causes the main thread to lock up; uitask does not +- make sure the first and last rows and columns of an Area are being drawn on Windows important things: - make specific wording in documentation consistent (make/create, etc.)