Adds scrolling.

This commit is contained in:
Felix Queißner 2016-05-02 18:17:15 +02:00
parent a17b936cfb
commit df83857843
3 changed files with 41 additions and 6 deletions

View file

@ -28,18 +28,28 @@ private:
public:
Console(Screen *screen);
/**
* Puts a character on the screen.
*/
void put(char c);
/**
* Inserts a line break and returns the cursor to the start.
*/
void newline();
/**
* Scrolls screen a line upwards
*/
void scroll();
inline Console operator << (char c)
inline Console & operator << (char c)
{
this->put(c);
return *this;
}
inline Console operator << (const char *str)
inline Console & operator << (const char *str)
{
while(*str) {
*this << *str++;
@ -47,13 +57,13 @@ public:
return *this;
}
inline Console operator << (const FColor &color)
inline Console & operator << (const FColor &color)
{
this->fg = color.color;
return *this;
}
inline Console operator << (const BColor &color)
inline Console & operator << (const BColor &color)
{
this->bg = color.color;
return *this;

View file

@ -3,11 +3,20 @@
#include "console.hpp"
#include "compat.h"
const char * numbers[] = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
};
extern "C" void init(void)
{
//*
Console::main
<< "Hello World!\n"
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
<< "Hello default color.";
<< "Hello default color.\n";
//*/
for(int i = 0; i < 22; i++) {
Console::main << "Line " << numbers[i%10] << "\n";
}
}

View file

@ -25,7 +25,7 @@ void Console::put(char c)
sc.bg = (int)this->bg;
break;
}
if(this->x >= this->screen->width) {
if(this->x >= this->screen->height) {
this->newline();
}
}
@ -33,4 +33,20 @@ void Console::put(char c)
void Console::newline() {
this->x = 0;
this->y += 1;
if(this->y >= this->screen->height) {
this->scroll();
}
}
void Console::scroll() {
if(this->y <= 0) {
return;
}
for(int i = 0; i <= this->y; i++) {
for(int j = 0; j < this->screen->width; j++) {
(*this->screen)(j, i) = (*this->screen)(j, i + 1);
}
}
this->y -= 1;
}