home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / desklib / !DeskLib / h / Coord < prev    next >
Encoding:
Text File  |  1993-05-11  |  5.5 KB  |  157 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Coord.h
  12.     Author:  Copyright © 1992 Edouard Poor and Jason Williams
  13.     Version: 1.01 (30 Apr 1993)
  14.     Purpose: Coord (point and rectangle) handling functions
  15. */
  16.  
  17. #ifndef __dl_coord_h
  18. #define __dl_coord_h
  19.  
  20. #ifndef __dl_core_h
  21. #include "Core.h"
  22. #endif
  23.  
  24. #ifndef __dl_wimp_h
  25. #include "Wimp.h"
  26. #endif
  27.  
  28.  
  29. typedef struct
  30. {
  31.   wimp_rect  screenrect;
  32.   wimp_point scroll;
  33. } convert_block;
  34.  
  35.  
  36.  
  37. /*
  38.  *  Coord_PointInRect(point, rectangle)
  39.  *
  40.  *    Tests whether the point in within the rectangle. If it on the line
  41.  *    its counted as in (just like in tennis).
  42.  *
  43.  */
  44. extern BOOL Coord_PointInRect(wimp_point *, wimp_rect *);
  45.  
  46.  
  47. /*
  48.  *  Coord_RectContained(InsideRect, OutsideRect)
  49.  *
  50.  *    Test whether the InsideRect is wholly contained by the OutsideRect.
  51.  *    Shared vertices/edges are considered to be inside.
  52.  */
  53. extern BOOL Coord_RectContained(wimp_rect *, wimp_rect *);
  54.  
  55.  
  56. /*
  57.  *  Coord_RectsOverlap(RectangleA, RectangeB)
  58.  *
  59.  *  Returns TRUE if the two rectangles overlap (includes containment)
  60.  */
  61. extern BOOL Coord_RectsOverlap(wimp_rect *, wimp_rect *);
  62.  
  63.  
  64. /*
  65.  *  Coord_RectsIntersect(RectangleA, RectangeB)
  66.  *
  67.  *  Returns TRUE if the two rectangles intersect but neither is contained
  68.  *  wholly within the other.
  69.  */
  70. #define Coord_RectsIntersect(r1, r2) (Coord_RectsOverlap(r1, r2) && \
  71.                                      !Coord_RectContained(r1, r2) && \
  72.                                      !Coord_RectContained(r2, r1))
  73.  
  74.  
  75.  
  76. /*  ------------------------------------------------------------------------
  77.  *  Screen <---> Work Area conversion routines.
  78.  *  NOTE:
  79.  *    "Screen Coordinates" refers to OS coordinates, with the bottom
  80.  *      left corner of the screen being placed at the screen origin, (0,0)
  81.  *    "Work Area Coordinates" refers to Coordinates within the Window's
  82.  *      work area, where the (0,0) origin is at the TOP left of the work area
  83.  *
  84.  *  Some of these routines have been defined as macros because they are
  85.  *  very elementary, and are common, so efficiency will be improved by
  86.  *  removing the function call overhead.
  87.  *
  88.  *  To keep compatibility with the syntax of Acorn's coords_ calls, these
  89.  *  macros still accept a pointer to a convert_block, which results in
  90.  *  code of the form (&convert)->xxx which would be better as convert.xxx
  91.  *  -I am banking on the compiler being smart enough to notice and generate
  92.  *  good code for this. If not, you can easily modify the macro to accept
  93.  *  the actual variable instead - just remember there's no type checking!
  94.  */
  95.  
  96.  
  97. /* Coord_WindowOrigin ------------------------------------------------------
  98.  * Returns the origin (TOP LEFT (0,0) corner) of the window's work-area
  99.  * in screen coordinates. This can then be used as a redraw-origin
  100.  * for redraws - any drawing done relative to this origin will appear at
  101.  * the correct screen position regardless of scroll bar offsets and screen
  102.  * position of the window.
  103.  * Remember to call this at the start of each redraw - whenever the window
  104.  * is moved or scrolled, the position of this origin (in screen coordinates)
  105.  * will change, so it must be recalculated.
  106.  */
  107. extern void Coord_WindowOrigin(wimp_point *origin, convert_block *convert);
  108.  
  109.  
  110. /* Coord_XToScreen ---------------------------------------------------------
  111.  * This takes in an integer x-workarea-coord and a pointer to a convert_block,
  112.  * and returns the screen-coordinate equivalent
  113.  */
  114. #define Coord_XToScreen(X, C) (((X) - (C)->scroll.x) + (C)->screenrect.min.x)
  115.  
  116.  
  117. /* Coord_YToScreen ---------------------------------------------------------
  118.  * This takes in an integer y-workarea-coord and a pointer to a convert_block,
  119.  * and returns the screen-coordinate equivalent
  120.  */
  121. #define Coord_YToScreen(Y, C) ( ((Y) - (C)->scroll.y) + (C)->screenrect.max.y )
  122.  
  123.  
  124. /* Coord_{Point/Rect}ToScreen ----------------------------------------------
  125.  * Input:  A point/rectangle in Work Area coords
  126.  * Output: The same point/rectangle in Screen coordinates
  127.  */
  128. extern void Coord_PointToScreen(wimp_point *point, convert_block *convert);
  129. extern void Coord_RectToScreen(wimp_rect *rect, convert_block *convert);
  130.  
  131.  
  132.  
  133.  
  134. /* Coord_XToWorkArea -------------------------------------------------------
  135.  * This takes in an integer x-screen-coord and a pointer to a convert_block,
  136.  * and returns the workarea-coordinate equivalent
  137.  */
  138. #define Coord_XToWorkArea(X, C) (((X)-(C)->screenrect.min.x)+(C)->scroll.x)
  139.  
  140.  
  141. /* Coord_YToWorkArea -------------------------------------------------------
  142.  * This takes in an integer y-screen-coord and a pointer to a convert_block,
  143.  * and returns the workarea-coordinate equivalent
  144.  */
  145. #define Coord_YToWorkArea(Y, C) (((Y)-(C)->screenrect.max.y)+(C)->scroll.y)
  146.  
  147.  
  148. /* Coord_{Point/Rect}ToWorkArea --------------------------------------------
  149.  * Input:  A point/rectangle in Screen coords
  150.  * Output: The same point/rectangle in Work Area coordinates
  151.  */
  152. extern void Coord_PointToWorkArea(wimp_point *point, convert_block *convert);
  153. extern void Coord_RectToWorkArea(wimp_rect *rect, convert_block *convert);
  154.  
  155.  
  156. #endif
  157.