Freeciv-3.3
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];
38};
39
40struct text_edit {
43 struct utf8_char *input_chain;
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
57static int (*baseclass_redraw)(struct widget *pwidget);
58
59/**********************************************************************/
62static int redraw_edit_chain(struct text_edit *edt)
63{
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) {
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),
113 /* save active element position */
114 edt->input_chain_x = dest_copy.x;
115 }
116
118 } /* while - draw loop */
119
120 widget_flush(edt->pwidget);
121
122 return 0;
123}
124
125/**********************************************************************/
138static int redraw_edit(struct widget *edit_widget)
139{
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
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
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/**********************************************************************/
213static 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/**********************************************************************/
233static 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/**********************************************************************/
259static 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;
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/**********************************************************************/
302static 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/**********************************************************************/
346struct 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));
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;
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/**********************************************************************/
388int 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) {
395 }
396
397 return redraw_edit(pedit);
398}
399
400/**********************************************************************/
420{
421 struct text_edit *edt = (struct text_edit *)data;
423 bool redraw = FALSE;
424
425 /* Find which key is pressed */
426 switch (key->key) {
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 /* Delete 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) {
577 }
578
579 return ID_ERROR;
580}
581
582/**********************************************************************/
585static Uint16 edit_textinput(const char *text, void *data)
586{
587 struct text_edit *edt = (struct text_edit *)data;
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_RenderText_Blended(edt->pwidget->string_utf8->font,
625 passwd_chr, 0,
626 edt->pwidget->string_utf8->fgcol);
627 } else {
628 edt->input_chain->prev->tsurf =
629 TTF_RenderText_Blended(edt->pwidget->string_utf8->font,
630 edt->input_chain->prev->chr, 0,
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
648
649 return ID_ERROR;
650}
651
652/**********************************************************************/
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/**********************************************************************/
678{
679 struct text_edit edt;
680 struct utf8_char ___last;
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
696#endif /* 0 */
697
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_RenderText_Blended(edit_widget->string_utf8->font,
720 edt.end_text_chain->chr, 0,
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
731 const char passwd_chr[2] = {'*', '\0'};
732
733 input_chain_tmp->tsurf =
734 TTF_RenderText_Blended(edit_widget->string_utf8->font,
735 passwd_chr, 0,
736 edit_widget->string_utf8->fgcol);
737 } else {
738 input_chain_tmp->tsurf =
739 TTF_RenderText_Blended(edit_widget->string_utf8->font,
740 input_chain_tmp->chr, 0,
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
751 }
752 /* set terminator of list */
753 input_chain_tmp->next = edt.input_chain;
754 edt.input_chain->prev = input_chain_tmp;
756 } else {
757 edt.begin_text_chain = edt.input_chain;
758 }
759
761
763 {
764 /* Local loop */
765 Uint16 rety = gui_event_loop((void *)&edt, 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) {
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;
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
810
811 /* Disable Unicode */
813#endif /* 0 */
814
815 return ret;
816}
char * incite_cost
Definition comments.c:76
QString current_theme
Definition fc_client.cpp:64
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1381
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
struct gui_layer * add_gui_layer(int width, int height)
Definition graphics.c:112
#define FREESURFACE(ptr)
Definition graphics.h:322
@ ID_ERROR
Definition gui_id.h:26
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)(const 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:603
#define adj_size(size)
Definition gui_main.h:141
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
Definition gui_string.c:106
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
#define SF_CENTER
Definition gui_string.h:40
#define SF_CENTER_RIGHT
Definition gui_string.h:41
@ COLOR_THEME_EDITFIELD_CARET
Definition themecolors.h:32
void correct_size_bcgnd_surf(SDL_Surface *ptheme, int *width, int *height)
Definition widget.c:63
void refresh_widget_background(struct widget *pwidget)
Definition widget.c:1151
SDL_Surface * create_bcgnd_surf(SDL_Surface *ptheme, enum widget_state state, Uint16 width, Uint16 height)
Definition widget.c:78
#define MAX_ID
Definition widget.h:38
@ FC_WS_DISABLED
Definition widget.h:99
@ FC_WS_NORMAL
Definition widget.h:96
@ FC_WS_PRESSED
Definition widget.h:98
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
enum widget_flag get_wflags(const struct widget *pwidget)
Definition widget_core.c:86
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
enum widget_state get_wstate(const struct widget *pwidget)
Definition widget_core.c:70
@ WF_FREE_GFX
Definition widget.h:70
@ WF_PASSWD_EDIT
Definition widget.h:90
@ WF_FREE_STRING
Definition widget.h:76
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
void set_wtype(struct widget *pwidget, enum widget_type type)
Definition widget_core.c:45
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
@ WT_EDIT
Definition widget.h:48
struct widget * widget_new(void)
static struct utf8_char * text2chain(const char *text_in)
static int redraw_edit_chain(struct text_edit *edt)
Definition widget_edit.c:66
static char * chain2text(const struct utf8_char *in_chain, size_t len, size_t *size)
static size_t chainlen(const struct utf8_char *chain)
struct widget * create_edit(SDL_Surface *background, struct gui_layer *pdest, utf8_str *pstr, int length, Uint32 flags)
enum edit_return_codes edit_field(struct widget *edit_widget)
static Uint16 edit_mouse_button_down(SDL_MouseButtonEvent *button_event, void *data)
static int(* baseclass_redraw)(struct widget *pwidget)
Definition widget_edit.c:61
static void del_chain(struct utf8_char *chain)
static int redraw_edit(struct widget *edit_widget)
static Uint16 edit_textinput(const char *text, void *data)
static Uint16 edit_key_down(SDL_Keysym key, void *data)
int draw_edit(struct widget *pedit, Sint16 start_x, Sint16 start_y)
edit_return_codes
Definition widget_edit.h:17
@ ED_FORCE_EXIT
Definition widget_edit.h:21
@ ED_ESC
Definition widget_edit.h:19
@ ED_RETURN
Definition widget_edit.h:18
@ ED_MOUSE
Definition widget_edit.h:20
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
int len
Definition packhand.c:127
#define MAX(x, y)
Definition shared.h:54
size_t size
Definition specvec.h:72
struct widget * pwidget
Definition widget_edit.c:49
int true_length
Definition widget_edit.c:52
int input_chain_x
Definition widget_edit.c:53
struct utf8_char * begin_text_chain
Definition widget_edit.c:45
struct utf8_char * end_text_chain
Definition widget_edit.c:46
SDL_Surface * bg
Definition widget_edit.c:48
struct utf8_char * input_chain
Definition widget_edit.c:47
int chain_len
Definition widget_edit.c:50
struct utf8_char * next
Definition widget_edit.c:37
struct utf8_char * prev
Definition widget_edit.c:38
SDL_Surface * tsurf
Definition widget_edit.c:41
char chr[7]
Definition widget_edit.c:40
Uint8 style
Definition gui_string.h:53
SDL_Keycode key
Definition widget.h:153
SDL_Surface * theme
Definition widget.h:118
union widget::@223 data
SDL_Surface * theme2
Definition widget.h:119
int(* redraw)(struct widget *pwidget)
Definition widget.h:163
struct gui_layer * dst
Definition widget.h:116
Uint16 mod
Definition widget.h:154
utf8_str * string_utf8
Definition widget.h:121
SDL_Rect size
Definition widget.h:145
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47