DisplayMatrix::drawLine

This commit is contained in:
Patrick Haßel 2025-01-23 11:54:10 +01:00
parent cfcb56898c
commit d975d7d207
2 changed files with 25 additions and 0 deletions

View File

@ -26,6 +26,8 @@ public:
void fillRect(int w = W, int h = H) const;
void drawLine(int w = W, int h = H, int thickness = 1) const;
// print ----------------------------------------------------------------------------------------
void printf(const char *format, ...);

View File

@ -18,4 +18,27 @@ void DisplayMatrix<W, H>::fillRect(const int w, const int h) const {
}
}
template<int W, int H>
void DisplayMatrix<W, H>::drawLine(const int w, const int h, const int thickness) const {
if (w >= h) {
const auto m = static_cast<double>(h) / w;
for (auto t = 0; t < thickness; ++t) {
const auto offset = t % 2 == 0 ? t / 2 : -t / 2;
for (auto x = 0; x < w; ++x) {
const auto y = static_cast<int>(round(offset + x * m));
matrix[cursorY + y][cursorX + x].blend(foreground, alpha);
}
}
} else {
const auto m = static_cast<double>(w) / h;
for (auto t = 0; t < thickness; ++t) {
const auto offset = t % 2 == 0 ? t / 2 : -t / 2;
for (auto y = 0; y < w; ++y) {
const auto x = static_cast<int>(round(offset + y * m));
matrix[cursorY + y][cursorX + x].blend(foreground, alpha);
}
}
}
}
#endif