Skip navigation.
 
mlRe: How to draw a rectangle around a (graph) view?
FROM : John C. Randolph
DATE : Sun Apr 29 11:18:14 2007

On Apr 25, 2007, at 8:48 AM, Arthur C. wrote:

> I have a window with two graph views in it. They are NSView 
> subclasses of which I don't have the source code.
> I have implemented a screen capture of the view by taking the 
> rectangle forming the view using
>     NSRect graphRect = [self frame];
> This gives the rectangle in the coordinates of the superview. Now I 
> extend the rectangle to be able to capture things just outside the 
> graph view (like axis labels etc.). The screen capture can then be 
> done by
>     NSData * myScreenCaptureData = [[self superview] 
> dataWithPDFInsideRect: captureRect];
>
> which is saved to file as PDF data.
>
> Question is how to draw the rectangle showing what part is to be 
> captured (the captureRect).
> It is too large to be drawn from within the graphView. But where 
> should it be done then? I have nothing but an NSWindow and the two 
> graph views. So should it be done from the NSWindow? But then I 
> would have to subclass the NSWindow(?)


I wrote some sample code several years ago that shows a couple of ways 
to draw a selection area.  You can find it at

http://developer.apple.com/samplecode/Cropped_Image/index.html

In your case, I'd use a crop marker to select the area to capture, 
then use -dataWithPDFInsideRect:.  You'll want to turn off the crop 
marker if you're not drawing to the screen, of course.  Use 
[NSGraphicsContext currentContextDrawingToScreen] to determine that.


> Another question: is it necessary to do all the drawing in the 
> drawRect method?


It's a really good idea to do so, especially when you're still learning.

-jcr

Related mailsAuthorDate
mlHow to draw a rectangle around a (graph) view? Arthur C. Apr 25, 17:48
mlRe: How to draw a rectangle around a (graph) view? Shawn Erickson Apr 25, 17:52
mlRe: How to draw a rectangle around a (graph) view? I. Savant Apr 25, 18:46
mlRe: How to draw a rectangle around a (graph) view? Arthur C. Apr 25, 19:29
mlRe: How to draw a rectangle around a (graph) view? Shawn Erickson Apr 25, 20:11
mlRe: How to draw a rectangle around a (graph) view? John C. Randolph Apr 29, 11:18
mlRe: How to draw a rectangle around a (graph) view? Arthur C. May 24, 23:10
mlRe: How to draw a rectangle around a (graph) view? I. Savant May 24, 23:16
mlRe: How to draw a rectangle around a (graph) view? Arthur C. May 25, 17:58
mlRe: How to draw a rectangle around a (graph) view? I. Savant May 25, 18:01
mlRe: How to draw a rectangle around a (graph) view? Arthur C. May 25, 20:44
mlRe: How to draw a rectangle around a (graph) view? I. Savant May 25, 20:56
mlRe: How to draw a rectangle around a (graph) view? Uli Kusterer May 27, 15:43
mlRe: How to draw a rectangle around a (graph) view? Arthur C. May 29, 23:19
mlRe: How to draw a rectangle around a (graph) view? Uli Kusterer May 29, 23:42
mlRe: How to draw a rectangle around a (graph) view? I. Savant May 30, 00:49