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