载入中...
搜索中...
未找到
Cursor.cpp
浏览该文件的文档.
1
2#include "mouse/sdl/Cursor.h"
3#include "common/Exception.h"
4#include "common/config.h"
5
7{
8
9Cursor::Cursor(image::ImageData *data, int hotx, int hoty)
10 : cursor(nullptr)
11 , is_custom(true)
12 , systemType("")
13{
14 Uint32 rmask, gmask, bmask, amask;
15#ifdef EVE_BIG_ENDIAN
16 rmask = 0xFF000000;
17 gmask = 0x00FF0000;
18 bmask = 0x0000FF00;
19 amask = 0x000000FF;
20#else
21 rmask = 0x000000FF;
22 gmask = 0x0000FF00;
23 bmask = 0x00FF0000;
24 amask = 0xFF000000;
25#endif
26
27 // int w = data->getWidth();
28 // int h = data->getHeight();
29 // int pitch = w * 4;
30
31 // SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(data->getData(), w, h, 32, pitch, rmask, gmask, bmask, amask);
32 // if (!surface)
33 // throw Exception("Cannot create cursor: out of memory!");
34
35 // cursor = SDL_CreateColorCursor(surface, hotx, hoty);
36 // SDL_FreeSurface(surface);
37
38 if (!cursor)
39 throw Exception("Cannot create cursor: %s", SDL_GetError());
40}
41
42Cursor::Cursor(std::string cursortype)
43 : cursor(nullptr)
44 , is_custom(false)
45 , systemType(cursortype)
46{
47 if (auto i = systemCursorEntries.find(cursortype); i != systemCursorEntries.end())
48 cursor = SDL_CreateSystemCursor(i->second);
49 else
50 throw Exception("Cannot create system cursor: invalid type.");
51
52 if (!cursor)
53 throw Exception("Cannot create system cursor: %s", SDL_GetError());
54}
55
57{
58 if (cursor)
59 SDL_FreeCursor(cursor);
60}
61
62void *Cursor::getHandle() const
63{
64 return cursor;
65}
66
67std::map<std::string, SDL_SystemCursor> Cursor::systemCursorEntries =
68{
69 {"ARROW", SDL_SYSTEM_CURSOR_ARROW},
70 {"IBEAM", SDL_SYSTEM_CURSOR_IBEAM},
71 {"WAIT", SDL_SYSTEM_CURSOR_WAIT},
72 {"CROSSHAIR", SDL_SYSTEM_CURSOR_CROSSHAIR},
73 {"WAITARROW", SDL_SYSTEM_CURSOR_WAITARROW},
74 {"SIZENWSE", SDL_SYSTEM_CURSOR_SIZENWSE},
75 {"SIZENESW", SDL_SYSTEM_CURSOR_SIZENESW},
76 {"SIZEWE", SDL_SYSTEM_CURSOR_SIZEWE},
77 {"SIZENS", SDL_SYSTEM_CURSOR_SIZENS},
78 {"SIZEALL", SDL_SYSTEM_CURSOR_SIZEALL},
79 {"NO", SDL_SYSTEM_CURSOR_NO},
80 {"HAND", SDL_SYSTEM_CURSOR_HAND},
81};
82
83} // eve::mouse::sdl
Represents raw pixel data.
Definition ImageData.h:26
void * getHandle() const
底层 SDL_Cursor 句柄。
Definition Cursor.cpp:62
Cursor(image::ImageData *imageData, int hotx, int hoty)
从图像数据创建自定义光标(热点 hotx/hoty)。
Definition Cursor.cpp:9