Files

54 lines
1.4 KiB
C

/* Example program that links against the waymini library.
* No external dependencies beyond waymini itself and the C standard library.
*/
#include "waymini.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void on_key(void *user, uint32_t keycode, uint32_t state) {
(void)user;
const char *label = state ? "down" : "up ";
printf("key %s: %u\n", label, keycode);
fflush(stdout);
}
int main(void) {
uint32_t w = 320, h = 200;
struct waymini *wm = waymini_create(w, h, on_key, NULL);
if (!wm) return 1;
printf("surface: %ux%u stride=%u\n",
waymini_get_width(wm), waymini_get_height(wm), waymini_get_stride(wm));
uint8_t *pixels = (uint8_t *)waymini_get_pixels(wm);
if (!pixels) {
waymini_destroy(wm);
return 1;
}
/* Fill a simple gradient. Each row is stride bytes. */
for (uint32_t y = 0; y < h; y++) {
for (uint32_t x = 0; x < w; x++) {
size_t i = (size_t)y * waymini_get_stride(wm) + (size_t)x * 4;
pixels[i + 0] = 0x20; /* B */
pixels[i + 1] = (uint8_t)(y * 255 / h); /* G */
pixels[i + 2] = (uint8_t)(x * 255 / w); /* R */
pixels[i + 3] = 0xff; /* A (ignored for XRGB) */
}
}
waymini_present(wm);
while (!waymini_should_close(wm)) {
if (waymini_dispatch(wm) < 0) break;
}
waymini_destroy(wm);
return 0;
}