Max OS 0.3
Loading...
Searching...
No Matches
console.h
Go to the documentation of this file.
1
9#ifndef MAXOS_CONSOLE_CONSOLE_H
10#define MAXOS_CONSOLE_CONSOLE_H
11
12#include <cstdint>
13
14#include <libcommon/outputStream.h>
15#include <libcommon/colour.h>
16
17
18namespace MaxOS::console {
19
20
25 class Console {
26 public:
27 Console();
28 ~Console();
29
30 virtual uint16_t width();
31 virtual uint16_t height();
32
33 virtual void put_character(uint16_t x, uint16_t y, char c);
34 virtual char get_character(uint16_t x, uint16_t y);
35
36 virtual void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground);
37 virtual void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background);
38
39 virtual common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y);
40 virtual common::ConsoleColour get_background_color(uint16_t x, uint16_t y);
41
42
43 virtual void put_character(uint16_t x, uint16_t y, char c, common::ConsoleColour foreground, common::ConsoleColour background);
44 virtual void put_string(uint16_t x, uint16_t y, string string, common::ConsoleColour foreground = common::ConsoleColour::LightGrey, common::ConsoleColour background = common::ConsoleColour::Black);
45
46 virtual void scroll_up();
47 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 = ' ');
48
49 virtual void clear();
50 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 = ' ');
51
52 virtual void invert_colors(uint16_t x, uint16_t y);
53
54 };
55
60 class ConsoleArea : public Console {
61 private:
62 Console* m_console;
63 uint16_t m_left;
64 uint16_t m_top;
65 uint16_t m_width;
66 uint16_t m_height;
67
68 public:
69 ConsoleArea(Console* console, uint16_t left, uint16_t top, uint16_t width, uint16_t height);
70 ConsoleArea(Console* console, uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground, common::ConsoleColour background);
72
73 uint16_t width() override;
74 uint16_t height() override;
75
76 void put_character(uint16_t x, uint16_t y, char c) override;
77 void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground) override;
78 void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background) override;
79
80 void scroll_up() override;
81 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;
82
83 char get_character(uint16_t x, uint16_t y) override;
84 common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y) override;
85 common::ConsoleColour get_background_color(uint16_t x, uint16_t y) override;
86 };
87
92 class ConsoleStream : public common::OutputStream {
93 private:
94 Console* m_console;
95
96 common::ConsoleColour m_foreground { common::ConsoleColour::LightGrey };
97 common::ConsoleColour m_background { common::ConsoleColour::Black };
98 bool is_ansi = false;
99
100 uint16_t m_cursor_x { 0 };
101 uint16_t m_cursor_y { 0 };
102
103 public:
104
105 explicit ConsoleStream(Console*);
107
108 void write_char(char c) override;
109 void set_cursor(uint16_t x, uint16_t y);
110 };
111
112}
113
114
115#endif //MAXOS_CONSOLE_CONSOLE_H
A console that is a subsection of another console, limited by a width and height.
Definition console.h:60
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.
Definition console.cpp:347
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 t...
Definition console.cpp:364
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...
Definition console.cpp:329
uint16_t height() override
Return the height of the console area.
Definition console.cpp:282
void scroll_up() override
Scroll the console area up by 1 line.
Definition console.cpp:395
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.
Definition console.cpp:293
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...
Definition console.cpp:311
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 t...
Definition console.cpp:382
uint16_t width() override
Return the width of the console area.
Definition console.cpp:273
A stream that can be used to write to a console.
Definition console.h:92
void write_char(char c) override
write a character to the console stream
Definition console.cpp:435
void set_cursor(uint16_t x, uint16_t y)
Set the m_position of the cursor.
Definition console.cpp:509
Abstract class for a console, allows for the printing of characters and strings with colours.
Definition console.h:25
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.
Definition console.cpp:131
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 void scroll_up()
Scroll the entire console up by 1 line.
Definition console.cpp:141
virtual char get_character(uint16_t x, uint16_t y)
Get the character at a given coordinate on the console.
Definition console.cpp:76
virtual uint16_t height()
Get the height of the console in characters.
Definition console.cpp:33
virtual void clear()
Definition console.cpp:174
virtual void put_character(uint16_t x, uint16_t y, char c)
Put a character on the console.
Definition console.cpp:44
virtual void invert_colors(uint16_t x, uint16_t y)
Invert the colors of a character on the console.
Definition console.cpp:210
virtual uint16_t width()
Get the width of the console in characters.
Definition console.cpp:24
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