Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::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::console::ConsoleArea:
MaxOS::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::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 string, 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 60 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 230 of file console.cpp.

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

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

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

Definition at line 382 of file console.cpp.

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

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

Definition at line 347 of file console.cpp.

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

Definition at line 364 of file console.cpp.

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

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

Definition at line 282 of file console.cpp.

282 {
283 return m_height;
284}

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

Definition at line 293 of file console.cpp.

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

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

◆ scroll_up() [1/2]

void ConsoleArea::scroll_up ( )
overridevirtual

Scroll the console area up by 1 line.

Reimplemented from MaxOS::console::Console.

Definition at line 395 of file console.cpp.

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

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

Definition at line 411 of file console.cpp.

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

References height(), MaxOS::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::console::Console.

Definition at line 329 of file console.cpp.

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

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

Definition at line 311 of file console.cpp.

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

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

Definition at line 273 of file console.cpp.

273 {
274 return m_width;
275}

Referenced by ConsoleArea(), and scroll_up().


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