Unit region

--- beta --- beta --- beta --- beta --- beta --- beta --- beta --- beta --- // TRegion // This is an experimental component which encapsulates a windows region. The specific aim is to avoid using the API calls, but use a TRegion instead. The direct parallel is the use of a TCanvas rather than the API drawing calls. // Regions can be used to clip the drawing to a form so that only drawing in prescribed regions can occur and also used to clip the form so that form can take on shapes other than rectangular. It is the latter behaviour that this component currently provides. Regions can be rectangular, elliptical, polygons and text. You can test to see if given points are inside a region, fill a region with a brush and frame a region with a brush. Regions when defined can be saved to disc and reloaded (which gives the possibility of defining the region and using the region in separate programs). Regions can be moved and scaled, and also with NT4 rotated and skewed. To obtain some of the features (such as text) I have encapsulated the drawing path API calls in another class, called suprisingly TPath. Many other shapes are possible by first using a path to create a region. Other shapes include bezier curves and areas drawn by lines (as against a polyline or polygon), and also with NT4, arcs, chords and pies (and more). Wherever possible I have used the TCanvas calling names, styles and parameter lists, so you can use Delphi help for ideas of what I am trying to do. // The current version is Form coordinate based *not* Client coordinate based. So 0, 0 is the top left corner of the title bar. You may need to convert client coordinates into form coordinates when hit testing (etc). // Comments/Ideas: 1) error handling is limited, checking is through (I hope) but the messages generated are not meaningful. 2) remove more of the NT4 dependencies by providing code in a win 95 version which carries out the things present under NT4 - see TPath.Rectangle as an (only) example. 3) no events included, but could have OnChanging and OnChanged (like TCanvas) and some type of form hit testing (NCHIT) and since the title bar often disappears, some provision for form dragging and resizing. 4) most unlikely to be thread-safe. Needs locking like a TCanvas? // ------------------------------------------------------------------------------ // I am releasing this beta version for trial and comment. I have no specific requirements of any one picking up and using this component. But I really would *appreciate* feedback. // Included with it is a demo program which shows-off most of it's features. // ------------------------------------------------------------------------------ // Note about Turbopower's Memory Sleuth: Memory Sleuth will report that region handles are not freed by this component. I think the problem may be with Memory Sleuth and I have contacted Turbopower to tell them this. But TurboPower have taken little/no interest in this report. Specifically Memory Sleuth does not recognise the "handing over" of a region handle to the operating system by a call to SetWindowRgn, when you do this you must not then delete the handle (according to win32.hlp). // ------------------------------------------------------------------------------ // If you have comment or critism of this component, or wishes but no time to delve into what is required, then please contact me at: // grahame.s.marsh@courtaulds.com // --- beta --- beta --- beta --- beta --- beta --- beta --- beta --- beta ---

Classes

TPath - === TPath ==================================================================== Encapsulates a windows drawing path.
TRegion -

Functions

Types

TRegionCombine
TRegionFillMode

Constants

IdentityXForm
rgComplex
rgEmpty
rgError
rgSimple

Variables


Functions


Types


TRegionCombine  = (rcAnd, rcIntersect, rcCopy, rcDifference, rcSubtract,
                         rcOr, rcUnion, rcXor);
Region combination modes, these are translated into the windows integer values by XlatCombineMode. Note duplication so rcAnd has same effect as rcIntersect; similarly rcDifference & rcSubtract; and rcUnion & rcOr.
TRegionFillMode = (fmAlternate, fmWinding);
Region fill modes see win32.hlp for explaination of ALTERNATE and WINDING

Constants

IdentityXForm = (eM11: 1; eM12: 0; eM21: 0; eM22: 1; eDx : 0; eDy : 0)

*** not done *** PaintRgn - not needed? CreatePolyPolygonRegion - don't see the use ------------------------------------------------------------------------------ This is the identity transform matrix - when used it causes no changes to the region's coordinates.

rgComplex = COMPLEXREGION

= 2

rgEmpty = NULLREGION

= 0

rgError = RGN_ERROR

*** not done *** TextHeight - lazy of me ExtTextOut - complex, later PolyPolygon PolyPolyLine - don't see value === TREGION ================================================================== convert region complexity constants into Delphiesque constants

rgSimple = SIMPLEREGION

= 1

Variables