CIDLib Core Class Reference: TArea

Class: TArea


Facility: CIDLib.Dll
Header: CIDLib_Area.Hpp
Derived From: TCIDObject [MCIDDuplicable, MCIDStreamable]

The TArea class is one of the foundations of the system. It represents a 2D rectangular area with 2D, integral coordinates. Sooo much code in a system, particularly graphic and window systems, depends upon points and areas. Knowing this class (and its cousin TPoint) well can save you a massive amount of work. Its been designed to do a lot of work for you and to handle lots of grunt code so that there is a lot of less 'magic formula' code in these types of apps.

TArea can be seen as a signed origin and and unsigned extent in the Y and Y, or it can be seen as a singed origin and signed upper left corner. Internally of course its one or the other, but you don't have to care. This allows the class to be more self documenting and convenient when the semantics of your problem naturally falls into one of these schemes.

Here are some simple examples of the TArea class.

    //
    //  Assume we have some widget object to draw. We also have a paint
    //  brush object to draw on and its current invalid area.
    //
    TSomeWidget* pwdgtToDraw;
    TPaintbrush ptbToDrawOn;
    TArea       areaInvalid;

    // If our widget area intersects the invalid area, then we draw
    if (areaInvalid.bIntersects(pwdgtToDraw->areaOf())
        pwdgtToDraw->Draw(ptbToDrawOn);



    //
    //  In this example, we show how to use it to draw a bitmap in the
    //  upper right of a window. Assume we have a window and a bitmap
    //  object to draw. Create a paintbrush to draw with, get the window
    //  area and create a new, upper right justified area and draw the
    //  bitmap into it.
    //
    //  areaWndSize() returns a 0 based TArea that holds the window's
    //  size. We want 0 based here becasue drawing is relative to the
    //  window. If we wanted the window's actual area, we would have
    //  used areaWnd().
    //
    TWindow*    pSomeWindow;
    TBitmap     bmpToDraw;

    TArea   areaDraw(bmpToDraw.areaBitMap());
    areaDraw.JustifyIn
    (
        pSomeWindow->areaWndSize()
        , tCIDLib::eHJustify_Right
        , tCIDLib::eVJustify_Top
    );

    TPaintbrush ptbToDrawOn(pSomeWindow);
    bmpToDraw.DrawOn(ptbToDrawOn, areaDraw);

Constructors

There are lot of constructors because these objects need to be created from many different formats of raw values. Many of these are primarily for internal use (the outside world should not have to deal with converting to and from PM structures), but are there for those who need them.
    TArea();

    TArea
    (
        const   RECTL&                  rectlSrc
        , const tCIDLib::eRectlTypes    eInclusive
    );

    TArea
    (
        const   SWP&                    swpSrc
    );

    TArea
    (
        const   POINTL&                 ptlLLeft
        , const POINTL&                 ptlURight
    );

    TArea
    (
        const   TPoint&                 pntLLeft
        , const TPoint&                 pntURight
    );

    TArea
    (
        const   tCIDLib::TInt4          x
        , const tCIDLib::TInt4          y
        , const tCIDLib::TCard4         cx
        , const tCIDLib::TCard4         cy
    );

    TArea
    (
        const   TPoint&                 pntOrg
        , const tCIDLib::TCard4         cx
        , const tCIDLib::TCard4         cy
    );

    TArea
    (
        const   TArea&                  areaSrc
    );

Caveats/Gotchas

Keep these issues in mind when using TArea objects:
  1. When converting to and from PM RECTL structures, you must indicate whether the PM rectangle is (or should be) inclusive or non-inclusive. TArea objects are always inclusive.
  2. The default constructor will just create an empty area.
  3. When doing the lower-left/upper-right corner style of construction, the coordinates will be flipped in order to make sure the origin is always in the lower left.

CIDCorp
Dean Roddey
Internet: droddey@ng.netgate.net
CIS: 72170,1614