summaryrefslogtreecommitdiff
path: root/userland/libgui/libgui.h
blob: 85e1dda35eec84eb7052837de3db9115d96d65ec (plain)
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
#ifndef LIBGUI_H
#define LIBGUI_H
#include <stddef.h>
#include <stdint.h>

#define WINDOWSERVER_EVENT_KEYPRESS 0
#define WINDOWSERVER_EVENT_WINDOW_EXIT 1
#define WINDOWSERVER_EVENT_WINDOW_RESIZE 2

#define EV_SHIFT(_mode) ((_mode) & (1 << 0))
#define EV_ALT(_mode) ((_mode) & (1 << 1))
#define EV_CTRL(_mode) ((_mode) & (1 << 2))

typedef struct {
  int ws_socket;
  int bitmap_fd;
  uint32_t *bitmap_ptr;
  int x;
  int y;
  int sx;
  int sy;
} GUI_Window;

// Taken from drivers/keyboard.c
struct KEY_EVENT {
  char c;
  uint8_t mode;    // (shift (0 bit)) (alt (1 bit)) (ctrl (2 bit))
  uint8_t release; // 0 pressed, 1 released
};

typedef struct {
  int type;
  union {
    struct KEY_EVENT ev;
    int vector[2];
  };
} WS_EVENT;

GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy);
void GUI_DrawFont(GUI_Window *w, uint32_t px, uint32_t py, const uint32_t c);
void GUI_UpdateWindow(GUI_Window *w);
void GUI_OverwriteFont(GUI_Window *w, uint32_t px, uint32_t py,
                       const uint32_t color);
void GUI_ClearScreen(GUI_Window *w, uint32_t color);
void GUI_DrawRectangle(GUI_Window *w, uint32_t x, uint32_t y, uint32_t sx,
                       uint32_t sy, uint32_t color);
void GUI_EventLoop(GUI_Window *w, void (*event_handler)(WS_EVENT ev));
int GUI_BufferResize(GUI_Window *w, uint32_t sx, uint32_t sy);
int GUI_SendResize(GUI_Window *w, uint32_t sx, uint32_t sy);
void GUI_DrawLine(GUI_Window *w, uint32_t sx, uint32_t sy, uint32_t dx,
                  uint32_t dy, uint32_t rgba);
void GUI_DrawRectangle(GUI_Window *w, uint32_t x, uint32_t y, uint32_t sx,
                       uint32_t sy, uint32_t color);
#endif