Re: nsbitmapimagerep from nsview subclass, obtaining and drawing
Re: nsbitmapimagerep from nsview subclass, obtaining and drawing
- Subject: Re: nsbitmapimagerep from nsview subclass, obtaining and drawing
- From: "I. Savant" <email@hidden>
- Date: Wed, 1 Aug 2007 11:46:29 -0400
David:
> I'm attempting to implement subview dragging, snapping etc. with transparency. I'm pretty sure the solution is not to create a temporary subview to be dragged (because there is no way to draw a subview with 50% transparency?), but I'd like the image of the view being dragged to appear over the other subviews.
If you're trying to make something like IB (where a view can be
dragged to a new location, your approach depends entirely on how
pretty you want to make it. The general approach I'd take is to USE
THE EXISTING DRAG-AND-DROP FUNCTIONALITY:
1 - Using typical d-n-d methods, first retain and remove the the
dragged subview from its superview (so it's not in two places at
once).
2 - Obtain the drag image and supply it to the d-n-d mechanism.
3 - Let d-n-d take care of drawing the image (so it appears to hover
*over* all your other subviews).
4 - On drop, record / convert the new location, set the dragged
subview's frame and re-add it to the superview.
> 1. the nsbitmapimagerep I'm obtaining from the subview being dragged is being either stored or drawn improperly. It basically appears that although the memory space is retained, the contents of that memory is highly corrupt; the view usually contains the color black with random spots of white (consistent with a ton of 0x00000000 bytes and other garbage values). I'm obtaining the image rep by setting myImageRep = [self bitmapImageRectForCachingDisplayInRect:[self bounds]], then passing that image rep to the controller which passes it to the window's primary view so it can be displayed anchored to the mouse position in the window.
You're referencing custom code you've written but are not including
it in your post. My guess is, your
-bitmapImageRectForCachingDisplayInRect: method is wrong somehow. :-D
I'm not sure why you're working directly with an NSBitmapImageRep -
why not use NSImage? Get the data from the view via NSView's
-dataWithPDFInsideRect: method and create an NSImage with that data.
That's about as much help as I can offer without seeing the code you
say is misbehaving.
>
> 2. the imagerep is drawn below all the subviews in the window. my drawRect function looks like this (note, I'm not clear on exactly how bitmap image drawing works, whether I need to obtain some context or what - however, since a square is being drawn at the correct location in relation to the mouse, I suspect that it is the image itself that's corrupt, as described above):
This is presumably because you're drawing it on the superview, whose
"canvas" is covered up by any subviews. This is why you should use the
existing Drag and Drop mechanism and why you should *not* draw all
this in the superview.
> I called the super drawrect with the expectation that maybe the subviews would be drawn first, and then the dragimage drawn on top of everything else.
> I have not yet tried to draw the image with 50% transparency. Is this done by first using [[NSColor colorWithRed:% green:% blue:% alpha:%] set] ? It doesn't seem to be the case that setting the nscolor has any effect.
Um .... no.
Have you even read the Cocoa Drawing Guide? If you have, re-read it.
If you haven't, BAD DEVELOPER.
--
I.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden