Setting A Clip Region - Xwindows

This is a discussion on Setting A Clip Region - Xwindows ; What I am trying to do is only output text in a rectangle and only within that rectangle where an existing region shows it should be drawn. I would like to set the area outside the rectangle in the region ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Setting A Clip Region

  1. Setting A Clip Region

    What I am trying to do is only output text in a rectangle and only within
    that rectangle where an existing region shows it should be drawn. I would
    like to set the area outside the rectangle in the region to not draw text
    while keeping any masked areas inside the rectangle in tact. Is there an
    XLib function to do this?

    Thanks in advance,
    Charlie



  2. Re: Setting A Clip Region

    CharlieB wrote in news:c0FPb.14323$xu6.12005
    @fe02.usenetserver.com:
    > What I am trying to do is only output text in a rectangle and only within
    > that rectangle where an existing region shows it should be drawn.


    Xlib supports clip rectangles via the graphics context.

    Ken Lee, http://www.rahul.net/kenton/

  3. Re: Setting A Clip Region

    Ken Lee wrote:

    > CharlieB wrote in news:c0FPb.14323$xu6.12005
    > @fe02.usenetserver.com:
    >> What I am trying to do is only output text in a rectangle and only within
    >> that rectangle where an existing region shows it should be drawn.

    >
    > Xlib supports clip rectangles via the graphics context.
    >
    > Ken Lee, http://www.rahul.net/kenton/


    Let me try to explain this one better using rectangles:

    |------------------------|
    | A |
    | |
    | |
    | | |---------|
    | | | B |
    | | | |
    | |----------------| |
    |-----------------|------| C | | |
    | | | |
    |----------------| |
    |---------|

    I have a region with rectangles A & B that need to be redrawn.

    I want to draw a text string that would take up the entire C rectangle but
    the only part of it that I want to actually draw is where rectangle A & B
    intersect C. If I use XUnionRectWithRegion() it would redraw the entire C
    rectangle and allow drawing beyond the C rectangle into the B rectangle.

    What I need is a region that just contains the overlapping areas and ends up
    looking like this:

    |------| |---|
    |------| | |
    | |
    |---|

    Is there a function that does the opposite of XUnionRectWithRegion() by
    masking the area outside of the C rectangle. Can I accomplish this with XLib
    functions?

    Thanks again,
    Charlie


  4. Re: Setting A Clip Region

    CharlieB wrote in
    news:tzZPb.25826$xu6.6823@fe02.usenetserver.com:
    > Is there a function that does the opposite of XUnionRectWithRegion() by
    > masking the area outside of the C rectangle. Can I accomplish this with
    > XLib functions?


    The rect functions are just conveniences. You can always create the
    rectangle list using your own logic. You can also use a bitmap to create an
    arbitrary non-rectangular clipmask.

    Ken Lee, http://www.rahul.net/kenton/

  5. Re: Setting A Clip Region

    CharlieB wrote:
    >
    > Let me try to explain this one better using rectangles:
    >
    > |------------------------|
    > | A |
    > | |
    > | |
    > | | |---------|
    > | | | B |
    > | | | |
    > | |----------------| |
    > |-----------------|------| C | | |
    > | | | |
    > |----------------| |
    > |---------|
    >
    > I have a region with rectangles A & B that need to be redrawn.
    >
    > I want to draw a text string that would take up the entire C rectangle but
    > the only part of it that I want to actually draw is where rectangle A & B
    > intersect C. If I use XUnionRectWithRegion() it would redraw the entire C
    > rectangle and allow drawing beyond the C rectangle into the B rectangle.
    >
    > What I need is a region that just contains the overlapping areas and ends
    > up looking like this:
    >
    > |------| |---|
    > |------| | |
    > | |
    > |---|
    >
    > Is there a function that does the opposite of XUnionRectWithRegion() by
    > masking the area outside of the C rectangle. Can I accomplish this with
    > XLib functions?
    >


    Could I create a new region and use XUnionRectWithRegion() to add rectangle
    C to it then use XIntersectRegion() to make a region with the desired
    overlapping rectangles?

    The man page for these X functions only have a 1 line description and I am
    not sure what they do:

    XIntersectRegion()
    XUnionRegion()
    XSubtractRegion()
    XXorRegion()

    Would any of these do what I need?

    Thanks,
    Charlie


  6. Re: Setting A Clip Region

    Hi CharlieB!

    On 22 Jan 04 at 21:36, "CharlieB" (CharlieB ) wrote:
    CharlieB> The man page for these X functions only have a 1 line
    CharlieB> description and I am not sure what they do:

    CharlieB> XIntersectRegion() XUnionRegion() XSubtractRegion()
    CharlieB> XXorRegion()

    Here is a link to msdn site with graphic explanation of the region
    arithmetic :
    http://msdn.microsoft.com/library/de...gions_7xwz.asp

    Although it's all about win32 api, this particular function maps directly
    into X api, where XIntersetRegion=RGN_AND, XUnionRegion=RGN_OR,
    XSubtractRegion=RGN_DIFF, XXorRegion=RGN_XOR.

    --
    HTH,
    Dmitry

    --- www.karasik.eu.org ---

    He who dies with most the toys wins

  7. Re: Setting A Clip Region

    In comp.windows.x, CharlieB

    wrote
    on Thu, 22 Jan 2004 20:36:42 +0000
    :
    > CharlieB wrote:
    >>
    >> Let me try to explain this one better using rectangles:
    >>
    >> |------------------------|
    >> | A |
    >> | |
    >> | |
    >> | | |---------|
    >> | | | B |
    >> | | | |
    >> | |----------------| |
    >> |-----------------|------| C | | |
    >> | | | |
    >> |----------------| |
    >> |---------|
    >>
    >> I have a region with rectangles A & B that need to be redrawn.
    >>
    >> I want to draw a text string that would take up the entire C rectangle but
    >> the only part of it that I want to actually draw is where rectangle A & B
    >> intersect C. If I use XUnionRectWithRegion() it would redraw the entire C
    >> rectangle and allow drawing beyond the C rectangle into the B rectangle.
    >>
    >> What I need is a region that just contains the overlapping areas and ends
    >> up looking like this:
    >>
    >> |------| |---|
    >> |------| | |
    >> | |
    >> |---|
    >>
    >> Is there a function that does the opposite of XUnionRectWithRegion() by
    >> masking the area outside of the C rectangle. Can I accomplish this with
    >> XLib functions?
    >>

    >
    > Could I create a new region and use XUnionRectWithRegion() to add rectangle
    > C to it then use XIntersectRegion() to make a region with the desired
    > overlapping rectangles?
    >
    > The man page for these X functions only have a 1 line description and I am
    > not sure what they do:
    >
    > XIntersectRegion()
    > XUnionRegion()
    > XSubtractRegion()
    > XXorRegion()
    >
    > Would any of these do what I need?
    >
    > Thanks,
    > Charlie
    >


    If you know A intersect C as a rectangle and B intersect
    C as another rectangle, you can use XSetClipRectangles on
    your drawing GC with these two rectangles. Be careful
    of inversions (negative height or width). Note that
    the width of (rectA and rectC) is *not* min(rectA.width,
    rectC.width).

    If you do not know how A, B, and C interrelate, but
    know that you want to draw into C (but only where
    C's bits are exposed by the other rectangles), you
    might compute XUnionRectWithRegion() of all other
    rectangles (start with an empty region, created by
    XCreateRegion()) then create another region using a
    single call of XUnionRectWithRegion() with C, and then
    call XIntersectRegion() on the two. This will create AC +
    BC, above, as (A + B)C. Note that a rectangle D that does
    not intersect C will not be included, which appears to be
    exactly what you want.

    I'm assuming you're generally familiar with such things
    as Boolean operations and Venn diagrams (which this
    vaguely resembles).

    If you want to futz with bitmaps, you can also use
    XSetClipMask(). Here's how that might work: create a
    bitmap and a bitmap GC (you can't use an existing GC
    here unless the depth of that GC is 1) and create a bitmap of
    the size of either the screen, or whatever big window is
    containing all this, to all 0's. Fill C with 0's.
    Fill rectangles A and B with 1's. Fill (not C), which
    is 4 rectangles completely surrounding C, with 0's.
    Set the bitmap as your drawing GC clip mask, and draw.

    If you don't mind variable size bitmaps, create a bitmap
    of dimension (C.width, C.height), create a bitmap GC, set
    its clip to a rectangle (0,0,C.width,C.height), blast the
    bitmap to 0's, fill the rectangles (A.x - C.x, A.y - C.y,
    A.width, A.height) and (B.x - C.x, B.y - C.y, B.width,
    B.height) with 1's, and then set the clip mask and origin
    of your drawing GC, and draw.

    If you *really* want to simplify your life, consider
    using windows for A, B, and C instead of rectangles, and
    handling the Expose events therefrom; the server will
    do most of the work for you in that case. However, your
    problem may preclude such a solution; I can't say at this time
    without more info. I should note here that X Windows are
    relatively cheap -- they don't have frames or scrollbars
    (although they do have a border). The drawback is: they don't
    have frames or scrollbars.

    I have no idea which of these is the fastest, but hope this helps.
    Bear in mind that you will need to destroy whatever you
    create eventually; otherwise the X server will run out of
    resources. I'm not sure if you need to reset the
    GC's clip region or mask first, or not.

    Happy hacking. :-)

    --
    #191, ewill3@earthlink.net
    It's still legal to go .sigless.

  8. Re: Setting A Clip Region

    Dmitry Karasik wrote:

    > Hi CharlieB!
    >
    > On 22 Jan 04 at 21:36, "CharlieB" (CharlieB ) wrote:
    > CharlieB> The man page for these X functions only have a 1 line
    > CharlieB> description and I am not sure what they do:
    >
    > CharlieB> XIntersectRegion() XUnionRegion() XSubtractRegion()
    > CharlieB> XXorRegion()
    >
    > Here is a link to msdn site with graphic explanation of the region
    > arithmetic :
    >

    http://msdn.microsoft.com/library/de...gions_7xwz.asp
    >
    > Although it's all about win32 api, this particular function maps directly
    > into X api, where XIntersetRegion=RGN_AND, XUnionRegion=RGN_OR,
    > XSubtractRegion=RGN_DIFF, XXorRegion=RGN_XOR.
    >

    Thanks to everyone that replied. The above info helped a lot. How would one
    go about submitting changes to the man pages?




+ Reply to Thread