Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::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::console::Console:
MaxOS::console::ConsoleArea MaxOS::console::FramebufferConsole MaxOS::console::TextModeConsole

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 string, 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 25 of file console.h.

Member Function Documentation

◆ clear() [1/2]

void Console::clear ( )
virtual

Clear the entire console

Definition at line 174 of file console.cpp.

174 {
175
176 clear(0, 0, width(), height());
177
178}
virtual uint16_t height()
Get the height of the console in characters.
Definition console.cpp:33
virtual void clear()
Definition console.cpp:174
virtual uint16_t width()
Get the width of the console in characters.
Definition console.cpp:24

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

Referenced by clear(), and MaxOS::console::FramebufferConsole::FramebufferConsole().

◆ 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 191 of file console.cpp.

191 {
192
193 // Check bounds
194 if(left > this->width() || top > this->height() || width > this->width() || height > this->height())
195 return;
196
197 // Fill the area with the character
198 for(uint16_t y = top; y < top + height; y++)
199 for(uint16_t x = left; x < left + width; x++)
200 put_character(x, y, fill, foreground, background);
201
202}
virtual void put_character(uint16_t x, uint16_t y, char c)
Put a character on the console.
Definition console.cpp:44

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::console::FramebufferConsole, MaxOS::console::TextModeConsole, and MaxOS::console::ConsoleArea.

Definition at line 98 of file console.cpp.

98 {
99 return ConsoleColour::Green;
100}

Referenced by MaxOS::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::console::FramebufferConsole, MaxOS::console::TextModeConsole, and MaxOS::console::ConsoleArea.

Definition at line 76 of file console.cpp.

76 {
77 return ' ';
78}

Referenced by MaxOS::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::console::FramebufferConsole, MaxOS::console::TextModeConsole, and MaxOS::console::ConsoleArea.

Definition at line 87 of file console.cpp.

87 {
88 return ConsoleColour::Green;
89}

Referenced by MaxOS::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::console::FramebufferConsole, MaxOS::console::TextModeConsole, and MaxOS::console::ConsoleArea.

Definition at line 33 of file console.cpp.

33 {
34 return 0;
35}

Referenced by clear(), clear(), scroll_up(), scroll_up(), and MaxOS::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 210 of file console.cpp.

210 {
211
212 // Get the colors of the character
213 ConsoleColour foreground = get_foreground_color(x, y);
214 ConsoleColour background = get_background_color(x, y);
215
216 // Set the colors of the character
217 set_foreground_color(x, y, background);
218 set_background_color(x, y, foreground);
219}
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:54
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:98
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:87
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:65

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::console::TextModeConsole, MaxOS::console::ConsoleArea, and MaxOS::console::FramebufferConsole.

Definition at line 44 of file console.cpp.

44 {
45}

Referenced by clear(), MaxOS::console::ConsoleArea::put_character(), put_character(), put_string(), scroll_up(), and MaxOS::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 111 of file console.cpp.

111 {
112
113 // Set the colors of the character
114 set_foreground_color(x, y, foreground);
115 set_background_color(x, y, background);
116
117 // Put the character on the console
118 put_character(x, y, c);
119
120}

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 131 of file console.cpp.

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

References put_character().

◆ scroll_up() [1/2]

void Console::scroll_up ( )
virtual

Scroll the entire console up by 1 line.

Reimplemented in MaxOS::console::ConsoleArea.

Definition at line 141 of file console.cpp.

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

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

Referenced by scroll_up(), MaxOS::console::ConsoleArea::scroll_up(), MaxOS::console::ConsoleArea::scroll_up(), and MaxOS::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::console::FramebufferConsole, and MaxOS::console::ConsoleArea.

Definition at line 157 of file console.cpp.

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

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::console::ConsoleArea, MaxOS::console::FramebufferConsole, and MaxOS::console::TextModeConsole.

Definition at line 65 of file console.cpp.

65 {
66
67}

Referenced by MaxOS::console::ConsoleArea::ConsoleArea(), invert_colors(), put_character(), and MaxOS::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::console::ConsoleArea, MaxOS::console::FramebufferConsole, and MaxOS::console::TextModeConsole.

Definition at line 54 of file console.cpp.

54 {
55
56}

Referenced by MaxOS::console::ConsoleArea::ConsoleArea(), invert_colors(), put_character(), and MaxOS::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::console::FramebufferConsole, MaxOS::console::TextModeConsole, and MaxOS::console::ConsoleArea.

Definition at line 24 of file console.cpp.

24 {
25 return 0;
26}

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


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