28 #include <boost/logic/tribool.hpp>
29 using boost::logic::tribool;
30 using boost::logic::indeterminate;
40 if(nsurf ==
nullptr) {
47 size_t cursor_width = 16;
49 size_t cursor_width = nsurf->w;
50 if((cursor_width%8) != 0) {
51 cursor_width += 8 - (cursor_width%8);
54 std::vector<Uint8>
data((cursor_width*nsurf->h)/8,0);
55 std::vector<Uint8>
mask(data.size(),0);
60 const Uint32*
const pixels = lock.pixels();
61 for(
int y = 0;
y != nsurf->h; ++
y) {
62 for(
int x = 0;
x != nsurf->w; ++
x) {
64 if (static_cast<size_t>(
x) < cursor_width) {
66 SDL_GetRGBA(pixels[
y*nsurf->w +
x],nsurf->format,&r,&g,&b,&a);
68 const size_t index =
y*cursor_width +
x;
69 const size_t shift = 7 - (index % 8);
71 const Uint8 trans = (a < 128 ? 0 : 1) << shift;
72 const Uint8 black = (trans == 0 || (r+g +
b) / 3 > 128 ? 0 : 1) << shift;
74 data[index/8] |= black;
75 mask[index/8] |= trans;
80 return SDL_CreateCursor(&data[0],&
mask[0],cursor_width,nsurf->h,0,0);
87 indeterminate, indeterminate, indeterminate, indeterminate,
88 indeterminate, indeterminate, indeterminate, indeterminate,
94 const std::string bw_images[
cursor::NUM_CURSORS] = {
"normal.png",
"wait-alt.png",
"move.png",
"attack.png",
"select.png",
"move_drag_alt.png" ,
"attack_drag_alt.png",
"no_cursor.png"};
96 const std::string bw_images[
cursor::NUM_CURSORS] = {
"normal.png",
"wait.png",
"move.png",
"attack.png",
"select.png",
"move_drag.png",
"attack_drag.png",
"no_cursor.png"};
99 const std::string color_images[
cursor::NUM_CURSORS] = {
"normal.png",
"wait.png",
"move.png",
"attack.png",
"select.png",
"move_drag.png",
"attack_drag.png",
""};
108 bool have_focus =
true;
115 if(
cache[type] ==
nullptr || indeterminate(cache_color[type]) || cache_color[type] != is_color) {
116 const std::string prefix = is_color ?
"cursors/" :
"cursors-bw/";
123 cache_color[
type] = is_color;
144 SDL_ShowCursor(SDL_ENABLE);
151 SDL_ShowCursor(SDL_ENABLE);
158 current_cursor =
type;
165 SDL_Cursor * cursor_image =
get_cursor(current_cursor);
169 SDL_SetCursor(cursor_image);
171 SDL_ShowCursor(SDL_ENABLE);
176 switch(current_cursor) {
196 return current_cursor;
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
SDL_Surface * get() const
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
GLuint GLuint GLsizei GLenum type
GLint GLint GLint GLint GLint GLint y
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble b
void set_dragging(bool drag)
void set_focus(bool focus)
GLboolean GLboolean GLboolean GLboolean a
static bool use_color_cursors()
static SDL_Cursor * create_cursor(surface surf)
GLint GLint GLint GLint GLint x
GLdouble GLdouble GLdouble r
Contains the SDL_Rect helper code.
static SDL_Cursor * get_cursor(cursor::CURSOR_TYPE type)
static void clear_cache()
surface make_neutral_surface(const surface &surf)
GLsizei const GLcharARB ** string