Skip to content

Commit f140d9e

Browse files
committed
Implemented actual rendering of screen_buffer
1 parent 2ce25a1 commit f140d9e

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/tgui/screen_buffer.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ namespace tgui {
2424
character( L' ' ), foreground( screen::color::WHITE ), background( screen::color::BLACK ) {
2525
}
2626

27+
void screen_buffer::cell::render ( screen::color& last_foreground, screen::color& last_background ) const {
28+
bool foreground_differs = foreground != last_foreground;
29+
bool background_differs = background != last_background;
30+
31+
if ( foreground_differs && background_differs )
32+
screen::set_color( foreground, background );
33+
else if ( foreground_differs )
34+
screen::set_foreground_color( foreground );
35+
else if ( background_differs )
36+
screen::set_background_color( background );
37+
38+
std::wcout << character;
39+
40+
last_foreground = foreground;
41+
last_background = background;
42+
}
43+
2744
bool screen_buffer::cell::operator == ( const cell& rhs ) const {
2845
return (character == rhs.character) && (foreground == rhs.foreground) && (background == rhs.background);
2946
}
@@ -44,12 +61,33 @@ namespace tgui {
4461
return cells[pos.column][pos.row] != old_buffer.cells[pos.column][pos.row];
4562
};
4663
} else {
47-
cell_changed = [](const screen::position&) {return true;};
64+
cell_changed = [](const screen::position&) {
65+
return true;
66+
};
4867
}
4968

69+
screen::position cur_pos;
70+
screen::color last_foreground = screen::color::WHITE;
71+
screen::color last_background = screen::color::BLACK;
72+
bool continuous = true;
73+
5074
screen::set_cursor_position( 0, 0 );
75+
screen::set_color( last_foreground, last_background );
76+
77+
for ( cur_pos.column = 0; cur_pos.column < size.column; ++cur_pos.column ) {
78+
for ( cur_pos.row = 0; cur_pos.row < size.row; ++cur_pos.row ) {
79+
if ( cell_changed( cur_pos ) ) {
80+
if ( !continuous )
81+
screen::set_cursor_position( cur_pos );
5182

52-
// TODO actual rendering
83+
cells[cur_pos.column][cur_pos.row].render( last_foreground, last_background );
84+
85+
continuous = true;
86+
} else {
87+
continuous = false;
88+
}
89+
}
90+
}
5391
}
5492

5593
bool screen_buffer::operator == ( const screen_buffer& rhs ) const {

src/tgui/screen_buffer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ namespace tgui {
3838
public:
3939
cell ();
4040

41+
virtual void render ( screen::color& last_foreground, screen::color& last_background ) const;
42+
4143
virtual bool operator == ( const cell& rhs ) const;
4244
virtual bool operator != ( const cell& rhs ) const;
4345
};

0 commit comments

Comments
 (0)