Files
wadamesh/web/platform/WebDisplay.cpp
T
Kaj SchittecatandClaude Opus 5.5 963c75df5d web: host build of the real touch UI (SDL2, demo backend)
The touch UI (src/ui-touch, unmodified apart from WADA_WEB board guards)
builds for macOS with CMake and runs in an SDL2 window: a compat layer
for the Arduino/ESP-IDF/FreeRTOS surface, a MyMesh stand-in with a
MeshBackend interface (DemoBackend now), and the web board's SDL
display/touch/keyboard drivers. WEB_BUILD.md follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 12:06:04 +02:00

37 lines
1.4 KiB
C++

// SPDX-License-Identifier: GPL-3.0-or-later
#include "WebDisplay.h"
#include <stdlib.h>
#include <string.h>
WebDisplay::WebDisplay() : DisplayDriver(WADA_WEB_W, WADA_WEB_H) {
_fb = (uint16_t*)calloc((size_t)WADA_WEB_W * WADA_WEB_H, sizeof(uint16_t));
}
void WebDisplay::clear() {
memset(_fb, 0, (size_t)WADA_WEB_W * WADA_WEB_H * sizeof(uint16_t));
_dirty = true;
}
void WebDisplay::fillRect(int x, int y, int w, int h) {
for (int r = y; r < y + h; ++r) {
if (r < 0 || r >= WADA_WEB_H) continue;
for (int c = x; c < x + w; ++c) if (c >= 0 && c < WADA_WEB_W) _fb[(size_t)r * WADA_WEB_W + c] = _color;
}
_dirty = true;
}
void WebDisplay::drawRect(int x, int y, int w, int h) {
fillRect(x, y, w, 1); fillRect(x, y + h - 1, w, 1);
fillRect(x, y, 1, h); fillRect(x + w - 1, y, 1, h);
}
uint16_t WebDisplay::getTextWidth(const char* str) { return str ? (uint16_t)(strlen(str) * 6) : 0; }
void WebDisplay::writePixelsRGB565(int x, int y, int w, int h, const uint16_t* px) {
if (!px || w <= 0 || h <= 0) return;
for (int r = 0; r < h; ++r) {
const int dy = y + r;
if (dy < 0 || dy >= WADA_WEB_H) continue;
int x0 = x, cw = w, sx = 0;
if (x0 < 0) { sx = -x0; cw += x0; x0 = 0; }
if (x0 + cw > WADA_WEB_W) cw = WADA_WEB_W - x0;
if (cw > 0) memcpy(_fb + (size_t)dy * WADA_WEB_W + x0, px + (size_t)r * w + sx, (size_t)cw * sizeof(uint16_t));
}
_dirty = true;
}