Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/gui-sdl2/gui_string.h Source File

Freeciv-3.2

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
52 typedef 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;
61} utf8_str;
62
63/* .._PLUS might end up being same as its base size */
64 enum font_origin {
65 FONTO_DEFAULT,
66 FONTO_DEFAULT_PLUS,
67 FONTO_ATTENTION,
68 FONTO_ATTENTION_PLUS,
69 FONTO_HEADING,
70 FONTO_BIG,
71 FONTO_MAX
72};
73
74 utf8_str *create_utf8_str_fonto(char *in_text, size_t n_alloc,
75 enum font_origin origin);
76 utf8_str *create_utf8_str(char *in_text, size_t n_alloc, Uint16 ptsize);
77 utf8_str *copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars);
78bool convert_utf8_str_to_const_surface_width(utf8_str *pstr, int width);
79int write_utf8(SDL_Surface *dest, Sint16 x, Sint16 y, utf8_str *pstr);
80 SDL_Surface *create_text_surf_from_utf8(utf8_str *pstr);
81 SDL_Surface *create_text_surf_smaller_than_w(utf8_str *pstr, int w);
82void utf8_str_size(utf8_str *pstr, SDL_Rect *fill);
83void change_ptsize_utf8(utf8_str *pstr, Uint16 new_ptsize);
84void change_fonto_utf8(utf8_str *pstr, enum font_origin origin);
85
86void unload_font(Uint16 ptsize);
87void free_font_system(void);
88
89/*
90 * Here we use ordinary free( ... ) because check is made
91 * on start.
92 */
93#define FREEUTF8STR( pstr ) \
94 do { \
95 if (pstr != NULL) { \
96 FC_FREE(pstr->text); \
97 unload_font(pstr->ptsize); \
98 free(pstr); \
99 pstr = NULL; \
100 } \
101} while (FALSE)
102
103#define create_utf8_from_char(string_in, ptsize) \
104 (string_in) == NULL ? \
105 create_utf8_str(NULL, 0, ptsize) : \
106 copy_chars_to_utf8_str(create_utf8_str(NULL, 0, ptsize), string_in)
107
108#define create_utf8_from_char_fonto(string_in, fonto) \
109 (string_in) == NULL ? \
110 create_utf8_str_fonto(NULL, 0, fonto) : \
111 copy_chars_to_utf8_str(create_utf8_str_fonto(NULL, 0, fonto), string_in)
112
113#endif /* FC__GUISTRING_H */
n_alloc
#define n_alloc
Definition astring.c:78
width
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
incite_cost
char * incite_cost
Definition comments.c:74
fc_types.h
change_ptsize_utf8
void change_ptsize_utf8(utf8_str *pstr, Uint16 new_ptsize)
Definition gui_string.c:559
utf8_str
struct utf8_str utf8_str
utf8_str_size
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
Definition gui_string.c:106
copy_chars_to_utf8_str
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
create_text_surf_from_utf8
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
change_fonto_utf8
void change_fonto_utf8(utf8_str *pstr, enum font_origin origin)
Definition gui_string.c:584
unload_font
void unload_font(Uint16 ptsize)
Definition gui_string.c:653
create_utf8_str
utf8_str * create_utf8_str(char *in_text, size_t n_alloc, Uint16 ptsize)
Definition gui_string.c:206
create_utf8_str_fonto
utf8_str * create_utf8_str_fonto(char *in_text, size_t n_alloc, enum font_origin origin)
Definition gui_string.c:241
write_utf8
int write_utf8(SDL_Surface *dest, Sint16 x, Sint16 y, utf8_str *pstr)
Definition gui_string.c:276
convert_utf8_str_to_const_surface_width
bool convert_utf8_str_to_const_surface_width(utf8_str *pstr, int width)
Definition gui_string.c:449
font_origin
font_origin
Definition gui_string.h:64
FONTO_HEADING
@ FONTO_HEADING
Definition gui_string.h:69
FONTO_DEFAULT
@ FONTO_DEFAULT
Definition gui_string.h:65
FONTO_DEFAULT_PLUS
@ FONTO_DEFAULT_PLUS
Definition gui_string.h:66
FONTO_BIG
@ FONTO_BIG
Definition gui_string.h:70
FONTO_ATTENTION
@ FONTO_ATTENTION
Definition gui_string.h:67
FONTO_ATTENTION_PLUS
@ FONTO_ATTENTION_PLUS
Definition gui_string.h:68
FONTO_MAX
@ FONTO_MAX
Definition gui_string.h:71
free_font_system
void free_font_system(void)
Definition gui_string.c:698
create_text_surf_smaller_than_w
SDL_Surface * create_text_surf_smaller_than_w(utf8_str *pstr, int w)
Definition gui_string.c:539
gui_main.h
y
struct sprite int int y
Definition sprite_g.h:31
x
struct sprite int x
Definition sprite_g.h:31
utf8_str
Definition gui_string.h:52
utf8_str::style
Uint8 style
Definition gui_string.h:53
utf8_str::font
TTF_Font * font
Definition gui_string.h:59
utf8_str::ptsize
Uint16 ptsize
Definition gui_string.h:55
utf8_str::bgcol
SDL_Color bgcol
Definition gui_string.h:58
utf8_str::fgcol
SDL_Color fgcol
Definition gui_string.h:57
utf8_str::n_alloc
size_t n_alloc
Definition gui_string.h:56
utf8_str::text
char * text
Definition gui_string.h:60
utf8_str::render
Uint8 render
Definition gui_string.h:54