Drawing a selection rectangle

  • Is there an efficient way to display a selection rectangle in a view
    without having to keep redrawing the stuff the rectangle passes over?
    Currently, I'm just drawing a dashed box as I drag the mouse, but as
    the rectangle moves, I need to redraw the old region (or the lazy
    way, redraw the entire view).

    I'd like a way, for example, to add a drawing "layer" that contains
    only the selection rectangle, and then simply redraw that layer.
    Seems like a common thing to do.

    Tips?

    Jeff
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • My first thought would be to use a mostly transparent view to represent
    the selected region.

    On Jan 30, 2004, at 12:03 AM, Jeffrey Mattox wrote:

    > Is there an efficient way to display a selection rectangle in a view
    > without having to keep redrawing the stuff the rectangle passes over?
    > Currently, I'm just drawing a dashed box as I drag the mouse, but as
    > the rectangle moves, I need to redraw the old region (or the lazy way,
    > redraw the entire view).
    >
    > I'd like a way, for example, to add a drawing "layer" that contains
    > only the selection rectangle, and then simply redraw that layer. Seems
    > like a common thing to do.
    >
    > Tips?
    >
    > Jeff
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.

    [demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • > Is there an efficient way to display a selection rectangle in a view
    > without having to keep redrawing the stuff the rectangle passes over?

    Sure - make a transparent window that is placed over your view. You can
    then draw in it and clear it without disturbing the view underneath.
    Because the window server uses the graphics card's texture mapping
    hardware
    to do the compositing, you can follow the mouse in "real time".

    I use this for all my temporary graphics and it works just fine.

    ......Bob Clair
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Jan 30, 2004, at 7:03 AM, Jeffrey Mattox wrote:

    > Is there an efficient way to display a selection rectangle in a view
    > without having to keep redrawing the stuff the rectangle passes over?
    > Currently, I'm just drawing a dashed box as I drag the mouse, but as
    > the rectangle moves, I need to redraw the old region (or the lazy way,
    > redraw the entire view).
    >
    > I'd like a way, for example, to add a drawing "layer" that contains
    > only the selection rectangle, and then simply redraw that layer. Seems
    > like a common thing to do.
    >
    > Tips?
    >
    >
    Hello!

    Did you look at [NSWindow cacheImageInRect:] ? I use it for exactly
    this purpose...

    izidor

    http://developer.apple.com/documentation/Cocoa/Reference/
    ApplicationKit/ObjC_classic/Classes/NSWindow.html#//apple_ref/doc/uid/
    20000013/BCIDFEII

    - (void)cacheImageInRect:(NSRect)aRect
    Stores the receivers raster image from aRect, which is expressed in
    the receivers base coordinate system. This method allows the receiver
    to perform temporary drawing, such as a band around the selection as
    the user drags the mouse, and to quickly restore the previous image by
    invoking restoreCachedImage andflushWindowIfNeeded. The next time the
    window displays, it discards its cached image rectangles. You can also
    explicitly use discardCachedImage to free the memory occupied by cached
    image rectangles. aRect is made integral before caching the image to
    avoid antialiasing artifacts.

    Only the last cached rectangle is remembered and can be restored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month january 2004 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Go to today