Files
Lab9_UNIX/core/PaintDevice.cpp
T
2026-06-05 11:45:04 +03:00

107 lines
1.8 KiB
C++

#include "PaintDevice.h"
PaintDevice::PaintDevice()
: m_Size(40, 40)
{
initscr();
noecho();
curs_set(0);
keypad(stdscr, TRUE);
nodelay(stdscr, TRUE);
resize(m_Size);
m_Ready = true;
}
PaintDevice::~PaintDevice()
{
endwin();
}
bool PaintDevice::ready() const
{
return m_Ready;
}
void PaintDevice::resize(const Size& size)
{
m_Size = size;
m_Buffer =
std::vector<std::vector<wchar_t>>
(
m_Size.height(),
std::vector<wchar_t>(
m_Size.width(),
L' '
)
);
}
void PaintDevice::clear()
{
for (int y = 0; y < m_Size.height(); y++)
{
for (int x = 0; x < m_Size.width(); x++)
{
m_Buffer[y][x] = L' ';
}
}
}
void PaintDevice::set_char(
const Vector2& position,
wchar_t c
)
{
if (
position.x() >= 0 &&
position.x() < m_Size.width() &&
position.y() >= 0 &&
position.y() < m_Size.height()
)
{
m_Buffer[position.y()][position.x()] = c;
}
}
wchar_t PaintDevice::get_char(
const Vector2& position
)
{
if (
position.x() >= 0 &&
position.x() < m_Size.width() &&
position.y() >= 0 &&
position.y() < m_Size.height()
)
{
return m_Buffer[position.y()][position.x()];
}
return L'\0';
}
void PaintDevice::render()
{
::clear();
for (int y = 0; y < m_Size.height(); y++)
{
for (int x = 0; x < m_Size.width(); x++)
{
mvaddch(
y,
x,
m_Buffer[y][x]
);
}
}
refresh();
}