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/* 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/* utility */
26#include "log.h"
27
28/* client */
29#include "tilespec.h"
30
31/* gui-sdl2 */
32#include "graphics.h"
33#include "mapview.h"
34#include "sprite.h"
35
36#include "gui_mouse.h"
37
43
45
48
51
53
54/**********************************************************************/
58{
59 int w, x, y;
60 Uint8 *data, *mask, *d, *m, r, g, b, a;
63
64 w = (image->w + 7) / 8;
65 data = (Uint8 *)fc_calloc(1, w * image->h * 2);
66 if (data == NULL) {
67 return NULL;
68 }
69 /* memset(data, 0, w * image->h * 2); */
70 mask = data + w * image->h;
72 for (y = 0; y < image->h; y++) {
73 d = data + y * w;
74 m = mask + y * w;
75 for (x = 0; x < image->w; x++) {
76 color = getpixel(image, x, y);
77 SDL_GetRGBA(color, image->format, &r, &g, &b, &a);
78 if (a != 0) {
79 color = (r + g + b) / 3;
80 m[x / 8] |= 128 >> (x & 7);
81 if (color < 128) {
82 d[x / 8] |= 128 >> (x & 7);
83 }
84 }
85 }
86 }
87
89
90 cursor = SDL_CreateCursor(data, mask, w * 8, image->h, hx, hy);
91
92 FC_FREE(data);
93
94 return cursor;
95}
96
97/**********************************************************************/
101{
102 int cursor_x = 0;
103 int cursor_y = 0;
104 static SDL_Rect area = {0, 0, 0, 0};
105
107 /* Restore background */
108 if (area.w != 0) {
109 flush_rect(&area, TRUE);
110 }
111
116 area.w = current_color_cursor.cursor->w;
117 area.h = current_color_cursor.cursor->h;
118
119 /* Show cursor */
121 /* Update screen */
123#if 0
124 SDL_UpdateRect(main_data.screen, area.x, area.y, area.w, area.h);
125#endif
126 } else {
127 area = (SDL_Rect){0, 0, 0, 0};
128 }
129 }
130}
131
132/**********************************************************************/
136void load_cursors(void)
137{
138 enum cursor_type cursor;
139 int frame;
140 SDL_Surface *surf;
141
143
144 surf = create_surf(1, 1, SDL_SWSURFACE);
145 disabled_cursor = SurfaceToCursor(surf, 0, 0);
146 FREESURFACE(surf);
147
148 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
149 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
150 int hot_x, hot_y;
151 struct sprite *sprite
152 = get_cursor_sprite(tileset, cursor, &hot_x, &hot_y, frame);
153
154 surf = GET_SURF(sprite);
155
156 fc_cursors[cursor][frame] = SurfaceToCursor(surf, hot_x, hot_y);
157 }
158 }
159}
160
161/**********************************************************************/
165{
166 enum cursor_type cursor;
167 int frame;
168
169 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
170 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
171 SDL_FreeCursor(fc_cursors[cursor][frame]);
172 }
173 }
174
177}
178
179/**********************************************************************/
210
211/**********************************************************************/
char * incite_cost
Definition comments.c:75
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: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