StuBS
GraphicsStream Class Reference

Output text (form different data type sources) on screen in graphic mode (similar to TextStream) More...

#include <graphicsstream.h>

Inheritance diagram for GraphicsStream:
Collaboration diagram for GraphicsStream:

Public Member Functions

 GraphicsStream (Graphics &graphics, const Point &start, unsigned width, unsigned height, Font *font=nullptr)
 Constructor. More...
 
void setPos (int x, int y)
 Set the cursor position. More...
 
void getPos (int &x, int &y) const
 Read the current cursor position. More...
 
void print (char *str, int length, const Color &color=LIGHT_GREY)
 Display multiple characters in the window starting at the current cursor position. More...
 
void reset (char character=' ', const Color &color=LIGHT_GREY)
 Clear window and reset cursor. More...
 
void show (int x, int y, char character, const Color &color=LIGHT_GREY)
 Basic output of a (colored) character at a certain position on the screen. More...
 
void draw ()
 Draw using the Graphics device.
 
- Public Member Functions inherited from OutputStream
 OutputStream ()
 Default constructor. Initial number system is decimal.
 
virtual ~OutputStream ()
 Destructor.
 
OutputStreamoperator<< (char c)
 Print a single character. More...
 
OutputStreamoperator<< (unsigned char c)
 Print a single character. More...
 
OutputStreamoperator<< (const char *string)
 Printing a null-terminated string. More...
 
OutputStreamoperator<< (bool b)
 Print a boolean value. More...
 
OutputStreamoperator<< (short ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned short ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (int ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned int ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (long long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned long long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (const void *ptr)
 Print a pointer as hexadecimal number. More...
 
OutputStreamoperator<< (OutputStream &(*f)(OutputStream &))
 Calls one of the manipulator functions. More...
 
- Public Member Functions inherited from Stringbuffer
virtual ~Stringbuffer ()
 Destructor (nothing to do here)
 

Public Attributes

Font *const FONT
 Default font.
 
const Point START
 Upper left corner of the window.
 
const unsigned ROWS
 Number of rows in the window.
 
const unsigned COLUMNS
 Number of columns in the window.
 
- Public Attributes inherited from OutputStream
int base
 Number system used for printing integral numbers (one of 2, 8, 10, or 16)
 

Static Public Attributes

static const Color BLACK
 CGA color palette.
 

Protected Member Functions

void flush ()
 Output the buffer contents of the base class Stringbuffer. More...
 
- Protected Member Functions inherited from Stringbuffer
 Stringbuffer ()
 Constructor; Marks the buffer as empty.
 
void put (char c)
 Inserts a character into the buffer. More...
 

Private Attributes

unsigned y
 Cursor position.
 

Additional Inherited Members

- Protected Attributes inherited from Stringbuffer
char buffer [80]
 buffer containing characters that will be printed upon flush()
 
long unsigned pos
 current position in the buffer
 

Detailed Description

Output text (form different data type sources) on screen in graphic mode (similar to TextStream)

Enables output of different data types using a monospaced font on a predefined area of the screen with activated graphics mode.

Constructor & Destructor Documentation

◆ GraphicsStream()

GraphicsStream::GraphicsStream ( Graphics graphics,
const Point start,
unsigned  width,
unsigned  height,
Font font = nullptr 
)

Constructor.

Creates a window (= area on the screen) for text output. Within the window text uses a virtual (invisible) cursor to offer a very similar behavior to TextStream – including automatic scrolling and column/row based positioning.

Parameters
graphicsGraphics device for output
startCoordinate of the upper left corner for the output window
widthWidth of the output window
heightHeight of the output window
fontFont used for output text (or nullptr for default font)

Member Function Documentation

◆ flush()

void GraphicsStream::flush ( )
protectedvirtual

Output the buffer contents of the base class Stringbuffer.

The method is automatically called when the buffer is full, but can also be called explicitly to force output of the current buffer.

Implements OutputStream.

◆ getPos()

void GraphicsStream::getPos ( int &  x,
int &  y 
) const

Read the current cursor position.

Parameters
xColumn in window
yRow in window

◆ print()

void GraphicsStream::print ( char *  str,
int  length,
const Color &  color = LIGHT_GREY 
)

Display multiple characters in the window starting at the current cursor position.

This method can be used to output a string, starting at the current cursor position. Since the string does not need to contain a '\0' termination (as it is usually the case in C), the parameter length is required to specify the number of characters in the string. When the output is complete, the cursor will be positioned after the last character printed. The entire text uniformly has the color color

If there is not enough space left at the end of the line, the output will be continued on the following line. As soon as the last window line is filled, the entire window area will be moved up one line. The first line disappears and the last line is blank, continuing output there.

A line break will also occurs wherever the character \\n is inserted in the text to be output.

Parameters
strString to output
lengthlength of string
colorForeground color of string

◆ reset()

void GraphicsStream::reset ( char  character = ' ',
const Color &  color = LIGHT_GREY 
)

Clear window and reset cursor.

Parameters
characterFilling character
colorForeground color

◆ setPos()

void GraphicsStream::setPos ( int  x,
int  y 
)

Set the cursor position.

Parameters
xColumn in window
yRow in window

◆ show()

void GraphicsStream::show ( int  x,
int  y,
char  character,
const Color &  color = LIGHT_GREY 
)

Basic output of a (colored) character at a certain position on the screen.

Outputs character at the absolute position (x, y) with the specified color: x specifies the column and y the row of the desired position, with 0 ≤ x < COLUMNS and 0 ≤ y < ROWS. The position (0,0) indicates the upper left corner of the window (at the coordinates START).

Parameters
xColumn for output of the character
yRow for output of the character
characterCharacter to be output
colorForeground color

The documentation for this class was generated from the following files: