18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TUI the implementation 333<br />

23.2.4 The class Screen<br />

The package Class_screen implements cursor position<strong>in</strong>g and output to an ANSI compatible display screen.<br />

The responsibilities of the class are:<br />

Method<br />

Clear_Screen<br />

Position_Cursor<br />

Put<br />

Responsibility<br />

Clears all the screen.<br />

Position the cursor at x, y on the screen.<br />

Write <strong>in</strong>formation to the current position on the screen.<br />

Note: The co-ord<strong>in</strong>ate system for the screen is shown <strong>in</strong> Figure 23.3.<br />

1,1 80,1<br />

y<br />

x<br />

1,24 80,24<br />

Figure 23.3 Co-ord<strong>in</strong>ate system for the screen.<br />

The class specification for Class_screen is:<br />

package Class_Screen is<br />

procedure Put( Ch :<strong>in</strong> Character ); --Put char<br />

procedure Put( Str:<strong>in</strong> Str<strong>in</strong>g ); --Put str<strong>in</strong>g<br />

procedure Clear_Screen; --Clear screen<br />

procedure Position_Cursor(Col:<strong>in</strong> Positive; Row:<strong>in</strong> Positive);<br />

private<br />

end Class_Screen;<br />

Note:<br />

As there is only one <strong>in</strong>stance of a screen the class Screen conta<strong>in</strong>s all class methods.<br />

The implementation of the class Screen uses the standard ANSI escape sequence to position the cursor onto<br />

a text term<strong>in</strong>al. The overloaded procedures put call the relevant put procedure <strong>in</strong> Pack_md_io.<br />

with Pack_Md_Io; use Pack_Md_Io;<br />

package body Class_Screen is<br />

Prefix: constant Str<strong>in</strong>g := Character'Val(27) & "[";<br />

procedure Put( N:<strong>in</strong> Positive ); --Write decimal number<br />

procedure Put( Ch :<strong>in</strong> Character ) is<br />

beg<strong>in</strong><br />

Pack_Md_Io.Put( Ch );<br />

end Put;<br />

procedure Put( Str:<strong>in</strong> Str<strong>in</strong>g ) is<br />

beg<strong>in</strong><br />

Pack_Md_Io.Put( Str );<br />

end Put;<br />

If an ANSI term<strong>in</strong>al is not available then the bodies of the procedures Clear_Screen and<br />

Position_Cursor will need to be amended to reflect the characteristics of the user's term<strong>in</strong>al or output<br />

environment.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!