41 lines
1.4 KiB
C
41 lines
1.4 KiB
C
#include "characters.h"
|
|
#include "draw.h"
|
|
|
|
void draw_image(struct image canvas, struct image texture, size_t xpos, size_t ypos, bool vertical) {
|
|
for (size_t y = 0; y < texture.height; y++) {
|
|
for (size_t x = 0; x < texture.width; x++) {
|
|
int canvas_y = (vertical ? x : y) + ypos;
|
|
int canvas_x = (vertical ? y : x) + xpos;
|
|
if (texture.color[y * texture.width + x].a == 0) continue;
|
|
if (canvas_x < 0 || canvas_x >= (int) canvas.width - 1 || canvas_y < 0 || canvas_y >= (int) canvas.height - 1) continue;
|
|
canvas.buf[canvas_y * canvas.width + canvas_x] = texture.buf[y * texture.width + x];
|
|
}
|
|
}
|
|
}
|
|
|
|
void draw_glyph(struct image canvas, uint32_t glyph, size_t xpos, size_t ypos, struct color color) {
|
|
struct image texture = {
|
|
.width = 5,
|
|
.height = 6,
|
|
.bufsize = 5 * 6,
|
|
.buf = (uint32_t[30]) {0}
|
|
};
|
|
|
|
for (size_t y = 0; y < texture.height; y++) {
|
|
for (size_t x = 0; x < texture.width; x++) {
|
|
if ((glyph >> ((texture.height - y - 1) * texture.width + (texture.width - x - 1))) & 1) {
|
|
texture.color[y * texture.width + x] = color;
|
|
}
|
|
}
|
|
}
|
|
draw_image(canvas, texture, xpos, ypos, 0);
|
|
}
|
|
|
|
void draw_text(struct image canvas, char *string, size_t xpos, size_t ypos, struct color color) {
|
|
for (size_t i = 0; string[i]; i++) {
|
|
uint32_t glyph = characters[string[i] - ' '];
|
|
draw_glyph(canvas, glyph, xpos + i * 5, ypos, color);
|
|
}
|
|
}
|
|
|