home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / c / gnu_c / patches / DeskLib / h / Coord < prev    next >
Encoding:
Text File  |  1994-10-03  |  11.9 KB  |  352 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, 1993, 1994 Edouard Poor, Jason Williams
  13.                                           and Tim Browse
  14.     Version: 1.02 (02 Mar 1994)
  15.     Purpose: Coord (point and rectangle) handling functions
  16. */
  17.  
  18. #ifndef __dl_coord_h
  19. #define __dl_coord_h
  20.  
  21. #ifndef __dl_core_h
  22. #include "Core.h"
  23. #endif
  24.  
  25. #ifndef __dl_wimp_h
  26. #include "Wimp.h"
  27. #endif
  28.  
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32.  
  33.  
  34. /*T*************************************************************************/
  35.  
  36.   typedef struct
  37.   {
  38.     wimp_rect  screenrect;
  39.     wimp_point scroll;
  40.   } convert_block;
  41.  
  42. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  43.  
  44.  
  45. ****************************************************************************/
  46.  
  47.  
  48.  
  49.  
  50. /*F*************************************************************************/
  51.  
  52.   extern BOOL Coord_PointInRect(wimp_point *point, wimp_rect *rect);
  53.  
  54. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  55.  
  56.   Inputs:   point - the point to test
  57.             rect - the rectangle to check for containment with.
  58.   Returns:  TRUE if point is in rectangle; FALSE otherwise.
  59.   Purpose:  Tests whether the point is within the rectangle. If it's on the
  60.             line it's counted as in (just like in tennis).
  61.   SeeAlso:  Coord_RectContained; Coord_RectsOverlap
  62.  
  63. ****************************************************************************/
  64.  
  65.  
  66.  
  67.  
  68. /*F*************************************************************************/
  69.  
  70.   extern BOOL Coord_RectContained(wimp_rect *InsideRect,
  71.                                   wimp_rect *OutsideRect);
  72.  
  73. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  74.  
  75.   Inputs:   See purpose.
  76.   Returns:  TRUE if InsideRect is withing OutsideRect;
  77.             FALSE otherwise.
  78.   Purpose:  Test whether the InsideRect is wholly contained by the
  79.             OutsideRect.  Shared vertices/edges are considered to be inside.
  80.   SeeAlso:  Coord_PointInRect; Coord_RectsOverlap
  81.  
  82. ****************************************************************************/
  83.  
  84.  
  85.  
  86.  
  87. /*F*************************************************************************/
  88.  
  89.   extern BOOL Coord_RectsOverlap(wimp_rect *rect1, wimp_rect *rect2);
  90.  
  91. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  92.  
  93.   Inputs:   rect1, rect2 - the rectangles to check for overlap.
  94.   Returns:  TRUE if rectangles overlap;
  95.             FALSE otherwise.
  96.   Purpose:  Checks to see if two rectangles overlap each other in any
  97.             way (includes containment).
  98.   SeeAlso:  Coord_RectsIntersect
  99.  
  100. ****************************************************************************/
  101.  
  102.  
  103.  
  104.  
  105. /*M*************************************************************************/
  106.  
  107.   #define Coord_RectsIntersect(r1, r2) (Coord_RectsOverlap(r1, r2) && \
  108.                                        !Coord_RectContained(r1, r2) && \
  109.                                        !Coord_RectContained(r2, r1))
  110.  
  111. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  112.  
  113.   MACRO:    BOOL Coord_RectsIntersect(wimp_rect *rect1, wimp_rect *rect2)
  114.  
  115.   Inputs:   rect1, rect2 - the rectangles to check for intersection
  116.   Returns:  TRUE if rectangles intersect but do not contain each other;
  117.             FALSE otherwise.
  118.   Purpose:  Tests if two rectangles intersect each other, but wil return
  119.             failure if either rectangle wholly contains the other one.
  120.             This is different to the behaviour of Coord_RectsOverlap.
  121.   SeeAlso:  Coord_RectsOverlap
  122.  
  123. ****************************************************************************/
  124.  
  125.  
  126.  
  127.  
  128. /*K**************************************************************************
  129.  
  130. > Coordinate conversion.
  131.  
  132.   Screen <---> Work Area conversion routines.
  133.   NOTE:
  134.     "Screen Coordinates" refers to OS coordinates, with the bottom
  135.       left corner of the screen being placed at the screen origin, (0,0)
  136.     "Work Area Coordinates" refers to Coordinates within the Window's
  137.       work area, where the (0,0) origin is at the TOP left of the work area
  138.  
  139.   Some of these routines have been defined as macros because they are
  140.   very elementary, and are common, so efficiency will be improved by
  141.   removing the function call overhead.
  142.  
  143.   To keep compatibility with the syntax of Acorn's coords_ calls, these
  144.   macros still accept a pointer to a convert_block.
  145.  
  146. ****************************************************************************/
  147.  
  148.  
  149.  
  150. /*F*************************************************************************/
  151.  
  152.   extern void Coord_WindowOrigin(wimp_point *origin, convert_block *convert);
  153.  
  154. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  155.  
  156.   Inputs:   convert - the standard convert_block.
  157.   Outputs:  origin - the window origin, in screen coordinates.
  158.   Purpose:  Returns the origin (TOP LEFT (0,0) corner) of the window's
  159.             work-area in screen coordinates. This can then be used as a
  160.             redraw-origin for redraws - any drawing done relative to this
  161.             origin will appear at the correct screen position regardless of
  162.             scroll bar offsets and screen position of the window.
  163.             Remember to call this at the start of each redraw - whenever the
  164.             window is moved or scrolled, the position of this origin (in
  165.             screen coordinates) will change, so it must be recalculated.
  166.   SeeAlso:  Coord_PointToScreen
  167.  
  168. ****************************************************************************/
  169.  
  170.  
  171.  
  172.  
  173. /*M*************************************************************************/
  174.  
  175.   #define Coord_XToScreen(X, C) \
  176.             (((X) - (C)->scroll.x) + (C)->screenrect.min.x)
  177.  
  178. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  179.  
  180.   MACRO:    int Coord_XToScreen(int xpos, convert_block *convert)
  181.  
  182.   Inputs:   xpos - the x coordinate to translate.
  183.             convert - the standard convert_block.
  184.   Returns:  The translated x coordinate.
  185.   Purpose:  Translate a x coordinate from the work-area to the screen
  186.             coordinate space.
  187.   SeeAlso:  Coord_PointToScreen; Coord_YToScreen
  188.  
  189. ****************************************************************************/
  190.  
  191.  
  192.  
  193.  
  194. /*M*************************************************************************/
  195.  
  196.   #define Coord_YToScreen(Y, C) \
  197.           ( ((Y) - (C)->scroll.y) + (C)->screenrect.max.y )
  198.  
  199. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  200.  
  201.   MACRO:    int Coord_YToScreen(int ypos, convert_block *convert)
  202.  
  203.   Inputs:   ypos - the y coordinate to translate.
  204.             convert - the standard convert_block.
  205.   Returns:  The translated y coordinate.
  206.   Purpose:  Translate a y coordinate from the work-area to the screen
  207.             coordinate space.
  208.   SeeAlso:  Coord_PointToScreen; Coord_XToScreen
  209.  
  210. ****************************************************************************/
  211.  
  212.  
  213.  
  214.  
  215. /*F*************************************************************************/
  216.  
  217.   extern void Coord_PointToScreen(wimp_point *point, convert_block *convert);
  218.  
  219. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  220.  
  221.   Inputs:   point - a point in Work Area coords.
  222.             convert - the standard convert_block.
  223.   Outputs:  point - the same point in screen coordinates
  224.   Purpose:  Convert a work-area coordinate to a screen coordinate.
  225.   SeeAlso:  Coord_RectToScreen; Coord_XToScreen; Coord_YToScreen;
  226.             Coord_PointToWorkArea
  227.  
  228. ****************************************************************************/
  229.  
  230.  
  231.  
  232.  
  233. /*F*************************************************************************/
  234.  
  235.   extern void Coord_RectToScreen(wimp_rect *rect, convert_block *convert);
  236.  
  237. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  238.  
  239.   Inputs:   rect - a rectangle in Work Area coords.
  240.             convert - the standard convert_block.
  241.   Outputs:  rect - the same rectangle in screen coordinates
  242.   Purpose:  Convert a rectangle in work-area coordinates to screen
  243.             coordinates.
  244.   SeeAlso:  Coord_PointToScreen
  245.  
  246. ****************************************************************************/
  247.  
  248.  
  249.  
  250.  
  251. /*M*************************************************************************/
  252.  
  253.   #define Coord_XToWorkArea(X, C) (((X)-(C)->screenrect.min.x)+(C)->scroll.x)
  254.  
  255. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  256.  
  257.   MACRO:    int Coord_XToWorkArea(int xpos, convert_block *convert)
  258.  
  259.   Inputs:   xpos - the screen x coordinate to convert.
  260.             convert - the standard convert_block.
  261.   Returns:  The x coordinate translated to work-area coordinates.
  262.   Purpose:  Convert an x coordinate from the screen coordinate space to
  263.             the work-area coordinate space.
  264.   SeeAlso:  Coord_YToWorkArea; Coord_PointToWorkArea
  265.  
  266. ****************************************************************************/
  267.  
  268.  
  269.  
  270.  
  271. /*M*************************************************************************/
  272.  
  273.   #define Coord_YToWorkArea(Y, C) (((Y)-(C)->screenrect.max.y)+(C)->scroll.y)
  274.  
  275. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  276.  
  277.   MACRO:    int Coord_YToWorkArea(int ypos, convert_block *convert)
  278.  
  279.   Inputs:   ypos - the screen y coordinate to convert.
  280.             convert - the standard convert_block.
  281.   Returns:  The y coordinate translated to work-area coordinates.
  282.   Purpose:  Convert an y coordinate from the screen coordinate space to
  283.             the work-area coordinate space.
  284.   SeeAlso:  Coord_XToWorkArea; Coord_PointToWorkArea
  285.  
  286. ****************************************************************************/
  287.  
  288.  
  289.  
  290.  
  291. /*F*************************************************************************/
  292.  
  293.   extern void Coord_PointToWorkArea(wimp_point *point,
  294.                                     convert_block *convert);
  295.  
  296. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  297.  
  298.   Inputs:   point - a point in screen coords.
  299.             convert - the standard convert_block.
  300.   Outputs:  point - the same point in work area coords.
  301.   Purpose:  Convert a coordinate from the screen coordinate space to the
  302.             work-area coordinate space.
  303.   SeeAlso:  Coord_PointToScreen; Coord_RectToWorkArea
  304.  
  305. ****************************************************************************/
  306.  
  307.  
  308.  
  309.  
  310. /*F*************************************************************************/
  311.  
  312.   extern void Coord_RectToWorkArea(wimp_rect *rect, convert_block *convert);
  313.  
  314. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  315.  
  316.   Inputs:   rect - a rectangle in screen coords.
  317.             convert - the standard convert_block.
  318.   Outputs:  rect - the same rectangle in work area coords.
  319.   Purpose:  Convert a rectangle from the screen coordinate space to the
  320.             work-area coordinate space.
  321.   SeeAlso:  Coord_PointToWorkArea; Coord_RectToScreen
  322.  
  323. ****************************************************************************/
  324.  
  325.  
  326.  
  327.  
  328. /*F*************************************************************************/
  329.  
  330.   extern void Coord_RectUnion(wimp_rect *dest,
  331.                               wimp_rect *src1, wimp_rect *src2);
  332.  
  333. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  334.  
  335.   Inputs:   src1, src2 - the two rectangles to find the union of.
  336.   Outputs:  dest - the rectangle structure to hold the union.
  337.   Purpose:  Find the union of two rectangles.  dest can be the same as
  338.             either src1 or src2 if you want to use this as an
  339.             accumulator.  (dest can be the same as src1 *and* src2, if
  340.             you're feeling really silly).
  341.   SeeAlso:  Coord_RectsOverlap; Coord_RectsIntersect
  342.  
  343. ****************************************************************************/
  344.  
  345.  
  346.  
  347. #ifdef __cplusplus
  348.            }
  349. #endif
  350.  
  351. #endif
  352.