2010-11-14 13:24:56 +01:00
|
|
|
/*
|
2011-03-05 13:44:21 +01:00
|
|
|
* This software is licensed under the terms of the MIT-License
|
2017-02-11 04:52:08 +01:00
|
|
|
* See COPYING for further information.
|
2011-03-05 13:44:21 +01:00
|
|
|
* ---
|
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>.
|
2010-11-14 13:24:56 +01:00
|
|
|
*/
|
|
|
|
|
2017-09-27 14:14:53 +02:00
|
|
|
#pragma once
|
2017-11-25 20:45:11 +01:00
|
|
|
#include "taisei.h"
|
2010-11-14 13:24:56 +01:00
|
|
|
|
2017-02-04 03:56:40 +01:00
|
|
|
#include <SDL_ttf.h>
|
2017-12-14 04:48:30 +01:00
|
|
|
|
2010-11-14 13:24:56 +01:00
|
|
|
#include "texture.h"
|
2017-12-14 04:48:30 +01:00
|
|
|
#include "hashtable.h"
|
2010-11-14 13:24:56 +01:00
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
typedef enum {
|
2011-06-24 12:35:03 +02:00
|
|
|
AL_Center,
|
|
|
|
AL_Left,
|
|
|
|
AL_Right
|
2011-06-13 18:48:36 +02:00
|
|
|
} Alignment;
|
|
|
|
|
2017-12-13 20:05:12 +01:00
|
|
|
enum {
|
|
|
|
AL_Flag_NoAdjust = 0x10,
|
|
|
|
};
|
2017-03-28 16:52:53 +02:00
|
|
|
|
2017-04-07 01:54:59 +02:00
|
|
|
// Size of the buffer used by the font renderer at quality == 1.0.
|
|
|
|
// No text larger than this can be drawn.
|
2017-03-28 16:52:53 +02:00
|
|
|
enum {
|
2018-01-12 19:26:07 +01:00
|
|
|
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-03-28 16:52:53 +02:00
|
|
|
};
|
|
|
|
|
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);
|
2018-01-29 09:35:35 +01:00
|
|
|
Texture* render_text(const char *text, Font *font, float *out_w, float *out_h);
|
2017-03-28 16:52:53 +02:00
|
|
|
|
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);
|
2017-10-23 12:10:40 +02:00
|
|
|
|
2017-12-28 04:49:37 +01:00
|
|
|
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);
|
2010-11-14 13:24:56 +01:00
|
|
|
|
2017-04-15 23:58:42 +02:00
|
|
|
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-04-15 23:58:42 +02:00
|
|
|
|
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;
|
|
|
|
};
|
2010-11-14 13:24:56 +01:00
|
|
|
|
2017-12-14 04:48:30 +01:00
|
|
|
Font *first;
|
|
|
|
};
|
|
|
|
} _fonts;
|