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{});
62std::vector<std::string> render_tile_with_highlights(
64 const std::set<std::pair<std::size_t, std::size_t>> &highlight_coords,
65 const Rgba32 &extrinsic_transparency,
68 std::vector<std::string> result{};
69 std::stringstream ss{};
72 result.emplace_back();
76 auto pixel_color = tile.
at(row, col);
77 if (pixel_color.is_intrinsically_transparent()) {
78 pixel_color = extrinsic_transparency;
80 const auto color_style_bg = rgba_to_bg_style(pixel_color);
81 const auto color_style_fg = rgba_to_fg_style(pixel_color);
82 if (highlight_coords.contains({row, col})) {
89 result.push_back(ss.str());
94 result.emplace_back();
111 const auto subtile_index =
static_cast<std::size_t
>(subtile);
113 case metatile::Layer::bottom:
114 return metatile.
bottom(subtile_index);
115 case metatile::Layer::middle:
116 return metatile.
middle(subtile_index);
117 case metatile::Layer::top:
118 return metatile.
top(subtile_index);
120 panic(
"invalid layer value");
139std::vector<std::string> render_metatile_with_highlights(
143 const std::set<std::pair<std::size_t, std::size_t>> &highlight_coords,
144 const Rgba32 &extrinsic_transparency,
146 bool highlight_subtile)
148 std::vector<std::string> result{};
149 std::stringstream ss{};
152 result.emplace_back();
154 if (highlight_subtile && subtile == metatile::Subtile::northwest) {
156 result.push_back(ss.str());
159 if (highlight_subtile && subtile == metatile::Subtile::northeast) {
160 push_to_stream(ss,
" ", 16 + 1);
162 result.push_back(ss.str());
170 std::size_t subtile_row = 0;
171 std::size_t subtile_col = 0;
173 if (i < 8 && j < 8) {
174 current_subtile = metatile::Subtile::northwest;
178 else if (i < 8 && j >= 8) {
179 current_subtile = metatile::Subtile::northeast;
183 else if (i >= 8 && j < 8) {
184 current_subtile = metatile::Subtile::southwest;
189 current_subtile = metatile::Subtile::southeast;
194 const bool is_in_target_subtile = current_subtile == subtile;
195 const auto ¤t_tile = get_tile_from_metatile(metatile, layer, current_subtile);
196 auto pixel_color = current_tile.at(subtile_row, subtile_col);
197 if (pixel_color.is_intrinsically_transparent()) {
198 pixel_color = extrinsic_transparency;
200 const auto color_style_bg = rgba_to_bg_style(pixel_color);
201 const auto color_style_fg = rgba_to_fg_style(pixel_color);
203 if (is_in_target_subtile) {
205 if (highlight_coords.contains({subtile_row, subtile_col})) {
225 result.push_back(ss.str());
232 result.push_back(ss.str());
237 if (highlight_subtile && subtile == metatile::Subtile::southwest) {
239 result.push_back(ss.str());
242 if (highlight_subtile && subtile == metatile::Subtile::southeast) {
243 push_to_stream(ss,
" ", 16 + 1);
245 result.push_back(ss.str());
250 result.emplace_back();
262 return render_metatile_with_highlights(
270 const Rgba32 &extrinsic_transparency)
const
272 return render_metatile_with_highlights(metatile, layer, subtile, {}, extrinsic_transparency, format_,
true);
281 const Rgba32 &extrinsic_transparency)
const
283 std::set<std::pair<std::size_t, std::size_t>> coords{{row, col}};
284 return render_metatile_with_highlights(metatile, layer, subtile, coords, extrinsic_transparency, format_,
true);
291 const std::vector<std::size_t> &indexes,
292 const Rgba32 &extrinsic_transparency)
const
294 std::set<std::pair<std::size_t, std::size_t>> coords{};
295 for (
const auto index : indexes) {
298 return render_metatile_with_highlights(metatile, layer, subtile, coords, extrinsic_transparency, format_,
true);
301std::vector<std::string>
304 return render_tile_with_highlights(tile, {}, extrinsic_transparency, format_);
307std::vector<std::string>
312 std::vector<std::string> result{};
313 std::stringstream ss{};
316 result.emplace_back();
320 const auto index_pixel = tile.
at(row, col);
323 const Rgba32 pixel_color = greyscale_palette[index_pixel.color_index()];
324 const auto color_style_bg = rgba_to_bg_style(pixel_color);
327 result.push_back(ss.str());
332 result.emplace_back();
340 std::set<std::pair<std::size_t, std::size_t>> coords{{row, col}};
341 return render_tile_with_highlights(tile, coords, extrinsic_transparency, format_);
345 const PixelTile<Rgba32> &tile,
const std::vector<std::size_t> &indexes,
const Rgba32 &extrinsic_transparency)
const
347 std::set<std::pair<std::size_t, std::size_t>> coords{};
348 for (
const auto index : indexes) {
351 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.
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
std::vector< Rgba32 > standard_greyscale_palette()
Returns the standard 16-color greyscale palette used for indexed tile output.
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.