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). */
102typedef 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. */
128
129/* The different text_tag link types.
130 * Changing the order doesn't break the network compatibility. */
136
137/* Default maximal link size */
138#define MAX_LEN_LINK 128
139
140/* Simplification for colors. */
141struct ft_color {
142 const char *foreground;
143 const char *background;
144};
145#define FT_COLOR(fg, bg) { fg, bg }
146/**********************************************************************/
150 const char *background)
151{
153
154 return color;
155}
156
157/**********************************************************************/
160static 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;
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. */
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,
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. */
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);
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. */
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 */
char * incite_cost
Definition comments.c:75
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
const struct ft_color ftc_chat_private
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,...)
const struct ft_color ftc_luaconsole_debug
const struct ft_color ftc_vote_abstain
enum text_link_type text_tag_link_type(const struct text_tag *ptag)
static bool ft_color_requested(const struct ft_color color)
const struct ft_color ftc_log
const struct ft_color ftc_player_lost
const char * city_tile_link(const struct city *pcity)
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)
const struct ft_color ftc_luaconsole_verbose
struct text_tag * text_tag_copy(const struct text_tag *ptag)
const char * tile_link(const struct tile *ptile)
const struct ft_color ftc_command
int ft_offset_t
text_link_type
@ TLT_TILE
@ TLT_UNIT
@ TLT_CITY
ft_offset_t text_tag_stop_offset(const struct text_tag *ptag)
const struct ft_color ftc_server
const struct ft_color ftc_vote_failed
void text_tag_destroy(struct text_tag *ptag)
const struct ft_color ftc_vote_yes
const struct ft_color ftc_luaconsole_error
const struct ft_color ftc_warning
text_tag_type
@ TTT_LINK
@ TTT_BOLD
@ TTT_ITALIC
@ TTT_STRIKE
@ TTT_COLOR
@ TTT_UNDERLINE
const char * text_tag_color_foreground(const struct text_tag *ptag)
const struct ft_color ftc_client
const struct ft_color ftc_luaconsole_normal
const struct ft_color ftc_editor
#define FT_COLOR(fg, bg)
const char * city_link(const struct city *pcity)
const struct ft_color ftc_any
const struct ft_color ftc_vote_no
const struct ft_color ftc_vote_passed
VAR_ARG_CONST struct ft_color ftc_changed
const struct ft_color ftc_luaconsole_warn
int text_tag_link_id(const struct text_tag *ptag)
const struct ft_color ftc_chat_luaconsole
ft_offset_t text_tag_start_offset(const struct text_tag *ptag)
struct text_tag * text_tag_new(enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
const struct ft_color ftc_vote_team
const struct ft_color ftc_game_start
const char * unit_link(const struct unit *punit)
const struct ft_color ftc_server_prompt
const struct ft_color ftc_vote_public
const char * unit_tile_link(const struct unit *punit)
static struct ft_color ft_color_construct(const char *foreground, const char *background)
const char * text_tag_color_background(const struct text_tag *ptag)
const struct ft_color ftc_luaconsole_input
const struct ft_color ftc_chat_public
const struct ft_color ftc_chat_ally
Definition city.h:320
Definition colors.h:21
const char * background
const char * foreground
ft_offset_t stop_offset
ft_offset_t start_offset
Definition tile.h:50
Definition unit.h:138
#define VAR_ARG_CONST
Definition support.h:152