Freeciv-3.1
Loading...
Searching...
No Matches
gui_string.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14/***********************************************************************
15 gui_string.h - description
16 -------------------
17 begin : Thu May 30 2002
18 copyright : (C) 2002 by Rafał Bursig
19 email : Rafał Bursig <bursig@poczta.fm>
20***********************************************************************/
21
22#ifndef FC__GUISTRING_H
23#define FC__GUISTRING_H
24
25/* SDL2 */
26#ifdef SDL2_PLAIN_INCLUDE
27#include <SDL.h>
28#include <SDL_ttf.h>
29#else /* SDL2_PLAIN_INCLUDE */
30#include <SDL2/SDL.h>
31#include <SDL2/SDL_ttf.h>
32#endif /* SDL2_PLAIN_INCLUDE */
33
34/* common */
35#include "fc_types.h"
36
37/* gui-sdl2 */
38#include "gui_main.h"
39
40#define SF_CENTER 0x10
41#define SF_CENTER_RIGHT 0x20
42
43/* styles:
44 TTF_STYLE_NORMAL 0
45 TTF_STYLE_BOLD 1
46 TTF_STYLE_ITALIC 2
47 TTF_STYLE_UNDERLINE 4
48 SF_CENTER 0x10 - use with multi string, must be > 0x0f
49 SF_CENTER_RIGHT 0x20 - use with multi string, must be > 0x0f
50*/
51
52typedef struct utf8_str {
53 Uint8 style;
54 Uint8 render;
55 Uint16 ptsize;
56 size_t n_alloc; /* total allocated text memory */
57 SDL_Color fgcol;
58 SDL_Color bgcol;
59 TTF_Font *font;
60 char *text;
62
72
73utf8_str *create_utf8_str_fonto(char *in_text, size_t n_alloc,
74 enum font_origin origin);
75utf8_str *create_utf8_str(char *in_text, size_t n_alloc, Uint16 ptsize);
76utf8_str *copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars);
78int write_utf8(SDL_Surface *dest, Sint16 x, Sint16 y, utf8_str *pstr);
79SDL_Surface *create_text_surf_from_utf8(utf8_str *pstr);
80SDL_Surface *create_text_surf_smaller_than_w(utf8_str *pstr, int w);
81void utf8_str_size(utf8_str *pstr, SDL_Rect *fill);
82void change_ptsize_utf8(utf8_str *pstr, Uint16 new_ptsize);
83void change_fonto_utf8(utf8_str *pstr, enum font_origin origin);
84
85void unload_font(Uint16 ptsize);
86void free_font_system(void);
87
88/*
89 * Here we use ordinary free( ... ) because check is made
90 * on start.
91 */
92#define FREEUTF8STR( pstr ) \
93 do { \
94 if (pstr != NULL) { \
95 FC_FREE(pstr->text); \
96 unload_font(pstr->ptsize); \
97 free(pstr); \
98 pstr = NULL; \
99 } \
100} while (FALSE)
101
102#define create_utf8_from_char(string_in, ptsize) \
103 (string_in) == NULL ? \
104 create_utf8_str(NULL, 0, ptsize) : \
105 copy_chars_to_utf8_str(create_utf8_str(NULL, 0, ptsize), string_in)
106
107#define create_utf8_from_char_fonto(string_in, fonto) \
108 (string_in) == NULL ? \
109 create_utf8_str_fonto(NULL, 0, fonto) : \
110 copy_chars_to_utf8_str(create_utf8_str_fonto(NULL, 0, fonto), string_in)
111
112#endif /* FC__GUISTRING_H */
#define n_alloc
Definition astring.c:78
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
void change_ptsize_utf8(utf8_str *pstr, Uint16 new_ptsize)
Definition gui_string.c:559
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
Definition gui_string.c:106
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
void change_fonto_utf8(utf8_str *pstr, enum font_origin origin)
Definition gui_string.c:584
void unload_font(Uint16 ptsize)
Definition gui_string.c:653
utf8_str * create_utf8_str(char *in_text, size_t n_alloc, Uint16 ptsize)
Definition gui_string.c:206
utf8_str * create_utf8_str_fonto(char *in_text, size_t n_alloc, enum font_origin origin)
Definition gui_string.c:241
int write_utf8(SDL_Surface *dest, Sint16 x, Sint16 y, utf8_str *pstr)
Definition gui_string.c:276
bool convert_utf8_str_to_const_surface_width(utf8_str *pstr, int width)
Definition gui_string.c:449
font_origin
Definition gui_string.h:63
@ FONTO_HEADING
Definition gui_string.h:68
@ FONTO_DEFAULT
Definition gui_string.h:64
@ FONTO_BIG
Definition gui_string.h:69
@ FONTO_SLIGHTLY_BIGGER
Definition gui_string.h:65
@ FONTO_ATTENTION
Definition gui_string.h:66
@ FONTO_ATTENTION_PLUS
Definition gui_string.h:67
@ FONTO_MAX
Definition gui_string.h:70
void free_font_system(void)
Definition gui_string.c:698
SDL_Surface * create_text_surf_smaller_than_w(utf8_str *pstr, int w)
Definition gui_string.c:539
Uint8 style
Definition gui_string.h:53
Uint16 ptsize
Definition gui_string.h:55
SDL_Color bgcol
Definition gui_string.h:58
SDL_Color fgcol
Definition gui_string.h:57
size_t n_alloc
Definition gui_string.h:56
TTF_Font * font
Definition gui_string.h:59
char * text
Definition gui_string.h:60
Uint8 render
Definition gui_string.h:54