Re: selecting images
Re: selecting images
- Subject: Re: selecting images
- From: John Fox <email@hidden>
- Date: Sat, 9 Apr 2005 08:51:49 -0700
Hi Stefan:
Unfortunately, you don't get this functionality for free. ;-)
Roughly speaking, this is what you'll need to do:
1) Create a subclass of NSImageView if you haven't already. Add an instance variable BOOL isSelected, and don't forget to create setter methods so the value of isSelected can be set by other objects.
In this subclass's drawRect method, you can do something like this:
...
if ([self isSelected])
{
[[NSColor blueColor] set];
NSFrameRect([self bounds]);
}
...
This will cause the outer edges of the to have a blue highlight. There are certainly other techniques you could use to highlight: for example if you really want to be clever you could highlight just the are within the image view actually covered by the image.
2) You might want to create an NSMutableSet in you NSView subclass in order to store the NSImageView (or rather your custom subclass) objects that are actually selected. This is useful if you want to do something elsewhere like enumerate the selected objects set in order to do something with the images (or objects which they represent).
3) In your NSView, you'll need to implement mouseDown: (for click select) and mouseDragged: (for drag select).
For click select, mouseDown: is where you will check to see if the mouse location defined by the NSEvent you get passed from mouseDown methods is inside one of your NSImageView subclasses' bounds. For drag select, mouseDown is where you will create your selection rectangle (an NSRect) by first setting it origin. In the case of mouseDragged, you will need to create an update the height and width as the mouse is dragged. Then you check to see if the bounds of any of your NSImageView bounds intersect with the NSRect you create while dragging.
In either case, you will need to perform this test for each NSImageView subclass by enumerating the subviews of your NSView.
Hope this helps: if not, feel free follow up with me and I can give you some more detail.
John
PS Keep in mind that NSImageView carries a lot of overhead from NSView, so if you are trying to display a lot of images in one view, your performance will not be good.
_______________________________________________
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