Professional Web Applications Themes

Regions in Quartz? Or use QuickDraw? - Mac Programming

Is there a "newfangled" structure for representing regions in Quartz, or should I still use the QuickDrawvariety? Apple's description of QD as "the legacy two-dimensional drawing engine" and Quartz as " the native two-dimensional drawing engine" leaves me a bit leery of QD. even though I don't see any region support in the Quartz docs I've looked through. Andrew...

  1. #1

    Default Regions in Quartz? Or use QuickDraw?

    Is there a "newfangled" structure for representing regions in Quartz,
    or should I still use the QuickDrawvariety? Apple's description of QD
    as "the legacy two-dimensional drawing engine" and Quartz as " the
    native two-dimensional drawing engine" leaves me a bit leery of QD.
    even though I don't see any region support in the Quartz docs I've
    looked through.

    Andrew
    Andrew Guest

  2. #2

    Default Re: Regions in Quartz? Or use QuickDraw?

    dans l'article google.com, Andrew
    Duncan à com a écrit le 21/05/04 21:18:
     

    Regions are not supported by Quartz, but you can use paths, which are much
    more powerful.

    If you need to convert existing regions, you can use QDRegionToRects.

    Good luck,

    Eric

    Eric Guest

  3. #3

    Default Re: Regions in Quartz? Or use QuickDraw?

    Eric VERGNAUD <fr> wrote in message news:<BCD43629.21A36%fr>...
     

    Thanks, Eric. Any pointers to doentation on using paths this way?
    As my following comment indicates, I don't find Apple's latest
    doentation very easy to use.
     

    This is something I am interested in. Searching for this in Xcode's
    doentation window turns up all of this:

    OSStatus QDRegionToRects (
    RgnHandle rgn,
    QDRegionPDirection dir,
    RegionToRectsUPP proc,
    void * userData
    );
    function result
    A result code. See "QuickDraw Result Codes"

    Exactly *no* discussion of what it does. Searching at Apple's
    Reference Library online turns up exactly the same (non-)
    information...

    Andrew
    Andrew Guest

  4. #4

    Default Re: Regions in Quartz? Or use QuickDraw?

    Andrew Duncan wrote: 

    You certainly shouldn't be writing any new code using Quickdraw. The
    kinds of things we used to do with quickdraw regions we do today with
    compositing or with NSBezierPath objects. What is it that you need to do?

    -jcr
    John Guest

  5. #5

    Default Re: Regions in Quartz? Or use QuickDraw?

    dans l'article google.com, Andrew
    Duncan à com a écrit le 25/05/04 20:49:
     
    >
    > Thanks, Eric. Any pointers to doentation on using paths this way?
    > As my following comment indicates, I don't find Apple's latest
    > doentation very easy to use.
    >[/ref]

    Here's a typical sequence (fPortRef is a CGContextRef):

    ::CGContextBeginPath(fPortRef);
    ::CGContextAddRect(fPortRef,r1);
    ::CGContextAddRect(fPortRef,r2);
    ::CGContextAddRect(fPortRef,r3);
    ::CGContextClosePath(fPortRef);

    Here's another one:
    ::CGContextBeginPath(fPortRef);
    ::CGContextMoveToPoint(fPortRef,x,y);
    ::CGContextAddLineToPoint(fPortRef,x1,y1);
    ::CGContextAddLineToPoint(fPortRef,x2,y2);
    ::CGContextAddLineToPoint(fPortRef,x3,y3);
    ::CGContextClosePath(fPortRef);

    The path is 'selected' in the CGContext, so you can only use one path.
    You can then frame or fill the path using:

    ::CGContextStrokePath(fPortRef);
    ::CGContextFillPath(fPortRef);
    ::CGContextEOFillPath(fPortRef);

    The nice thing is you can add arcs and bezier curves.

    I don't know any easy way to save paths however, but I guess you can record
    all the calls and save them in an appropriate format.
     
    >
    > This is something I am interested in. Searching for this in Xcode's
    > doentation window turns up all of this:
    >
    > OSStatus QDRegionToRects (
    > RgnHandle rgn,
    > QDRegionPDirection dir,
    > RegionToRectsUPP proc,
    > void * userData
    > );
    > function result
    > A result code. See "QuickDraw Result Codes"
    >
    > Exactly *no* discussion of what it does. Searching at Apple's
    > Reference Library online turns up exactly the same (non-)
    > information...[/ref]

    I've never used this, but my guess is that it turns a region into rects that
    are passed to the proc. So converting from a QDRegion to a CGPath would look
    like the following:

    OSStatus MyRegionToRects(UInt16 message, RgnHandle rgn, const Rect
    *rect, void *refCon)
    {
    CGContextRef port = (CGContextRef)refCon;
    CGRect rect = {
    { rect->left, rect->top },
    { rect->right-rect-left , rect->bottom-rect->top } };
    CGContextAddRect(port , rect );
    }

    RegionToRectsUPP proc = NewRegionToRectsUPP(MyRegionToRects);
    ::CGContextBeginPath(fPortRef);
    ::QDRegionToRects(rgn, kQDPRegionFromTopLeft, proc, fPortRef);
    ::CGContextClosePath(fPortRef);
    DisposeRegionToRectsUPP(proc);

    At this point the 'region' should be selected as a path in the context.

    You'll have to experiment.

    Good luck,

    Eric

    Eric Guest

  6. #6

    Default Re: Regions in Quartz? Or use QuickDraw?

    In article <BCD9A0F0.21E03%fr>,
    Eric VERGNAUD <fr> wrote:
     

    I think that should be { rect->left, rect->bottom }. Quartz coordinates
    start at the lower left and increase towards the upper right. Or
    otherwise, it may be nice to mention where you got the port from so
    people know it's flipped.

    Cheers,
    -- Uli
    http://www.zathras.de
    Uli Guest

  7. #7

    Default Re: Regions in Quartz? Or use QuickDraw?

    dans l'article t-online.com, Uli Kusterer
    à de a écrit le 26/05/04 11:23:
     
    >
    > I think that should be { rect->left, rect->bottom }. Quartz coordinates
    > start at the lower left and increase towards the upper right. Or
    > otherwise, it may be nice to mention where you got the port from so
    > people know it's flipped.
    >[/ref]

    Good point. In my code, ports are always flipped, so I forgot.

    Eric

    Eric Guest

  8. #8

    Default Re: Regions in Quartz? Or use QuickDraw?

    "John C. Randolph" <idiom.com> wrote in message news:<idiom.com>... 

    Thanks, John, this is just the sort of "horse's mouth" (nothing
    personal :) advice I can use.

    I'm porting Windows code that processes captured screen images,
    breaking it up into separate regions to apply various compression
    schemes. The code uses Win32 HRGN structures, and it looks pretty
    simple to just substitute RgnHandles one-for-one, at least to get
    things going. But of course I'd prefer to do things in the 21st
    century way.

    As I mentioned earlier, I seem too often to get into circular
    definition cycles with Apple's new doentation format. (Where's
    Caroline Rose when you need her? I still have Inside Mac v.1 on my
    bookshelf... a masterpiece.) Any pointers to more in-depth exposition
    will be welcome.

    Andrew
    Andrew Guest

  9. #9

    Default Re: Regions in Quartz? Or use QuickDraw?

    In article <google.com>,
    com (Andrew Duncan) wrote:
     

    Try Apple's quartz-dev mailing list:
    <http://www.lists.apple.com/mailman/listinfo/quartz-dev>

    -Eric

    --
    Eric Albert stanford.edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

  10. #10

    Default Re: Regions in Quartz? Or use QuickDraw?

    On 2004-05-26 18:20:49 +0200, com (Andrew Duncan) said:
     
    news:<idiom.com>... [/ref]
    do? 

    Regions are perfectly compatible with the 21st century. In fact, if the
    Windows version is already using regions, then I would recommend to simply
    replace them with QD regions on the Mac side.

    Regions are a data structure which was specifically designed for making the
    computation of geometric operations like computing the union, intersection
    and difference of them fast and easy. Another big advantage of regions is
    that they make it easy to iterate in terms of axes parallel rectangles over
    the area described by the region.

    Doing the same with arbitrary PS / PDF style Bezier paths is by far more
    complicated compared to regions especially if the resulting path should be
    able to contain Bezier curves rather than just line segments. This is
    probably the simple reason why neither AppKit's NSBezierPath class nor the
    Quartz API has any public API for computing the union, intersection or
    difference of Bezier paths.

    The simple truth is that PS / PDF style Bezier paths are not a replacement
    for regions because they were designed for a very different purpose. Namely
    for describing paths in a device independent way for rendering proposes
    only. In fact, its very common among PS / PDF rendering libraries to
    convert those Bezier paths into regions (shape structures) before they
    clip those paths to the output device and before they finally render them.

    Note also that starting with system version 10.3, QD regions sit on top of
    Quartz's region implementation. There is however, sadly still no public
    region API in Quartz or AppKit...
     

    The QD region API should be doented in the QD API reference doent
    which can be found in the Carbon section. Anyway, just don't get me started
    on Apple's QuickTime or Cocoa docs. The former are absolutely unhelpful and
    the latter has a tendency to still happily describe the NeXTStep AppKit and
    Foundation - but not the MacOS X versions of those frameworks. I.e. the
    text system doentation still talks about DPS which has never been part
    of MacOS X...


    Regards,

    Dietmar Planitzer

    Dietmar Guest

Similar Threads

  1. Editable Regions and Locked Regions
    By danieljdonnelly@hotmail.com in forum Macromedia Contribute General Discussion
    Replies: 0
    Last Post: January 24th, 01:45 PM
  2. Quickdraw in CGContexts
    By Eric in forum Mac Programming
    Replies: 2
    Last Post: October 19th, 08:07 PM
  3. QuickDraw view bug?
    By Dad in forum Mac Programming
    Replies: 1
    Last Post: August 14th, 02:59 AM
  4. HIViews and Quickdraw
    By Eric VERGNAUD in forum Mac Programming
    Replies: 1
    Last Post: August 2nd, 09:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139