载入中...
搜索中...
未找到
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 // int w = data->getWidth();
15 // int h = data->getHeight();
16 // int pitch = w * 4;
17
18 // SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(data->getData(), w, h, 32, pitch, rmask, gmask, bmask, amask);
19 // if (!surface)
20 // throw Exception("Cannot create cursor: out of memory!");
21
22 // cursor = SDL_CreateColorCursor(surface, hotx, hoty);
23 // SDL_FreeSurface(surface);
24
25 if (!cursor)
26 throw Exception("Cannot create cursor: %s", SDL_GetError());
27}
28
29Cursor::Cursor(std::string cursortype)
30 : cursor(nullptr)
31 , is_custom(false)
32 , systemType(cursortype)
33{
34 if (auto i = systemCursorEntries.find(cursortype); i != systemCursorEntries.end())
35 cursor = SDL_CreateSystemCursor(i->second);
36 else
37 throw Exception("Cannot create system cursor: invalid type.");
38
39 if (!cursor)
40 throw Exception("Cannot create system cursor: %s", SDL_GetError());
41}
42
44{
45 if (cursor)
46 SDL_FreeCursor(cursor);
47}
48
49void *Cursor::getHandle() const
50{
51 return cursor;
52}
53
54std::map<std::string, SDL_SystemCursor> Cursor::systemCursorEntries =
55{
56 {"ARROW", SDL_SYSTEM_CURSOR_ARROW},
57 {"IBEAM", SDL_SYSTEM_CURSOR_IBEAM},
58 {"WAIT", SDL_SYSTEM_CURSOR_WAIT},
59 {"CROSSHAIR", SDL_SYSTEM_CURSOR_CROSSHAIR},
60 {"WAITARROW", SDL_SYSTEM_CURSOR_WAITARROW},
61 {"SIZENWSE", SDL_SYSTEM_CURSOR_SIZENWSE},
62 {"SIZENESW", SDL_SYSTEM_CURSOR_SIZENESW},
63 {"SIZEWE", SDL_SYSTEM_CURSOR_SIZEWE},
64 {"SIZENS", SDL_SYSTEM_CURSOR_SIZENS},
65 {"SIZEALL", SDL_SYSTEM_CURSOR_SIZEALL},
66 {"NO", SDL_SYSTEM_CURSOR_NO},
67 {"HAND", SDL_SYSTEM_CURSOR_HAND},
68};
69
70} // eve::mouse::sdl
std::size_t cursor
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Represents raw pixel data.
Definition ImageData.h:38
~Cursor()
Frees the underlying SDL_Cursor.
Definition Cursor.cpp:43
void * getHandle() const
Underlying SDL_Cursor handle.
Definition Cursor.cpp:49
Cursor(image::ImageData *imageData, int hotx, int hoty)
Builds a custom cursor from image data with hotspot (hotx, hoty).
Definition Cursor.cpp:9