mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-15 07:27:42 -04:00
Offscreen painting
This commit is contained in:
parent
7ed2ef6d31
commit
2c08bee567
@ -19,6 +19,8 @@ namespace stdio {
|
||||
void init_console();
|
||||
|
||||
struct console {
|
||||
void init();
|
||||
|
||||
size_t get_columns() const ;
|
||||
size_t get_rows() const ;
|
||||
|
||||
@ -26,6 +28,7 @@ struct console {
|
||||
|
||||
void wipeout();
|
||||
|
||||
void set_active(bool active);
|
||||
void save();
|
||||
void restore();
|
||||
|
||||
@ -35,7 +38,8 @@ private:
|
||||
size_t current_line = 0;
|
||||
size_t current_column = 0;
|
||||
|
||||
void* buffer;
|
||||
void* buffer = nullptr;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
} // end of namespace stdio
|
||||
|
@ -83,9 +83,6 @@ struct virtual_terminal {
|
||||
|
||||
void set_active(bool);
|
||||
|
||||
void save();
|
||||
void restore();
|
||||
|
||||
console& get_console();
|
||||
|
||||
size_t id;
|
||||
|
@ -12,11 +12,19 @@
|
||||
|
||||
struct vesa_console {
|
||||
void init();
|
||||
size_t lines();
|
||||
size_t columns();
|
||||
|
||||
size_t lines() const ;
|
||||
size_t columns() const ;
|
||||
|
||||
void clear();
|
||||
void clear(void* buffer);
|
||||
|
||||
void scroll_up();
|
||||
void scroll_up(void* buffer);
|
||||
|
||||
void print_char(size_t line, size_t column, char c);
|
||||
void print_char(void* buffer, size_t line, size_t column, char c);
|
||||
|
||||
void* save(void* buffer);
|
||||
void restore(void* buffer);
|
||||
};
|
||||
|
@ -35,6 +35,12 @@ void stdio::init_console(){
|
||||
}
|
||||
}
|
||||
|
||||
void stdio::console::init(){
|
||||
if(!text){
|
||||
buffer = vesa::create_buffer();
|
||||
}
|
||||
}
|
||||
|
||||
size_t stdio::console::get_rows() const {
|
||||
if(text){
|
||||
return t_console.lines();
|
||||
@ -67,7 +73,11 @@ void stdio::console::print(char key){
|
||||
if(text){
|
||||
t_console.print_char(current_line, current_column, key);
|
||||
} else {
|
||||
if(active){
|
||||
v_console.print_char(current_line, current_column, key);
|
||||
} else {
|
||||
v_console.print_char(buffer, current_line, current_column, key);
|
||||
}
|
||||
}
|
||||
|
||||
++current_column;
|
||||
@ -82,7 +92,11 @@ void stdio::console::wipeout(){
|
||||
if(text){
|
||||
t_console.clear();
|
||||
} else {
|
||||
if(active){
|
||||
v_console.clear();
|
||||
} else {
|
||||
v_console.clear(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
current_line = 0;
|
||||
@ -101,6 +115,10 @@ void stdio::console::restore(){
|
||||
v_console.restore(buffer);
|
||||
}
|
||||
|
||||
void stdio::console::set_active(bool active){
|
||||
this->active = active;
|
||||
}
|
||||
|
||||
void stdio::console::next_line(){
|
||||
++current_line;
|
||||
|
||||
@ -108,7 +126,11 @@ void stdio::console::next_line(){
|
||||
if(text){
|
||||
t_console.scroll_up();
|
||||
} else {
|
||||
if(active){
|
||||
v_console.scroll_up();
|
||||
} else {
|
||||
v_console.scroll_up(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
--current_line;
|
||||
|
@ -136,8 +136,11 @@ void stdio::init_terminals(){
|
||||
terminal.mouse = false;
|
||||
}
|
||||
|
||||
// Initialize the active terminal
|
||||
|
||||
active_terminal = 0;
|
||||
terminals[active_terminal].active = true;
|
||||
terminals[active_terminal].get_console().set_active(true);
|
||||
}
|
||||
|
||||
void stdio::register_devices(){
|
||||
@ -162,7 +165,7 @@ void stdio::finalize(){
|
||||
terminal.input_thread_pid = input_process.pid;
|
||||
|
||||
// Save the initial image of the terminal
|
||||
terminal.save();
|
||||
terminal.get_console().save();
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,8 +187,9 @@ void stdio::switch_terminal(size_t id){
|
||||
if(active_terminal != id){
|
||||
logging::logf(logging::log_level::TRACE, "stdio: Switch activate virtual terminal %u\n", id);
|
||||
|
||||
terminals[active_terminal].save();
|
||||
terminals[id].restore();
|
||||
// Effectively switch the terminal
|
||||
terminals[active_terminal].set_active(false);
|
||||
terminals[id].set_active(true);
|
||||
|
||||
active_terminal = id;
|
||||
}
|
||||
|
@ -130,12 +130,20 @@ bool stdio::virtual_terminal::is_canonical() const {
|
||||
return canonical;
|
||||
}
|
||||
|
||||
void stdio::virtual_terminal::save(){
|
||||
cons.save();
|
||||
void stdio::virtual_terminal::set_active(bool active){
|
||||
if(this->active == active){
|
||||
return;
|
||||
}
|
||||
|
||||
void stdio::virtual_terminal::restore(){
|
||||
this->active = active;
|
||||
|
||||
cons.set_active(active);
|
||||
|
||||
if(active){
|
||||
cons.restore();
|
||||
} else {
|
||||
cons.save();
|
||||
}
|
||||
}
|
||||
|
||||
stdio::console& stdio::virtual_terminal::get_console(){
|
||||
|
@ -47,11 +47,11 @@ void vesa_console::init() {
|
||||
vesa::draw_char(title_left + 24, PADDING + MARGIN, 'R', _color);
|
||||
}
|
||||
|
||||
size_t vesa_console::lines() {
|
||||
size_t vesa_console::lines() const {
|
||||
return _lines;
|
||||
}
|
||||
|
||||
size_t vesa_console::columns() {
|
||||
size_t vesa_console::columns() const {
|
||||
return _columns;
|
||||
}
|
||||
|
||||
@ -59,15 +59,28 @@ void vesa_console::clear() {
|
||||
vesa::draw_rect(LEFT, TOP, _columns * 8, _lines * 16, vesa::make_color(0, 0, 0));
|
||||
}
|
||||
|
||||
void vesa_console::clear(void* buffer) {
|
||||
vesa::draw_rect(buffer, LEFT, TOP, _columns * 8, _lines * 16, vesa::make_color(0, 0, 0));
|
||||
}
|
||||
|
||||
void vesa_console::scroll_up() {
|
||||
vesa::move_lines_up(TOP + 16, LEFT, _columns * 8, (_lines - 1) * 16, 16);
|
||||
vesa::draw_rect(LEFT, TOP + (_lines - 1) * 16, _columns * 8, 16, vesa::make_color(0, 0, 0));
|
||||
}
|
||||
|
||||
void vesa_console::scroll_up(void* buffer) {
|
||||
vesa::move_lines_up(buffer, TOP + 16, LEFT, _columns * 8, (_lines - 1) * 16, 16);
|
||||
vesa::draw_rect(buffer, LEFT, TOP + (_lines - 1) * 16, _columns * 8, 16, vesa::make_color(0, 0, 0));
|
||||
}
|
||||
|
||||
void vesa_console::print_char(size_t line, size_t column, char c) {
|
||||
vesa::draw_char(LEFT + 8 * column, TOP + 16 * line, c, _color);
|
||||
}
|
||||
|
||||
void vesa_console::print_char(void* buffer, size_t line, size_t column, char c) {
|
||||
vesa::draw_char(buffer, LEFT + 8 * column, TOP + 16 * line, c, _color);
|
||||
}
|
||||
|
||||
void* vesa_console::save(void* buffer) {
|
||||
void* buffer32 = static_cast<uint32_t*>(buffer);
|
||||
if (!buffer32) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user