home *** CD-ROM | disk | FTP | other *** search
- Unit GrafRead;
- {--------------------------------------------------------------}
- { This unit will provide a user with a routine to input any }
- { type of information regradless of the currently active video }
- { display mode. This unit interfaces a typed constant that }
- { must be set to indicate which mode is active. }
- {--------------------------------------------------------------}
-
- Interface
-
- Uses Crt, Graph; { Include the standard library units }
-
- Const
- GraphicsMode : Boolean = False;
-
- Procedure ReadString( Var S : String );
-
- Implementation
-
- Procedure DrawCursor( On : Boolean );
- { This procedure will turn on and off a cursor for graphics }
- { mode. The boolean parameter determines whether the cursor }
- { will be drawn (TRUE) and when it will be deleted (FALSE). }
-
- Var
- CursorHeight, { Value for the height of the cursor }
- CursorWidth : Word; { Value for the width of the cursor }
- F : FillSettingsType; { Variable to store the current fill }
- { settings, as we will modify them in }
- { this procedure. }
- XStart, { Beginning X coordinate for cursor }
- XEnd, { Ending X coordinate for the cursor }
- YStart, { Beginning Y coordinate for cursor }
- YEnd : Word; { Ending Y coordinate for the cursor }
-
- Begin
- CursorHeight := ( TextHeight( 'W' ) Div 8 );
- { This calculation creates an underscore }
- CursorWidth := TextWidth( 'H' );
- { Calculation to create width of cursor }
- XStart := GetX; { Set Beginning as current X screen pos. }
- XEnd := XStart + CursorWidth;
- { Define end location for cursor width }
- YStart := GetY + TextHeight( 'W' );
- { Define start location for cursor height}
- YEnd := YStart + CursorHeight;
- { Define end location for cursor height }
- GetFillSettings( F );{ Store current fill settings }
- If( On ) Then
- SetFillStyle( SolidFill, GetColor )
- { Set the fill style with drawing color }
- Else
- SetFillStyle( SolidFill, GetBKColor );
- { Set the fill style with backgnd color }
- Bar( XStart, YStart, XEnd, YEnd );
- { Draws the cursor using the bar proc }
- SetFillStyle( F.Pattern, F.Color );
- { Restore the saved fill information }
- End;
-
- Procedure EchoIt( Ch : Char );
- { This procedure will echo the charachter CH to the currently }
- { active screen type with either OutText or Write }
- Begin
- If( GraphicsMode ) Then
- Begin
- DrawCursor( False );{ Erase the cursor from current loc }
- OutText( Ch ); { Draw the new character }
- DrawCursor( True ); { Replace the cursor on current loc }
- End
- Else
- Write( Ch ); { Simply write the char as its text }
- End;
-
- Procedure BlankIt( Ch : Char );
- { This procedure will erase the last character in the input }
- { string by redrawing the character in the current background }
- { color. }
- Var
- XPos, { Value of current X screen position }
- YPos : Word; { Value of current Y screen position }
- OrigDrawingColor : Byte;{ Temporary storage for active }
- { drawing color }
-
- Begin
- If( GraphicsMode ) Then
- Begin
- DrawCursor( False );{ Erase the cursor }
- XPos := GetX; { Store the current X position }
- XPos := XPos - TextWidth( Ch );
- { Calculate the previous characters }
- { starting X position }
- YPos := GetY; { Store the current Y Position }
- OrigDrawingColor := GetColor;
- { Save the previous drawing color }
- SetColor( GetBKColor );{ Set color to the background color }
- MoveTo( XPos,YPos );{ Update the current pointer }
- OutText( Ch ); { Erase the character from the screen }
- SetColor( OrigDrawingColor );
- { Restore the drawing color }
- MoveTo( XPos,YPos );{ Restore the current pointer }
- End
- Else
- Begin
- XPos := WhereX; { Store current X position }
- XPos := XPos - 1; { Backup position on character }
- YPos := WhereY; { Store current Y position }
- GotoXY( XPos,Ypos );{ Update the current screen position }
- Write( ' ' ); { Erase the character from the screen }
- GotoXY( XPos,YPos );{ Update current screen position }
- End;
- End;
-
- Procedure ReadChar( Var Ch : Char );
- { This procedure is necessary so we can place a cursor on the }
- { screen if we are in graphics mode. }
- Begin
- If( GraphicsMode ) Then
- DrawCursor( True ); { Place the cursor on the screen }
- Ch := Readkey; { Get a keypress from the user }
- End;
-
- Procedure ReadString( Var S : String );
- { This is the driving procedure for this unit. If the enter }
- { key is pressed in response to the prompt, or if the user }
- { deletes all the inputted characters from the string, then }
- { the procedure will not assign a value to this parameter. }
- Var
- Ch : Char; { Inputted character from Readkey FN }
- TempString : String; { Input string that will be built }
-
- Begin
- FillChar( TempString, SizeOf( TempString ), #0 );
- { Initialize the temporary string }
- ReadChar( Ch ); { Get user input from the keyboard }
- While( Ch <> #13 ) Do { Loop until the ENTER key is hit }
- Begin
- If( Ch = #8 ) Then { Was the delete key hit? }
- Begin
- If( TempString[0] > #0 ) Then
- { Check if there is a deletable char }
- Begin
- Blankit( TempString[Length( TempString )] );
- { Remove the char from the screen }
- Dec( TempString[0] );
- { Update the length of the string }
- End
- End
- Else
- Begin
- EchoIt( Ch ); { Echo character to active display }
- TempString := TempString + Ch;
- { Add character to temporary string }
- End;
- ReadChar( Ch ); { Get next input character }
- End;
- If( Length( TempString) > 0 ) Then
- { To determine if anything was entered }
- S := TempString; { If so, return the result to caller }
- If( GraphicsMode ) Then
- DrawCursor( False );{ Erase the graphics cursor. }
- End;
-
- End.