19void push_to_stream(std::stringstream &ss,
const std::string_view s,
const std::size_t n)
21 for (std::size_t i = 0; i < n; i++) {
27 std::stringstream &ss,
const TextFormatter &format,
const std::string_view s,
Style style,
const std::size_t n)
29 for (std::size_t i = 0; i < n; i++) {
34void reset_stream(std::stringstream &ss)
37 ss.str(std::string{});
64std::vector<std::string> render_tile_with_highlights(
66 const std::set<std::pair<std::size_t, std::size_t>> &highlight_coords,
67 const Rgba32 &extrinsic_transparency,
70 std::vector<std::string> result{};
71 std::stringstream ss{};
74 result.emplace_back();
78 auto pixel_color = tile.
at(row, col);
79 if (pixel_color.is_intrinsically_transparent()) {
80 pixel_color = extrinsic_transparency;
82 const auto color_style_bg = rgba_to_bg_style(pixel_color);
83 const auto color_style_fg = rgba_to_fg_style(pixel_color);
84 if (highlight_coords.contains({row, col})) {
91 result.push_back(ss.str());
96 result.emplace_back();
115 const auto subtile_index =
static_cast<std::size_t
>(subtile);
117 case metatile::Layer::bottom:
118 return metatile.
bottom(subtile_index);
119 case metatile::Layer::middle:
120 return metatile.
middle(subtile_index);
121 case metatile::Layer::top:
122 return metatile.
top(subtile_index);
124 panic(
"invalid layer value");
145std::vector<std::string> render_metatile_with_highlights(
149 const std::set<std::pair<std::size_t, std::size_t>> &highlight_coords,
150 const Rgba32 &extrinsic_transparency,
152 bool highlight_subtile)
154 std::vector<std::string> result{};
155 std::stringstream ss{};
158 result.emplace_back();
160 if (highlight_subtile && subtile == metatile::Subtile::northwest) {
162 result.push_back(ss.str());
165 if (highlight_subtile && subtile == metatile::Subtile::northeast) {
166 push_to_stream(ss,
" ", 16 + 1);
168 result.push_back(ss.str());
176 std::size_t subtile_row = 0;
177 std::size_t subtile_col = 0;
179 if (i < 8 && j < 8) {
180 current_subtile = metatile::Subtile::northwest;
184 else if (i < 8 && j >= 8) {
185 current_subtile = metatile::Subtile::northeast;
189 else if (i >= 8 && j < 8) {
190 current_subtile = metatile::Subtile::southwest;
195 current_subtile = metatile::Subtile::southeast;
200 const bool is_in_target_subtile = current_subtile == subtile;
201 const auto ¤t_tile = get_tile_from_metatile(metatile, layer, current_subtile);
202 auto pixel_color = current_tile.at(subtile_row, subtile_col);
203 if (pixel_color.is_intrinsically_transparent()) {
204 pixel_color = extrinsic_transparency;
206 const auto color_style_bg = rgba_to_bg_style(pixel_color);
207 const auto color_style_fg = rgba_to_fg_style(pixel_color);
209 if (is_in_target_subtile) {
211 if (highlight_coords.contains({subtile_row, subtile_col})) {
231 result.push_back(ss.str());
238 result.push_back(ss.str());
243 if (highlight_subtile && subtile == metatile::Subtile::southwest) {
245 result.push_back(ss.str());
248 if (highlight_subtile && subtile == metatile::Subtile::southeast) {
249 push_to_stream(ss,
" ", 16 + 1);
251 result.push_back(ss.str());
256 result.emplace_back();
268 return render_metatile_with_highlights(
276 const Rgba32 &extrinsic_transparency)
const
278 return render_metatile_with_highlights(metatile, layer, subtile, {}, extrinsic_transparency, format_,
true);
287 const Rgba32 &extrinsic_transparency)
const
289 std::set<std::pair<std::size_t, std::size_t>> coords{{row, col}};
290 return render_metatile_with_highlights(metatile, layer, subtile, coords, extrinsic_transparency, format_,
true);
297 const std::vector<std::size_t> &indexes,
298 const Rgba32 &extrinsic_transparency)
const
300 std::set<std::pair<std::size_t, std::size_t>> coords{};
301 for (
const auto index : indexes) {
304 return render_metatile_with_highlights(metatile, layer, subtile, coords, extrinsic_transparency, format_,
true);
307std::vector<std::string>
310 return render_tile_with_highlights(tile, {}, extrinsic_transparency, format_);
313std::vector<std::string>
318 std::vector<std::string> result{};
319 std::stringstream ss{};
322 result.emplace_back();
326 const auto index_pixel = tile.
at(row, col);
329 const Rgba32 pixel_color = greyscale_pal[index_pixel.color_index()];
330 const auto color_style_bg = rgba_to_bg_style(pixel_color);
333 result.push_back(ss.str());
338 result.emplace_back();
346 std::set<std::pair<std::size_t, std::size_t>> coords{{row, col}};
347 return render_tile_with_highlights(tile, coords, extrinsic_transparency, format_);
351 const PixelTile<Rgba32> &tile,
const std::vector<std::size_t> &indexes,
const Rgba32 &extrinsic_transparency)
const
353 std::set<std::pair<std::size_t, std::size_t>> coords{};
354 for (
const auto index : indexes) {
357 return render_tile_with_highlights(tile, coords, extrinsic_transparency, format_);
std::vector< std::string > print_metatile_pixel_highlight(const Metatile< Rgba32 > &metatile, metatile::Layer layer, metatile::Subtile subtile, std::size_t row, std::size_t col, const Rgba32 &extrinsic_transparency) const override
std::vector< std::string > print_metatile_tile_highlight(const Metatile< Rgba32 > &metatile, metatile::Layer layer, metatile::Subtile subtile, const Rgba32 &extrinsic_transparency) const override
std::vector< std::string > print_tile_pixel_highlight(const PixelTile< Rgba32 > &tile, std::size_t row, std::size_t col, const Rgba32 &extrinsic_transparency) const override
std::vector< std::string > print_tile_pixel_highlights(const PixelTile< Rgba32 > &tile, const std::vector< std::size_t > &indexes, const Rgba32 &extrinsic_transparency) const override
std::vector< std::string > print_metatile_pixel_highlights(const Metatile< Rgba32 > &metatile, metatile::Layer layer, metatile::Subtile subtile, const std::vector< std::size_t > &indexes, const Rgba32 &extrinsic_transparency) const override
std::vector< std::string > print_metatile(const Metatile< Rgba32 > &metatile, metatile::Layer layer, const Rgba32 &extrinsic_transparency) const override
std::vector< std::string > print_tile(const PixelTile< Rgba32 > &tile, const Rgba32 &extrinsic_transparency) const override
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.
PixelType at(std::size_t i) const
Represents a 32-bit RGBA color.
std::uint8_t blue() const
std::uint8_t green() const
Text styling class supporting formatting, foreground colors, and background colors.
static const Style yellow
Yellow foreground color.
static const Style bold
Bold text formatting.
static const Style blink
Blink text formatting.
Abstract base class for applying text styling with context-aware formatting.
virtual std::string format(const std::string &format_str, const std::vector< FormatParam > ¶ms) const
Formats a string with styled parameters using fmtlib syntax.
constexpr std::size_t side_length_pix
constexpr std::pair< std::size_t, std::size_t > index_to_row_col(std::size_t index)
Converts a linear index to row and column coordinates.
std::vector< Rgba32 > standard_greyscale_pal()
Returns the standard 16-color greyscale palette used for indexed tile output.
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
constexpr Style rgb_fg_style(std::uint8_t r, std::uint8_t g, std::uint8_t b)
Creates a Style value with a custom RGB foreground color.
constexpr Style rgb_bg_style(std::uint8_t r, std::uint8_t g, std::uint8_t b)
Creates a Style value with a custom RGB background color.