Update ResHandler. Update Cursor.

This commit is contained in:
Kirigaya Kazuto 2017-07-30 17:48:22 +08:00
parent 0f351a077e
commit af41d54a4a
3 changed files with 33 additions and 25 deletions

View File

@ -22,36 +22,33 @@ SDL_Cursor* Cursor::_get()
//private
void Cursor::_clear()
{
_cur.reset();
_cur.release();
}
Cursor::Cursor(Surface surf,Point hotspot)
{
Cursor ns;
SDL_Cursor* cursor=SDL_CreateColorCursor(surf._get(),hotspot.x,hotspot.y);
ns._set(cursor);
_set(SDL_CreateColorCursor(surf._get(),hotspot.x,hotspot.y));
}
Cursor::Cursor(SystemCursorType type)
{
Cursor ns;
ns._set(SDL_CreateSystemCursor(_internal::getSDLSystemCursorFromSystemCursorType(type)));
_set(SDL_CreateSystemCursor(_internal::getSDLSystemCursorFromSystemCursorType(type)));
}
//static
Cursor Cursor::GetActiveCursor()
Cursor&& Cursor::GetActiveCursor()
{
Cursor ns;
ns._set_no_delete(SDL_GetCursor());
return ns;
return std::move(ns);
}
//static
Cursor Cursor::GetDefaultCursor()
Cursor&& Cursor::GetDefaultCursor()
{
Cursor ns;
ns._set_no_delete(SDL_GetDefaultCursor());
return ns;
return std::move(ns);
}
//static

View File

@ -1,19 +1,21 @@
#pragma once
#include "include.h"
#include "__Noncopyable.h"
#include "_handler.h"
#include "_SystemCursorType.h"
#include "Point.h"
#include "Surface.h"
#include "__Plugin.h"
#include "begin_code.h"
class Cursor
class Cursor : public NonCopyable
{
public:
Cursor()=default;
Cursor(SystemCursorType);
Cursor(Surface surf,Point hotspot= {0,0});
static Cursor GetActiveCursor();
static Cursor GetDefaultCursor();
static Cursor&& GetActiveCursor();
static Cursor&& GetDefaultCursor();
static void setShow(bool);
static bool isShow();
@ -22,7 +24,8 @@ public:
void release();
private:
std::shared_ptr<SDL_Cursor> _cur;
res_ptr<SDL_Cursor> _cur;
void _set(SDL_Cursor*);
void _set_no_delete(SDL_Cursor*);
SDL_Cursor* _get();

View File

@ -8,7 +8,7 @@ template<typename T>
class res_ptr
{
public:
res_ptr(T* ptr) : _ptr(ptr) {}
res_ptr() : _ptr(nullptr) {}
res_ptr(T* ptr,const std::function<void(T*)>& delFunc) : _ptr(ptr), _delfunc(delFunc) {}
res_ptr(const res_ptr&)=delete;
res_ptr& operator = (const res_ptr&)=delete;
@ -30,26 +30,34 @@ public:
{
release();
}
void release()
{
if(_ptr)
{
if(_delfunc)
{
_delfunc(_ptr);
}
else
{
}
_delfunc(_ptr);
_ptr=nullptr;
}
}
T* get() const
void reset(T* ptr,const std::function<void(T*)>& delFunc)
{
release();
_ptr=ptr;
_delfunc=delFunc;
}
T* get()
{
return _ptr;
}
void reset()
const T* get() const
{
return _ptr;
}
T* operator -> ()
{
return _ptr;
}
private:
T* _ptr;
std::function<void(T*)> _delfunc;