displaying an NSImage in custom NSView
displaying an NSImage in custom NSView
- Subject: displaying an NSImage in custom NSView
- From: "Bill So" <email@hidden>
- Date: Wed, 9 Aug 2006 15:36:25 +0800
Dear All,
I m playing around with the graphics related APIs in Cocoa. And, I
encountered a problem to display the NSImage properly while scrolling.
This is what I've done:
1. Created an NSView subclass called CmCanvasView (hoping to build a
simple graphics app) and put it in an NSScrollView.
2. The image is larger than the scroll view's content view region. So,
scrolling is needed to look around the image.
3. in CmCanvasView's drawRect: method, I wanna display only the
portion of the image which intersects the input rect of drawRect:.
However, I can't make it work...
NSScrollView documentation has described about the "copy-on-scroll"
feature of the NSClipView. When I scroll up one screen (press the
empty space in the vertical scroll bar), things seem to work fine...
But, when I try to scroll down one screen (press the empty space in
the vertical scroll bar), the image's got messed up.
I found that input argument of CmCanvasView's drawRect: is the correct
newly exposed region ((0, 0), (783, 417)). When I call the NSImage's
drawAtPoint: and
specify the rect (passed as input argument), Cocoa did display that
portion of the image but stretched to fit the height of the scroll
view's **visible** content view. (the visible size is 783 by 583)
Code excerpt (this is exactly what's in the drawRect: of CmCanvasView):
[[NSColor whiteColor] setFill];
NSRectFill(rect);
[screenCaptureImage drawAtPoint:rect.origin fromRect:rect
operation:NSCompositeSourceOver fraction:1.0];
What did I do wrong? Please kindly advise.
The complete source can be downloaded here:
www. headnix. com /files /ScrollingAutoResizeCanvas.zip
Thanks for your help.
Bill
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden