Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::drivers::console::Console Class Reference

Abstract class for a console, allows for the printing of characters and strings with colours. More...

#include <console.h>

Inheritance diagram for MaxOS::drivers::console::Console:
MaxOS::drivers::console::ConsoleArea MaxOS::drivers::console::TextModeConsole MaxOS::drivers::console::VESABootConsole

Public Member Functions

virtual uint16_t width ()
 Get the width of the console in characters.
 
virtual uint16_t height ()
 Get the height of the console in characters.
 
virtual void put_character (uint16_t x, uint16_t y, char c)
 Put a character on the console.
 
virtual char get_character (uint16_t x, uint16_t y)
 Get the character at a given coordinate on the console.
 
virtual void set_foreground_color (uint16_t x, uint16_t y, common::ConsoleColour foreground)
 Set the foreground color of a character on the console.
 
virtual void set_background_color (uint16_t x, uint16_t y, common::ConsoleColour background)
 Set the background color of a character on the console.
 
virtual common::ConsoleColour get_foreground_color (uint16_t x, uint16_t y)
 Get the background color of a character on the console.
 
virtual common::ConsoleColour get_background_color (uint16_t x, uint16_t y)
 Get the background color of a character on the console.
 
virtual void put_character (uint16_t x, uint16_t y, char c, common::ConsoleColour foreground, common::ConsoleColour background)
 Put a character on the console with a given foreground and background color.
 
virtual void put_string (uint16_t x, uint16_t y, string s, common::ConsoleColour foreground=common::ConsoleColour::LightGrey, common::ConsoleColour background=common::ConsoleColour::Black)
 Put a string on the console.
 
virtual void scroll_up ()
 Scroll the entire console up by 1 line.
 
virtual void scroll_up (uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground=common::ConsoleColour::LightGrey, common::ConsoleColour background=common::ConsoleColour::Black, char fill=' ')
 Scroll an area of the console up by 1 line.
 
virtual void clear ()
 
virtual void clear (uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground=common::ConsoleColour::LightGrey, common::ConsoleColour background=common::ConsoleColour::Black, char fill=' ')
 Clear an area of the console.
 
virtual void invert_colors (uint16_t x, uint16_t y)
 Invert the colors of a character on the console.
 

Detailed Description

Abstract class for a console, allows for the printing of characters and strings with colours.

Definition at line 24 of file console.h.

Member Function Documentation

◆ clear() [1/2]

void Console::clear ( )
virtual

Clear the entire console

Definition at line 175 of file console.cpp.

175 {
176
177 clear(0, 0, width(), height());
178
179}
virtual uint16_t height()
Get the height of the console in characters.
Definition console.cpp:34
virtual uint16_t width()
Get the width of the console in characters.
Definition console.cpp:25

References clear(), height(), and width().

Referenced by clear(), and MaxOS::drivers::console::VESABootConsole::VESABootConsole().

◆ clear() [2/2]

void Console::clear ( uint16_t  left,
uint16_t  top,
uint16_t  width,
uint16_t  height,
common::ConsoleColour  foreground = common::ConsoleColour::LightGrey,
common::ConsoleColour  background = common::ConsoleColour::Black,
char  fill = ' ' 
)
virtual

Clear an area of the console.

Parameters
leftThe left coordinate of the area to clear
topThe top coordinate of the area to clear
widthThe m_width of the area to clear
heightThe m_height of the area to clear
foregroundThe foreground color of the area
backgroundThe background color of the area
fillThe character to fill the area with

Definition at line 192 of file console.cpp.

192 {
193
194 // Check bounds
195 if(left > this->width() || top > this->height() || width > this->width() || height > this->height())
196 return;
197
198 // Fill the area with the character
199 for(uint16_t y = top; y < top + height; y++)
200 for(uint16_t x = left; x < left + width; x++)
202
203}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
virtual void put_character(uint16_t x, uint16_t y, char c)
Put a character on the console.
Definition console.cpp:45

References height(), put_character(), and width().

◆ get_background_color()

ConsoleColour Console::get_background_color ( uint16_t  x,
uint16_t  y 
)
virtual

Get the background color of a character on the console.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
Returns
The background color of the character

Reimplemented in MaxOS::drivers::console::TextModeConsole, MaxOS::drivers::console::VESABootConsole, and MaxOS::drivers::console::ConsoleArea.

