Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Includes/CardIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ void CardIo::Command_78_PrintSettings2()
{
status.SoftReset();
runningCommand = false;

if (currentPacket.size() >= 2)
m_printer->SetPrintMethod(currentPacket[1]);
}

void CardIo::Command_7A_RegisterFont()
Expand Down
14 changes: 10 additions & 4 deletions Includes/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,21 @@ bool Printer::QueuePrintLine(std::vector<uint8_t>& data)
Append = '1',
};

if (m_cardImage == nullptr)
LoadCardImage(m_localName);

// Microsoft in their infinite wisdom defines min in windows.h, so we can't use std::min
constexpr uint8_t maxOffset = 0x14;
const uint8_t offset = data[2] < maxOffset ? data[2] : maxOffset;

if (static_cast<BufferControl>(data[1]) == BufferControl::Clear)
bool skip_printed_image = false;
if (static_cast<BufferControl>(data[1]) == BufferControl::Clear) {
if (m_eraseOnClear) {
Erase();
skip_printed_image = true;
}
m_printQueue.clear();
}

if (m_cardImage == nullptr)
LoadCardImage(m_localName, skip_printed_image);

std::vector<uint8_t> temp = {};
std::copy(data.begin() + 3, data.end(), std::back_inserter(temp));
Expand Down
28 changes: 19 additions & 9 deletions Includes/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Printer
m_cardImage = nullptr;
}
m_localName = "";
m_eraseOnClear = false;
}

void Erase()
Expand All @@ -83,6 +84,11 @@ class Printer
m_cardImage = nullptr;
}
}

void SetPrintMethod(uint8_t method) {
m_eraseOnClear = method == 0x30;
g_logger->trace("Printer::SetPrintMethod: m_eraseOnClear = {}", m_eraseOnClear);
}

bool RegisterFont(std::vector<uint8_t>& data);
bool QueuePrintLine(std::vector<uint8_t>& data);
Expand All @@ -102,20 +108,24 @@ class Printer
std::vector<PrintCommand> m_printQueue = {};
std::vector<SDL_Surface*> m_customGlyphs = {};

bool m_eraseOnClear = false;

SDL_Surface* m_cardImage = nullptr;

void PrintLine();

void LoadCardImage(std::string& cardName)
void LoadCardImage(std::string& cardName, bool skip_printed_image = false)
{
std::string temp = cardName;
temp.append(".png");

if (ghc::filesystem::exists(temp)) {
m_cardImage = IMG_Load(temp.c_str());
if (m_cardImage != nullptr)
return;
g_logger->warn("Printer::LoadCardImage: Found card image but IMG_Load couldn't create the surface, generating a transparent surface");
if (!skip_printed_image) {
std::string temp = cardName;
temp.append(".png");

if (ghc::filesystem::exists(temp)) {
m_cardImage = IMG_Load(temp.c_str());
if (m_cardImage != nullptr)
return;
g_logger->warn("Printer::LoadCardImage: Found card image but IMG_Load couldn't create the surface, generating a transparent surface");
}
}

std::string cwd = ghc::filesystem::current_path().string();
Expand Down