#ifndef DRW_H #define DRW_H #include #include #include FT_FREETYPE_H #include FT_BITMAP_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; } 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); unsigned font_width(FontCache *fontcache, const char *text); #endif