50 using cursor_ptr = std::unique_ptr<SDL_Cursor, void(*)(SDL_Cursor*)>;
51 cursor_ptr
cursor{
nullptr, SDL_DestroyCursor};
55auto available_cursors = std::array
57 cursor_data{
"normal.png",
"normal.png", 0, 0 },
58 cursor_data{
"wait.png",
"wait.png", 0, 0 },
59 cursor_data{
"ibeam.png",
"ibeam.png", 14, 14 },
60 cursor_data{
"move.png",
"move.png", 0, 0 },
61 cursor_data{
"attack.png",
"attack.png", 2, 2 },
62 cursor_data{
"select.png",
"select.png", 10, 2 },
63 cursor_data{
"move_drag.png",
"move_drag.png", 2, 20 },
64 cursor_data{
"attack_drag.png",
"attack_drag.png", 3, 22 },
65 cursor_data{
"no_cursor.png",
"", 0, 0 }
71bool have_focus =
true;
73bool use_color_cursors()
85 std::size_t cursor_width =
surf->w;
86 if((cursor_width % 8) != 0) {
87 cursor_width += 8 - (cursor_width % 8);
90 std::vector<uint8_t>
data((cursor_width *
surf->h) / 8, 0);
91 std::vector<uint8_t> mask(
data.size(), 0);
98 for(
int y = 0; y !=
surf->h; ++y) {
99 for(
int x = 0; x !=
surf->w; ++x) {
100 if(
static_cast<std::size_t
>(x) < cursor_width) {
102 SDL_GetRGBA(pixels[y *
surf->w + x], SDL_GetPixelFormatDetails(
surf->format), SDL_GetSurfacePalette(
surf), &r, &
g, &
b, &a);
104 const std::size_t
index = y * cursor_width + x;
105 const std::size_t shift = 7 - (
index % 8);
107 const uint8_t trans = (a < 128 ? 0 : 1) << shift;
108 const uint8_t black = (trans == 0 || (r +
g +
b) / 3 > 128 ? 0 : 1) << shift;
111 mask[
index / 8] |= trans;
116 return SDL_CreateCursor(&
data[0], &mask[0], cursor_width,
surf->h, 0, 0);
121 const bool use_color = use_color_cursors();
123 cursor_data&
data = available_cursors[
type];
125 if(
data.cursor ==
nullptr || boost::indeterminate(
data.is_color) ||
data.is_color != use_color ||
data.scale !=
scale) {
126 static const std::string color_prefix =
"cursors/";
127 static const std::string bw_prefix =
"cursors-bw/";
140 data.cursor.reset(create_cursor(
surf));
143 data.is_color = use_color;
147 return data.cursor.get();
165 current_cursor = type;
172 SDL_SetCursor(get_cursor(current_cursor));
177 switch(current_cursor) {
197 return current_cursor;
210 : old_(current_cursor)
surface get_surface(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image surface suitable for software manipulation.