Freeciv-3.2
Loading...
Searching...
No Matches
widget_core.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 "mapview.h"
25#include "themespec.h"
26#include "widget.h"
27#include "widget_p.h"
28
29/**********************************************************************/
32void set_wstate(struct widget *pwidget, enum widget_state state)
33{
35 pwidget->state_types_flags |= state;
36}
37
38/**********************************************************************/
41void set_wtype(struct widget *pwidget, enum widget_type type)
42{
43 pwidget->state_types_flags &= ~TYPE_MASK;
44 pwidget->state_types_flags |= type;
45}
46
47/**********************************************************************/
50void set_wflag(struct widget *pwidget, enum widget_flag flag)
51{
52 (pwidget)->state_types_flags |= ((flag) & FLAG_MASK);
53}
54
55/**********************************************************************/
58void clear_wflag(struct widget *pwidget, enum widget_flag flag)
59{
60 (pwidget)->state_types_flags &= ~((flag) & FLAG_MASK);
61}
62
63/**********************************************************************/
66enum widget_state get_wstate(const struct widget *pwidget)
67{
68 return ((enum widget_state)(pwidget->state_types_flags & STATE_MASK));
69}
70
71/**********************************************************************/
74enum widget_type get_wtype(const struct widget *pwidget)
75{
76 return ((enum widget_type)(pwidget->state_types_flags & TYPE_MASK));
77}
78
79/**********************************************************************/
82enum widget_flag get_wflags(const struct widget *pwidget)
83{
84 return ((enum widget_flag)(pwidget->state_types_flags & FLAG_MASK));
85}
86
87/**********************************************************************/
90void widget_free(struct widget **pwidget)
91{
92 struct widget *gui = *pwidget;
93
95 FREEUTF8STR(gui->string_utf8);
96 }
98 FREEUTF8STR(gui->info_label);
99 }
100 if (get_wflags(gui) & WF_FREE_GFX) {
101 FREESURFACE(gui->gfx);
102 }
104 if (get_wtype(gui) == WT_CHECKBOX) {
105 FREESURFACE(gui->private_data.cbox->true_theme);
106 FREESURFACE(gui->private_data.cbox->false_theme);
107 } else {
108 FREESURFACE(gui->theme);
109 }
110 }
112 FREESURFACE(gui->theme2);
113 }
114 if (get_wflags(gui) & WF_FREE_DATA) {
115 FC_FREE(gui->data.ptr);
116 }
118 FC_FREE(gui->private_data.ptr);
119 }
120 if (NULL != gui->destroy) {
121 gui->destroy(gui);
122 }
123
124 FC_FREE(*pwidget);
125}
126
127/**********************************************************************/
130static void widget_core_set_area(struct widget *pwidget, SDL_Rect area)
131{
132 pwidget->area = area;
133}
134
135/**********************************************************************/
138static void widget_core_set_position(struct widget *pwidget, int x, int y)
139{
140 pwidget->size.x = x;
141 pwidget->size.y = y;
142}
143
144/**********************************************************************/
147static void widget_core_resize(struct widget *pwidget, int w, int h)
148{
149 pwidget->size.w = w;
150 pwidget->size.h = h;
151}
152
153/**********************************************************************/
156static int widget_core_redraw(struct widget *pwidget)
157{
158 if (!pwidget || (get_wflags(pwidget) & WF_HIDDEN)) {
159 return -1;
160 }
161
162 if (pwidget->gfx) {
163 widget_undraw(pwidget);
164 }
165
166 if (!pwidget->gfx && (get_wflags(pwidget) & WF_RESTORE_BACKGROUND)) {
168 }
169
170 return 0;
171}
172
173/**********************************************************************/
176static void widget_core_draw_frame(struct widget *pwidget)
177{
179}
180
181/**********************************************************************/
184static void widget_core_mark_dirty(struct widget *pwidget)
185{
186 SDL_Rect rect = {
187 pwidget->dst->dest_rect.x + pwidget->size.x,
188 pwidget->dst->dest_rect.y + pwidget->size.y,
189 pwidget->size.w,
190 pwidget->size.h
191 };
192
193 dirty_sdl_rect(&rect);
194}
195
196/**********************************************************************/
199static void widget_core_flush(struct widget *pwidget)
200{
201 SDL_Rect rect = {
202 pwidget->dst->dest_rect.x + pwidget->size.x,
203 pwidget->dst->dest_rect.y + pwidget->size.y,
204 pwidget->size.w,
205 pwidget->size.h
206 };
207
208 flush_rect(&rect, FALSE);
209}
210
211/**********************************************************************/
214static void widget_core_undraw(struct widget *pwidget)
215{
216 if (get_wflags(pwidget) & WF_RESTORE_BACKGROUND) {
217 if (pwidget->gfx) {
218 clear_surface(pwidget->dst->surface, &pwidget->size);
219 blit_entire_src(pwidget->gfx, pwidget->dst->surface,
220 pwidget->size.x, pwidget->size.y);
221 }
222 } else {
223 clear_surface(pwidget->dst->surface, &pwidget->size);
224 }
225}
226
227/**********************************************************************/
230static void widget_core_select(struct widget *pwidget)
231{
232 widget_redraw(pwidget);
233 widget_flush(pwidget);
234}
235
236/**********************************************************************/
239static void widget_core_unselect(struct widget *pwidget)
240{
241 widget_redraw(pwidget);
242 widget_flush(pwidget);
243}
244
245/**********************************************************************/
248struct widget *widget_new(void)
249{
250 struct widget *pwidget = fc_calloc(1, sizeof(struct widget));
251
254 pwidget->resize = widget_core_resize;
255 pwidget->redraw = widget_core_redraw;
258 pwidget->flush = widget_core_flush;
259 pwidget->undraw = widget_core_undraw;
260 pwidget->select = widget_core_select;
262
263 return pwidget;
264}
char * incite_cost
Definition comments.c:74
GType type
Definition repodlgs.c:1313
int blit_entire_src(SDL_Surface *psrc, SDL_Surface *pdest, Sint16 dest_x, Sint16 dest_y)
Definition graphics.c:417
int clear_surface(SDL_Surface *surf, SDL_Rect *dstrect)
Definition graphics.c:400
#define FREESURFACE(ptr)
Definition graphics.h:322
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
void flush_rect(SDL_Rect *rect, bool force_flush)
Definition mapview.c:103
void dirty_sdl_rect(SDL_Rect *Rect)
Definition mapview.c:181
void refresh_widget_background(struct widget *pwidget)
Definition widget.c:1151
widget_state
Definition widget.h:95
#define draw_frame_inside_widget(pwidget)
Definition widget.h:315
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
static void widget_undraw(struct widget *pwidget)
Definition widget.h:296
widget_flag
Definition widget.h:67
@ WF_FREE_GFX
Definition widget.h:70
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
@ WF_FREE_DATA
Definition widget.h:78
@ WF_FREE_PRIVATE_DATA
Definition widget.h:80
@ WF_FREE_THEME2
Definition widget.h:74
@ WF_FREE_STRING
Definition widget.h:76
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
@ WF_HIDDEN
Definition widget.h:68
@ WF_FREE_THEME
Definition widget.h:72
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
widget_type
Definition widget.h:41
@ WT_CHECKBOX
Definition widget.h:58
static void widget_core_mark_dirty(struct widget *pwidget)
static int widget_core_redraw(struct widget *pwidget)
static void widget_core_unselect(struct widget *pwidget)
static void widget_core_select(struct widget *pwidget)
void clear_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:62
void widget_free(struct widget **pwidget)
Definition widget_core.c:94
static void widget_core_set_position(struct widget *pwidget, int x, int y)
static void widget_core_resize(struct widget *pwidget, int w, int h)
static void widget_core_flush(struct widget *pwidget)
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
void set_wtype(struct widget *pwidget, enum widget_type type)
Definition widget_core.c:45
static void widget_core_set_area(struct widget *pwidget, SDL_Rect area)
enum widget_type get_wtype(const struct widget *pwidget)
Definition widget_core.c:78
struct widget * widget_new(void)
static void widget_core_draw_frame(struct widget *pwidget)
static void widget_core_undraw(struct widget *pwidget)
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
#define STATE_MASK
Definition widget_p.h:17
#define FLAG_MASK
Definition widget_p.h:19
#define TYPE_MASK
Definition widget_p.h:18
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
static mpgui * gui
Definition mpgui_qt.cpp:52
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
SDL_Surface * surface
Definition graphics.h:229
SDL_Rect dest_rect
Definition graphics.h:228
void(* unselect)(struct widget *pwidget)
Definition widget.h:168
void(* set_area)(struct widget *pwidget, SDL_Rect area)
Definition widget.h:159
void(* draw_frame)(struct widget *pwidget)
Definition widget.h:162
void(* set_position)(struct widget *pwidget, int x, int y)
Definition widget.h:160
void(* resize)(struct widget *pwidget, int w, int h)
Definition widget.h:161
void(* flush)(struct widget *pwidget)
Definition widget.h:165
int(* redraw)(struct widget *pwidget)
Definition widget.h:163
struct gui_layer * dst
Definition widget.h:116
void(* mark_dirty)(struct widget *pwidget)
Definition widget.h:164
Uint32 state_types_flags
Definition widget.h:143
SDL_Rect area
Definition widget.h:149
void(* undraw)(struct widget *pwidget)
Definition widget.h:166
SDL_Surface * gfx
Definition widget.h:120
void(* select)(struct widget *pwidget)
Definition widget.h:167
SDL_Rect size
Definition widget.h:145
#define FALSE
Definition support.h:47