summaryrefslogtreecommitdiff
path: root/pui.c
diff options
context:
space:
mode:
authorMikhail Burakov <mburakov@mailbox.org>2021-01-13 14:27:14 +0100
committerMikhail Burakov <mburakov@mailbox.org>2021-01-13 14:27:14 +0100
commit11688cf348f283dc1f95957338137fe8dd958c71 (patch)
tree572be35a19fd41b1895a093a216609f666b20135 /pui.c
parentf65e4f5502d88125f145dc257ec7a012e08dd6d6 (diff)
Add text rendering and update pui interface types
Diffstat (limited to 'pui.c')
-rw-r--r--pui.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/pui.c b/pui.c
index cb89991..660ac4b 100644
--- a/pui.c
+++ b/pui.c
@@ -33,19 +33,19 @@ struct PuiElement {
static_assert(sizeof(struct PuiHeader) == 4, "Invalid PuiHeader size");
static_assert(sizeof(struct PuiElement) == 4, "Invalid PuiElement size");
-int PuiGetWidth(const void* pui_data) {
+size_t PuiGetWidth(const void* pui_data) {
const struct PuiHeader* pui_header = pui_data;
- int sx = pui_header->scale >> 4;
- return pui_header->w << sx;
+ size_t sx = pui_header->scale >> 4;
+ return (size_t)pui_header->w << sx;
}
-int PuiGetHeight(const void* pui_data) {
+size_t PuiGetHeight(const void* pui_data) {
const struct PuiHeader* pui_header = pui_data;
- int sy = pui_header->scale & 0xf;
- return pui_header->h << sy;
+ size_t sy = pui_header->scale & 0xf;
+ return (size_t)pui_header->h << sy;
}
-int PuiHitTest(const void* pui_data, int x, int y) {
+int PuiHitTest(const void* pui_data, size_t x, size_t y) {
int result = 0;
const struct PuiHeader* pui_header = pui_data;
x >>= pui_header->scale >> 4;
@@ -61,28 +61,29 @@ int PuiHitTest(const void* pui_data, int x, int y) {
return result;
}
-void PuiRender(const void* pui_data, void* buffer, int stride, int active) {
+void PuiRender(const void* pui_data, void* buffer, size_t stride, int active) {
const struct PuiHeader* pui_header = pui_data;
- int width = pui_header->w << (pui_header->scale >> 4);
- int height = pui_header->h << (pui_header->scale & 0xf);
- int elements = pui_header->count >> 4;
- int colors = pui_header->count & 0xf;
+ size_t width = PuiGetWidth(pui_data);
+ size_t height = PuiGetHeight(pui_data);
+ size_t size = width * height;
+ size_t elements = pui_header->count >> 4;
+ size_t colors = pui_header->count & 0xf;
const uint32_t* palettes[] = {
(const uint32_t*)pui_data + 1 + elements,
(const uint32_t*)pui_data + 1 + elements + colors,
};
const uint8_t* bitmap_data =
(const uint8_t*)pui_data + 4 * (1 + elements + 2 * colors);
- for (int idx = 0, counter = 0, offset = 0; offset < width * height; idx++) {
- int value = bitmap_data[idx >> 1];
+ for (size_t idx = 0, counter = 0, offset = 0; offset < size; idx++) {
+ uint8_t value = bitmap_data[idx >> 1];
if (~idx & 1) value = value >> 4;
if (value & 0x8) {
counter = counter << 3 | (value & 0x7);
continue;
}
for (counter = counter ? counter + 2 : 1; counter-- > 0; offset++) {
- int x = offset % width;
- int y = offset / width;
+ size_t x = offset % width;
+ size_t y = offset / width;
int palette = !!(PuiHitTest(pui_data, x, y) & active);
((uint32_t*)buffer)[x + y * stride] = palettes[palette][value & 0x7];
}