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
|
|
|
* ---
|
2017-09-12 03:28:15 +02:00
|
|
|
* Copyright (c) 2011-2017, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2017, Andrei Alexeyev <akari@alienslab.net>.
|
2010-11-14 13:24:56 +01:00
|
|
|
*/
|
|
|
|
|
2017-09-27 14:14:53 +02:00
|
|
|
#pragma once
|
2010-11-14 13:24:56 +01:00
|
|
|
|
2017-02-04 03:56:40 +01:00
|
|
|
#include <SDL_ttf.h>
|
2010-11-14 13:24:56 +01:00
|
|
|
#include "texture.h"
|
|
|
|
|
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 {
|
2017-04-15 23:58:42 +02: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
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct FontRenderer FontRenderer;
|
|
|
|
struct FontRenderer {
|
|
|
|
Texture tex;
|
|
|
|
GLuint pbo;
|
2017-04-07 01:54:59 +02:00
|
|
|
float quality;
|
2017-03-28 16:52:53 +02:00
|
|
|
};
|
|
|
|
|
2017-04-07 01:54:59 +02:00
|
|
|
void fontrenderer_init(FontRenderer *f, float quality);
|
2017-03-28 16:52:53 +02:00
|
|
|
void fontrenderer_free(FontRenderer *f);
|
2017-04-02 16:06:18 +02:00
|
|
|
void fontrenderer_draw(FontRenderer *f, const char *text, TTF_Font *font);
|
|
|
|
void fontrenderer_draw_prerendered(FontRenderer *f, SDL_Surface *surf);
|
2017-04-07 01:54:59 +02:00
|
|
|
SDL_Surface* fontrender_render(FontRenderer *f, const char *text, TTF_Font *font);
|
2017-03-28 16:52:53 +02:00
|
|
|
|
2010-11-14 13:24:56 +01:00
|
|
|
Texture *load_text(const char *text, TTF_Font *font);
|
2011-06-13 18:48:36 +02:00
|
|
|
void draw_text(Alignment align, float x, float y, const char *text, TTF_Font *font);
|
2017-10-23 12:10:40 +02:00
|
|
|
void draw_text_auto_wrapped(Alignment align, float x, float y, const char *text, int width, TTF_Font *font);
|
2017-04-02 16:06:18 +02:00
|
|
|
void draw_text_prerendered(Alignment align, float x, float y, SDL_Surface *surf);
|
2017-03-28 16:52:53 +02:00
|
|
|
|
2012-07-29 22:39:52 +02:00
|
|
|
int stringwidth(char *s, TTF_Font *font);
|
2012-08-05 03:36:55 +02:00
|
|
|
int stringheight(char *s, TTF_Font *font);
|
2012-07-29 22:39:52 +02:00
|
|
|
int charwidth(char c, TTF_Font *font);
|
2017-10-23 12:10:40 +02:00
|
|
|
|
2017-08-28 13:51:05 +02:00
|
|
|
void shorten_text_up_to_width(char *s, float width, TTF_Font *font);
|
2017-10-23 12:10:40 +02:00
|
|
|
void wrap_text(char *buf, size_t bufsize, const char *src, int width, TTF_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);
|
|
|
|
|
2010-11-14 13:24:56 +01:00
|
|
|
struct Fonts {
|
2011-06-13 18:48:36 +02:00
|
|
|
TTF_Font *standard;
|
|
|
|
TTF_Font *mainmenu;
|
2017-04-06 02:58:57 +02:00
|
|
|
TTF_Font *small;
|
2017-11-23 03:25:53 +01:00
|
|
|
TTF_Font *hud;
|
|
|
|
TTF_Font *mono;
|
|
|
|
TTF_Font *monosmall;
|
2017-12-13 20:05:12 +01:00
|
|
|
TTF_Font *monotiny;
|
2010-11-14 13:24:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct Fonts _fonts;
|