GliderPRO/Sources/RectUtils.c

1 line
8.3 KiB
C
Raw Permalink Normal View History

//============================================================================ //---------------------------------------------------------------------------- // RectUtils.c //---------------------------------------------------------------------------- //============================================================================ #include "Externs.h" #include "RectUtils.h" //============================================================== Functions //-------------------------------------------------------------- FrameWHRect // Given the top left corner and a width and height, this function<6F> // simply creates the necessary rectangle and frames it. void FrameWHRect (short left, short top, short wide, short high) { Rect theRect; theRect.left = left; theRect.top = top; theRect.right = left + wide; theRect.bottom = top + high; FrameRect(&theRect); } //-------------------------------------------------------------- NormalizeRect // This function ensures that a rect's top is less than it's bottom<6F> // and that left is less than right. void NormalizeRect (Rect *theRect) { short tempSide; if (theRect->left > theRect->right) { tempSide = theRect->left; theRect->left = theRect->right; theRect->right = tempSide; } if (theRect->top > theRect->bottom) { tempSide = theRect->top; theRect->top = theRect->bottom; theRect->bottom = tempSide; } } //-------------------------------------------------------------- ZeroRectCorner // The rect passed in is slid over so that its top left corner is<69> // at coordinates (0, 0). void ZeroRectCorner (Rect *theRect) // Offset rect to (0, 0) { theRect->right -= theRect->left; theRect->bottom -= theRect->top; theRect->left = 0; theRect->top = 0; } //-------------------------------------------------------------- CenterRectOnPoint // Given a rectangle and a point, this function centers the rectangle<6C> // on that point. void CenterRectOnPoint (Rect *theRect, Point where) { ZeroRectCorner(theRect); QOffsetRect(theRect, -HalfRectWide(theRect), -HalfRectTall(theRect)); QOffsetRect(theRect, where.h, where.v); } //-------------------------------------------------------------- HalfRectWide // Given a rectangle, this function returns the rect's width divided by 2. short HalfRectWide (Rect *theRect) { return ((theRect->right - theRect->left) / 2); } //-------------------------------------------------------------- HalfRectTall // Given a rectangle, this function returns the rect's height divided by 2. short HalfRectTall (Rect *theRect) { return ((theRect->bottom - theRect->top) / 2); } //-------------------------------------------------------------- RectWide // Given a rectangle, this simple function returns the rect's width. short RectWide (Rect *theRect) { return (theRect->right - theRect->left); } //-------------------------------------------------------------- RectTall // Given a rectangle, this simple function returns the rect's height. short RectTall (Rect *theRect) { return (theRect->bottom - theRect->top); } //-------------------------------------------------------------- GlobalToLocalRect // This function offsets a rectangle from global to local coordinates. // The "local" coordinate system is assumed to be the current port (window). void GlobalToLocalRect (Rect *theRect) { Point upperLeftPt; upperLeftPt.h = 0; upperLeftPt.v = 0; GlobalToLocal(&upperLeftPt); QOffsetRect(theRect, upperLeftPt.h, upperLeftPt.v); } //-------------------------------------------------------------- LocalToGlobalRect // This function offsets a rectangle from local to global coordinates. // The "local" coordinate system is assumed to be the current port (window). void LocalToGlobalRect (Rect *theRect) { Point upperLeftPt; upperLeftPt.h = 0; upperLeftPt.v = 0; LocalToGlobal(&upperLeftPt); QOffsetRect(theRect, upperLeftPt.h, upperLeftPt.v); } //-------------------------------------------------------------- CenterRectInRect // Given two rectangles, this function centers the first rectangle<6C> // within the second. The second rect is