#include "TerminalScreen.h"
using namespace Terminal;
Screen::Screen(OBJHANDLE const hVessel, Terminal::Info const &info) {
this->hVessel = hVessel;
this->info = info;
}
void Screen::HandleLoadMesh(MESHHANDLE const mh, UINT const tid)
{
meshhg = mh;
texId = tid;
}
void Screen::SetHeader(std::string const newHeader) {
header = newHeader;
oapiVCTriggerRedrawArea(-1, info.aid);
}
void Screen::cls() {
lines.clear();
cursor.y = lines.size();
oapiVCTriggerRedrawArea(-1, info.aid);
}
void Screen::PrintLn(std::string const newLine, COLORREF const newColor) {
if (lastLine == newLine) return;
if (lines.size() > info.dim.height) {
lines.pop_front();
}
{
Line m;
m.line = newLine;
m.color = newColor;
lines.push_back(m);
}
lastLine = newLine;
*(int*)&cursor.y = lines.size();
oapiVCTriggerRedrawArea(-1, info.aid);
}
bool Screen::HandleLoadVC(UINT const vcId)
{
SURFHANDLE const surface = oapiGetTextureHandle(meshhg, texId);
oapiVCRegisterArea(info.aid, info.client_area, PANEL_REDRAW_USER, PANEL_MOUSE_IGNORE, PANEL_MAP_NONE, surface);
return true;
}
bool Screen::HandleRedrawEvent(int const areaId, int const event, SURFHANDLE const surface) {
if (areaId != this->info.aid) return false;
Update(surface);
return true;
}
void Screen::Update(SURFHANDLE const surface) {
HDC const hDC = oapiGetDC(surface);
SelectObject(hDC, info.background_brush);
SetBkMode(hDC, OPAQUE);
Rectangle(hDC, info.client_area.left, info.client_area.top, info.client_area.right, info.client_area.bottom);
SelectObject(hDC, info.font);
SetTextAlign(hDC, TA_LEFT);
SetTextColor(hDC, info.header_foreground_color);
SetBkMode(hDC, TRANSPARENT);
{
size_t const len = header.length();
TextOut(hDC, 5, 2, header.c_str(), min(info.dim.width,len));
if (len > info.dim.width)
TextOut(hDC, 5, 20, header.c_str()+info.dim.width, len-info.dim.width);
}
int line = 0;
for (std::list<Line>::iterator i = lines.begin(); i != lines.end(); ++i) {
SetTextColor(hDC, i->color);
TextOut(hDC, 5, 44 + 19 * line, i->line.data(), i->line.length());
line++;
}
oapiReleaseDC(surface, hDC);
}