StuBS
TextWindow Class Reference

Virtual windows in text mode. More...

#include <machine/textwindow.h>

Inheritance diagram for TextWindow:
[legend]
Collaboration diagram for TextWindow:
[legend]

Public Member Functions

 TextWindow (unsigned from_col, unsigned to_col, unsigned from_row, unsigned to_row, bool use_cursor=false)
 Constructor of a text window. More...
 
void setPos (unsigned rel_x, unsigned rel_y)
 Set the cursor position in the window. More...
 
void setPos (int rel_x, int rel_y)
 Set the cursor position in the window. More...
 
void getPos (unsigned &rel_x, unsigned &rel_y) const
 Get the current cursor position in the window. More...
 
void getPos (int &rel_x, int &rel_y) const
 Get the current cursor position in the window. More...
 
void print (const char *string, size_t length, Attribute attrib=TextMode::Attribute())
 Display multiple characters in the window. More...
 
void reset (char character=' ', Attribute attrib=TextMode::Attribute())
 Delete all contents in the window and reset the cursor. More...
 

Protected Attributes

unsigned from_col
 Start column position (inclusive) of window.
 
unsigned to_col
 End column position (exclusive) of window.
 
unsigned from_row
 Start row position (inclusive) of window.
 
unsigned to_row
 End row position (exclusive) of window.
 
bool use_cursor
 use hardware cursor More...
 
unsigned pos_x
 Software cursor column.
 
unsigned pos_y
 Software cursor row.
 

Additional Inherited Members

- Public Types inherited from TextMode
enum  Color {
  BLACK ,
  BLUE ,
  GREEN ,
  CYAN ,
  RED ,
  MAGENTA ,
  BROWN ,
  LIGHT_GREY ,
  DARK_GREY ,
  LIGHT_BLUE ,
  LIGHT_GREEN ,
  LIGHT_CYAN ,
  LIGHT_RED ,
  LIGHT_MAGENTA ,
  YELLOW ,
  WHITE
}
 CGA color palette. More...
 
- Static Public Member Functions inherited from TextMode
static void setCursor (unsigned abs_x, unsigned abs_y)
 Set the keyboard hardware cursor to absolute screen position. More...
 
static void getCursor (unsigned &abs_x, unsigned &abs_y)
 Retrieve the keyboard hardware cursor position on screen. More...
 
static void show (unsigned abs_x, unsigned abs_y, char character, Attribute attrib=Attribute())
 Basic output of a character at a specific position on the screen. More...
 
static void show (int abs_x, int abs_y, char character, Attribute attrib=Attribute())
 Basic output of a character at a specific position on the screen. More...
 
- Static Public Attributes inherited from TextMode
static const unsigned ROWS = 25
 Visible rows in text mode.
 
static const unsigned COLUMNS = 80
 Visible columns in text mode.
 
- Protected Member Functions inherited from TextMode
 TextMode ()
 Default constructor.
 
- Static Protected Attributes inherited from TextMode
static Cell *const TEXT_BUFFER_BASE = reinterpret_cast<TextMode::Cell *>(0xb8000)
 Base address for linear text buffer in video memory.
 

Detailed Description

Virtual windows in text mode.

Outputs text on a part of the screen in text mode, a window defined in its position and size (with its own cursor).

This allows to separate the output of the application from the debug output on the screen without having to synchronize.

Constructor & Destructor Documentation

◆ TextWindow()

TextWindow::TextWindow ( unsigned  from_col,
unsigned  to_col,
unsigned  from_row,
unsigned  to_row,
bool  use_cursor = false 
)

Constructor of a text window.

Creates a virtual, rectangular text window on the screen. The coordinates to construct the window are absolute positions in the TextMode screen.

Note
Overlapping windows are neither supported nor prevented – better just try to avoid construction windows with overlapping coordinates!
Warning
Don't use the hardware cursor in more than one window!
Parameters
from_colText Window starts in column from_col, the first (leftmost) possible column is 0
to_colText Window extends to the right to column to_col (exclusive). This column has to be strictly greater than from_col, the maximum allowed value is TextMode::COLUMNS (rightmost)
from_rowText Window starts in row from_row, the first possible (uppermost) row is 0
to_rowText Window extends down to row to_row (exclusive). This row has to be strictly greater than from_row, the maximum allowed value is TextMode::ROWS (bottom-most)
use_cursorSpecifies whether the hardware cursor (true) or a software cursor/variable (false) should be used to store the current position
Todo:
Implement constructor

Member Function Documentation

◆ setPos() [1/2]

void TextWindow::setPos ( unsigned  rel_x,
unsigned  rel_y 
)

Set the cursor position in the window.

Depending on the constructor parameter use_cursor either the hardware cursor (and only the hardware cursor!) is used or the position is stored internally in the object.

The coordinates are relative to the upper left starting position of the window.

Parameters
rel_xColumn in window
rel_yRow in window
Todo:
Implement method, use TextMode::setCursor() for the hardware cursor

◆ setPos() [2/2]

void TextWindow::setPos ( int  rel_x,
int  rel_y 
)

Set the cursor position in the window.

Depending on the constructor parameter use_cursor either the hardware cursor (and only the hardware cursor!) is used or the position is stored internally in the object.

The coordinates are relative to the upper left starting position of the window. Negative coordinates are interpreted relative to the right and bottom border of the window.

Optional:
Implement this method (it can either use or replace setPos(unsigned, unsigned))

◆ getPos() [1/2]

void TextWindow::getPos ( unsigned &  rel_x,
unsigned &  rel_y 
) const

Get the current cursor position in the window.

Depending on the constructor parameter use_cursor either the hardware cursor (and only the hardware cursor!) is used or the position is retrieved from the internally stored object.

Parameters
rel_xColumn in window
rel_yRow in window
Todo:
Implement Method, use TextMode::getCursor() for the hardware cursor

◆ getPos() [2/2]

void TextWindow::getPos ( int &  rel_x,
int &  rel_y 
) const

Get the current cursor position in the window.

Depending on the constructor parameter use_cursor either the hardware cursor (and only the hardware cursor!) is used or the position is retrieved from the internally stored object.

Parameters
rel_xColumn in window
rel_yRow in window
Todo:
Implement Method, use TextMode::getCursor() for the hardware cursor

◆ print()

void TextWindow::print ( const char *  string,
size_t  length,
Attribute  attrib = TextMode::Attribute() 
)

Display multiple characters in the window.

Output a character string, starting at the current cursor position. Since the string does not need to contain a \0 termination (unlike the common C string), a length parameter is required to specify the number of characters in the string. When the output is complete, the cursor is positioned after the last printed character. The same attributes (colors) are used for the entire text.

If there is not enough space left at the end of the line, the output continues on the following line. As soon as the last window line is filled, the entire window area is moved up one line: The first line disappears, the bottom line is cleared.

A line break also occurs whenever the character \n appears in the text.

Parameters
stringText to be printed
lengthLength of text
attribAttribute for text
Todo:
Implement Method

◆ reset()

void TextWindow::reset ( char  character = ' ',
Attribute  attrib = TextMode::Attribute() 
)

Delete all contents in the window and reset the cursor.

Parameters
characterFill character
attribAttribute for fill character
Todo:
Implement Method

Member Data Documentation

◆ use_cursor

bool TextWindow::use_cursor
protected

use hardware cursor

otherwise the position is stored in local variables


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