Skip to content

Commit

Permalink
Merge pull request #6 from Kiritow/pre-merge
Browse files Browse the repository at this point in the history
Weekly Update
  • Loading branch information
Kiritow committed May 2, 2017
2 parents 21a30cc + f4c6293 commit 9d9ba52
Show file tree
Hide file tree
Showing 12 changed files with 1,396 additions and 8 deletions.
150 changes: 147 additions & 3 deletions MiniEngine.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -98,7 +164,7 @@ namespace MiniEngine
{
auto p = toSDLPoint();
auto r = rect.toSDLRect();
return SDL_PointInRect(&p, &r);
return ( SDL_PointInRect(&p, &r) == SDL_TRUE );
}

ColorMode::ColorMode(int R, int G, int B)
Expand Down Expand Up @@ -735,6 +801,74 @@ 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
Cursor Cursor::GetActiveCursor()
{
Cursor ns;
ns._set(SDL_GetCursor());
return ns;
}

//static
Cursor Cursor::GetDefaultCursor()
{
Cursor ns;
ns._set(SDL_GetDefaultCursor());
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);
}

void Cursor::activate()
{
SDL_SetCursor(_get());
}

bool Renderer::isReady()
{
return (_get() != nullptr);
Expand Down Expand Up @@ -829,6 +963,16 @@ namespace MiniEngine
return std::string(SDL_GetWindowTitle(_get()));
}

void Window::setGrab(bool isGrab)
{
SDL_SetWindowGrab(_get(),isGrab?SDL_TRUE:SDL_FALSE);
}

bool Window::getGrab()
{
return (SDL_GetWindowGrab(_get())==SDL_TRUE)?true:false;
}

void Window::setResizable(bool resizable)
{
//SDL_SetWindowResizable(_get(), resizable?SDL_TRUE:SDL_FALSE);
Expand Down Expand Up @@ -1438,12 +1582,12 @@ namespace MiniEngine

bool MusicPlayer::isPlaying()
{
return Mix_PlayingMusic();
return (Mix_PlayingMusic() == 1);
}

bool MusicPlayer::isPaused()
{
return Mix_PausedMusic();
return (Mix_PausedMusic() == 1);
}

int MusicPlayer::isFading()
Expand Down
39 changes: 37 additions & 2 deletions MiniEngine.h
Expand Up @@ -7,6 +7,9 @@
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <SDL_mixer.h>

/// VC++ does not implied C++ exception. Use this to ignore compile warning on this.
#pragma warning (disable:4290)
#else
/// CodeBlocks (MinGW Compiler)
#include <SDL2/SDL.h>
Expand All @@ -20,8 +23,7 @@
#include <memory>
#include <functional>

#define _DECL_DEPRECATED __declspec(deprecated)
#define _DECL_DEPRECATED_MSG(InfoString) __declspec(deprecated(InfoString))
#define _DECL_DEPRECATED [[deprecated]]

namespace MiniEngine
{
Expand Down Expand Up @@ -150,6 +152,7 @@ namespace MiniEngine
friend class Window;
friend class Renderer;
friend class Font;
friend class Cursor;
};

class Texture
Expand Down Expand Up @@ -232,6 +235,35 @@ 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();

void activate();
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
Expand Down Expand Up @@ -268,6 +300,9 @@ namespace MiniEngine
void setTitle(std::string Title);
std::string getTitle();

void setGrab(bool);
bool getGrab();

void setResizable(bool resizable);

/// Use UTF8 in Title and Message please.
Expand Down

0 comments on commit 9d9ba52

Please sign in to comment.