// screen.h // // This is the specification for a screen class - an abstraction of an // old-fashioned character display. The screen supports some useful // operations, such as displaying text and drawing lines and rectangles. // // The coordinate system for the screen is as follows: the origin is // at the top left corner of the screen, and has coordinates (0,0). // The column number grows as you move to the right and the row number grows // as you move down. The width of the screen is given by the constant // SCREEN_WIDTH and the height is given by the constant SCREEN_HEIGHT. // That means that the lower-right corner is at // (SCREEN_WIDTH-1,SCREEN_HEIGHT-1). // // For the member functions below that return a bool, the return value is // a status code indicating whether the operation succeeded. If true is // returned, the operation completed successfully. If false is returned, // the operation could not run and _nothing changed on the screen_. In // other words, all operations check _ahead of time_ whether they can // complete. If they can't, they stop before modifying the screen. An // operation is unable to complete if any part of what would get drawn // is outside the dimensions of the screen instance. #ifndef __SCREEN_H__ #define __SCREEN_H__ #include // The width and height of the screen are given by these two constants. The // class should work no matter what values are placed here. const int SCREEN_WIDTH = 78; const int SCREEN_HEIGHT = 24; class Screen { public: // Construct a new screen, initialize it to be blank. Screen(); // Construct a new screen, initialize it to the char 'ch'. Screen( char ch ); // Put the character 'ch' at position (col, row). bool putChar( int col, int row, char ch ); // Get the contents of the screen at position (col, row); bool getChar( int col, int row, char& ch ); // Draw a horizontal line starting at position (col, row), // extending to the right 'length' units, made out of the character 'ch'. bool horizontalLine( int col, int row, int length, char ch ); // Draw a vertical line starting at position (col, row), // extending down 'length' units, made out of the character 'ch'. bool verticalLine( int col, int row, int length, char ch ); // Draw a rectangle, with top left corner at position (col, row), // of dimension 'width' x 'height' units. The vertical lines in the // border are made out of '|'. The horizontal lines are made out of // '-'. The corners are made out of '+'. The rectangle is filled // with the character 'fill'. bool rectangle( int col, int row, int width, int height, char fill ); // Draw the text contained in the buffer, starting at position (col, row) bool putText( int col, int row, char text[] ); // Draw the text contained in the buffer, centered on line 'row'. bool putCenteredText( int row, char text[] ); // Fill the whole screen with the character 'ch'. void fill( char ch ); // Write the contents of the screen to the output stream 'os'. ostream& print( ostream& os ); // Fill in the screen by reading in an existing screen from // a file. The file should contain SCREEN_HEIGHT lines of text, // each line exactly SCREEN_WIDTH characters in length. istream& read( istream& is ); private: }; #endif // __SCREEN_H__