summaryrefslogtreecommitdiff
path: root/applications
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-05-19 14:39:06 -0400
committerBenji Dial <benji@benjidial.net>2024-05-19 14:39:06 -0400
commit5a54df93c4e9368c36e69d1e9c88cd2904e92308 (patch)
tree094f294c51701a34a6ce18b43965fff708f3fdd5 /applications
parent649ff9636fe7289749c91141bbf32b2dcbe6dde4 (diff)
downloadhilbert-os-5a54df93c4e9368c36e69d1e9c88cd2904e92308.tar.gz
rework daguerre a bit
Diffstat (limited to 'applications')
-rw-r--r--applications/init/source/main.cpp126
1 files changed, 65 insertions, 61 deletions
diff --git a/applications/init/source/main.cpp b/applications/init/source/main.cpp
index c5df77c..cae17a2 100644
--- a/applications/init/source/main.cpp
+++ b/applications/init/source/main.cpp
@@ -1,23 +1,37 @@
#include <daguerre.hpp>
-void alpha_overlay(
- daguerre::hilbert_color &dest, const daguerre::rgb24 &src) {
- if (src.r != 0xff || src.g != 0x00 || src.b != 0xff)
- daguerre::default_overlay(dest, src);
-}
+static daguerre::hilbert_color transparent_color;
-void invert(daguerre::rgb24 &dest, const daguerre::rgb24 &src) {
- dest.r = 255 - src.r;
- dest.g = 255 - src.g;
- dest.b = 255 - src.b;
+void alpha_overlay(
+ daguerre::hilbert_color &dest, const daguerre::hilbert_color &src) {
+ if (src != transparent_color)
+ dest = src;
}
int main(int, char **) {
- auto framebuffer = daguerre::get_hilbert_framebuffer();
-
- daguerre::image<daguerre::rgb24> burden;
- daguerre::try_load_ppm("/assets/burden.ppm", burden);
+ 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);
@@ -25,54 +39,64 @@ int main(int, char **) {
daguerre::fixed_bitmap_font<bool> terminus;
daguerre::try_load_psf("/assets/terminus-bold-18x10.psf", terminus);
- terminus.overlay_text<>(burden, 0, 0, "this is a test");
+ 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);
- int32_t width = burden.width < framebuffer.width
- ? burden.width : framebuffer.width;
- int32_t height = burden.height < framebuffer.height
- ? burden.height : framebuffer.height;
- unsigned x = (framebuffer.width - width) / 2;
- unsigned y = (framebuffer.height - height) / 2;
+ daguerre::image<daguerre::hilbert_color> double_buffer(
+ fbw + pointer.width - 1, fbh + pointer.height - 1);
- int32_t new_mouse_x = width / 2;
- int32_t new_mouse_y = height / 2;
- int32_t old_mouse_x = new_mouse_x;
- int32_t old_mouse_y = new_mouse_y;
+ int32_t mouse_x = fbw / 2;
+ int32_t mouse_y = fbh / 2;
bool was_left_mouse_down = false;
- daguerre::overlay_region<>(framebuffer, x, y, burden, 0, 0, width, height);
+ 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 anything_changed = false;
bool should_invert = false;
if (packet_type == __EULER_IPT_MOUSE) {
if (mouse_change_x != 0 || mouse_change_y != 0) {
- old_mouse_x = new_mouse_x;
- old_mouse_y = new_mouse_y;
- new_mouse_x += mouse_change_x;
- new_mouse_y += mouse_change_y;
+ mouse_x += mouse_change_x;
+ mouse_y += mouse_change_y;
- if (new_mouse_x < 0)
- new_mouse_x = 0;
- else if ((unsigned)new_mouse_x > width - pointer.width)
- new_mouse_x = width - pointer.width;
+ if (mouse_x < 0)
+ mouse_x = 0;
+ else if ((unsigned)mouse_x >= fbw)
+ mouse_x = fbw - 1;
- if (new_mouse_y < 0)
- new_mouse_y = 0;
- else if ((unsigned)new_mouse_y > height - pointer.height)
- new_mouse_y = height - pointer.height;
+ if (mouse_y < 0)
+ mouse_y = 0;
+ else if ((unsigned)mouse_y >= fbh)
+ mouse_y = fbh - 1;
- anything_changed = true;
+ should_draw = true;
}
@@ -88,28 +112,8 @@ int main(int, char **) {
should_invert = true;
if (should_invert) {
-
- //this works with the current implementation of overlay_region, but
- //maybe it would be better to have a dedicated function for when the
- //two regions are exactly the same, given the comment on overlay_region.
- daguerre::overlay_region<daguerre::rgb24, daguerre::rgb24, invert>(
- burden, 0, 0, burden, 0, 0, width, height);
-
- daguerre::overlay_region<>(
- framebuffer, x, y, burden, 0, 0, width, height);
-
- anything_changed = true;
-
- }
-
- if (anything_changed) {
- daguerre::overlay_region<>(
- framebuffer, old_mouse_x + x, old_mouse_y + y, burden,
- old_mouse_x, old_mouse_y, pointer.width, pointer.height);
- daguerre::overlay_region<
- daguerre::hilbert_color, daguerre::rgb24, alpha_overlay>(
- framebuffer, new_mouse_x + x, new_mouse_y + y,
- pointer, 0, 0, pointer.width, pointer.height);
+ daguerre::swap(burden_stretch_hilbert, burden_stretch_inverted_hilbert);
+ should_draw = true;
}
}