summaryrefslogtreecommitdiff
path: root/applications/init/source/main.cpp
blob: cae17a242ea030b5e640e1a1f49fd60134694010 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#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;
    }

  }

}