diff options
Diffstat (limited to 'macosx/tkMacOSXDraw.c')
-rw-r--r-- | macosx/tkMacOSXDraw.c | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 089097e..40400c2 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -18,6 +18,7 @@ #include "tkMacOSXDebug.h" #include "xbytes.h" + /* #ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_DRAWING @@ -769,7 +770,8 @@ DrawCGImage( dstBounds.size.width, dstBounds.size.height); #else /* TK_MAC_DEBUG_IMAGE_DRAWING */ CGContextSaveGState(context); - CGContextTranslateCTM(context, 0, dstBounds.origin.y + CGRectGetMaxY(dstBounds)); + CGContextTranslateCTM(context, + 0, dstBounds.origin.y + CGRectGetMaxY(dstBounds)); CGContextScaleCTM(context, 1, -1); CGContextDrawImage(context, dstBounds, image); CGContextRestoreGState(context); @@ -1480,59 +1482,51 @@ TkScrollWindow( Drawable drawable = Tk_WindowId(tkwin); MacDrawable *macDraw = (MacDrawable *) drawable; NSView *view = TkMacOSXDrawableView(macDraw); - CGRect dmgRect, dstRect, visRectBL, srcRectBL, dstRectBL; - NSRect visible, frame; - HIShapeRef dmgRgn = NULL, dstRgn; + CGRect visRect, srcRect, dstRect, scroll_src, scroll_dst; + HIShapeRef dmgRgn = NULL; + NSRect bounds; int result; if ( view ) { - visible = [view visibleRect]; - - /* Find the frame for the Tk window within its NSview. */ - frame = NSMakeRect(Tk_X(tkwin), - Tk_Y(tkwin) + visible.size.height - Tk_Height(tkwin), - Tk_Width(tkwin), - Tk_Height(tkwin)); - /* Get the scroll area in NSView coordinates (origin at bottom left). */ - srcRectBL = CGRectMake(frame.origin.x + x, - frame.origin.y + frame.size.height - height - y, + bounds = [view bounds]; + scroll_src = CGRectMake( + macDraw->xOff + x, + bounds.size.height - height - (macDraw->yOff + y), width, height); - dstRectBL = CGRectOffset(srcRectBL, dx, -dy); - + scroll_dst = CGRectOffset(scroll_src, dx, -dy); /* Limit scrolling to the window content area. */ - visRectBL = NSRectToCGRect(frame); - srcRectBL = CGRectIntersection(srcRectBL, visRectBL); - dstRectBL = CGRectIntersection(dstRectBL, visRectBL); + visRect = NSRectToCGRect([view visibleRect]); + scroll_src = CGRectIntersection(scroll_src, visRect); + scroll_dst = CGRectIntersection(scroll_dst, visRect); - if ( !CGRectIsEmpty(srcRectBL) && !CGRectIsEmpty(dstRectBL) ) { + if ( !CGRectIsEmpty(scroll_src) && !CGRectIsEmpty(scroll_dst) ) { /* - * Construct the damage region. We extend it to the top - * or bottom of the window, in order to avoid artifacts when - * scrolling. + * Mark the difference between source and destination as damaged. + * This region is described in the Tk coordinate system, after shifting by dy. */ - if ( dy < 0 ) { /* extend to bottom */ - dmgRect = CGRectMake(x, y, Tk_Width(tkwin), Tk_Height(tkwin) - y); - } else { /* extend to top */ - dmgRect = CGRectMake(x , 0, Tk_Width(tkwin), Tk_Height(tkwin) + y); - } - dstRect = CGRectMake(x+dx, y+dy, width, height); - - dmgRgn = HIShapeCreateMutableWithRect(&dmgRect); - dstRgn = HIShapeCreateWithRect(&dstRect); + srcRect = CGRectMake(x - macDraw->xOff, y - macDraw->yOff, + width, height); + dstRect = CGRectOffset(srcRect, dx, dy); + dmgRgn = HIShapeCreateMutableWithRect(&srcRect); + HIShapeRef dstRgn = HIShapeCreateWithRect(&dstRect); ChkErr(HIShapeDifference, dmgRgn, dstRgn, (HIMutableShapeRef) dmgRgn); CFRelease(dstRgn); /* Scroll the rectangle. */ - [view scrollRect:NSRectFromCGRect(srcRectBL) by:NSMakeSize(dx, -dy)]; + [view scrollRect:NSRectFromCGRect(scroll_src) by:NSMakeSize(dx, -dy)]; + [view displayRect:NSRectFromCGRect(scroll_dst)]; } } + + if ( dmgRgn == NULL ) { dmgRgn = HIShapeCreateEmpty(); } + TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn); result = HIShapeIsEmpty(dmgRgn) ? 0 : 1; CFRelease(dmgRgn); |