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;
60
61 w = (image->w + 7) / 8;
62 data = (Uint8 *)fc_calloc(1, w * image->h * 2);
63 if (data == NULL) {
64 return NULL;
65 }
66 /* memset(data, 0, w * image->h * 2); */
67 mask = data + w * image->h;
69 for (y = 0; y < image->h; y++) {
70 d = data + y * w;
71 m = mask + y * w;
72 for (x = 0; x < image->w; x++) {
73 color = get_pixel(image, x, y);
75 &r, &g, &b, &a);
76 if (a != 0) {
77 color = (r + g + b) / 3;
78 m[x / 8] |= 128 >> (x & 7);
79 if (color < 128) {
80 d[x / 8] |= 128 >> (x & 7);
81 }
82 }
83 }
84 }
85
87
88 cursor = SDL_CreateCursor(data, mask, w * 8, image->h, hx, hy);
89
90 FC_FREE(data);
91
92 return cursor;
93}
94
95/**********************************************************************/
99{
100 float cursor_x = 0;
101 float cursor_y = 0;
102 static SDL_Rect area = {0, 0, 0, 0};
103
105 /* Restore background */
106 if (area.w != 0) {
107 flush_rect(&area, TRUE);
108 }
109
114 area.w = current_color_cursor.cursor->w;
115 area.h = current_color_cursor.cursor->h;
116
117 /* Show cursor */
119 /* Update screen */
121#if 0
122 SDL_UpdateRect(main_data.screen, area.x, area.y, area.w, area.h);
123#endif
124 } else {
125 area = (SDL_Rect){0, 0, 0, 0};
126 }
127 }
128}
129
130/**********************************************************************/
134void load_cursors(void)
135{
136 enum cursor_type cursor;
137 int frame;
138 SDL_Surface *surf;
139
141
142 surf = create_surf(1, 1);
143 disabled_cursor = SurfaceToCursor(surf, 0, 0);
144 FREESURFACE(surf);
145
146 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
147 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
148 int hot_x, hot_y;
149 struct sprite *sprite
150 = get_cursor_sprite(tileset, cursor, &hot_x, &hot_y, frame);
151
152 surf = GET_SURF(sprite);
153
154 fc_cursors[cursor][frame] = SurfaceToCursor(surf, hot_x, hot_y);
155 }
156 }
157}
158
159/**********************************************************************/
163{
164 enum cursor_type cursor;
165 int frame;
166
167 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
168 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
169 SDL_DestroyCursor(fc_cursors[cursor][frame]);
170 }
171 }
172
175}
176
177/**********************************************************************/
208
209/**********************************************************************/
char * incite_cost
Definition comments.c:75
static int cursor_frame
Definition mapview.c:67
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
Uint32 get_pixel(SDL_Surface *surf, Sint16 x, Sint16 y)
Definition graphics.c:430
#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:6960
#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