diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 222503d..7b03851 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -316,83 +316,7 @@ namespace MiniEngine - //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(); - } - - //private - void Cursor::_clear() - { - _cur.reset(); - } - - Cursor::Cursor(Surface surf,Point hotspot) - { - Cursor ns; - SDL_Cursor* cursor=SDL_CreateColorCursor(surf._get(),hotspot.x,hotspot.y); - ns._set(cursor); - } - - Cursor::Cursor(SystemCursorType type) - { - Cursor ns; - ns._set(SDL_CreateSystemCursor(_internal::getSDLSystemCursorFromSystemCursorType(type))); - } - - //static - Cursor Cursor::GetActiveCursor() - { - Cursor ns; - ns._set_no_delete(SDL_GetCursor()); - return ns; - } - - //static - Cursor Cursor::GetDefaultCursor() - { - Cursor ns; - ns._set_no_delete(SDL_GetDefaultCursor()); - return ns; - } - - //static - bool Cursor::isShow() - { - return (SDL_ShowCursor(SDL_QUERY)==SDL_ENABLE); - } - - //static - void Cursor::setShow(bool Settings) - { - SDL_ShowCursor(Settings?SDL_ENABLE:SDL_DISABLE); - } - - void Cursor::release() - { - _clear(); - } - - void Cursor::activate() - { - if(_get()!=nullptr) - { - SDL_SetCursor(_get()); - } - } WindowMessageBoxButton::WindowMessageBoxButton() { diff --git a/MiniEngine.h b/MiniEngine.h index 229eef8..6ba721f 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -62,29 +62,6 @@ namespace MiniEngine No, Hand }; - class Cursor - { - public: - Cursor()=default; - Cursor(SystemCursorType); - Cursor(Surface surf,Point hotspot={0,0}); - - static Cursor GetActiveCursor(); - static Cursor GetDefaultCursor(); - - static void setShow(bool); - static bool isShow(); - - void activate(); - - void release(); - private: - std::shared_ptr _cur; - void _set(SDL_Cursor*); - void _set_no_delete(SDL_Cursor*); - SDL_Cursor* _get(); - void _clear(); - }; enum class MessageBoxType { Error, Warning, Information }; diff --git a/SDLWrapper/Cursor.cpp b/SDLWrapper/Cursor.cpp new file mode 100644 index 0000000..35f402c --- /dev/null +++ b/SDLWrapper/Cursor.cpp @@ -0,0 +1,80 @@ +#include "Cursor.h" +#include "begin_code.h" +//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(); +} + +//private +void Cursor::_clear() +{ + _cur.reset(); +} + +Cursor::Cursor(Surface surf,Point hotspot) +{ + Cursor ns; + SDL_Cursor* cursor=SDL_CreateColorCursor(surf._get(),hotspot.x,hotspot.y); + ns._set(cursor); +} + +Cursor::Cursor(SystemCursorType type) +{ + Cursor ns; + ns._set(SDL_CreateSystemCursor(_internal::getSDLSystemCursorFromSystemCursorType(type))); +} + +//static +Cursor Cursor::GetActiveCursor() +{ + Cursor ns; + ns._set_no_delete(SDL_GetCursor()); + return ns; +} + +//static +Cursor Cursor::GetDefaultCursor() +{ + Cursor ns; + ns._set_no_delete(SDL_GetDefaultCursor()); + return ns; +} + +//static +bool Cursor::isShow() +{ + return (SDL_ShowCursor(SDL_QUERY)==SDL_ENABLE); +} + +//static +void Cursor::setShow(bool Settings) +{ + SDL_ShowCursor(Settings?SDL_ENABLE:SDL_DISABLE); +} + +void Cursor::release() +{ + _clear(); +} + +void Cursor::activate() +{ + if(_get()!=nullptr) + { + SDL_SetCursor(_get()); + } +} +#include "end_code.h" diff --git a/SDLWrapper/Cursor.h b/SDLWrapper/Cursor.h new file mode 100644 index 0000000..4016f7c --- /dev/null +++ b/SDLWrapper/Cursor.h @@ -0,0 +1,27 @@ +#pragma once +#include "include.h" +#include "begin_code.h" +class Cursor +{ +public: + Cursor()=default; + Cursor(SystemCursorType); + Cursor(Surface surf,Point hotspot= {0,0}); + + static Cursor GetActiveCursor(); + static Cursor GetDefaultCursor(); + + static void setShow(bool); + static bool isShow(); + + void activate(); + + void release(); +private: + std::shared_ptr _cur; + void _set(SDL_Cursor*); + void _set_no_delete(SDL_Cursor*); + SDL_Cursor* _get(); + void _clear(); +}; +#include "end_code.h"