Box Functions for Final Project

This module is responsible for drawing framed boxes, and removing them from the screen. It also provides support for FIELD structures, and let's you draw a box on the screen large enough to contain (visually) the array of FIELD structures (it calculates the the field positions and their lengths). See the BoxFields and ClearBoxFields functions below for more details.

Changes to myio.h

Add the following to the end of myio.h (make sure you back up all your work first):

```/*** BOX.C ***/
void ClearBox( int Row, int Col, int Height, int Width, int Color );
void Box( int Row, int Col, int Height, int Width, int Color );
void BoxFields( FIELD *Field, int Row, int Col, int Color );
void ClearBoxFields( FIELD *Field, int Row, int Col, int Color );
void GetFieldDim( FIELD *Field, int *Width, int *Row );
```

Box.c File

```#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include "myio.h"

/* ClearBox - Removes a rectangle from the screen by clearing it's screen rectangle
** Parameters: Row = top row of box
**             Col = left column of box
**             Height = Height of box
**             Width = Width of box
**             Color = Color to draw over box, to make it 'disappear'
*/
void ClearBox( int Row, int Col, int Height, int Width, int Color )
{
ClearRect( Row, Col, Height, Width, Color );
}

/* Box - Draws a box with a framed border
** Parameters: Row = top row of box
**             Col = left column of box
**             Height = Height of box
**             Width = Width of box
**             Color = Color of box (foreground and background
*/
void Box( int Row, int Col, int Height, int Width, int Color )
{
int i;
ClearBox(Row, Col, Height, Width, Color );
Width+=Col;
Height+=Row;
Locate( Row, Col );
CPrintChar( '\xDA', Color );
Locate( Row, Width );
CPrintChar( '\xBF', Color );
Locate( Height, Col );
CPrintChar( '\xC0', Color );
Locate( Height, Width );
CPrintChar( '\xD9', Color );
for( i=Row+1; i<Height; i++ )
{
Locate( i, Col );
CPrintChar('\xB3', Color );
Locate( i, Width );
CPrintChar('\xB3', Color );
}
for( i=Col+1; i<Width; i++ )
{
Locate( Row, i );
CPrintChar('\xC4', Color );
Locate( Height, i );
CPrintChar('\xC4', Color );
}
}

/* GetFieldDim - Determines size of Box needed for an array of fields
** Parameters: Field = Pointer to array of field structures
**             Height = Pointer of int to receive height of box
**             Width = Pointer of int to receive width of box
** Comments: You can use this function to determine how large a box you
**           need to contain a set of FIELD values.
*/
void GetFieldDim( FIELD *Field, int *Height, int *Width )
{
int Extra;
*Width = *Height = 0;
while( Field->Dest||Field->Label )
{
Extra=Field->Label?strlen(Field->Label)+1:0;
*Height = max( *Height, Field->Row );
*Width = max( *Width, Field->Col+Field->Length+Extra );
Field++;
}
*Height+=2; /* For 'inside-box' relative acoordinates */
*Width+=2;
}

/* BoxFields - Draws a box at a coordinate, large enough to hold an aray of FIELDS
** Parameters: Field = Pointer to array of field structures
**             Row = top row to display Box at
**             Col = left column to display Box at
**             Color = Color of Box (foreground and background)
** Comments: Call this function to draw a box visually large enough to
**           hold all the FIELDs in the FIELD pointer
**
*/
void BoxFields( FIELD *Field, int Row, int Col, int Color )
{
int Height, Width;
GetFieldDim(Field, &Height, &Width );
Box( Row, Col, Height, Width, Color );
}

/* ClearBoxFields - Clears a box at a coordinate, large enough to hold an aray of FIELDS
** Parameters: Field = Pointer to array of field structures
**             Row = top row to clear Box from
**             Col = left column to clear Box from
**             Color = Color to clear with (foreground and background)
** Comments: Call this function to erase(clear) a box visually large
**           enough to hold all the FIELDs in the FIELD pointer
**