Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/gui-sdl3/widget_edit.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
widget_edit.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2006 - The Freeciv Project
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#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* SDL3 */
19#include <SDL3/SDL.h>
20
21/* gui-sdl3 */
22#include "colors.h"
23#include "graphics.h"
24#include "gui_id.h"
25#include "gui_tilespec.h"
26#include "mapview.h"
27#include "themespec.h"
28#include "utf8string.h"
29#include "widget.h"
30#include "widget_p.h"
31
32struct utf8_char {
33 struct utf8_char *next;
34 struct utf8_char *prev;
35 int bytes;
36 char chr[7];
37 SDL_Surface *tsurf;
38};
39
40struct text_edit {
41 struct utf8_char *begin_text_chain;
42 struct utf8_char *end_text_chain;
43 struct utf8_char *input_chain;
44 SDL_Surface *bg;
45 struct widget *pwidget;
46 int chain_len;
47 int start_x;
48 int true_length;
49 int input_chain_x;
50};
51
52static size_t chainlen(const struct utf8_char *chain);
53static void del_chain(struct utf8_char *chain);
54static struct utf8_char *text2chain(const char *text_in);
55static char *chain2text(const struct utf8_char *in_chain, size_t len, size_t *size);
56
57 static int (*baseclass_redraw)(struct widget *pwidget);
58
59/**********************************************************************/
62 static int redraw_edit_chain(struct text_edit *edt)
63{
64 struct utf8_char *input_chain_tmp;
65 SDL_Rect dest, dest_copy = {0, 0, 0, 0};
66 int start_mod_x;
67 int ret;
68
69 dest_copy.x = edt->pwidget->size.x;
70 dest_copy.y = edt->pwidget->size.y;
71
72 ret = (*baseclass_redraw)(edt->pwidget);
73 if (ret != 0) {
74 return ret;
75 }
76
77 /* blit theme */
78 dest = dest_copy;
79
80 alphablit(edt->bg, NULL, edt->pwidget->dst->surface, &dest, 255);
81
82 /* set start parameters */
83 input_chain_tmp = edt->begin_text_chain;
84 start_mod_x = 0;
85
86 dest_copy.y += (edt->bg->h - input_chain_tmp->tsurf->h) / 2;
87 dest_copy.x += edt->start_x;
88
89 /* draw loop */
90 while (input_chain_tmp) {
91 dest_copy.x += start_mod_x;
92 /* check if we draw inside of edit rect */
93 if (dest_copy.x > edt->pwidget->size.x + edt->bg->w - 4) {
94 break;
95 }
96
97 if (dest_copy.x > edt->pwidget->size.x) {
98 dest = dest_copy;
99 alphablit(input_chain_tmp->tsurf, NULL, edt->pwidget->dst->surface, &dest,
100 255);
101 }
102
103 start_mod_x = input_chain_tmp->tsurf->w;
104
105 /* draw cursor */
106 if (input_chain_tmp == edt->input_chain) {
107 dest = dest_copy;
108
109 create_line(edt->pwidget->dst->surface,
110 dest.x - 1, dest.y + (edt->bg->h / 8),
111 dest.x - 1, dest.y + edt->bg->h - (edt->bg->h / 4),
112 get_theme_color(COLOR_THEME_EDITFIELD_CARET));
113 /* save active element position */
114 edt->input_chain_x = dest_copy.x;
115 }
116
117 input_chain_tmp = input_chain_tmp->next;
118 } /* while - draw loop */
119
120 widget_flush(edt->pwidget);
121
122 return 0;
123}
124
125/**********************************************************************/
138 static int redraw_edit(struct widget *edit_widget)
139{
140 if (get_wstate(edit_widget) == FC_WS_PRESSED) {
141 return redraw_edit_chain((struct text_edit *)edit_widget->data.ptr);
142 } else {
143 int ret;
144 SDL_Rect rdest = {edit_widget->size.x, edit_widget->size.y, 0, 0};
145 SDL_Surface *pedit = NULL;
146 SDL_Surface *text;
147
148 ret = (*baseclass_redraw)(edit_widget);
149 if (ret != 0) {
150 return ret;
151 }
152
153 if (edit_widget->string_utf8->text != NULL
154 && get_wflags(edit_widget) & WF_PASSWD_EDIT) {
155 char *backup = edit_widget->string_utf8->text;
156 size_t len = strlen(backup) + 1;
157 char *cbuf = fc_calloc(1, len);
158
159 memset(cbuf, '*', len - 1);
160 cbuf[len - 1] = '\0';
161 edit_widget->string_utf8->text = cbuf;
162 text = create_text_surf_from_utf8(edit_widget->string_utf8);
163 FC_FREE(cbuf);
164 edit_widget->string_utf8->text = backup;
165 } else {
166 text = create_text_surf_from_utf8(edit_widget->string_utf8);
167 }
168
169 pedit = create_bcgnd_surf(edit_widget->theme, get_wstate(edit_widget),
170 edit_widget->size.w, edit_widget->size.h);
171
172 if (!pedit) {
173 return -1;
174 }
175
176 /* blit theme */
177 alphablit(pedit, NULL, edit_widget->dst->surface, &rdest, 255);
178
179 /* set position and blit text */
180 if (text) {
181 rdest.y += (pedit->h - text->h) / 2;
182 /* blit centred text to botton */
183 if (edit_widget->string_utf8->style & SF_CENTER) {
184 rdest.x += (pedit->w - text->w) / 2;
185 } else {
186 if (edit_widget->string_utf8->style & SF_CENTER_RIGHT) {
187 rdest.x += pedit->w - text->w - adj_size(5);
188 } else {
189 rdest.x += adj_size(5); /* center left */
190 }
191 }
192
193 alphablit(text, NULL, edit_widget->dst->surface, &rdest, 255);
194 }
195 /* text */
196 ret = pedit->h;
197
198 /* Free memory */
199 FREESURFACE(text);
200 FREESURFACE(pedit);
201
202 return ret;
203 }
204
205 return 0;
206}
207
208/**********************************************************************/
213 static size_t chainlen(const struct utf8_char *chain)
214{
215 size_t length = 0;
216
217 if (chain) {
218 while (TRUE) {
219 length++;
220 if (chain->next == NULL) {
221 break;
222 }
223 chain = chain->next;
224 }
225 }
226
227 return length;
228}
229
230/**********************************************************************/
233 static void del_chain(struct utf8_char *chain)
234{
235 int i, len = 0;
236
237 if (!chain) {
238 return;
239 }
240
241 len = chainlen(chain);
242
243 if (len > 1) {
244 chain = chain->next;
245 for (i = 0; i < len - 1; i++) {
246 FREESURFACE(chain->prev->tsurf);
247 FC_FREE(chain->prev);
248 chain = chain->next;
249 }
250 }
251
252 FC_FREE(chain);
253}
254
255/**********************************************************************/
259 static struct utf8_char *text2chain(const char *text_in)
260{
261 int i, len;
262 struct utf8_char *out_chain = NULL;
263 struct utf8_char *chr_tmp = NULL;
264 int j;
265
266 if (text_in == NULL) {
267 return NULL;
268 }
269
270 len = strlen(text_in);
271
272 if (len == 0) {
273 return NULL;
274 }
275
276 out_chain = fc_calloc(1, sizeof(struct utf8_char));
277 out_chain->chr[0] = text_in[0];
278 for (j = 1; (text_in[j] & (128 + 64)) == 128; j++) {
279 out_chain->chr[j] = text_in[j];
280 }
281 out_chain->bytes = j;
282 chr_tmp = out_chain;
283
284 for (i = 1; i < len; i += j) {
285 chr_tmp->next = fc_calloc(1, sizeof(struct utf8_char));
286 chr_tmp->next->chr[0] = text_in[i];
287 for (j = 1; (text_in[i + j] & (128 + 64)) == 128; j++) {
288 chr_tmp->next->chr[j] = text_in[i + j];
289 }
290 chr_tmp->next->bytes = j;
291 chr_tmp->next->prev = chr_tmp;
292 chr_tmp = chr_tmp->next;
293 }
294
295 return out_chain;
296}
297
298/**********************************************************************/
302 static char *chain2text(const struct utf8_char *in_chain, size_t len,
303 size_t *size)
304{
305 int i;
306 char *out_text = NULL;
307 int oi = 0;
308 int total_size = 0;
309
310 if (!(len && in_chain)) {
311 return out_text;
312 }
313
314 out_text = fc_calloc(8, len + 1);
315 for (i = 0; i < len; i++) {
316 int j;
317
318 for (j = 0; j < in_chain->bytes && i < len; j++) {
319 out_text[oi++] = in_chain->chr[j];
320 }
321
322 total_size += in_chain->bytes;
323 in_chain = in_chain->next;
324 }
325
326 *size = total_size;
327
328 return out_text;
329}
330
331/* =================================================== */
332
333/**********************************************************************/
346 struct widget *create_edit(SDL_Surface *background, struct gui_layer *pdest,
347 utf8_str *pstr, int length, Uint32 flags)
348{
349 SDL_Rect buf = {0, 0, 0, 0};
350 struct widget *pedit = widget_new();
351
352 pedit->theme = current_theme->edit;
353 pedit->theme2 = background; /* FIXME: Make use of it somewhere. */
354 pedit->string_utf8 = pstr;
355 set_wflag(pedit, (WF_FREE_STRING | WF_FREE_GFX | flags));
356 set_wstate(pedit, FC_WS_DISABLED);
357 set_wtype(pedit, WT_EDIT);
358 pedit->mod = SDL_KMOD_NONE;
359
360 baseclass_redraw = pedit->redraw;
361 pedit->redraw = redraw_edit;
362
363 if (pstr != NULL) {
364 pedit->string_utf8->style |= SF_CENTER;
365 utf8_str_size(pstr, &buf);
366 buf.h += adj_size(4);
367 }
368
369 length = MAX(length, buf.w + adj_size(10));
370
371 correct_size_bcgnd_surf(current_theme->edit, &length, &buf.h);
372
373 pedit->size.w = length;
374 pedit->size.h = buf.h;
375
376 if (pdest) {
377 pedit->dst = pdest;
378 } else {
379 pedit->dst = add_gui_layer(pedit->size.w, pedit->size.h);
380 }
381
382 return pedit;
383}
384
385/**********************************************************************/
388 int draw_edit(struct widget *pedit, Sint16 start_x, Sint16 start_y)
389{
390 pedit->size.x = start_x;
391 pedit->size.y = start_y;
392
393 if (get_wflags(pedit) & WF_RESTORE_BACKGROUND) {
394 refresh_widget_background(pedit);
395 }
396
397 return redraw_edit(pedit);
398}
399
400/**********************************************************************/
419 static Uint16 edit_key_down(SDL_Keysym key, void *data)
420{
421 struct text_edit *edt = (struct text_edit *)data;
422 struct utf8_char *input_chain_tmp;
423 bool redraw = FALSE;
424
425 /* find which key is pressed */
426 switch (key.sym) {
427 case SDLK_ESCAPE:
428 /* exit from loop without changes */
429 return ED_ESC;
430 case SDLK_RETURN:
431 case SDLK_KP_ENTER:
432 /* exit from loop */
433 return ED_RETURN;
434 /*
435 case SDLK_KP6:
436 if (key.mod & KMOD_NUM) {
437 goto INPUT;
438 }
439 */
440 case SDLK_RIGHT:
441 {
442 /* move cursor right */
443 if (edt->input_chain->next) {
444 if (edt->input_chain_x >= (edt->pwidget->size.x + edt->bg->w - adj_size(10))) {
445 edt->start_x -= edt->input_chain->tsurf->w -
446 (edt->pwidget->size.x + edt->bg->w - adj_size(5) - edt->input_chain_x);
447 }
448
449 edt->input_chain = edt->input_chain->next;
450 redraw = TRUE;
451 }
452 }
453 break;
454 /*
455 case SDLK_KP4:
456 if (key.mod & KMOD_NUM) {
457 goto INPUT;
458 }
459 */
460 case SDLK_LEFT:
461 {
462 /* move cursor left */
463 if (edt->input_chain->prev) {
464 edt->input_chain = edt->input_chain->prev;
465 if ((edt->input_chain_x <=
466 (edt->pwidget->size.x + adj_size(9))) && (edt->start_x != adj_size(5))) {
467 if (edt->input_chain_x != (edt->pwidget->size.x + adj_size(5))) {
468 edt->start_x += (edt->pwidget->size.x - edt->input_chain_x + adj_size(5));
469 }
470
471 edt->start_x += (edt->input_chain->tsurf->w);
472 }
473 redraw = TRUE;
474 }
475 }
476 break;
477 /*
478 case SDLK_KP7:
479 if (key.mod & KMOD_NUM) {
480 goto INPUT;
481 }
482 */
483 case SDLK_HOME:
484 {
485 /* move cursor to begin of chain (and edit field) */
486 edt->input_chain = edt->begin_text_chain;
487 redraw = TRUE;
488 edt->start_x = adj_size(5);
489 }
490 break;
491 /*
492 case SDLK_KP1:
493 if (key.mod & KMOD_NUM) {
494 goto INPUT;
495 }
496 */
497 case SDLK_END:
498 {
499 /* move cursor to end of chain (and edit field) */
500 edt->input_chain = edt->end_text_chain;
501 redraw = TRUE;
502
503 if (edt->pwidget->size.w - edt->true_length < 0) {
504 edt->start_x = edt->pwidget->size.w - edt->true_length - adj_size(5);
505 }
506 }
507 break;
508 case SDLK_BACKSPACE:
509 {
510 /* del element of chain (and move cursor left) */
511 if (edt->input_chain->prev) {
512 if ((edt->input_chain_x <=
513 (edt->pwidget->size.x + adj_size(9))) && (edt->start_x != adj_size(5))) {
514 if (edt->input_chain_x != (edt->pwidget->size.x + adj_size(5))) {
515 edt->start_x += (edt->pwidget->size.x - edt->input_chain_x + adj_size(5));
516 }
517 edt->start_x += (edt->input_chain->prev->tsurf->w);
518 }
519
520 if (edt->input_chain->prev->prev) {
521 edt->input_chain->prev->prev->next = edt->input_chain;
522 input_chain_tmp = edt->input_chain->prev->prev;
523 edt->true_length -= edt->input_chain->prev->tsurf->w;
524 FREESURFACE(edt->input_chain->prev->tsurf);
525 FC_FREE(edt->input_chain->prev);
526 edt->input_chain->prev = input_chain_tmp;
527 } else {
528 edt->true_length -= edt->input_chain->prev->tsurf->w;
529 FREESURFACE(edt->input_chain->prev->tsurf);
530 FC_FREE(edt->input_chain->prev);
531 edt->begin_text_chain = edt->input_chain;
532 }
533
534 edt->chain_len--;
535 redraw = TRUE;
536 }
537 }
538 break;
539 /*
540 case SDLK_KP_PERIOD:
541 if (key.mod & KMOD_NUM) {
542 goto INPUT;
543 }
544 */
545 case SDLK_DELETE:
546 {
547 /* del element of chain */
548 if (edt->input_chain->next && edt->input_chain->prev) {
549 edt->input_chain->prev->next = edt->input_chain->next;
550 edt->input_chain->next->prev = edt->input_chain->prev;
551 input_chain_tmp = edt->input_chain->next;
552 edt->true_length -= edt->input_chain->tsurf->w;
553 FREESURFACE(edt->input_chain->tsurf);
554 FC_FREE(edt->input_chain);
555 edt->input_chain = input_chain_tmp;
556 edt->chain_len--;
557 redraw = TRUE;
558 }
559
560 if (edt->input_chain->next && !edt->input_chain->prev) {
561 edt->input_chain = edt->input_chain->next;
562 edt->true_length -= edt->input_chain->prev->tsurf->w;
563 FREESURFACE(edt->input_chain->prev->tsurf);
564 FC_FREE(edt->input_chain->prev);
565 edt->begin_text_chain = edt->input_chain;
566 edt->chain_len--;
567 redraw = TRUE;
568 }
569 }
570 break;
571 default:
572 break;
573 } /* key pressed switch */
574
575 if (redraw) {
576 redraw_edit_chain(edt);
577 }
578
579 return ID_ERROR;
580}
581
582/**********************************************************************/
585 static Uint16 edit_textinput(char *text, void *data)
586{
587 struct text_edit *edt = (struct text_edit *)data;
588 struct utf8_char *input_chain_tmp;
589 int i;
590
591 for (i = 0; text[i] != '\0';) {
592 int charlen = 1;
593 unsigned char leading = text[i++];
594 int sum = 128 + 64;
595 int addition = 32;
596
597 /* add new element of chain (and move cursor right) */
598 if (edt->input_chain != edt->begin_text_chain) {
599 input_chain_tmp = edt->input_chain->prev;
600 edt->input_chain->prev = fc_calloc(1, sizeof(struct utf8_char));
601 edt->input_chain->prev->next = edt->input_chain;
602 edt->input_chain->prev->prev = input_chain_tmp;
603 input_chain_tmp->next = edt->input_chain->prev;
604 } else {
605 edt->input_chain->prev = fc_calloc(1, sizeof(struct utf8_char));
606 edt->input_chain->prev->next = edt->input_chain;
607 edt->begin_text_chain = edt->input_chain->prev;
608 }
609
610 edt->input_chain->prev->chr[0] = leading;
611 /* UTF-8 multibyte handling */
612 while (leading >= sum) {
613 edt->input_chain->prev->chr[charlen++] = text[i++];
614 sum += addition;
615 addition /= 2;
616 }
617 edt->input_chain->prev->chr[charlen] = '\0';
618 edt->input_chain->prev->bytes = charlen;
619
620 if (get_wflags(edt->pwidget) & WF_PASSWD_EDIT) {
621 char passwd_chr[2] = {'*', '\0'};
622
623 edt->input_chain->prev->tsurf =
624 TTF_RenderUTF8_Blended(edt->pwidget->string_utf8->font,
625 passwd_chr,
626 edt->pwidget->string_utf8->fgcol);
627 } else {
628 edt->input_chain->prev->tsurf =
629 TTF_RenderUTF8_Blended(edt->pwidget->string_utf8->font,
630 edt->input_chain->prev->chr,
631 edt->pwidget->string_utf8->fgcol);
632 }
633 edt->true_length += edt->input_chain->prev->tsurf->w;
634
635 if (edt->input_chain_x >= edt->pwidget->size.x + edt->bg->w - adj_size(10)) {
636 if (edt->input_chain == edt->end_text_chain) {
637 edt->start_x = edt->bg->w - adj_size(5) - edt->true_length;
638 } else {
639 edt->start_x -= edt->input_chain->prev->tsurf->w -
640 (edt->pwidget->size.x + edt->bg->w - adj_size(5) - edt->input_chain_x);
641 }
642 }
643
644 edt->chain_len++;
645 }
646
647 redraw_edit_chain(edt);
648
649 return ID_ERROR;
650}
651
652/**********************************************************************/
655 static Uint16 edit_mouse_button_down(SDL_MouseButtonEvent *button_event,
656 void *data)
657{
658 struct text_edit *edt = (struct text_edit *)data;
659
660 if (button_event->button == SDL_BUTTON_LEFT) {
661 if (!(button_event->x >= edt->pwidget->size.x
662 && button_event->x < edt->pwidget->size.x + edt->bg->w
663 && button_event->y >= edt->pwidget->size.y
664 && button_event->y < edt->pwidget->size.y + edt->bg->h)) {
665 /* exit from loop */
666 return (Uint16)ED_MOUSE;
667 }
668 }
669
670 return (Uint16)ID_ERROR;
671}
672
673/**********************************************************************/
677 enum edit_return_codes edit_field(struct widget *edit_widget)
678{
679 struct text_edit edt;
680 struct utf8_char ___last;
681 struct utf8_char *input_chain_tmp = NULL;
682 enum edit_return_codes ret;
683 void *backup = edit_widget->data.ptr;
684
685 edt.pwidget = edit_widget;
686 edt.chain_len = 0;
687 edt.true_length = 0;
688 edt.start_x = adj_size(5);
689 edt.input_chain_x = 0;
690
691 edit_widget->data.ptr = (void *)&edt;
692
693#if 0
694 SDL_EnableUNICODE(1);
695 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
696#endif /* 0 */
697
698 edt.bg = create_bcgnd_surf(edit_widget->theme, FC_WS_PRESSED,
699 edit_widget->size.w, edit_widget->size.h);
700
701 /* Creating Chain */
702 edt.begin_text_chain = text2chain(edit_widget->string_utf8->text);
703
704 /* Creating Empty (Last) pice of Chain */
705 edt.input_chain = &___last;
706 edt.end_text_chain = edt.input_chain;
707 edt.end_text_chain->chr[0] = 32; /* spacebar */
708 edt.end_text_chain->chr[1] = 0; /* spacebar */
709 edt.end_text_chain->next = NULL;
710 edt.end_text_chain->prev = NULL;
711
712 /* set font style (if any ) */
713 if (!((edit_widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
714 TTF_SetFontStyle(edit_widget->string_utf8->font,
715 (edit_widget->string_utf8->style & 0x0F));
716 }
717
718 edt.end_text_chain->tsurf =
719 TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
720 edt.end_text_chain->chr,
721 edit_widget->string_utf8->fgcol);
722
723 /* create surface for each font in chain and find chain length */
724 if (edt.begin_text_chain) {
725 input_chain_tmp = edt.begin_text_chain;
726
727 while (TRUE) {
728 edt.chain_len++;
729
730 if (get_wflags(edit_widget) & WF_PASSWD_EDIT) {
731 const char passwd_chr[2] = {'*', '\0'};
732
733 input_chain_tmp->tsurf =
734 TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
735 passwd_chr,
736 edit_widget->string_utf8->fgcol);
737 } else {
738 input_chain_tmp->tsurf =
739 TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
740 input_chain_tmp->chr,
741 edit_widget->string_utf8->fgcol);
742 }
743
744 edt.true_length += input_chain_tmp->tsurf->w;
745
746 if (input_chain_tmp->next == NULL) {
747 break;
748 }
749
750 input_chain_tmp = input_chain_tmp->next;
751 }
752 /* set terminator of list */
753 input_chain_tmp->next = edt.input_chain;
754 edt.input_chain->prev = input_chain_tmp;
755 input_chain_tmp = NULL;
756 } else {
757 edt.begin_text_chain = edt.input_chain;
758 }
759
760 redraw_edit_chain(&edt);
761
762 set_wstate(edit_widget, FC_WS_PRESSED);
763 {
764 /* local loop */
765 Uint16 rety = gui_event_loop((void *)&edt, NULL,
766 edit_key_down, NULL, edit_textinput, NULL, NULL, NULL,
767 edit_mouse_button_down, NULL, NULL);
768
769 if (edt.begin_text_chain == edt.end_text_chain) {
770 edt.begin_text_chain = NULL;
771 }
772
773 if (rety == MAX_ID) {
774 ret = ED_FORCE_EXIT;
775 } else {
776 ret = (enum edit_return_codes) rety;
777
778 /* this is here because we have no knowledge that edit_widget exist
779 or nor in force exit mode from gui loop */
780
781 /* reset font settings */
782 if (!((edit_widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
783 TTF_SetFontStyle(edit_widget->string_utf8->font, TTF_STYLE_NORMAL);
784 }
785
786 if (ret != ED_ESC) {
787 size_t len = 0;
788
789 FC_FREE(edit_widget->string_utf8->text);
790 edit_widget->string_utf8->text =
791 chain2text(edt.begin_text_chain, edt.chain_len, &len);
792 edit_widget->string_utf8->n_alloc = len + 1;
793 }
794
795 edit_widget->data.ptr = backup;
796 set_wstate(edit_widget, FC_WS_NORMAL);
797 }
798 }
799
800 FREESURFACE(edt.end_text_chain->tsurf);
801
802 del_chain(edt.begin_text_chain);
803
804 FREESURFACE(edt.bg);
805
806 /* disable repeat key */
807
808#if 0
809 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
810
811 /* disable Unicode */
812 SDL_EnableUNICODE(0);
813#endif /* 0 */
814
815 return ret;
816}
incite_cost
char * incite_cost
Definition comments.c:74
current_theme
QString current_theme
Definition fc_client.cpp:65
get_theme_color
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
create_line
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1379
alphablit
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
add_gui_layer
struct gui_layer * add_gui_layer(int width, int height)
Definition graphics.c:112
FREESURFACE
#define FREESURFACE(ptr)
Definition graphics.h:322
ID_ERROR
@ ID_ERROR
Definition gui_id.h:26
gui_event_loop
Uint16 gui_event_loop(void *data, void(*loop_action)(void *data), Uint16(*key_down_handler)(SDL_Keysym key, void *data), Uint16(*key_up_handler)(SDL_Keysym key, void *data), Uint16(*textinput_handler)(char *text, void *data), Uint16(*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*finger_motion_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event, void *data), Uint16(*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event, void *data), Uint16(*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event, void *data))
Definition gui_main.c:598
adj_size
#define adj_size(size)
Definition gui_main.h:141
utf8_str_size
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
Definition gui_string.c:106
create_text_surf_from_utf8
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
SF_CENTER
#define SF_CENTER
Definition gui_string.h:40
SF_CENTER_RIGHT
#define SF_CENTER_RIGHT
Definition gui_string.h:41
COLOR_THEME_EDITFIELD_CARET
@ COLOR_THEME_EDITFIELD_CARET
Definition themecolors.h:31
correct_size_bcgnd_surf
void correct_size_bcgnd_surf(SDL_Surface *ptheme, int *width, int *height)
Definition widget.c:63
refresh_widget_background
void refresh_widget_background(struct widget *pwidget)
Definition widget.c:1151
create_bcgnd_surf
SDL_Surface * create_bcgnd_surf(SDL_Surface *ptheme, enum widget_state state, Uint16 width, Uint16 height)
Definition widget.c:78
MAX_ID
#define MAX_ID
Definition widget.h:38
FC_WS_DISABLED
@ FC_WS_DISABLED
Definition widget.h:99
FC_WS_NORMAL
@ FC_WS_NORMAL
Definition widget.h:96
FC_WS_PRESSED
@ FC_WS_PRESSED
Definition widget.h:98
widget_flush
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
get_wflags
enum widget_flag get_wflags(const struct widget *pwidget)
Definition widget_core.c:86
set_wstate
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
get_wstate
enum widget_state get_wstate(const struct widget *pwidget)
Definition widget_core.c:70
WF_FREE_GFX
@ WF_FREE_GFX
Definition widget.h:70
WF_PASSWD_EDIT
@ WF_PASSWD_EDIT
Definition widget.h:90
WF_FREE_STRING
@ WF_FREE_STRING
Definition widget.h:76
WF_RESTORE_BACKGROUND
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
set_wtype
void set_wtype(struct widget *pwidget, enum widget_type type)
Definition widget_core.c:45
set_wflag
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
WT_EDIT
@ WT_EDIT
Definition widget.h:48
widget_new
struct widget * widget_new(void)
Definition widget_core.c:252
text2chain
static struct utf8_char * text2chain(const char *text_in)
Definition widget_edit.c:263
redraw_edit_chain
static int redraw_edit_chain(struct text_edit *edt)
Definition widget_edit.c:66
chain2text
static char * chain2text(const struct utf8_char *in_chain, size_t len, size_t *size)
Definition widget_edit.c:306
chainlen
static size_t chainlen(const struct utf8_char *chain)
Definition widget_edit.c:217
create_edit
struct widget * create_edit(SDL_Surface *background, struct gui_layer *pdest, utf8_str *pstr, int length, Uint32 flags)
Definition widget_edit.c:350
edit_field
enum edit_return_codes edit_field(struct widget *edit_widget)
Definition widget_edit.c:681
edit_mouse_button_down
static Uint16 edit_mouse_button_down(SDL_MouseButtonEvent *button_event, void *data)
Definition widget_edit.c:659
baseclass_redraw
static int(* baseclass_redraw)(struct widget *pwidget)
Definition widget_edit.c:61
edit_textinput
static Uint16 edit_textinput(char *text, void *data)
Definition widget_edit.c:589
del_chain
static void del_chain(struct utf8_char *chain)
Definition widget_edit.c:237
redraw_edit
static int redraw_edit(struct widget *edit_widget)
Definition widget_edit.c:142
edit_key_down
static Uint16 edit_key_down(SDL_Keysym key, void *data)
Definition widget_edit.c:423
draw_edit
int draw_edit(struct widget *pedit, Sint16 start_x, Sint16 start_y)
Definition widget_edit.c:392
edit_return_codes
edit_return_codes
Definition widget_edit.h:17
ED_FORCE_EXIT
@ ED_FORCE_EXIT
Definition widget_edit.h:21
ED_ESC
@ ED_ESC
Definition widget_edit.h:19
ED_RETURN
@ ED_RETURN
Definition widget_edit.h:18
ED_MOUSE
@ ED_MOUSE
Definition widget_edit.h:20
gui_id.h
gui_tilespec.h
themespec.h
utf8string.h
widget.h
widget_p.h
colors.h
graphics.h
mapview.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
len
int len
Definition packhand.c:127
MAX
#define MAX(x, y)
Definition shared.h:54
size
size_t size
Definition specvec.h:72
gui_layer
Definition graphics.h:227
text_edit
Definition widget_edit.c:44
text_edit::start_x
int start_x
Definition widget_edit.c:51
text_edit::pwidget
struct widget * pwidget
Definition widget_edit.c:49
text_edit::true_length
int true_length
Definition widget_edit.c:52
text_edit::input_chain_x
int input_chain_x
Definition widget_edit.c:53
text_edit::begin_text_chain
struct utf8_char * begin_text_chain
Definition widget_edit.c:45
text_edit::end_text_chain
struct utf8_char * end_text_chain
Definition widget_edit.c:46
text_edit::bg
SDL_Surface * bg
Definition widget_edit.c:48
text_edit::input_chain
struct utf8_char * input_chain
Definition widget_edit.c:47
text_edit::chain_len
int chain_len
Definition widget_edit.c:50
utf8_char
Definition widget_edit.c:36
utf8_char::next
struct utf8_char * next
Definition widget_edit.c:37
utf8_char::prev
struct utf8_char * prev
Definition widget_edit.c:38
utf8_char::bytes
int bytes
Definition widget_edit.c:39
utf8_char::tsurf
SDL_Surface * tsurf
Definition widget_edit.c:41
utf8_char::chr
char chr[7]
Definition widget_edit.c:40
utf8_str
Definition gui_string.h:52
utf8_str::style
Uint8 style
Definition gui_string.h:53
widget
Definition widget.h:112
widget::key
SDL_Keycode key
Definition widget.h:153
widget::theme
SDL_Surface * theme
Definition widget.h:118
widget::data
union widget::@192 data
widget::theme2
SDL_Surface * theme2
Definition widget.h:119
widget::redraw
int(* redraw)(struct widget *pwidget)
Definition widget.h:163
widget::dst
struct gui_layer * dst
Definition widget.h:116
widget::mod
Uint16 mod
Definition widget.h:154
widget::string_utf8
utf8_str * string_utf8
Definition widget.h:121
widget::size
SDL_Rect size
Definition widget.h:145
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47