Commit 373171a9 authored by Jack's avatar Jack
Browse files

added newline management to print function

parent 6c640b83
......@@ -37,6 +37,8 @@ namespace retro8
using palette_index_t = size_t;
using address_t = int32_t;
struct point_t { coord_t x, y; };
static constexpr coord_t TEXT_LINE_HEIGHT = 6;
}
#define RASTERIZE_PIXEL_PAIR(machine, dest, pixels) do { \
......
......@@ -317,7 +317,7 @@ int print(lua_State* L)
retro8::coord_t y = cursor->y();
retro8::color_t c = machine.memory().penColor()->low();
machine.print(text, x, y, c);
cursor->set(cursor->x(), cursor->y() + 6); //TODO: check height / magic number
cursor->set(cursor->x(), cursor->y() + TEXT_LINE_HEIGHT); //TODO: check height
}
else if (lua_gettop(L) >= 3)
{
......
......@@ -293,6 +293,7 @@ void Machine::sspr(coord_t sx, coord_t sy, coord_t sw, coord_t sh, coord_t dx, c
// TODO: add support for strange characters like symbols
void Machine::print(const std::string& string, coord_t x, coord_t y, color_t color)
{
struct SpecialGlyph
{
std::vector<uint8_t> encoding;
......@@ -313,10 +314,18 @@ void Machine::print(const std::string& string, coord_t x, coord_t y, color_t col
static const std::array<uint8_t, 2> Prefixes = { 0xe2, 0xf0 };
const coord_t sx = x;
for (size_t i = 0; i < string.length(); ++i)
{
auto c = string[i];
if (c == '\n')
{
y += TEXT_LINE_HEIGHT;
x = sx;
continue;
}
auto specialGlyph = std::find_if(SpecialGlyphs.begin(), SpecialGlyphs.end(), [&string, &i](const SpecialGlyph& glyph) {
return string.size() >= i + glyph.encoding.size() && memcmp(&string[i], &glyph.encoding[0], glyph.encoding.size()) == 0; //TODO: memcmp is not best design ever
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment