32 #include <c/resources/fonts/fonts.h>
44 template<auto Context,
template<auto>
typename DisplayImpl>
50 using Impl = DisplayImpl<Context>;
58 static auto init(
auto ... args) {
59 return Impl::init(args...);
68 return Impl::deinit(args...);
84 return Impl::getWidth();
93 return Impl::getHeight();
102 return Impl::getDefaultPalette();
111 return Impl::getFramebufferAddress();
120 Impl::setPalette(palette);
142 static void clear(
auto colorIndex) {
143 Impl::clear(
static_cast<u8>(colorIndex));
161 for (
u16 x = x1; x < x2; x++)
163 for (
u16 x = x1; x < x2; x++)
165 for (
u16 y = y1; y < y2; y++)
167 for (
u16 y = y1; y < y2; y++)
186 for (
u16 x = x1; x < x2; x++)
187 for (
u16 y = y1; y < y2; y++)
200 u8 colorValue =
static_cast<u8>(colorIndex);
201 Impl::setPixel(x, y, colorValue);
219 i16 deltaX = std::abs(x2 - x1);
220 i16 deltaY = -std::abs(y2 - y1);
221 i16 speedX = x1 < x2 ? 1 : -1;
222 i16 speedY = y1 < y2 ? 1 : -1;
224 i16 error = deltaX + deltaY;
227 while (!(x1 == x2 && y1 == y2)) {
230 if ((error * 2) > deltaY) {
234 if ((error * 2) < deltaX) {
250 auto setPixels = [](
i16 centerX,
i16 centerY,
i16 x,
i16 y,
u8 colorIndex) {
261 i16 x = 0, y = radius;
262 i16 d = 3 - 2 * radius;
263 setPixels(centerX, centerY, x, y, colorIndex);
271 d = d + 4 * (x - y) + 10;
276 setPixels(centerX, centerY, x, y, colorIndex);
292 i16 xChange = 1 - (radius << 1);
297 for (
i16 i = centerX - x; i <= centerX + x; i++) {
298 i16 y1 = centerY + y;
299 i16 y2 = centerY - y;
311 for (
i16 i = centerX - y; i <= centerX + y; i++) {
312 i16 y1 = centerY + x;
313 i16 y2 = centerY - x;
325 radiusError += yChange;
327 if (((radiusError << 1) + xChange) > 0) {
329 radiusError += xChange;
348 u16 width = font.Width;
349 u16 height = font.Height;
351 const u8 *dataStart = &font.table[(c -
' ') * height * ((width + 7) / 8)];
353 u8 offset = 8 * ((width + 7) / 8) - width;
358 for (
u32 i = 0; i < height; i++) {
359 const u8 *data = (dataStart + (width + 7) / 8 * i);
361 switch ((width + 7) / 8) {
366 line = data[0] << 8 | data[1];
370 line = data[0] << 16 | data[1] << 8 | data[0];
374 for (
u16 bit = 0; bit < width; bit++) {
375 if (line & (1 << (width - bit + offset - 1)))
392 static void drawString(
u16 x,
u16 y, std::string_view
string,
auto colorIndex, Font& font) {
393 for (
char c :
string) {