Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/featured_text.h Source File

Freeciv-3.2

Loading...
Searching...
No Matches
featured_text.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#ifndef FC__FEATURED_TEXT_H
14#define FC__FEATURED_TEXT_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "support.h" /* bool type. */
22
23/* common */
24#include "fc_types.h"
25
26/*
27 * Some words about the featured text module.
28 *
29 * Bored to have black only chat, players used to hack their clients, to
30 * obtain colored chat based patterns. Also for strategic communication,
31 * they added some clickable links on particular city or location.
32 * The present code is not based on old warclient code, but it also contains
33 * the same tools. Whereas colors were determined in client side only,
34 * here the server also has the possibility to choose what color to display
35 * to the clients. Such embellishments are performed using escape sequences
36 * (which are described below) in the strings.
37 *
38 * Plain text vs featured text.
39 *
40 * What is called plain text in those files is actually a string without any
41 * escape sequence. It is the text which should basically displayed in the
42 * client, without taking account of the features. On the other side, what
43 * is called featured text is also a string, but which could include one of
44 * many escape sequences.
45 *
46 * Text tag.
47 *
48 * The text_tag type is a structure which tag a particular modification for
49 * a string. It contains many informations, which the type of modification,
50 * the start of the modification in bytes from the start of the string, and
51 * the stop of it. It also can contains many others fields, according to
52 * sequence type.
53 * Note that all offset datas are calculated in bytes and not in character
54 * number, so the client must translate those offsets before using them.
55 *
56 * Escape sequences.
57 *
58 * - Bold.
59 * Full name sequence: [bold] ... [/bold]
60 * Abbreviation sequence: [b] ... [/b]
61 * Text tag type: TTT_BOLD
62 *
63 * - Italic.
64 * Full name sequence: [italic] ... [/italic]
65 * Abbreviation sequence: [i] ... [/i]
66 * Text tag type: TTT_ITALIC
67 *
68 * - Strike.
69 * Full name sequence: [strike] ... [/strike]
70 * Abbreviation sequence: [s] ... [/s]
71 * Text tag type: TTT_STRIKE
72 *
73 * - Underline.
74 * Full name sequence: [underline] ... [/underline]
75 * Abbreviation sequence: [u] ... [/u]
76 * Text tag type: TTT_UNDERLINE
77 *
78 * - Color.
79 * Full name sequence: [color] ... [/color]
80 * Abbreviation sequence: [c] ... [/c]
81 * Text tag type: TTT_COLOR
82 * Option: foreground (abbreviation fg): a color name or a hex specification
83 * such as #3050b2 or #35b.
84 * Option: background (abbreviation bg): same type of data.
85 *
86 * - Link.
87 * Full name sequence: [link] ... [/link] or [link/]
88 * Abbreviation sequence: [l] ... [/l] or [l/]
89 * Text tag type: TTT_LINK
90 * Option: target (abbreviation tgt): absolutely needed. It is set to
91 * "city" (then link type is TLT_CITY), "tile" (TLT_TILE) or "unit"
92 * (TLT_UNIT).
93 * Option: id: if target type is TLT_CITY or TLT_UNIT, it is the id of
94 * the target.
95 * Option: name: if target type is TLT_CITY or TLT_UNIT, it is an additional
96 * string to display if the target is not known by the receiver.
97 * Options: x and y: if target type is TLT_TILE, they are the coordinates
98 * of the target.
99 */
100
101/* Offset type (in bytes). */
102 typedef int ft_offset_t;
103/* Unset offset value. */
104#define FT_OFFSET_UNSET ((ft_offset_t) -1)
105
106/* Opaque type. */
107struct text_tag;
108
109/* Define struct text_tag_list. */
110#define SPECLIST_TAG text_tag
111#define SPECLIST_TYPE struct text_tag
112#include "speclist.h"
113
114#define text_tag_list_iterate(tags, ptag) \
115 TYPED_LIST_ITERATE(struct text_tag, tags, ptag)
116#define text_tag_list_iterate_end LIST_ITERATE_END
117
118/* The different text_tag types.
119 * Changing the order doesn't break the network compatibility. */
120 enum text_tag_type {
121 TTT_BOLD = 0,
122 TTT_ITALIC,
123 TTT_STRIKE,
124 TTT_UNDERLINE,
125 TTT_COLOR,
126 TTT_LINK
127};
128
129/* The different text_tag link types.
130 * Changing the order doesn't break the network compatibility. */
131 enum text_link_type {
132 TLT_CITY,
133 TLT_TILE,
134 TLT_UNIT
135};
136
137/* Default maximal link size */
138#define MAX_LEN_LINK 128
139
140/* Simplification for colors. */
141 struct ft_color {
142 const char *foreground;
143 const char *background;
144};
145#define FT_COLOR(fg, bg) { fg, bg }
146/**********************************************************************/
149 static inline struct ft_color ft_color_construct(const char *foreground,
150 const char *background)
151{
152 struct ft_color color = FT_COLOR(foreground, background);
153
154 return color;
155}
156
157/**********************************************************************/
160 static inline bool ft_color_requested(const struct ft_color color)
161{
162 return ((NULL != color.foreground && '\0' != color.foreground[0])
163 || (NULL != color.background && '\0' != color.background[0]));
164}
165
166/* Predefined colors. */
167extern const struct ft_color ftc_any;
168
169extern const struct ft_color ftc_warning;
170extern const struct ft_color ftc_log;
171extern const struct ft_color ftc_server;
172extern const struct ft_color ftc_client;
173extern const struct ft_color ftc_editor;
174extern const struct ft_color ftc_command;
175extern struct ft_color ftc_changed;
176extern const struct ft_color ftc_server_prompt;
177extern const struct ft_color ftc_player_lost;
178extern const struct ft_color ftc_game_start;
179
180extern const struct ft_color ftc_chat_public;
181extern const struct ft_color ftc_chat_ally;
182extern const struct ft_color ftc_chat_private;
183extern const struct ft_color ftc_chat_luaconsole;
184
185extern const struct ft_color ftc_vote_public;
186extern const struct ft_color ftc_vote_team;
187extern const struct ft_color ftc_vote_passed;
188extern const struct ft_color ftc_vote_failed;
189extern const struct ft_color ftc_vote_yes;
190extern const struct ft_color ftc_vote_no;
191extern const struct ft_color ftc_vote_abstain;
192
193extern const struct ft_color ftc_luaconsole_input;
194extern const struct ft_color ftc_luaconsole_error;
195extern const struct ft_color ftc_luaconsole_warn;
196extern const struct ft_color ftc_luaconsole_normal;
197extern const struct ft_color ftc_luaconsole_verbose;
198extern const struct ft_color ftc_luaconsole_debug;
199
200/* Main functions. */
201size_t featured_text_to_plain_text(const char *featured_text,
202 char *plain_text, size_t plain_text_len,
203 struct text_tag_list **tags,
204 bool replace_link_text);
205size_t featured_text_apply_tag(const char *text_source,
206 char *featured_text, size_t featured_text_len,
207 enum text_tag_type tag_type,
208 ft_offset_t start_offset,
209 ft_offset_t stop_offset,
210 ...);
211
212/* Text tag list functions. NB: Overwrite the ones defined in speclist.h. */
213#define text_tag_list_new() \
214 text_tag_list_new_full(text_tag_destroy)
215#define text_tag_list_copy(tags) \
216 text_tag_list_copy_full(tags, text_tag_copy, text_tag_destroy)
217
218
219/* Text tag functions. */
220struct text_tag *text_tag_new(enum text_tag_type tag_type,
221 ft_offset_t start_offset,
222 ft_offset_t stop_offset,
223 ...);
224struct text_tag *text_tag_copy(const struct text_tag *ptag);
225void text_tag_destroy(struct text_tag *ptag);
226
227enum text_tag_type text_tag_type(const struct text_tag *ptag);
228 ft_offset_t text_tag_start_offset(const struct text_tag *ptag);
229 ft_offset_t text_tag_stop_offset(const struct text_tag *ptag);
230
231/* Specific TTT_COLOR text tag type functions. */
232const char *text_tag_color_foreground(const struct text_tag *ptag);
233const char *text_tag_color_background(const struct text_tag *ptag);
234
235/* Specific TTT_LINK text tag type functions. */
236enum text_link_type text_tag_link_type(const struct text_tag *ptag);
237int text_tag_link_id(const struct text_tag *ptag);
238
239/* Tools. */
240const char *city_link(const struct city *pcity);
241const char *city_tile_link(const struct city *pcity);
242const char *tile_link(const struct tile *ptile);
243const char *unit_link(const struct unit *punit);
244const char *unit_tile_link(const struct unit *punit);
245
246#ifdef __cplusplus
247}
248#endif /* __cplusplus */
249
250#endif /* FC__FEATURED_TEXT_H */
incite_cost
char * incite_cost
Definition comments.c:74
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
fc_types.h
ftc_chat_private
const struct ft_color ftc_chat_private
Definition featured_text.c:88
featured_text_apply_tag
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Definition featured_text.c:993
ftc_luaconsole_debug
const struct ft_color ftc_luaconsole_debug
Definition featured_text.c:104
ftc_vote_abstain
const struct ft_color ftc_vote_abstain
Definition featured_text.c:97
text_tag_link_type
enum text_link_type text_tag_link_type(const struct text_tag *ptag)
Definition featured_text.c:741
ft_color_requested
static bool ft_color_requested(const struct ft_color color)
Definition featured_text.h:160
ftc_log
const struct ft_color ftc_log
Definition featured_text.c:76
ftc_player_lost
const struct ft_color ftc_player_lost
Definition featured_text.c:83
city_tile_link
const char * city_tile_link(const struct city *pcity)
Definition featured_text.c:1089
featured_text_to_plain_text
size_t featured_text_to_plain_text(const char *featured_text, char *plain_text, size_t plain_text_len, struct text_tag_list **tags, bool replace_link_text)
Definition featured_text.c:864
ftc_luaconsole_verbose
const struct ft_color ftc_luaconsole_verbose
Definition featured_text.c:103
text_tag_copy
struct text_tag * text_tag_copy(const struct text_tag *ptag)
Definition featured_text.c:663
tile_link
const char * tile_link(const struct tile *ptile)
Definition featured_text.c:1106
ftc_command
const struct ft_color ftc_command
Definition featured_text.c:80
ft_offset_t
int ft_offset_t
Definition featured_text.h:102
text_link_type
text_link_type
Definition featured_text.h:131
TLT_TILE
@ TLT_TILE
Definition featured_text.h:133
TLT_UNIT
@ TLT_UNIT
Definition featured_text.h:134
TLT_CITY
@ TLT_CITY
Definition featured_text.h:132
text_tag_stop_offset
ft_offset_t text_tag_stop_offset(const struct text_tag *ptag)
Definition featured_text.c:704
ftc_server
const struct ft_color ftc_server
Definition featured_text.c:77
ftc_vote_failed
const struct ft_color ftc_vote_failed
Definition featured_text.c:94
text_tag_destroy
void text_tag_destroy(struct text_tag *ptag)
Definition featured_text.c:680
ftc_vote_yes
const struct ft_color ftc_vote_yes
Definition featured_text.c:95
ftc_luaconsole_error
const struct ft_color ftc_luaconsole_error
Definition featured_text.c:100
ftc_warning
const struct ft_color ftc_warning
Definition featured_text.c:75
text_tag_type
text_tag_type
Definition featured_text.h:120
TTT_LINK
@ TTT_LINK
Definition featured_text.h:126
TTT_BOLD
@ TTT_BOLD
Definition featured_text.h:121
TTT_ITALIC
@ TTT_ITALIC
Definition featured_text.h:122
TTT_STRIKE
@ TTT_STRIKE
Definition featured_text.h:123
TTT_COLOR
@ TTT_COLOR
Definition featured_text.h:125
TTT_UNDERLINE
@ TTT_UNDERLINE
Definition featured_text.h:124
text_tag_color_foreground
const char * text_tag_color_foreground(const struct text_tag *ptag)
Definition featured_text.c:713
ftc_client
const struct ft_color ftc_client
Definition featured_text.c:78
ftc_luaconsole_normal
const struct ft_color ftc_luaconsole_normal
Definition featured_text.c:102
ftc_editor
const struct ft_color ftc_editor
Definition featured_text.c:79
FT_COLOR
#define FT_COLOR(fg, bg)
Definition featured_text.h:145
city_link
const char * city_link(const struct city *pcity)
Definition featured_text.c:1072
ftc_any
const struct ft_color ftc_any
Definition featured_text.c:73
ftc_vote_no
const struct ft_color ftc_vote_no
Definition featured_text.c:96
ftc_vote_passed
const struct ft_color ftc_vote_passed
Definition featured_text.c:93
ftc_luaconsole_warn
const struct ft_color ftc_luaconsole_warn
Definition featured_text.c:101
text_tag_link_id
int text_tag_link_id(const struct text_tag *ptag)
Definition featured_text.c:756
ftc_chat_luaconsole
const struct ft_color ftc_chat_luaconsole
Definition featured_text.c:89
text_tag_start_offset
ft_offset_t text_tag_start_offset(const struct text_tag *ptag)
Definition featured_text.c:696
text_tag_new
struct text_tag * text_tag_new(enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Definition featured_text.c:638
ftc_vote_team
const struct ft_color ftc_vote_team
Definition featured_text.c:92
ftc_game_start
const struct ft_color ftc_game_start
Definition featured_text.c:84
unit_link
const char * unit_link(const struct unit *punit)
Definition featured_text.c:1122
ftc_server_prompt
const struct ft_color ftc_server_prompt
Definition featured_text.c:82
ftc_changed
struct ft_color ftc_changed
Definition featured_text.c:81
ftc_vote_public
const struct ft_color ftc_vote_public
Definition featured_text.c:91
unit_tile_link
const char * unit_tile_link(const struct unit *punit)
Definition featured_text.c:1139
ft_color_construct
static struct ft_color ft_color_construct(const char *foreground, const char *background)
Definition featured_text.h:149
text_tag_color_background
const char * text_tag_color_background(const struct text_tag *ptag)
Definition featured_text.c:727
ftc_luaconsole_input
const struct ft_color ftc_luaconsole_input
Definition featured_text.c:99
ftc_chat_public
const struct ft_color ftc_chat_public
Definition featured_text.c:86
ftc_chat_ally
const struct ft_color ftc_chat_ally
Definition featured_text.c:87
speclist.h
city
Definition city.h:320
color
Definition colors.h:21
ft_color
Definition featured_text.h:141
ft_color::background
const char * background
Definition featured_text.h:143
ft_color::foreground
const char * foreground
Definition featured_text.h:142
text_tag
Definition featured_text.c:49
text_tag::stop_offset
ft_offset_t stop_offset
Definition featured_text.c:52
text_tag::start_offset
ft_offset_t start_offset
Definition featured_text.c:51
tile
Definition tile.h:50
unit
Definition unit.h:138
support.h