121 lines
3.5 KiB
C++
121 lines
3.5 KiB
C++
#include <daguerre.hpp>
|
|
|
|
static daguerre::hilbert_color transparent_color;
|
|
|
|
void alpha_overlay(
|
|
daguerre::hilbert_color &dest, const daguerre::hilbert_color &src) {
|
|
if (src != transparent_color)
|
|
dest = src;
|
|
}
|
|
|
|
int main(int, char **) {
|
|
|
|
daguerre::default_overlay(
|
|
transparent_color, (daguerre::rgb24){.r = 255, .g = 0, .b = 255});
|
|
|
|
auto raw_framebuffer = daguerre::get_hilbert_framebuffer();
|
|
const unsigned fbw = raw_framebuffer.width;
|
|
const unsigned fbh = raw_framebuffer.height;
|
|
|
|
daguerre::image<daguerre::rgb24> raw_burden;
|
|
daguerre::try_load_ppm("/assets/burden.ppm", raw_burden);
|
|
|
|
daguerre::image<daguerre::rgb24> burden_stretch(fbw, fbh);
|
|
daguerre::image<daguerre::rgb24> burden_stretch_inverted(fbw, fbh);
|
|
for (unsigned y = 0; y < fbh; ++y)
|
|
for (unsigned x = 0; x < fbw; ++x) {
|
|
daguerre::rgb24 color = raw_burden.get(
|
|
x * raw_burden.width / fbw, y * raw_burden.height / fbh);
|
|
burden_stretch.set(x, y, color);
|
|
burden_stretch_inverted.set(x, y, {
|
|
.r = (uint8_t)(255 - color.r),
|
|
.g = (uint8_t)(255 - color.g),
|
|
.b = (uint8_t)(255 - color.b)});
|
|
}
|
|
|
|
daguerre::image<daguerre::rgb24> pointer;
|
|
daguerre::try_load_ppm("/assets/pointer.ppm", pointer);
|
|
|
|
daguerre::fixed_bitmap_font<bool> terminus;
|
|
daguerre::try_load_psf("/assets/terminus-bold-18x10.psf", terminus);
|
|
|
|
terminus.overlay_text<>(burden_stretch, 0, 0, "this is a test");
|
|
terminus.overlay_text<>(burden_stretch_inverted, 0, 0, "tset a si siht");
|
|
|
|
daguerre::image<daguerre::hilbert_color>
|
|
burden_stretch_hilbert(burden_stretch);
|
|
|
|
daguerre::image<daguerre::hilbert_color>
|
|
burden_stretch_inverted_hilbert(burden_stretch_inverted);
|
|
|
|
daguerre::image<daguerre::hilbert_color> pointer_hilbert(pointer);
|
|
|
|
daguerre::image<daguerre::hilbert_color> double_buffer(
|
|
fbw + pointer.width - 1, fbh + pointer.height - 1);
|
|
|
|
int32_t mouse_x = fbw / 2;
|
|
int32_t mouse_y = fbh / 2;
|
|
bool was_left_mouse_down = false;
|
|
|
|
bool should_draw = true;
|
|
|
|
while (1) {
|
|
|
|
if (should_draw) {
|
|
double_buffer.overlay_from<>(
|
|
burden_stretch_hilbert, 0, 0, 0, 0, fbw, fbh);
|
|
double_buffer.overlay_from<daguerre::hilbert_color, alpha_overlay>(
|
|
pointer_hilbert, mouse_x, mouse_y,
|
|
0, 0, pointer.width, pointer.height);
|
|
raw_framebuffer.overlay_from<>(double_buffer, 0, 0, 0, 0, fbw, fbh);
|
|
should_draw = false;
|
|
}
|
|
|
|
__euler_mouse_buttons mouse_buttons;
|
|
int16_t mouse_change_x, mouse_change_y;
|
|
uint32_t key_packet;
|
|
__euler_input_packet_type packet_type = __euler_get_input_packet(
|
|
mouse_buttons, mouse_change_x, mouse_change_y, key_packet);
|
|
|
|
bool should_invert = false;
|
|
|
|
if (packet_type == __EULER_IPT_MOUSE) {
|
|
|
|
if (mouse_change_x != 0 || mouse_change_y != 0) {
|
|
|
|
mouse_x += mouse_change_x;
|
|
mouse_y += mouse_change_y;
|
|
|
|
if (mouse_x < 0)
|
|
mouse_x = 0;
|
|
else if ((unsigned)mouse_x >= fbw)
|
|
mouse_x = fbw - 1;
|
|
|
|
if (mouse_y < 0)
|
|
mouse_y = 0;
|
|
else if ((unsigned)mouse_y >= fbh)
|
|
mouse_y = fbh - 1;
|
|
|
|
should_draw = true;
|
|
|
|
}
|
|
|
|
if (!was_left_mouse_down && (mouse_buttons & __EULER_MB_LEFT))
|
|
should_invert = true;
|
|
|
|
was_left_mouse_down = mouse_buttons & __EULER_MB_LEFT;
|
|
|
|
}
|
|
|
|
else if (packet_type == __EULER_IPT_KEYBOARD)
|
|
if ((key_packet & 0x0400ff) == 0x00005a)
|
|
should_invert = true;
|
|
|
|
if (should_invert) {
|
|
daguerre::swap(burden_stretch_hilbert, burden_stretch_inverted_hilbert);
|
|
should_draw = true;
|
|
}
|
|
|
|
}
|
|
|
|
}
|