40 lines
913 B
C
40 lines
913 B
C
|
|
/* Standalone demo equivalent to the original waymini.c main(). */
|
||
|
|
|
||
|
|
#include "waymini.h"
|
||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
|
||
|
|
static void on_keycode(void *user, uint32_t keycode, uint32_t state) {
|
||
|
|
(void)user;
|
||
|
|
printf("key=%u state=%u\n", keycode, state);
|
||
|
|
fflush(stdout);
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(void) {
|
||
|
|
uint32_t w = 320, h = 200;
|
||
|
|
struct waymini *wm = waymini_create(w, h, on_keycode, NULL);
|
||
|
|
if (!wm) return 1;
|
||
|
|
|
||
|
|
uint8_t *p = (uint8_t *)waymini_get_pixels(wm);
|
||
|
|
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;
|
||
|
|
p[i + 0] = 0x20;
|
||
|
|
p[i + 1] = (uint8_t)(y * 255 / h);
|
||
|
|
p[i + 2] = (uint8_t)(x * 255 / w);
|
||
|
|
p[i + 3] = 0xff;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
waymini_present(wm);
|
||
|
|
|
||
|
|
while (!waymini_should_close(wm)) {
|
||
|
|
if (waymini_dispatch(wm) < 0) break;
|
||
|
|
}
|
||
|
|
|
||
|
|
waymini_destroy(wm);
|
||
|
|
return 0;
|
||
|
|
}
|