Skip to content

Commit

Permalink
ScreenHandler.h:
Browse files Browse the repository at this point in the history
* Added support for rendering to offscreen buffer/texture via print_screen_buffer().
  • Loading branch information
razterizer committed Nov 20, 2024
1 parent 102db79 commit 6eb9ff5
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions ScreenHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Rectangle.h"
#include "Styles.h"
#include "RC.h"
#include "Texture.h"
#include <Core/StringHelper.h>
#include <Core/StringBox.h>
#include <Core/StlUtils.h>
Expand Down Expand Up @@ -277,23 +278,44 @@ class ScreenHandler
}
}

void print_screen_buffer(Color bg_color) const
void print_screen_buffer(Color bg_color, drawing::Texture* texture = nullptr, const RC& pos = {}) const
{
std::vector<std::tuple<char, Color, Color>> colored_str;
colored_str.resize(NR*(NC + 1));
int i = 0;
for (int r = 0; r < NR; ++r)
if (texture != nullptr)
{
for (int c = 0; c < NC; ++c)
for (int r = 0; r < NR; ++r)
{
auto rl = r - pos.r;
for (int c = 0; c < NC; ++c)
{
auto cl = c - pos.c;

drawing::Textel textel;
textel.ch = screen_buffer[r][c];
textel.fg_color = fg_color_buffer[r][c];
textel.bg_color = bg_color_buffer[r][c];

texture->set_textel(rl, cl, textel);
}
}
}
else
{
std::vector<std::tuple<char, Color, Color>> colored_str;
colored_str.resize(NR*(NC + 1));
int i = 0;
for (int r = 0; r < NR; ++r)
{
Color bg_col_buf = bg_color_buffer[r][c];
if (bg_col_buf == Color::Transparent || bg_col_buf == Color::Transparent2)
bg_col_buf = bg_color;
colored_str[i++] = { screen_buffer[r][c], fg_color_buffer[r][c], bg_col_buf };
for (int c = 0; c < NC; ++c)
{
Color bg_col_buf = bg_color_buffer[r][c];
if (bg_col_buf == Color::Transparent || bg_col_buf == Color::Transparent2)
bg_col_buf = bg_color;
colored_str[i++] = { screen_buffer[r][c], fg_color_buffer[r][c], bg_col_buf };
}
colored_str[i++] = { '\n', Color::Default, Color::Default };
}
colored_str[i++] = { '\n', Color::Default, Color::Default };
m_text->print_complex(colored_str);
}
m_text->print_complex(colored_str);
}

void print_screen_buffer_chars() const
Expand Down

0 comments on commit 6eb9ff5

Please sign in to comment.