Re: Dragging to select rectangle
Re: Dragging to select rectangle
- Subject: Re: Dragging to select rectangle
- From: Lorenzo <email@hidden>
- Date: Wed, 03 Sep 2003 09:52:59 +0200
Hi,
I had the same need, and I learned how to do by this sample. It's great.
Anyway, I would like to say that this sample doesn't work when the image is
resized inside the NSImageView. In such a case it's very hard to know:
1) The scale factor. The developer should calculate this by himself, basing
on the size of the NSImageView and the size of the [self image], but the
accuracy could not be perfect. This way the scale factor could not be the
same used by the NSImageView to draw the resized image. Please let me know
if there is a better way.
2) The origin of the resized image shown in the NSImageView. Once calculated
the scale factor the developer can easily calculate this info.
Without this info is not possible to calculate the origin of the drag.
Please let me know if there is a better way to know this info.
3) The "real rect" (origin and size) of the cropped [self image] to be set
to the pasterboard. The developer should calculate this info basing on the
original cropped rect, the scale factor, the origin of the resized image
shown in the NSImageView and, the size of the [self image].
4) A problem that could be easily fixed is that, during the drag, this
sample redraws the entire area of the NSImageView any time, so the refresh
is not so fast in case of big images. To increase the speed of the refresh
simply change
[self setNeedsDisplay:YES];
with
[self setNeedsDisplayInRect:croppedRect];
which will result much much faster.
Anyway, even with these small inconvenients, this sample is really great.
I hope to find samples like this all the time.
Best Regards
--
Lorenzo
email: email@hidden
>
Message: 16
>
Cc: email@hidden
>
From: John Randolph <email@hidden>
>
Subject: Re: Dragging to select rectangle
>
Date: Tue, 2 Sep 2003 17:26:53 -0700
>
To: John Nairn <email@hidden>
>
>
On Sep 2, 2003, at 4:14 PM, John Nairn wrote:
>
>
> I need an option to click on NSView and drag out a rectangle to select
>
> a region of a picture. I thought I came across a method to accomplish
>
> this once before in a single call, but I can not find it now. Is there
>
> a simple call or do I need something more involved such as
>
>
>
> a. Use mouseDown method and keep control while mouse is down updating
>
> current rectangle as needed until mouse is released.
>
>
>
> b. Implement drag and drop methods with feedback to connect origin to
>
> current position.
>
>
>
You may want to have a look at the "Cropped Image" sample at:
>
>
http://developer.apple.com/samplecode/Sample_Code/Cocoa/
>
Cropped_Image.htm
>
>
-jcr
>
>
>
John C. Randolph <email@hidden> (408) 974-8819
>
Sr. Cocoa Software Engineer,
>
Apple Worldwide Developer Relations
>
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.