Definition at line 99 of file console.cpp.

99 {
100 return ConsoleColour::Green;
101}

Referenced by MaxOS::drivers::console::ConsoleArea::get_background_color(), invert_colors(), and scroll_up().

◆ get_character()

char Console::get_character ( uint16_t  x,
uint16_t  y 
)
virtual

Get the character at a given coordinate on the console.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
Returns
The character at the given coordinate

Reimplemented in MaxOS::drivers::console::TextModeConsole, MaxOS::drivers::console::VESABootConsole, and MaxOS::drivers::console::ConsoleArea.

Definition at line 77 of file console.cpp.

77 {
78 return ' ';
79}

Referenced by MaxOS::drivers::console::ConsoleArea::get_character(), and scroll_up().

◆ get_foreground_color()

ConsoleColour Console::get_foreground_color ( uint16_t  x,
uint16_t  y 
)
virtual

Get the background color of a character on the console.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
Returns
The background color of the character

Reimplemented in MaxOS::drivers::console::TextModeConsole, MaxOS::drivers::console::VESABootConsole, and MaxOS::drivers::console::ConsoleArea.

Definition at line 88 of file console.cpp.

88 {
89 return ConsoleColour::Green;
90}

Referenced by MaxOS::drivers::console::ConsoleArea::get_foreground_color(), invert_colors(), and scroll_up().

◆ height()

uint16_t Console::height ( )
virtual

Get the height of the console in characters.

Returns
The height of the console in characters

Reimplemented in MaxOS::drivers::console::TextModeConsole, MaxOS::drivers::console::VESABootConsole, and MaxOS::drivers::console::ConsoleArea.

Definition at line 34 of file console.cpp.

34 {
35 return 0;
36}

Referenced by clear(), clear(), scroll_up(), scroll_up(), and MaxOS::drivers::console::ConsoleStream::write_char().

◆ invert_colors()

void Console::invert_colors ( uint16_t  x,
uint16_t  y 
)
virtual

Invert the colors of a character on the console.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character

Definition at line 211 of file console.cpp.

211 {
212
213 // Get the colors of the character
216
217 // Set the colors of the character
220}
virtual void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground)
Set the foreground color of a character on the console.
Definition console.cpp:55
virtual common::ConsoleColour get_background_color(uint16_t x, uint16_t y)
Get the background color of a character on the console.
Definition console.cpp:99
virtual common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y)
Get the background color of a character on the console.
Definition console.cpp:88
virtual void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background)
Set the background color of a character on the console.
Definition console.cpp:66
ConsoleColour
Enumeration of console colour codes.
Definition colour.h:67

References get_background_color(), get_foreground_color(), set_background_color(), and set_foreground_color().

◆ put_character() [1/2]

void Console::put_character ( uint16_t  x,
uint16_t  y,
char  c 
)
virtual

Put a character on the console.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
cThe character to put on the console

Reimplemented in MaxOS::drivers::console::TextModeConsole, MaxOS::drivers::console::ConsoleArea, and MaxOS::drivers::console::VESABootConsole.

Definition at line 45 of file console.cpp.

45 {
46}

Referenced by clear(), MaxOS::drivers::console::ConsoleArea::put_character(), put_character(), put_string(), scroll_up(), and MaxOS::drivers::console::ConsoleStream::write_char().

◆ put_character() [2/2]

void Console::put_character ( uint16_t  x,
uint16_t  y,
char  c,
common::ConsoleColour  foreground,
common::ConsoleColour  background 
)
virtual

Put a character on the console with a given foreground and background color.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
cThe character to put on the console
foregroundThe foreground color of the character
backgroundThe background color of the character

Definition at line 112 of file console.cpp.

112 {
113
114 // Set the colors of the character
117
118 // Put the character on the console
119 put_character(x, y, c);
120
121}

References put_character(), set_background_color(), and set_foreground_color().

◆ put_string()

void Console::put_string ( uint16_t  x,
uint16_t  y,
string  string,
common::ConsoleColour  foreground = common::ConsoleColour::LightGrey,
common::ConsoleColour  background = common::ConsoleColour::Black 
)
virtual

Put a string on the console.

