uLib  User mode C/C++ extended API library for Win32 programmers.
Rectangle Support

Module Description

Supplementary rectangle functions.

Some special rectangle "border" legacy operations.
These APIs augment Inflate/OffsetRect by using separate delta for each edge.
Synopsis:

   +-Outer-------------------------------------+ <---
   |                                           |  (+)
   |   +-Inner-------------------------+       | <---
   |   |                               |       |
   |   |                               |       |
   |   +-------------------------------+       | <---
   |                                           |  (-)
   +-------------------------------------------+ <---
   ^   ^                               ^       ^
   |(+)|                               |  (-)  |

DiffRect() subtracts Inner - Outer, such that left/top borders get a positive sign,
and right/bottom borders get a negative sign in the Border diff.
(Hence, if the Inner rect is not entirely enclosed in the Outer, examining the signs
of the result will indicate if an edge is inside or outside.)

InflateBorders() inflates each edge of Target by the related Borders edge.

AbsDiffRect() and AbsInflateBorders() performs the same operations,
but with uniform values, which might be easier to deal with sometimes.

Example: Per synopsis, take DiffRect( Borders, Outer, Inner ).
InflateBorders( Inner, Border ) will then result in the the Outer rect,
and NegateRect( Borders ); InflateBorders( Outer, Borders )
will result in the Inner rect.

Macros

#define RECT_WIDTH(r)   ((r).right - (r).left)
 
#define RECT_HEIGHT(r)   ((r).bottom - (r).top)
 

Functions

void DiffRect (PRECT Borders, LPCRECT Outer, LPCRECT Inner)
 
void InflateBorders (PRECT Target, LPCRECT Borders)
 
void AbsDiffRect (PRECT Borders, LPCRECT Outer, LPCRECT Inner)
 
void AbsInflateBorders (PRECT Target, LPCRECT Borders)
 
LPRECT AbsToDimRect (LPRECT pRect)
 
LPRECT DimToAbsRect (LPRECT pRect)
 
LPRECT AbsToRelRect (LPRECT pRect)
 
LPRECT NegateRect (LPRECT pRect)
 
void FitRect (IN PRECT pRc, IN PRECT pBounds, OUT PRECT pOut)
 

Macro Definition Documentation

◆ RECT_WIDTH

#define RECT_WIDTH (   r)    ((r).right - (r).left)

Definition at line 161 of file UtilFunc.h.

◆ RECT_HEIGHT

#define RECT_HEIGHT (   r)    ((r).bottom - (r).top)

Definition at line 162 of file UtilFunc.h.

Function Documentation

◆ DiffRect()

void DiffRect ( PRECT  Borders,
LPCRECT  Outer,
LPCRECT  Inner 
)

DiffRect subtracts Inner - Outer and puts the result in Borders.
See the group description for further details.

Definition at line 141 of file UtilFunc.cpp.

◆ InflateBorders()

void InflateBorders ( PRECT  Target,
LPCRECT  Borders 
)

InflateBorders inflates each edge of Target by the related Borders edge.
See the group description for further details.

Definition at line 158 of file UtilFunc.cpp.

◆ AbsDiffRect()

void AbsDiffRect ( PRECT  Borders,
LPCRECT  Outer,
LPCRECT  Inner 
)

[Preliminary]
See the group description .

Definition at line 150 of file UtilFunc.cpp.

◆ AbsInflateBorders()

void AbsInflateBorders ( PRECT  Target,
LPCRECT  Borders 
)

[Preliminary]
See the group description .

Definition at line 167 of file UtilFunc.cpp.

◆ AbsToDimRect()

LPRECT AbsToDimRect ( LPRECT  pRect)

Set right,bottom = width,height.
Convert a (X,Y,X2,Y2) rect to dimension form (X,Y,W,H).
Return pRect.

Definition at line 86 of file UtilFunc.cpp.

◆ DimToAbsRect()

LPRECT DimToAbsRect ( LPRECT  pRect)

Reciprocal of AbsToDimRect().
Convert a (X,Y,W,H) dimension rect back to absolute form (X,Y,X2,Y2).
Return pRect.

Definition at line 92 of file UtilFunc.cpp.

◆ AbsToRelRect()

LPRECT AbsToRelRect ( LPRECT  pRect)

Set top,left = 0; right,bottom = width,height.
Convert an (X,Y,X2,Y2) absolute rect to relative form (0,0,W,H).
Return pRect.

Definition at line 98 of file UtilFunc.cpp.

◆ NegateRect()

LPRECT NegateRect ( LPRECT  pRect)

Change sign of all rect fields.
Return pRect.

Definition at line 103 of file UtilFunc.cpp.

◆ FitRect()

void FitRect ( IN PRECT  pRc,
IN PRECT  pBounds,
OUT PRECT  pOut 
)

Fit one rectangle inside another with preserved aspect ratio.

Parameters
pRcSource rectangle to adjust.
pBoundsDestination rectangle to fit inside.
pOutRecieves the fitted source rectangle.