taisei/src/resource/font.h

72 lines
1.7 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
2018-01-04 18:14:31 +01:00
* Copyright (c) 2011-2018, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2018, Andrei Alexeyev <akari@alienslab.net>.
*/
2017-09-27 14:14:53 +02:00
#pragma once
#include "taisei.h"
2017-02-04 03:56:40 +01:00
#include <SDL_ttf.h>
2017-12-14 04:48:30 +01:00
#include "texture.h"
2017-12-14 04:48:30 +01:00
#include "hashtable.h"
typedef enum {
2011-06-24 12:35:03 +02:00
AL_Center,
AL_Left,
AL_Right
} Alignment;
2017-12-13 20:05:12 +01:00
enum {
AL_Flag_NoAdjust = 0x10,
};
// Size of the buffer used by the font renderer at quality == 1.0.
// No text larger than this can be drawn.
enum {
FONTREN_MAXW = 1024, // must be a power of two that is >= SCREEN_W
FONTREN_MAXH = 64, // must be a power of two that is > largest font size
};
2017-12-14 04:48:30 +01:00
typedef struct Font Font;
Texture *load_text(const char *text, Font *font);
void draw_text(Alignment align, float x, float y, const char *text, Font *font);
void draw_text_auto_wrapped(Alignment align, float x, float y, const char *text, int width, Font *font);
Texture* render_text(const char *text, Font *font, float *out_w, float *out_h);
2017-12-14 04:48:30 +01:00
int stringwidth(char *s, Font *font);
int stringheight(char *s, Font *font);
int charwidth(char c, Font *font);
int font_line_spacing(Font *font);
2017-12-14 04:48:30 +01:00
void shorten_text_up_to_width(char *s, float width, Font *font);
void wrap_text(char *buf, size_t bufsize, const char *src, int width, Font *font);
void init_fonts(void);
void uninit_fonts(void);
void load_fonts(float quality);
void reload_fonts(float quality);
void free_fonts(void);
2017-12-14 04:48:30 +01:00
void update_font_cache(void);
2017-12-14 04:48:30 +01:00
extern struct Fonts {
union {
struct {
Font *standard;
Font *mainmenu;
Font *small;
Font *hud;
Font *mono;
Font *monosmall;
Font *monotiny;
};
2017-12-14 04:48:30 +01:00
Font *first;
};
} _fonts;