mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Add class Cursor
This commit is contained in:
parent
9786aea48a
commit
bf3fc19eaa
113
MiniEngine.cpp
113
MiniEngine.cpp
|
@ -50,6 +50,72 @@ namespace MiniEngine
|
|||
return SDL_BLENDMODE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
SystemCursorType getCursorTypeFromSDLSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
switch(id)
|
||||
{
|
||||
case SDL_SYSTEM_CURSOR_ARROW:
|
||||
return SystemCursorType::Arrow;
|
||||
case SDL_SYSTEM_CURSOR_CROSSHAIR:
|
||||
return SystemCursorType::CrossHair;
|
||||
case SDL_SYSTEM_CURSOR_HAND:
|
||||
return SystemCursorType::Hand;
|
||||
case SDL_SYSTEM_CURSOR_IBEAM:
|
||||
return SystemCursorType::Ibeam;
|
||||
case SDL_SYSTEM_CURSOR_NO:
|
||||
return SystemCursorType::No;
|
||||
case SDL_SYSTEM_CURSOR_SIZEALL:
|
||||
return SystemCursorType::SizeAll;
|
||||
case SDL_SYSTEM_CURSOR_SIZENESW:
|
||||
return SystemCursorType::SizeNESW;
|
||||
case SDL_SYSTEM_CURSOR_SIZENS:
|
||||
return SystemCursorType::SizeNS;
|
||||
case SDL_SYSTEM_CURSOR_SIZENWSE:
|
||||
return SystemCursorType::SizeNWSE;
|
||||
case SDL_SYSTEM_CURSOR_SIZEWE:
|
||||
return SystemCursorType::SizeWE;
|
||||
case SDL_SYSTEM_CURSOR_WAIT:
|
||||
return SystemCursorType::Wait;
|
||||
case SDL_SYSTEM_CURSOR_WAITARROW:
|
||||
return SystemCursorType::WaitArrow;
|
||||
default:/// return SystemCursorType::Arrow on default.
|
||||
return SystemCursorType::Arrow;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SystemCursor getSDLSystemCursorFromSystemCursorType(SystemCursorType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case SystemCursorType::Arrow:
|
||||
return SDL_SYSTEM_CURSOR_ARROW;
|
||||
case SystemCursorType::CrossHair:
|
||||
return SDL_SYSTEM_CURSOR_CROSSHAIR;
|
||||
case SystemCursorType::Hand:
|
||||
return SDL_SYSTEM_CURSOR_HAND;
|
||||
case SystemCursorType::Ibeam:
|
||||
return SDL_SYSTEM_CURSOR_IBEAM;
|
||||
case SystemCursorType::No:
|
||||
return SDL_SYSTEM_CURSOR_NO;
|
||||
case SystemCursorType::SizeAll:
|
||||
return SDL_SYSTEM_CURSOR_SIZEALL;
|
||||
case SystemCursorType::SizeNESW:
|
||||
return SDL_SYSTEM_CURSOR_SIZENESW;
|
||||
case SystemCursorType::SizeNS:
|
||||
return SDL_SYSTEM_CURSOR_SIZENS;
|
||||
case SystemCursorType::SizeNWSE:
|
||||
return SDL_SYSTEM_CURSOR_SIZENWSE;
|
||||
case SystemCursorType::SizeWE:
|
||||
return SDL_SYSTEM_CURSOR_SIZEWE;
|
||||
case SystemCursorType::Wait:
|
||||
return SDL_SYSTEM_CURSOR_WAIT;
|
||||
case SystemCursorType::WaitArrow:
|
||||
return SDL_SYSTEM_CURSOR_WAITARROW;
|
||||
default:/// return SDL_SYSTEM_CURSOR_ARROW on default.
|
||||
return SDL_SYSTEM_CURSOR_ARROW;
|
||||
}
|
||||
}
|
||||
}/// End of namespace _internal
|
||||
|
||||
Rect::Rect(int X, int Y, int W, int H)
|
||||
|
@ -735,6 +801,53 @@ namespace MiniEngine
|
|||
return t;
|
||||
}
|
||||
|
||||
//private
|
||||
void Cursor::_set(SDL_Cursor* p)
|
||||
{
|
||||
_cur.reset(p,SDL_FreeCursor);
|
||||
}
|
||||
|
||||
//private
|
||||
void Cursor::_set_no_delete(SDL_Cursor* p)
|
||||
{
|
||||
_cur.reset(p,[](SDL_Cursor* p){});
|
||||
}
|
||||
|
||||
//private
|
||||
SDL_Cursor* Cursor::_get()
|
||||
{
|
||||
return _cur.get();
|
||||
}
|
||||
|
||||
//static
|
||||
Cursor Cursor::CreateCursor(Surface surf,Point hotspot)
|
||||
{
|
||||
Cursor ns;
|
||||
SDL_Cursor* cursor=SDL_CreateColorCursor(surf._get(),hotspot.x,hotspot.y);
|
||||
ns._set(cursor);
|
||||
return ns;
|
||||
}
|
||||
|
||||
//static
|
||||
Cursor Cursor::CreateSystemCursor(SystemCursorType type)
|
||||
{
|
||||
Cursor ns;
|
||||
ns._set(SDL_CreateSystemCursor(_internal::getSDLSystemCursorFromSystemCursorType(type)));
|
||||
return ns;
|
||||
}
|
||||
|
||||
//static
|
||||
bool Cursor::isShow()
|
||||
{
|
||||
return (SDL_ShowCursor(SDL_QUERY)==SDL_ENABLE);
|
||||
}
|
||||
|
||||
//static
|
||||
void Cursor::show(bool Settings)
|
||||
{
|
||||
SDL_ShowCursor(Settings?SDL_ENABLE:SDL_DISABLE);
|
||||
}
|
||||
|
||||
bool Renderer::isReady()
|
||||
{
|
||||
return (_get() != nullptr);
|
||||
|
|
28
MiniEngine.h
28
MiniEngine.h
|
@ -150,6 +150,7 @@ namespace MiniEngine
|
|||
friend class Window;
|
||||
friend class Renderer;
|
||||
friend class Font;
|
||||
friend class Cursor;
|
||||
};
|
||||
|
||||
class Texture
|
||||
|
@ -232,6 +233,33 @@ namespace MiniEngine
|
|||
friend class Window;
|
||||
};
|
||||
|
||||
enum class SystemCursorType
|
||||
{
|
||||
Arrow, Ibeam, CrossHair,
|
||||
Wait, WaitArrow,
|
||||
SizeNWSE, SizeNESW, SizeWE, SizeNS, SizeAll,
|
||||
No, Hand
|
||||
};
|
||||
|
||||
class Cursor
|
||||
{
|
||||
public:
|
||||
static Cursor CreateSystemCursor(SystemCursorType);
|
||||
static Cursor CreateCursor(Surface surf,Point hotspot={0,0});
|
||||
|
||||
static Cursor GetActiveCursor();
|
||||
static Cursor GetDefaultCursor();
|
||||
|
||||
static void show(bool);
|
||||
static bool isShow();
|
||||
private:
|
||||
std::shared_ptr<SDL_Cursor> _cur;
|
||||
void _set(SDL_Cursor*);
|
||||
void _set_no_delete(SDL_Cursor*);
|
||||
SDL_Cursor* _get();
|
||||
void _clear();
|
||||
};
|
||||
|
||||
enum class MessageBoxType { Error, Warning, Information };
|
||||
|
||||
class Window
|
||||
|
|
Loading…
Reference in New Issue
Block a user