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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
// MIT License, Copyright (c) 2020 Marvin Borner
// Some GFX functions
#ifndef GFX_H
#define GFX_H
#include <def.h>
#include <sys.h>
#include <vec.h>
#define WM_PATH "wm"
#define GET_COLOR(color, n) (((color) >> ((n) << 3)) & 0xff)
#define GET_ALPHA(color) (GET_COLOR((color), 3))
#define GET_RED(color) (GET_COLOR((color), 2))
#define GET_GREEN(color) (GET_COLOR((color), 1))
#define GET_BLUE(color) (GET_COLOR((color), 0))
#define COLOR_TRANSPARENT 0x00000000
#define COLOR_INVISIBLE 0x00000000
#define COLOR_BLACK 0xff0f0f0f
#define COLOR_RED 0xfff07f7f
#define COLOR_GREEN 0xff7ff088
#define COLOR_YELLOW 0xffeef07f
#define COLOR_BLUE 0xff7facf0
#define COLOR_MAGENTA 0xffd67ff0
#define COLOR_CYAN 0xff7fe7f0
#define COLOR_WHITE 0xffe9e9e9
#define COLOR_BRIGHT_BLACK 0xff928374
#define COLOR_BRIGHT_RED 0xffed9a9a
#define COLOR_BRIGHT_GREEN 0xff9ef0a5
#define COLOR_BRIGHT_YELLOW 0xffe7e897
#define COLOR_BRIGHT_BLUE 0xff98b9eb
#define COLOR_BRIGHT_MAGENTA 0xffd196e3
#define COLOR_BRIGHT_CYAN 0xff94dae0
#define COLOR_BRIGHT_WHITE 0xffe3e3e3
#define COLOR_FG COLOR_WHITE
#define COLOR_BG COLOR_BLACK
#define WF_DEFAULT (0 << 0)
#define WF_NO_FOCUS (1 << 0)
#define WF_NO_DRAG (1 << 1)
#define WF_NO_RESIZE (1 << 2)
#define WF_NO_FB (1 << 3)
#define WF_NO_WINDOW (1 << 4)
#define WF_ALPHA (1 << 5)
#define WF_BAR (1 << 6)
#define GFX_NON_ALPHA 0
#define GFX_ALPHA 1
/**
* Useful macros
*/
#define GFX_CENTER_IN(a, b) (ABS((a) - (b)) / 2)
#define GFX_RECT(pos, size) ((struct gfx_rect){ .pos = (pos), .size = (size) })
#define GFX_IN_RECT(rect, p) \
((p).x >= (rect).pos.x && (p).x < (rect).pos.x + (rect).size.x && (p).y >= (rect).pos.y && \
(p).y < (rect).pos.y + (rect).size.y)
/**
* Structures
*/
enum font_type { FONT_8, FONT_12, FONT_16, FONT_24, FONT_32, FONT_64 };
enum gfx_filter {
GFX_FILTER_NONE,
GFX_FILTER_INVERT,
};
// Generalized font struct
struct gfx_font {
void *raw;
char *chars;
vec2 size;
int char_size;
};
struct gfx_context {
vec2 size;
u8 *fb;
u32 bpp;
u32 pitch;
u32 bytes;
};
struct gfx_rect {
vec2 pos; // Upper left
vec2 size;
};
struct gfx_context *gfx_new_ctx(struct gfx_context *ctx, vec2 size, u8 bpp) NONNULL;
struct gfx_context *gfx_clone(struct gfx_context *ctx) NONNULL;
/**
* Text stuff
*/
struct gfx_font *gfx_resolve_font(enum font_type font_type);
void gfx_write_char(struct gfx_context *ctx, vec2 pos, enum font_type font_type, u32 c,
char ch) NONNULL;
void gfx_write(struct gfx_context *ctx, vec2 pos, enum font_type font_type, u32 c,
const char *text) NONNULL;
vec2 gfx_font_size(enum font_type font_type);
/**
* Image loading
*/
void gfx_draw_image(struct gfx_context *ctx, vec2 pos, vec2 size, const char *path) NONNULL;
void gfx_draw_image_filter(struct gfx_context *ctx, vec2 pos, vec2 size, enum gfx_filter filter,
const char *path) NONNULL;
void gfx_load_wallpaper(struct gfx_context *ctx, const char *path) NONNULL;
/**
* Context copying
*/
void gfx_copy(struct gfx_context *dest, struct gfx_context *src, vec2 pos, vec2 size) NONNULL;
void gfx_ctx_on_ctx(struct gfx_context *dest, struct gfx_context *src, vec2 pos, u8 alpha) NONNULL;
/**
* Context transformations
*/
struct gfx_context *gfx_scale(struct gfx_context *ctx, vec2 size) NONNULL;
/**
* Drawing functions
*/
void gfx_draw_pixel(struct gfx_context *ctx, vec2 pos1, u32 c);
void gfx_draw_rectangle(struct gfx_context *ctx, vec2 pos1, vec2 pos2, u32 c) NONNULL;
void gfx_draw_line(struct gfx_context *ctx, vec2 pos1, vec2 pos2, u32 scale, u32 c);
void gfx_clear(struct gfx_context *ctx);
void gfx_fill(struct gfx_context *ctx, u32 c) NONNULL;
void gfx_draw_border(struct gfx_context *ctx, u32 width, u32 c) NONNULL;
#endif
|