home *** CD-ROM | disk | FTP | other *** search
- /*
- #### # # # #
- # # # # # The FreeWare C library for
- # # ## ### # # # # ### RISC OS machines
- # # # # # # # # # # # ___________________________________
- # # #### ### ## # # # #
- # # # # # # # # # # Please refer to the accompanying
- #### ### #### # # ##### # ### documentation for conditions of use
- ________________________________________________________________________
-
- File: Coord.h
- Author: Copyright © 1992 Edouard Poor and Jason Williams
- Version: 1.01 (30 Apr 1993)
- Purpose: Coord (point and rectangle) handling functions
- */
-
- #ifndef __dl_coord_h
- #define __dl_coord_h
-
- #ifndef __dl_core_h
- #include "Core.h"
- #endif
-
- #ifndef __dl_wimp_h
- #include "Wimp.h"
- #endif
-
-
- typedef struct
- {
- wimp_rect screenrect;
- wimp_point scroll;
- } convert_block;
-
-
-
- /*
- * Coord_PointInRect(point, rectangle)
- *
- * Tests whether the point in within the rectangle. If it on the line
- * its counted as in (just like in tennis).
- *
- */
- extern BOOL Coord_PointInRect(wimp_point *, wimp_rect *);
-
-
- /*
- * Coord_RectContained(InsideRect, OutsideRect)
- *
- * Test whether the InsideRect is wholly contained by the OutsideRect.
- * Shared vertices/edges are considered to be inside.
- */
- extern BOOL Coord_RectContained(wimp_rect *, wimp_rect *);
-
-
- /*
- * Coord_RectsOverlap(RectangleA, RectangeB)
- *
- * Returns TRUE if the two rectangles overlap (includes containment)
- */
- extern BOOL Coord_RectsOverlap(wimp_rect *, wimp_rect *);
-
-
- /*
- * Coord_RectsIntersect(RectangleA, RectangeB)
- *
- * Returns TRUE if the two rectangles intersect but neither is contained
- * wholly within the other.
- */
- #define Coord_RectsIntersect(r1, r2) (Coord_RectsOverlap(r1, r2) && \
- !Coord_RectContained(r1, r2) && \
- !Coord_RectContained(r2, r1))
-
-
-
- /* ------------------------------------------------------------------------
- * Screen <---> Work Area conversion routines.
- * NOTE:
- * "Screen Coordinates" refers to OS coordinates, with the bottom
- * left corner of the screen being placed at the screen origin, (0,0)
- * "Work Area Coordinates" refers to Coordinates within the Window's
- * work area, where the (0,0) origin is at the TOP left of the work area
- *
- * Some of these routines have been defined as macros because they are
- * very elementary, and are common, so efficiency will be improved by
- * removing the function call overhead.
- *
- * To keep compatibility with the syntax of Acorn's coords_ calls, these
- * macros still accept a pointer to a convert_block, which results in
- * code of the form (&convert)->xxx which would be better as convert.xxx
- * -I am banking on the compiler being smart enough to notice and generate
- * good code for this. If not, you can easily modify the macro to accept
- * the actual variable instead - just remember there's no type checking!
- */
-
-
- /* Coord_WindowOrigin ------------------------------------------------------
- * Returns the origin (TOP LEFT (0,0) corner) of the window's work-area
- * in screen coordinates. This can then be used as a redraw-origin
- * for redraws - any drawing done relative to this origin will appear at
- * the correct screen position regardless of scroll bar offsets and screen
- * position of the window.
- * Remember to call this at the start of each redraw - whenever the window
- * is moved or scrolled, the position of this origin (in screen coordinates)
- * will change, so it must be recalculated.
- */
- extern void Coord_WindowOrigin(wimp_point *origin, convert_block *convert);
-
-
- /* Coord_XToScreen ---------------------------------------------------------
- * This takes in an integer x-workarea-coord and a pointer to a convert_block,
- * and returns the screen-coordinate equivalent
- */
- #define Coord_XToScreen(X, C) (((X) - (C)->scroll.x) + (C)->screenrect.min.x)
-
-
- /* Coord_YToScreen ---------------------------------------------------------
- * This takes in an integer y-workarea-coord and a pointer to a convert_block,
- * and returns the screen-coordinate equivalent
- */
- #define Coord_YToScreen(Y, C) ( ((Y) - (C)->scroll.y) + (C)->screenrect.max.y )
-
-
- /* Coord_{Point/Rect}ToScreen ----------------------------------------------
- * Input: A point/rectangle in Work Area coords
- * Output: The same point/rectangle in Screen coordinates
- */
- extern void Coord_PointToScreen(wimp_point *point, convert_block *convert);
- extern void Coord_RectToScreen(wimp_rect *rect, convert_block *convert);
-
-
-
-
- /* Coord_XToWorkArea -------------------------------------------------------
- * This takes in an integer x-screen-coord and a pointer to a convert_block,
- * and returns the workarea-coordinate equivalent
- */
- #define Coord_XToWorkArea(X, C) (((X)-(C)->screenrect.min.x)+(C)->scroll.x)
-
-
- /* Coord_YToWorkArea -------------------------------------------------------
- * This takes in an integer y-screen-coord and a pointer to a convert_block,
- * and returns the workarea-coordinate equivalent
- */
- #define Coord_YToWorkArea(Y, C) (((Y)-(C)->screenrect.max.y)+(C)->scroll.y)
-
-
- /* Coord_{Point/Rect}ToWorkArea --------------------------------------------
- * Input: A point/rectangle in Screen coords
- * Output: The same point/rectangle in Work Area coordinates
- */
- extern void Coord_PointToWorkArea(wimp_point *point, convert_block *convert);
- extern void Coord_RectToWorkArea(wimp_rect *rect, convert_block *convert);
-
-
- #endif
-