Freeciv-3.2
Loading...
Searching...
No Matches
gui_mouse.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2006 The Freeciv Team
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/* utility */
22#include "log.h"
23
24/* client */
25#include "tilespec.h"
26
27/* gui-sdl3 */
28#include "graphics.h"
29#include "mapview.h"
30#include "sprite.h"
31
32#include "gui_mouse.h"
33
34struct color_cursor {
36 int hot_x;
37 int hot_y;
38};
39
41
44
47
49
50/**********************************************************************/
54{
55 int w, x, y;
56 Uint8 *data, *mask, *d, *m, r, g, b, a;
59
60 w = (image->w + 7) / 8;
61 data = (Uint8 *)fc_calloc(1, w * image->h * 2);
62 if (data == NULL) {
63 return NULL;
64 }
65 /* memset(data, 0, w * image->h * 2); */
66 mask = data + w * image->h;
68 for (y = 0; y < image->h; y++) {
69 d = data + y * w;
70 m = mask + y * w;
71 for (x = 0; x < image->w; x++) {
72 color = getpixel(image, x, y);
73 SDL_GetRGBA(color, image->format, &r, &g, &b, &a);
74 if (a != 0) {
75 color = (r + g + b) / 3;
76 m[x / 8] |= 128 >> (x & 7);
77 if (color < 128) {
78 d[x / 8] |= 128 >> (x & 7);
79 }
80 }
81 }
82 }
83
85
86 cursor = SDL_CreateCursor(data, mask, w * 8, image->h, hx, hy);
87
88 FC_FREE(data);
89
90 return cursor;
91}
92
93/**********************************************************************/
97{
98 float cursor_x = 0;
99 float cursor_y = 0;
100 static SDL_Rect area = {0, 0, 0, 0};
101
103 /* Restore background */
104 if (area.w != 0) {
105 flush_rect(&area, TRUE);
106 }
107
112 area.w = current_color_cursor.cursor->w;
113 area.h = current_color_cursor.cursor->h;
114
115 /* Show cursor */
117 /* Update screen */
119#if 0
120 SDL_UpdateRect(main_data.screen, area.x, area.y, area.w, area.h);
121#endif
122 } else {
123 area = (SDL_Rect){0, 0, 0, 0};
124 }
125 }
126}
127
128/**********************************************************************/
132void load_cursors(void)
133{
134 enum cursor_type cursor;
135 int frame;
136 SDL_Surface *surf;
137
139
140 surf = create_surf(1, 1, SDL_SWSURFACE);
141 disabled_cursor = SurfaceToCursor(surf, 0, 0);
142 FREESURFACE(surf);
143
144 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
145 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
146 int hot_x, hot_y;
147 struct sprite *sprite
148 = get_cursor_sprite(tileset, cursor, &hot_x, &hot_y, frame);
149
150 surf = GET_SURF(sprite);
151
152 fc_cursors[cursor][frame] = SurfaceToCursor(surf, hot_x, hot_y);
153 }
154 }
155}
156
157/**********************************************************************/
161{
162 enum cursor_type cursor;
163 int frame;
164
165 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
166 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
167 SDL_DestroyCursor(fc_cursors[cursor][frame]);
168 }
169 }
170
173}
174
175/**********************************************************************/
206
207/**********************************************************************/
char * incite_cost
Definition comments.c:74
static int cursor_frame
Definition mapview.c:67
Uint32 getpixel(SDL_Surface *surf, Sint16 x, Sint16 y)
Definition graphics.c:430
void update_main_screen(void)
Definition graphics.c:669
int screen_blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:223
struct sdl2_data main_data
Definition graphics.c:57
SDL_Surface * create_surf(int width, int height, Uint32 flags)
Definition graphics.c:351
#define FREESURFACE(ptr)
Definition graphics.h:322
#define unlock_surf(surf)
Definition graphics.h:344
#define lock_surf(surf)
Definition graphics.h:333
#define GUI_SDL_OPTION(optname)
Definition gui_main.h:37
SDL_Cursor * fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES]
Definition gui_mouse.c:44
static SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy)
Definition gui_mouse.c:57
enum cursor_type mouse_cursor_type
Definition gui_mouse.c:46
void animate_mouse_cursor(void)
Definition gui_mouse.c:182
struct color_cursor current_color_cursor
Definition gui_mouse.c:52
bool mouse_cursor_changed
Definition gui_mouse.c:47
void unload_cursors(void)
Definition gui_mouse.c:164
SDL_Cursor * disabled_cursor
Definition gui_mouse.c:50
SDL_Cursor * std_cursor
Definition gui_mouse.c:49
void draw_mouse_cursor(void)
Definition gui_mouse.c:100
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition gui_mouse.c:214
void load_cursors(void)
Definition gui_mouse.c:136
void flush_rect(SDL_Rect *rect, bool force_flush)
Definition mapview.c:103
#define GET_SURF(m_sprite)
Definition sprite.h:29
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
struct sprite int int int int struct sprite * mask
Definition sprite_g.h:32
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
SDL_Surface * cursor
Definition gui_mouse.c:39
Definition colors.h:21
SDL_Window * screen
Definition graphics.h:209
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct sprite * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Definition tilespec.c:6964
#define NUM_CURSOR_FRAMES
Definition tilespec.h:303
cursor_type
Definition tilespec.h:287
@ CURSOR_DEFAULT
Definition tilespec.h:300
@ CURSOR_LAST
Definition tilespec.h:299