DisplayMatrix::drawLine
This commit is contained in:
parent
cfcb56898c
commit
d975d7d207
@ -26,6 +26,8 @@ public:
|
|||||||
|
|
||||||
void fillRect(int w = W, int h = H) const;
|
void fillRect(int w = W, int h = H) const;
|
||||||
|
|
||||||
|
void drawLine(int w = W, int h = H, int thickness = 1) const;
|
||||||
|
|
||||||
// print ----------------------------------------------------------------------------------------
|
// print ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void printf(const char *format, ...);
|
void printf(const char *format, ...);
|
||||||
|
|||||||
@ -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
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user