Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl3/widget_core.c Source File

Freeciv-3.3

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/**********************************************************************/
32 void set_wstate(struct widget *pwidget, enum widget_state state)
33{
34 pwidget->state_types_flags &= ~STATE_MASK;
35 pwidget->state_types_flags |= state;
36}
37
38/**********************************************************************/
41 void 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/**********************************************************************/
50 void set_wflag(struct widget *pwidget, enum widget_flag flag)
51{
52 (pwidget)->state_types_flags |= ((flag) & FLAG_MASK);
53}
54
55/**********************************************************************/
58 void clear_wflag(struct widget *pwidget, enum widget_flag flag)
59{
60 (pwidget)->state_types_flags &= ~((flag) & FLAG_MASK);
61}
62
63/**********************************************************************/
66 enum widget_state get_wstate(const struct widget *pwidget)
67{
68 return ((enum widget_state)(pwidget->state_types_flags & STATE_MASK));
69}
70
71/**********************************************************************/
74 enum widget_type get_wtype(const struct widget *pwidget)
75{
76 return ((enum widget_type)(pwidget->state_types_flags & TYPE_MASK));
77}
78
79/**********************************************************************/
82 enum widget_flag get_wflags(const struct widget *pwidget)
83{
84 return ((enum widget_flag)(pwidget->state_types_flags & FLAG_MASK));
85}
86
87/**********************************************************************/
90 void widget_free(struct widget **pwidget)
91{
92 struct widget *gui = *pwidget;
93
94 if (get_wflags(gui) & WF_FREE_STRING) {
95 FREEUTF8STR(gui->string_utf8);
96 }
97 if (get_wflags(gui) & WF_WIDGET_HAS_INFO_LABEL) {
98 FREEUTF8STR(gui->info_label);
99 }
100 if (get_wflags(gui) & WF_FREE_GFX) {
101 FREESURFACE(gui->gfx);
102 }
103 if (get_wflags(gui) & WF_FREE_THEME) {
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 }
111 if (get_wflags(gui) & WF_FREE_THEME2) {
112 FREESURFACE(gui->theme2);
113 }
114 if (get_wflags(gui) & WF_FREE_DATA) {
115 FC_FREE(gui->data.ptr);
116 }
117 if (get_wflags(gui) & WF_FREE_PRIVATE_DATA) {
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/**********************************************************************/
130 static void widget_core_set_area(struct widget *pwidget, SDL_Rect area)
131{
132 pwidget->area = area;
133}
134
135/**********************************************************************/
138 static 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/**********************************************************************/
147 static 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/**********************************************************************/
156 static 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)) {
167 refresh_widget_background(pwidget);
168 }
169
170 return 0;
171}
172
173/**********************************************************************/
176 static void widget_core_draw_frame(struct widget *pwidget)
177{
178 draw_frame_inside_widget(pwidget);
179}
180
181/**********************************************************************/
184 static 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/**********************************************************************/
199 static 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/**********************************************************************/
214 static 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/**********************************************************************/
230 static void widget_core_select(struct widget *pwidget)
231{
232 widget_redraw(pwidget);
233 widget_flush(pwidget);
234}
235
236/**********************************************************************/
239 static void widget_core_unselect(struct widget *pwidget)
240{
241 widget_redraw(pwidget);
242 widget_flush(pwidget);
243}
244
245/**********************************************************************/
248 struct widget *widget_new(void)
249{
250 struct widget *pwidget = fc_calloc(1, sizeof(struct widget));
251
252 pwidget->set_area = widget_core_set_area;
253 pwidget->set_position = widget_core_set_position;
254 pwidget->resize = widget_core_resize;
255 pwidget->redraw = widget_core_redraw;
256 pwidget->draw_frame = widget_core_draw_frame;
257 pwidget->mark_dirty = widget_core_mark_dirty;
258 pwidget->flush = widget_core_flush;
259 pwidget->undraw = widget_core_undraw;
260 pwidget->select = widget_core_select;
261 pwidget->unselect = widget_core_unselect;
262
263 return pwidget;
264}
incite_cost
char * incite_cost
Definition comments.c:74
type
GType type
Definition repodlgs.c:1313
blit_entire_src
int blit_entire_src(SDL_Surface *psrc, SDL_Surface *pdest, Sint16 dest_x, Sint16 dest_y)
Definition graphics.c:417
clear_surface
int clear_surface(SDL_Surface *surf, SDL_Rect *dstrect)
Definition graphics.c:400
FREESURFACE
#define FREESURFACE(ptr)
Definition graphics.h:322
FREEUTF8STR
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
flush_rect
void flush_rect(SDL_Rect *rect, bool force_flush)
Definition mapview.c:103
dirty_sdl_rect
void dirty_sdl_rect(SDL_Rect *Rect)
Definition mapview.c:181
refresh_widget_background
void refresh_widget_background(struct widget *pwidget)
Definition widget.c:1151
widget_state
widget_state
Definition widget.h:95
draw_frame_inside_widget
#define draw_frame_inside_widget(pwidget)
Definition widget.h:315
widget_flush
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
widget_undraw
static void widget_undraw(struct widget *pwidget)
Definition widget.h:296
widget_flag
widget_flag
Definition widget.h:67
WF_FREE_GFX
@ WF_FREE_GFX
Definition widget.h:70
WF_WIDGET_HAS_INFO_LABEL
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
WF_FREE_DATA
@ WF_FREE_DATA
Definition widget.h:78
WF_FREE_PRIVATE_DATA
@ WF_FREE_PRIVATE_DATA
Definition widget.h:80
WF_FREE_THEME2
@ WF_FREE_THEME2
Definition widget.h:74
WF_FREE_STRING
@ WF_FREE_STRING
Definition widget.h:76
WF_RESTORE_BACKGROUND
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
WF_HIDDEN
@ WF_HIDDEN
Definition widget.h:68
WF_FREE_THEME
@ WF_FREE_THEME
Definition widget.h:72
widget_redraw
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
widget_type
widget_type
Definition widget.h:41
WT_CHECKBOX
@ WT_CHECKBOX
Definition widget.h:58
widget_core_mark_dirty
static void widget_core_mark_dirty(struct widget *pwidget)
Definition widget_core.c:188
widget_core_redraw
static int widget_core_redraw(struct widget *pwidget)
Definition widget_core.c:160
widget_core_unselect
static void widget_core_unselect(struct widget *pwidget)
Definition widget_core.c:243
widget_core_select
static void widget_core_select(struct widget *pwidget)
Definition widget_core.c:234
clear_wflag
void clear_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:62
widget_free
void widget_free(struct widget **pwidget)
Definition widget_core.c:94
widget_core_set_position
static void widget_core_set_position(struct widget *pwidget, int x, int y)
Definition widget_core.c:142
widget_core_resize
static void widget_core_resize(struct widget *pwidget, int w, int h)
Definition widget_core.c:151
widget_core_flush
static void widget_core_flush(struct widget *pwidget)
Definition widget_core.c:203
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
set_wtype
void set_wtype(struct widget *pwidget, enum widget_type type)
Definition widget_core.c:45
widget_core_set_area
static void widget_core_set_area(struct widget *pwidget, SDL_Rect area)
Definition widget_core.c:134
get_wtype
enum widget_type get_wtype(const struct widget *pwidget)
Definition widget_core.c:78
widget_new
struct widget * widget_new(void)
Definition widget_core.c:252
widget_core_draw_frame
static void widget_core_draw_frame(struct widget *pwidget)
Definition widget_core.c:180
widget_core_undraw
static void widget_core_undraw(struct widget *pwidget)
Definition widget_core.c:218
set_wflag
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
STATE_MASK
#define STATE_MASK
Definition widget_p.h:17
FLAG_MASK
#define FLAG_MASK
Definition widget_p.h:19
TYPE_MASK
#define TYPE_MASK
Definition widget_p.h:18
themespec.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
gui
static mpgui * gui
Definition mpgui_qt.cpp:52
y
struct sprite int int y
Definition sprite_g.h:31
x
struct sprite int x
Definition sprite_g.h:31
gui_layer::surface
SDL_Surface * surface
Definition graphics.h:229
gui_layer::dest_rect
SDL_Rect dest_rect
Definition graphics.h:228
widget
Definition widget.h:112
widget::unselect
void(* unselect)(struct widget *pwidget)
Definition widget.h:168
widget::set_area
void(* set_area)(struct widget *pwidget, SDL_Rect area)
Definition widget.h:159
widget::draw_frame
void(* draw_frame)(struct widget *pwidget)
Definition widget.h:162
widget::set_position
void(* set_position)(struct widget *pwidget, int x, int y)
Definition widget.h:160
widget::resize
void(* resize)(struct widget *pwidget, int w, int h)
Definition widget.h:161
widget::flush
void(* flush)(struct widget *pwidget)
Definition widget.h:165
widget::redraw
int(* redraw)(struct widget *pwidget)
Definition widget.h:163
widget::dst
struct gui_layer * dst
Definition widget.h:116
widget::mark_dirty
void(* mark_dirty)(struct widget *pwidget)
Definition widget.h:164
widget::state_types_flags
Uint32 state_types_flags
Definition widget.h:143
widget::area
SDL_Rect area
Definition widget.h:149
widget::undraw
void(* undraw)(struct widget *pwidget)
Definition widget.h:166
widget::gfx
SDL_Surface * gfx
Definition widget.h:120
widget::select
void(* select)(struct widget *pwidget)
Definition widget.h:167
widget::size
SDL_Rect size
Definition widget.h:145
FALSE
#define FALSE
Definition support.h:47