The t_point and t_rect structures

All GUI's (Graphic User Interface) must have some rectangular objects so we must define some functions and types for this purpose.


The t_point structure

t_point is the structure of a point in a 2D perspective.

     Name:         l_rect x;

     Description:  X-coordinate of the point.

 

     Name:         l_rect y;

     Description:  Y-coordinate of the point.
      



The t_rect structure

The t_rect structure defines a rectangle in a 2D space. It consists of two points, "a" which is the coordinate of the rectangles top left corner and "b" that defines the lower right corner.

     Name:         l_point a;

     Description:  Coordinate of the upper-left corner.

 

     Name:         l_point b;

     Description:  Coordinate of the lower-right corner.
      



t_rect functions and variables


     Name:         t_Rect rect_empty; 

     Description:  A global variable for an empty rectangle.



point_assign ()
     Description:
       Creates a new t_point structure. Same as "t_point p = (x, y);".

     Syntax:
       t_point  point_assign ( l_rect x, l_rect y );

     Parameters:
       x           X-value to assign.
       y           Y-value to assign.

     Returns:
       The new t_point structure.



rect_assign ()
     Description:
       Creates a new t_rect structure from the given values.

     Syntax:
       t_rect  rect_assign ( l_rect ax, l_rect ay, l_rect bx, l_rect by );

     Parameters:
       ax          X-coordinate of the upper-left corner.
       ay          Y-coordinate of the upper-left corner.
       bx          X-coordinate of the lower-right corner.
       by          Y-coordinate of the lower-right corner.

     Returns:
       The new t_rect structure.


     Example:

          t_rect r = rect_assign(100, 150, 200, 250);

       This creates a rectangle with these values:

          r.a.x = 100
          r.a.y = 150
          r.b.x = 200
          r.b.y = 250



rect_move ()
     Description:
       Moves a rectangle.

     Syntax:
       t_rect  rect_move ( t_rect r, l_rect mx, l_rect my );

     Parameters:
       r           Rectangle to move.
       mx          Distance (in pixels) to move horizontally.
       my          Distance (in pixels) to move vertically.

     Returns:
       The new t_rect structure.



rect_size ()
     Description:
       Gets the size of a rectangle.

     Syntax:
       t_point rect_size ( t_rect r );

     Parameters:
       r           Rectangle to get information about.

     Returns:
       A t_point structure where p.x is width of rectangle
       and p.y is its height.



rect_cliped ()
     Description:
       Clips a rectangle with another one.

     Syntax:
       t_rect  rect_cliped ( t_rect r, t_rect d );

     Parameters:
       r           Rectangle to clip.
       d           Rectangle to clip with.

     Returns:
       The clipped rectangle. If the two don't overlap,
       it returns rect_empty.



rect_overlay ()
     Description:
       Determines wether a rectangle overlays another one.
       WARNING: Do not attempt to change t_rect by l_rect!

     Syntax:
       l_bool  rect_overlay ( t_rect r, t_rect d );

     Parameters:
       r           The overlaying rectangle.
       d           Overlaid rectangle.

     Returns:
       True if they overlay, false if not.