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

A console that is a subsection of another console, limited by a width and height. More...

#include <console.h>

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

Public Member Functions

 ConsoleArea (Console *console, uint16_t left, uint16_t top, uint16_t width, uint16_t height)
 Construct a new Console Area object.
 
 ConsoleArea (Console *console, uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground, common::ConsoleColour background)
 Construct a new Console Area object with specified foreground and background colors.
 
uint16_t width () override
 Return the width of the console area.
 
uint16_t height () override
 Return the height of the console area.
 
void put_character (uint16_t x, uint16_t y, char c) override
 Place a character on the console area if the coordinates are within the area.
 
void set_foreground_color (uint16_t x, uint16_t y, common::ConsoleColour foreground) override
 Change the foreground color of a character on the console area if the coordinates are within the area.
 
void set_background_color (uint16_t x, uint16_t y, common::ConsoleColour background) override
 Change the background color of a character on the console area if the coordinates are within the area.
 
void scroll_up () override
 Scroll the console area up by 1 line.
 
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=' ') override
 Scroll an area of the console up by 1 line.
 
char get_character (uint16_t x, uint16_t y) override
 Return the character at the given coordinates if the coordinates are within the console area.
 
common::ConsoleColour get_foreground_color (uint16_t x, uint16_t y) override
 Return the foreground color of the character at the given coordinates if the coordinates are within the console area.
 
common::ConsoleColour get_background_color (uint16_t x, uint16_t y) override
 Return the background color of the character at the given coordinates if the coordinates are within the console area.
 
- Public Member Functions inherited from MaxOS::drivers::console::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 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

A console that is a subsection of another console, limited by a width and height.

Definition at line 59 of file console.h.

Constructor & Destructor Documentation

◆ ConsoleArea() [1/2]

ConsoleArea::ConsoleArea ( Console console,
uint16_t  left,
uint16_t  top,
uint16_t  width,
uint16_t  height 
)

Construct a new Console Area object.

Parameters
consoleThe console to create the area on
leftHow far from the left the area starts
topHow far from the top the area starts
widthThe width of the area
heightThe height of the area

Definition at line 231 of file console.cpp.

232 : m_console(console),
233 m_left(left),
234 m_top(top),
235 m_width(width),
236 m_height(height) {
237
238}
uint16_t height() override
Return the height of the console area.
Definition console.cpp:283
uint16_t width() override
Return the width of the console area.
Definition console.cpp:274

◆ ConsoleArea() [2/2]

ConsoleArea::ConsoleArea ( Console console,
uint16_t  left,
uint16_t  top,
uint16_t  width,
uint16_t  height,
common::ConsoleColour  foreground,
common::ConsoleColour  background 
)

Construct a new Console Area object with specified foreground and background colors.

Parameters
consoleThe console to create the area on
leftHow far from the left the area starts
topHow far from the top the area starts
widthThe width of the area
heightThe height of the area
foregroundThe foreground color of the area
backgroundThe background color of the area

Definition at line 251 of file console.cpp.

252 : m_console(console),
253 m_left(left),
254 m_top(top),
255 m_width(width),
256 m_height(height) {
257
258 // Store the colours of the console
259 for(uint16_t y = top; y < top + height; y++)
260 for(uint16_t x = left; x < left + width; x++) {
261 console->set_foreground_color(x, y, foreground);
262 console->set_background_color(x, y, background);
263 }
264
265}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
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 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

References height(), MaxOS::drivers::console::Console::set_background_color(), MaxOS::drivers::console::Console::set_foreground_color(), and width().

Member Function Documentation

◆ get_background_color()

ConsoleColour ConsoleArea::get_background_color ( uint16_t  x,
uint16_t  y 
)
overridevirtual

Return the background color of the character at the given coordinates if the coordinates are within the console area.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
Returns
The background color of the character at the given coordinates, if the coordinates are within the console area otherwise ConsoleColour::Black

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 383 of file console.cpp.

383 {
384
385 // Make sure the coordinates are within the console area
386 if(x >= m_width || y >= m_height)
387 return ConsoleColour::Black;
388
389 // Return the background color of the character at the given coordinates
390 return m_console->get_background_color(m_left + x, m_top + y);
391}
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

References MaxOS::drivers::console::Console::get_background_color().

◆ get_character()

char ConsoleArea::get_character ( uint16_t  x,
uint16_t  y 
)
overridevirtual

