Freeciv-3.2
Loading...
Searching...
No Matches
messagewin.c
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 messagewin.c - description
16 -------------------
17 begin : Feb 2 2003
18 copyright : (C) 2003 by Rafał Bursig
19 email : Rafał Bursig <bursig@poczta.fm>
20 **********************************************************************/
21
22#ifdef HAVE_CONFIG_H
23#include <fc_config.h>
24#endif
25
26/* SDL2 */
27#ifdef SDL2_PLAIN_INCLUDE
28#include <SDL.h>
29#else /* SDL2_PLAIN_INCLUDE */
30#include <SDL2/SDL.h>
31#endif /* SDL2_PLAIN_INCLUDE */
32
33/* utility */
34#include "fcintl.h"
35#include "log.h"
36
37/* client */
38#include "options.h"
39
40/* gui-sdl2 */
41#include "citydlg.h"
42#include "colors.h"
43#include "graphics.h"
44#include "gui_id.h"
45#include "gui_main.h"
46#include "gui_tilespec.h"
47#include "mapview.h"
48#include "themespec.h"
49#include "utf8string.h"
50#include "widget.h"
51
52#include "messagewin.h"
53
54
55#ifdef SMALL_SCREEN
56#define N_MSG_VIEW 3 /* max before scrolling happens */
57#else
58#define N_MSG_VIEW 6
59#endif
60
61/* 0 -> use theme default */
62#define PTSIZE_LOG_FONT 0
63
64static struct advanced_dialog *msg_dlg = NULL;
65
66/**********************************************************************/
69static int msg_callback(struct widget *pwidget)
70{
72 int message_index = *(int*)pwidget->data.ptr;
73
76
79 }
80
81 return -1;
82}
83
84/**********************************************************************/
87static int move_msg_window_callback(struct widget *pwindow)
88{
91 }
92
93 return -1;
94}
95
96/* ======================================================================
97 Public
98 ====================================================================== */
99
100/**********************************************************************/
104{
105 int msg_count;
106 int current_count;
107 const struct message *msg = NULL;
108 struct widget *buf = NULL, *pwindow = NULL;
109 utf8_str *pstr = NULL;
110 SDL_Rect area = {0, 0, 0, 0};
111 bool create;
112 int label_width;
113
114 if (msg_dlg == NULL) {
116 }
117
120
121 if (current_count > 0) {
128 /* hide scrollbar */
130 msg_dlg->scroll->count = 0;
131 current_count = 0;
132 }
133 create = (current_count == 0);
134
135 pwindow = msg_dlg->end_widget_list;
136
137 area = pwindow->area;
138
140
141 if (msg_count > 0) {
145
147 /* string must be divided to fit into the given area */
150 int count = 0;
151
152 while (utf8_texts[count]) {
154 strlen(utf8_texts[count]) + 1, PTSIZE_LOG_FONT);
155
156 buf = create_iconlabel(NULL, pwindow->dst, pstr2,
158
159 /* this block is duplicated in the "else" branch */
160 {
161 buf->string_utf8->bgcol = (SDL_Color) {0, 0, 0, 0};
162
163 buf->size.w = label_width;
164 buf->data.ptr = fc_calloc(1, sizeof(int));
165 *(int*)buf->data.ptr = current_count;
166 buf->action = msg_callback;
167 if (msg->tile) {
169 if (msg->visited) {
171 } else {
172 buf->string_utf8->fgcol = *get_theme_color(COLOR_THEME_MESWIN_ACTIVE_TEXT);
173 }
174 }
175
176 buf->id = ID_LABEL;
177
179
180 /* add to widget list */
181 if (create) {
183 area.x, area.y);
184 create = FALSE;
185 } else {
188 FALSE, area.x, area.y);
189 }
190 }
191 count++;
192 } /* while */
194 } else {
195 buf = create_iconlabel(NULL, pwindow->dst, pstr,
197
198 /* duplicated block */
199 {
200 buf->string_utf8->bgcol = (SDL_Color) {0, 0, 0, 0};
201
202 buf->size.w = label_width;
203 buf->data.ptr = fc_calloc(1, sizeof(int));
204 *(int*)buf->data.ptr = current_count;
205 buf->action = msg_callback;
206 if (msg->tile) {
208 if (msg->visited) {
210 } else {
211 buf->string_utf8->fgcol = *get_theme_color(COLOR_THEME_MESWIN_ACTIVE_TEXT);
212 }
213 }
214
215 buf->id = ID_LABEL;
216
218
219 /* add to widget list */
220 if (create) {
222 pwindow, FALSE,
223 area.x, area.y);
224 create = FALSE;
225 } else {
228 FALSE, area.x, area.y);
229 }
230 }
231 } /* if */
232 } /* for */
233 } /* if */
234
236 widget_flush(pwindow);
237}
238
239/**********************************************************************/
243{
244 utf8_str *pstr;
245 struct widget *pwindow = NULL;
246 SDL_Surface *background;
249
250 if (msg_dlg) {
251 return;
252 }
253
254 msg_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
255
256 /* Create window */
258 pstr->style = TTF_STYLE_BOLD;
259
260 pwindow = create_window_skeleton(NULL, pstr, 0);
261
263 set_wstate(pwindow, FC_WS_NORMAL);
265
266 msg_dlg->end_widget_list = pwindow;
267 msg_dlg->begin_widget_list = pwindow;
268
269 /* create scrollbar */
271
273
274 /* define content area */
275 area.w = (adj_size(520) - (pwindow->size.w - pwindow->area.w));
277 area.h = (N_MSG_VIEW + 1) * size.h;
278
280
281 /* create window background */
283 if (resize_window(pwindow, background, NULL,
284 (pwindow->size.w - pwindow->area.w) + area.w,
285 (pwindow->size.h - pwindow->area.h) + area.h)) {
286 FREESURFACE(background);
287 }
288
289 area = pwindow->area;
290
292 area.x + area.w, area.y,
293 area.h, TRUE);
294
296
297 widget_set_position(pwindow, (main_window_width() - pwindow->size.w)/2, adj_size(25));
298
299 widget_redraw(pwindow);
300
302}
303
304/**********************************************************************/
316
317/**********************************************************************/
321{
322 return (msg_dlg != NULL);
323}
char * incite_cost
Definition comments.c:75
#define _(String)
Definition fcintl.h:67
void meswin_dialog_popdown(void)
Definition messagewin.c:432
void meswin_dialog_popup(bool raise)
Definition messagewin.c:417
void real_meswin_dialog_update(void *unused)
Definition messagewin.c:451
bool meswin_dialog_is_open(void)
Definition messagewin.c:443
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
int main_window_width(void)
Definition graphics.c:685
struct sdl2_data main_data
Definition graphics.c:57
#define FREESURFACE(ptr)
Definition graphics.h:322
@ ID_CHATLINE_WINDOW
Definition gui_id.h:57
@ ID_LABEL
Definition gui_id.h:27
#define adj_size(size)
Definition gui_main.h:141
#define PRESSED_EVENT(event)
Definition gui_main.h:71
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
Definition gui_string.c:106
utf8_str * create_utf8_str(char *in_text, size_t n_alloc, Uint16 ptsize)
Definition gui_string.c:206
bool convert_utf8_str_to_const_surface_width(utf8_str *pstr, int width)
Definition gui_string.c:449
#define create_utf8_from_char(string_in, ptsize)
Definition gui_string.h:103
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
@ FONTO_ATTENTION
Definition gui_string.h:67
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
static struct advanced_dialog * msg_dlg
Definition messagewin.c:64
#define N_MSG_VIEW
Definition messagewin.c:58
static int move_msg_window_callback(struct widget *pwindow)
Definition messagewin.c:87
static int msg_callback(struct widget *pwidget)
Definition messagewin.c:69
#define PTSIZE_LOG_FONT
Definition messagewin.c:62
SDL_Surface * theme_get_background(const struct theme *t, enum theme_background background)
@ BACKGROUND_MESSAGEWIN
@ COLOR_THEME_MESWIN_ACTIVE_TEXT
Definition themecolors.h:97
@ COLOR_THEME_MESWIN_ACTIVE_TEXT2
Definition themecolors.h:98
struct theme * active_theme
Definition themespec.c:154
char ** create_new_line_utf8strs(const char *pstr)
Definition utf8string.c:35
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
void del_group_of_widgets_from_gui_list(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:863
void unselect_widget_action(void)
Definition widget.c:418
void undraw_group(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:754
Uint16 redraw_group(const struct widget *begin_group_widget_list, const struct widget *end_group_widget_list, int add_to_update)
Definition widget.c:720
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:983
void move_window_group(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:1039
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
@ FC_WS_NORMAL
Definition widget.h:96
bool add_widget_to_vertical_scroll_widget_list(struct advanced_dialog *dlg, struct widget *new_widget, struct widget *add_dock, bool dir, Sint16 start_x, Sint16 start_y) fc__attribute((nonnull(2)))
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
@ WF_FREE_DATA
Definition widget.h:78
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
@ WF_DRAW_TEXT_LABEL_WITH_SPACE
Definition widget.h:87
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
static void widget_set_area(struct widget *pwidget, SDL_Rect area)
Definition widget.h:261
struct widget * create_iconlabel(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, Uint32 flags)
void setup_vertical_scrollbar_area(struct scroll_bar *scroll, Sint16 start_x, Sint16 start_y, Uint16 height, bool swap_start_x)
Uint32 create_vertical_scrollbar(struct advanced_dialog *dlg, Uint8 step, Uint8 active, bool create_scrollbar, bool create_buttons)
#define hide_scrollbar(scrollbar)
bool resize_window(struct widget *pwindow, SDL_Surface *bcgd, SDL_Color *pcolor, Uint16 new_w, Uint16 new_h)
struct widget * create_window_skeleton(struct gui_layer *pdest, utf8_str *title, Uint32 flags)
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
int meswin_get_num_messages(void)
const struct message * meswin_get_message(int message_index)
void meswin_double_click(int message_index)
void meswin_set_visited_state(int message_index, bool state)
size_t size
Definition specvec.h:72
struct widget * begin_active_widget_list
Definition widget.h:184
struct widget * end_widget_list
Definition widget.h:182
struct widget * end_active_widget_list
Definition widget.h:185
struct widget * active_widget_list
Definition widget.h:186
struct scroll_bar * scroll
Definition widget.h:187
struct widget * begin_widget_list
Definition widget.h:181
struct tile * tile
struct widget * up_left_button
SDL_Event event
Definition graphics.h:217
SDL_Color fgcol
Definition gui_string.h:57
void * ptr
Definition widget.h:133
union widget::@194 data
utf8_str * string_utf8
Definition widget.h:121
int(* action)(struct widget *)
Definition widget.h:157
SDL_Rect area
Definition widget.h:149
SDL_Rect size
Definition widget.h:145
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47