Parameters
xThe x coordinate of the string
yThe y coordinate of the string
stringThe string to put on the console
foregroundThe foreground color of the string
backgroundThe background color of the string

Definition at line 132 of file console.cpp.

132 {
133
134 // Print each character on the screen
135 for(size_t i = 0; i < string.length(); i++)
136 put_character(x + i, y, string[i], foreground, background);
137}

References put_character().

◆ scroll_up() [1/2]

void Console::scroll_up ( )
virtual

Scroll the entire console up by 1 line.

Reimplemented in MaxOS::drivers::console::ConsoleArea.

Definition at line 142 of file console.cpp.

142 {
143
144 scroll_up(0, 0, width(), height());
145}
virtual void scroll_up()
Scroll the entire console up by 1 line.
Definition console.cpp:142

References height(), scroll_up(), and width().

Referenced by scroll_up(), MaxOS::drivers::console::ConsoleArea::scroll_up(), MaxOS::drivers::console::ConsoleArea::scroll_up(), and MaxOS::drivers::console::ConsoleStream::write_char().

◆ scroll_up() [2/2]

void Console::scroll_up ( uint16_t  left,
uint16_t  top,
uint16_t  width,
uint16_t  height,
common::ConsoleColour  foreground = common::ConsoleColour::LightGrey,
common::ConsoleColour  background = common::ConsoleColour::Black,
char  fill = ' ' 
)
virtual

Scroll an area of the console up by 1 line.

Parameters
leftThe left coordinate of the area to scroll
topThe top coordinate of the area to scroll
widthThe m_width of the area to scroll
heightThe m_height of the area to scroll
foregroundThe foreground color of the new line
backgroundThe background color of the new line
fillThe character to fill the new line with

Reimplemented in MaxOS::drivers::console::VESABootConsole, and MaxOS::drivers::console::ConsoleArea.

Definition at line 158 of file console.cpp.

158 {
159
160 // Shift everything but the last line by getting what is below it
161 for(int y = top; y < top + height - 1; y++)
162 for(uint32_t x = left; x < left + width; x++)
163 put_character(x, y, get_character(x, y + 1), get_foreground_color(x, y + 1),
164 get_background_color(x, y + 1));
165
166 // Fill the last line
167 for(uint16_t x = left; x < left + width; x++)
169
170}
virtual char get_character(uint16_t x, uint16_t y)
Get the character at a given coordinate on the console.
Definition console.cpp:77

References get_background_color(), get_character(), get_foreground_color(), height(), put_character(), and width().

◆ set_background_color()

void Console::set_background_color ( uint16_t  x,
uint16_t  y,
common::ConsoleColour  background 
)
virtual

Set the background color of a character on the console.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
backgroundThe background color to set

Reimplemented in MaxOS::drivers::console::ConsoleArea, MaxOS::drivers::console::TextModeConsole, and MaxOS::drivers::console::VESABootConsole.

Definition at line 66 of file console.cpp.

66 {
67
68}

Referenced by MaxOS::drivers::console::ConsoleArea::ConsoleArea(), invert_colors(), put_character(), and MaxOS::drivers::console::ConsoleArea::set_background_color().

◆ set_foreground_color()

void Console::set_foreground_color ( uint16_t  x,
uint16_t  y,
common::ConsoleColour  foreground 
)
virtual

Set the foreground color of a character on the console.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
foregroundThe foreground color to set

Reimplemented in MaxOS::drivers::console::ConsoleArea, MaxOS::drivers::console::TextModeConsole, and MaxOS::drivers::console::VESABootConsole.

Definition at line 55 of file console.cpp.

55 {
56
57}

Referenced by MaxOS::drivers::console::ConsoleArea::ConsoleArea(), invert_colors(), put_character(), and MaxOS::drivers::console::ConsoleArea::set_foreground_color().

◆ width()

uint16_t Console::width ( )
virtual

Get the width of the console in characters.

Returns
The width of the console in characters

Reimplemented in MaxOS::drivers::console::TextModeConsole, MaxOS::drivers::console::VESABootConsole, and MaxOS::drivers::console::ConsoleArea.

Definition at line 25 of file console.cpp.

25 {
26 return 0;
27}

Referenced by clear(), clear(), scroll_up(), scroll_up(), and MaxOS::drivers::console::ConsoleStream::write_char().


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