Return the character at the given coordinates if the coordinates are within the console area.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
Returns
The character at the given coordinates, if the coordinates are within the console area otherwise " "

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 348 of file console.cpp.

348 {
349
350 // Make sure the coordinates are within the console area
351 if(x >= m_width || y >= m_height)
352 return ' ';
353
354 // Return the character at the given coordinates
355 return m_console->get_character(m_left + x, m_top + y);
356}
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 MaxOS::drivers::console::Console::get_character().

◆ get_foreground_color()

ConsoleColour ConsoleArea::get_foreground_color ( uint16_t  x,
uint16_t  y 
)
overridevirtual

Return the foreground color of the character at the given coordinates if the coordinates are within the console area.

Parameters
xThe x coordinate of the character
yThe y coordinate of the character
Returns
The foreground color of the character at the given coordinates, if the coordinates are within the console area otherwise ConsoleColour::LightGrey

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 365 of file console.cpp.

365 {
366
367 // Make sure the coordinates are within the console area
368 if(x >= m_width || y >= m_height)
369 return ConsoleColour::LightGrey;
370
371 // Return the foreground color of the character at the given coordinates
372 return m_console->get_foreground_color(m_left + x, m_top + y);
373
374}
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

References MaxOS::drivers::console::Console::get_foreground_color().

◆ height()

uint16_t ConsoleArea::height ( )
overridevirtual

Return the height of the console area.

Returns
The height of the console area

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 283 of file console.cpp.

283 {
284 return m_height;
285}

Referenced by ConsoleArea(), and scroll_up().

◆ put_character()

void ConsoleArea::put_character ( uint16_t  x,
uint16_t  y,
char  c 
)
overridevirtual

Place a character on the console area if the coordinates are within the area.

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

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 294 of file console.cpp.

294 {
295
296 // Check bounds
297 if(x >= m_width || y >= m_height)
298 return;
299
300 // Write to the console
301 m_console->put_character(m_left + x, m_top + y, c);
302}
virtual void put_character(uint16_t x, uint16_t y, char c)
Put a character on the console.
Definition console.cpp:45

References MaxOS::drivers::console::Console::put_character().

◆ scroll_up() [1/2]

void ConsoleArea::scroll_up ( )
overridevirtual

Scroll the console area up by 1 line.

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 396 of file console.cpp.

396 {
397
398 m_console->scroll_up(m_left, m_top, m_width, m_height);
399}
virtual void scroll_up()
Scroll the entire console up by 1 line.
Definition console.cpp:142

References MaxOS::drivers::console::Console::scroll_up().

◆ scroll_up() [2/2]

void ConsoleArea::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 = ' ' 
)
overridevirtual

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 from MaxOS::drivers::console::Console.

Definition at line 412 of file console.cpp.

414 {
415
416 m_console->scroll_up(m_left + left, m_top + top, width, height, foreground, background, fill);
417
418}

References height(), MaxOS::drivers::console::Console::scroll_up(), and width().

◆ set_background_color()

void ConsoleArea::set_background_color ( uint16_t  x,
uint16_t  y,
common::ConsoleColour  background 
)
overridevirtual

Change the background color of a character on the console area if the coordinates are within the area.

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

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 330 of file console.cpp.

330 {
331
332 // Make sure the coordinates are within the console area
333 if(x >= m_width || y >= m_height)
334 return;
335
336 // Set the background color of the character
337 m_console->set_background_color(m_left + x, m_top + y, background);
338
339}

References MaxOS::drivers::console::Console::set_background_color().

◆ set_foreground_color()

void ConsoleArea::set_foreground_color ( uint16_t  x,
uint16_t  y,
common::ConsoleColour  foreground 
)
overridevirtual

Change the foreground color of a character on the console area if the coordinates are within the area.

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

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 312 of file console.cpp.

312 {
313
314 // Make sure the coordinates are within the console area
315 if(x >= m_width || y >= m_height)
316 return;
317
318 // Set the foreground color of the character
319 m_console->set_foreground_color(m_left + x, m_top + y, foreground);
320
321}

References MaxOS::drivers::console::Console::set_foreground_color().

◆ width()

uint16_t ConsoleArea::width ( )
overridevirtual

Return the width of the console area.

Returns
The width of the console area

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 274 of file console.cpp.

274 {
275 return m_width;
276}

Referenced by ConsoleArea(), and scroll_up().


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