aboutsummaryrefslogtreecommitdiff
path: root/drw.h
blob: 8417e156e63b15355dacd4589e674b1e35b603ba (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef DRW_H
#define DRW_H

#include <stdint.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_BITMAP_H
#include FT_STROKER_H

#include "wayland.h"

/* type definitions */
typedef struct {
	uint32_t *data;
	uint32_t *buffer_data;
	unsigned width;
	unsigned height;
	unsigned size;
	struct wl_buffer *buffer;
} Canvas;

typedef struct {
	const char *path;
	int loaded;
	FT_Library library;
	FT_Face face;
	FT_Stroker stroke;
} Font;

enum FontType {
	FONT_NORMAL,
	FONT_ITALIC,
	FONT_BOLD,
	FONT_BOLD_ITALIC,
	FONT_TYPE_SIZE
};

typedef Font FontFamily[FONT_TYPE_SIZE];
typedef char *FontPath[FONT_TYPE_SIZE];

struct FontCacheElement_;
typedef struct FontCacheElement_ {
	FontFamily *family;
	struct FontCacheElement_ *next;
} FontCacheElement;

typedef struct {
	FontCacheElement *first;
	unsigned fontsize;
	unsigned fonttype;
	struct {
		unsigned width;
		unsigned height;
	} box;
} FontCache;

typedef struct {
	uint8_t r;
	uint8_t g;
	uint8_t b;
	uint8_t a;
} Color;

/* exported functions */
Canvas* create_drw(struct wl_shm *shm, unsigned width, unsigned height);
void free_drw(Canvas *canvas);
void push_buffer(Canvas *canvas);

void draw_rect(Canvas *canvas, unsigned x, unsigned y, unsigned width, unsigned height, uint32_t color);
void draw_point(Canvas *canvas, unsigned x, unsigned y, uint32_t color);

FontCache *create_font_cache(FontPath *fontpath, int size, unsigned fontsize);
void      font_cache_generate_box(FontCache *fontcache);
void      free_font_cache(FontCache *fontcache);
unsigned draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigned x, unsigned y, uint32_t color);

#endif