79 template <FramebufferLike FB>
94 template <FramebufferLike FB>
110 template <FramebufferLike FB>
126 template <FramebufferLike FB>
143 template <FramebufferLike FB>
144 static auto draw_bitmap(FB &fb,
Point pos, std::span<const std::uint8_t> data, std::size_t w, std::size_t h,
145 std::size_t target_w, std::size_t target_h,
Orientation orientation) -> void;
170template <FramebufferLike FB>
174 int x0 =
static_cast<int>(start.x);
175 int y0 =
static_cast<int>(start.y);
176 int x1 =
static_cast<int>(end.x);
177 int y1 =
static_cast<int>(end.y);
179 int dx = std::abs(x1 - x0);
180 int dy = std::abs(y1 - y0);
181 int sx = (x0 < x1) ? 1 : -1;
182 int sy = (y0 < y1) ? 1 : -1;
189 fb.set_pixel(
static_cast<std::size_t
>(x0),
static_cast<std::size_t
>(y0), color, orientation);
193 if (x0 == x1 && y0 == y1) {
225template <FramebufferLike FB>
229 draw_line(fb, top_left, {bottom_right.x, top_left.y}, style, color, orientation);
230 draw_line(fb, {bottom_right.x, top_left.y}, bottom_right, style, color, orientation);
231 draw_line(fb, bottom_right, {top_left.x, bottom_right.y}, style, color, orientation);
232 draw_line(fb, {top_left.x, bottom_right.y}, top_left, style, color, orientation);
236 for (std::size_t y = top_left.y + 1; y < bottom_right.y; ++y) {
237 draw_line(fb, {top_left.x + 1, y}, {bottom_right.x - 1, y}, style, color, orientation);
264template <FramebufferLike FB>
267 int x =
static_cast<int>(radius);
273 auto plot_points = [&](
int cx,
int cy,
int px,
int py) {
275 fb.set_pixel(
static_cast<std::size_t
>(cx + px),
static_cast<std::size_t
>(cy + py), color, orientation);
276 fb.set_pixel(
static_cast<std::size_t
>(cx - px),
static_cast<std::size_t
>(cy + py), color, orientation);
278 fb.set_pixel(
static_cast<std::size_t
>(cx + px),
static_cast<std::size_t
>(cy - py), color, orientation);
279 fb.set_pixel(
static_cast<std::size_t
>(cx - px),
static_cast<std::size_t
>(cy - py), color, orientation);
281 fb.set_pixel(
static_cast<std::size_t
>(cx + py),
static_cast<std::size_t
>(cy + px), color, orientation);
282 fb.set_pixel(
static_cast<std::size_t
>(cx - py),
static_cast<std::size_t
>(cy + px), color, orientation);
283 fb.set_pixel(
static_cast<std::size_t
>(cx + py),
static_cast<std::size_t
>(cy - px), color, orientation);
284 fb.set_pixel(
static_cast<std::size_t
>(cx - py),
static_cast<std::size_t
>(cy - px), color, orientation);
290 auto fill_horizontal_line = [&](
int cx,
int cy,
int px,
int py) {
294 for (
int fx = -px; fx <= px; ++fx) {
295 fb.set_pixel(
static_cast<std::size_t
>(cx + fx),
static_cast<std::size_t
>(cy + py), color, orientation);
296 fb.set_pixel(
static_cast<std::size_t
>(cx + fx),
static_cast<std::size_t
>(cy - py), color, orientation);
300 for (
int fx = -py; fx <= py; ++fx) {
301 fb.set_pixel(
static_cast<std::size_t
>(cx + fx),
static_cast<std::size_t
>(cy + px), color, orientation);
302 fb.set_pixel(
static_cast<std::size_t
>(cx + fx),
static_cast<std::size_t
>(cy - px), color, orientation);
311 plot_points(
static_cast<int>(center.x),
static_cast<int>(center.y), x, y);
312 fill_horizontal_line(
static_cast<int>(center.x),
static_cast<int>(center.y), x, y);
327template <FramebufferLike FB>
330 std::size_t cursor_x = pos.x;
331 std::size_t cursor_y = pos.y;
334 const auto &metrics = font.metrics();
335 const auto font_width = metrics.width;
336 const auto font_height = metrics.height;
340 const auto width_bytes = (font_width % 8 == 0) ? (font_width / 8) : ((font_width / 8) + 1);
343 for (
char c : text) {
345 auto bitmap = font.char_data(c);
346 if (bitmap.empty()) {
351 for (std::size_t j = 0; j < font_height; ++j) {
352 for (std::size_t i = 0; i < font_width; ++i) {
355 std::size_t byte_idx = (j * width_bytes) + (i / 8);
356 if (byte_idx >= bitmap.size()) {
361 std::uint8_t
byte = bitmap[byte_idx];
362 bool is_set = (
byte & (0x80 >> (i % 8))) != 0;
366 Color pixel_color = is_set ? foreground : background;
367 fb.set_pixel(cursor_x + i, cursor_y + j, pixel_color, orientation);
371 cursor_x += font_width;
375template <FramebufferLike FB>
377 std::size_t target_w, std::size_t target_h,
Orientation orientation) ->
void {
379 std::size_t tw = (target_w > 0) ? target_w : w;
380 std::size_t th = (target_h > 0) ? target_h : h;
385 float scale_x =
static_cast<float>(w) /
static_cast<float>(tw);
386 float scale_y =
static_cast<float>(h) /
static_cast<float>(th);
389 for (std::size_t y = 0; y < th; ++y) {
390 for (std::size_t x = 0; x < tw; ++x) {
393 auto src_x =
static_cast<std::size_t
>(
static_cast<float>(x) * scale_x);
394 auto src_y =
static_cast<std::size_t
>(
static_cast<float>(y) * scale_y);
397 std::size_t idx = (src_y * w) + src_x;
399 if (idx < data.size()) {
403 fb.set_pixel(pos.x + x, pos.y + y, color, orientation);
Definition graphics.hpp:66
static auto draw_line(FB &fb, Point start, Point end, LineStyle style, Color color, Orientation orientation) -> void
Draw a line on the framebuffer.
Definition graphics.hpp:171
static auto draw_circle(FB &fb, Point center, std::size_t radius, LineStyle style, Color color, DrawFill fill, Orientation orientation) -> void
Draw a circle on the framebuffer.
Definition graphics.hpp:265
static auto draw_rectangle(FB &fb, Point top_left, Point bottom_right, LineStyle style, Color color, DrawFill fill, Orientation orientation) -> void
Draw a rectangle on the framebuffer.
Definition graphics.hpp:226
static auto draw_bitmap(FB &fb, Point pos, std::span< const std::uint8_t > data, std::size_t w, std::size_t h, std::size_t target_w, std::size_t target_h, Orientation orientation) -> void
Draw a bitmap on the framebuffer.
Definition graphics.hpp:376
static auto draw_text(FB &fb, Point pos, std::string_view text, const Font &font, Color foreground, Color background, Orientation orientation) -> void
Draw text string on the framebuffer.
Definition graphics.hpp:328
Bitmap font rendering for e-paper displays.
DrawFill
Definition types.hpp:151
@ Full
Draw filled shape (solid interior)
Orientation
Definition types.hpp:66
Color
Definition types.hpp:32
@ White
White (or lightest gray in grayscale modes)
@ Black
Black (or darkest gray in grayscale modes)
LineStyle
Definition types.hpp:120
@ Solid
Continuous solid line.
Definition geometry.hpp:37