summaryrefslogtreecommitdiff
path: root/src/user/mdemo/main.c
blob: fc7de80adb6869f759bb2015583c9f824cf570e5 (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
#include <pland/syscall.h>
#include <popups/info.h>

#define TEXT_COLOR ((_pixel_t){.r = 0x00, .g = 0x00, .b = 0x00})
#define BG_COLOR   ((_pixel_t){.r = 0xbf, .g = 0xbf, .b = 0xbf})

static const char *const mb_names[] = {
  "left", "right", "middle"
};

void main() {
  struct popup main_win;
  info_popup(&main_win, "Click me!", TEXT_COLOR, BG_COLOR);

  while (1) {
    struct window_action winact;
    _get_win_action(main_win.handle, &winact);

    switch (winact.action_type) {
      struct popup modal;
    case NOT_READY:
      _wait_for_action();
      _yield_task();
      continue;

    case KEY_DOWN:
      return;

    case MOUSE_DOWN:
      info_popupf(&modal,
        "Got %s click at (%d, %d)!",
        TEXT_COLOR, BG_COLOR,
        mb_names[winact.as_mouse.which],
        winact.as_mouse.x, winact.as_mouse.y);
      make_modal(&modal);
      continue;

    default:
      continue;
    }
  }
}