Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl2/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/* SDL2 */
19#ifdef SDL2_PLAIN_INCLUDE
20#include <SDL.h>
21#else /* SDL2_PLAIN_INCLUDE */
22#include <SDL2/SDL.h>
23#endif /* SDL2_PLAIN_INCLUDE */
24
25/* gui-sdl2 */
26#include "colors.h"
27#include "graphics.h"
28#include "mapview.h"
29#include "themespec.h"
30#include "widget.h"
31#include "widget_p.h"
32
33/**********************************************************************/
36 void set_wstate(struct widget *pwidget, enum widget_state state)
37{
38 pwidget->state_types_flags &= ~STATE_MASK;
39 pwidget->state_types_flags |= state;
40}
41
42/**********************************************************************/
45 void set_wtype(struct widget *pwidget, enum widget_type type)
46{
47 pwidget->state_types_flags &= ~TYPE_MASK;
48 pwidget->state_types_flags |= type;
49}
50
51/**********************************************************************/
54 void set_wflag(struct widget *pwidget, enum widget_flag flag)
55{
56 (pwidget)->state_types_flags |= ((flag) & FLAG_MASK);
57}
58
59/**********************************************************************/
62 void clear_wflag(struct widget *pwidget, enum widget_flag flag)
63{
64 (pwidget)->state_types_flags &= ~((flag) & FLAG_MASK);
65}
66
67/**********************************************************************/
70 enum widget_state get_wstate(const struct widget *pwidget)
71{
72 return ((enum widget_state)(pwidget->state_types_flags & STATE_MASK));
73}
74
75/**********************************************************************/
78 enum widget_type get_wtype(const struct widget *pwidget)
79{
80 return ((enum widget_type)(pwidget->state_types_flags & TYPE_MASK));
81}
82
83/**********************************************************************/
86 enum widget_flag get_wflags(const struct widget *pwidget)
87{
88 return ((enum widget_flag)(pwidget->state_types_flags & FLAG_MASK));
89}
90
91/**********************************************************************/
94 void widget_free(struct widget **pwidget)
95{
96 struct widget *gui = *pwidget;
97
98 if (get_wflags(gui) & WF_FREE_STRING) {
99 FREEUTF8STR(gui->string_utf8);
100 }
101 if (get_wflags(gui) & WF_WIDGET_HAS_INFO_LABEL) {
102 FREEUTF8STR(gui->info_label);
103 }
104 if (get_wflags(gui) & WF_FREE_GFX) {
105 FREESURFACE(gui->gfx);
106 }
107 if (get_wflags(gui) & WF_FREE_THEME) {
108 if (get_wtype(gui) == WT_CHECKBOX) {
109 FREESURFACE(gui->private_data.cbox->true_theme);
110 FREESURFACE(gui->private_data.cbox->false_theme);
111 } else {
112 FREESURFACE(gui->theme);
113 }
114 }
115 if (get_wflags(gui) & WF_FREE_THEME2) {
116 FREESURFACE(gui->theme2);
117 }
118 if (get_wflags(gui) & WF_FREE_DATA) {
119 FC_FREE(gui->data.ptr);
120 }
121 if (get_wflags(gui) & WF_FREE_PRIVATE_DATA) {
122 FC_FREE(gui->private_data.ptr);
123 }
124 if (NULL != gui->destroy) {
125 gui->destroy(gui);
126 }
127
128 FC_FREE(*pwidget);
129}
130
131/**********************************************************************/
134 static void widget_core_set_area(struct widget *pwidget, SDL_Rect area)
135{
136 pwidget->area = area;
137}
138
139/**********************************************************************/
142 static void widget_core_set_position(struct widget *pwidget, int x, int y)
143{
144 pwidget->size.x = x;
145 pwidget->size.y = y;
146}
147
148/**********************************************************************/
151 static void widget_core_resize(struct widget *pwidget, int w, int h)
152{
153 pwidget->size.w = w;
154 pwidget->size.h = h;
155}
156
157/**********************************************************************/
160 static int widget_core_redraw(struct widget *pwidget)
161{
162 if (!pwidget || (get_wflags(pwidget) & WF_HIDDEN)) {
163 return -1;
164 }
165
166 if (pwidget->gfx) {
167 widget_undraw(pwidget);
168 }
169
170 if (!pwidget->gfx && (get_wflags(pwidget) & WF_RESTORE_BACKGROUND)) {
171 refresh_widget_background(pwidget);
172 }
173
174 return 0;
175}
176
177/**********************************************************************/
180 static void widget_core_draw_frame(struct widget *pwidget)
181{
182 draw_frame_inside_widget(pwidget);
183}
184
185/**********************************************************************/
188 static void widget_core_mark_dirty(struct widget *pwidget)
189{
190 SDL_Rect rect = {
191 pwidget->dst->dest_rect.x + pwidget->size.x,
192 pwidget->dst->dest_rect.y + pwidget->size.y,
193 pwidget->size.w,
194 pwidget->size.h
195 };
196
197 dirty_sdl_rect(&rect);
198}
199
200/**********************************************************************/
203 static void widget_core_flush(struct widget *pwidget)
204{
205 SDL_Rect rect = {
206 pwidget->dst->dest_rect.x + pwidget->size.x,
207 pwidget->dst->dest_rect.y + pwidget->size.y,
208 pwidget->size.w,
209 pwidget->size.h
210 };
211
212 flush_rect(&rect, FALSE);
213}
214
215/**********************************************************************/
218 static void widget_core_undraw(struct widget *pwidget)
219{
220 if (get_wflags(pwidget) & WF_RESTORE_BACKGROUND) {
221 if (pwidget->gfx) {
222 clear_surface(pwidget->dst->surface, &pwidget->size);
223 blit_entire_src(pwidget->gfx, pwidget->dst->surface,
224 pwidget->size.x, pwidget->size.y);
225 }
226 } else {
227 clear_surface(pwidget->dst->surface, &pwidget->size);
228 }
229}
230
231/**********************************************************************/
234 static void widget_core_select(struct widget *pwidget)
235{
236 widget_redraw(pwidget);
237 widget_flush(pwidget);
238}
239
240/**********************************************************************/
243 static void widget_core_unselect(struct widget *pwidget)
244{
245 widget_redraw(pwidget);
246 widget_flush(pwidget);
247}
248
249/**********************************************************************/
252 struct widget *widget_new(void)
253{
254 struct widget *pwidget = fc_calloc(1, sizeof(struct widget));
255
256 pwidget->set_area = widget_core_set_area;
257 pwidget->set_position = widget_core_set_position;
258 pwidget->resize = widget_core_resize;
259 pwidget->redraw = widget_core_redraw;
260 pwidget->draw_frame = widget_core_draw_frame;
261 pwidget->mark_dirty = widget_core_mark_dirty;
262 pwidget->flush = widget_core_flush;
263 pwidget->undraw = widget_core_undraw;
264 pwidget->select = widget_core_select;
265 pwidget->unselect = widget_core_unselect;
266
267 return pwidget;
268}
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