Fix Compile error on low level SDL2.

This commit is contained in:
Kirigaya Kazuto 2017-06-01 22:50:17 +08:00
parent d8e8deb031
commit 7cecae5695
2 changed files with 53 additions and 4 deletions

View File

@ -87,8 +87,7 @@ namespace MiniEngine
case WindowType::MouseCapture: case WindowType::MouseCapture:
return SDL_WINDOW_MOUSE_CAPTURE; return SDL_WINDOW_MOUSE_CAPTURE;
/// The following value are not defined on C4. #if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5) /// SDL 2.0.5 Required
#ifndef __C4DROID__
case WindowType::AlwaysOnTop: case WindowType::AlwaysOnTop:
return SDL_WINDOW_ALWAYS_ON_TOP; return SDL_WINDOW_ALWAYS_ON_TOP;
case WindowType::SkipTaskBar: case WindowType::SkipTaskBar:
@ -99,7 +98,7 @@ namespace MiniEngine
return SDL_WINDOW_TOOLTIP; return SDL_WINDOW_TOOLTIP;
case WindowType::PopUpMenu: case WindowType::PopUpMenu:
return SDL_WINDOW_POPUP_MENU; return SDL_WINDOW_POPUP_MENU;
#endif // __C4DROID__ #endif // End of SDL2.0.5 Require
default: default:
return 0;/// Return 0 on default. return 0;/// Return 0 on default.
@ -1256,14 +1255,22 @@ namespace MiniEngine
int Window::setOpacity(float opacity) int Window::setOpacity(float opacity)
{ {
#if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5)
return SDL_SetWindowOpacity(_get(),opacity); return SDL_SetWindowOpacity(_get(),opacity);
#else
return -1;
#endif
} }
float Window::getOpacity() const float Window::getOpacity() const
{ {
#if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5)
float op=-1; float op=-1;
SDL_GetWindowOpacity(_get(),&op); SDL_GetWindowOpacity(_get(),&op);
return op; return op;
#else
return -1;
#endif
} }
void Window::setResizable(bool resizable) void Window::setResizable(bool resizable)
@ -1719,46 +1726,55 @@ namespace MiniEngine
_clear(); _clear();
} }
//static
int SDLSystem::SDLInit() int SDLSystem::SDLInit()
{ {
return SDL_Init(SDL_INIT_EVERYTHING); return SDL_Init(SDL_INIT_EVERYTHING);
} }
//static
void SDLSystem::SDLQuit() void SDLSystem::SDLQuit()
{ {
SDL_Quit(); SDL_Quit();
} }
//static
int SDLSystem::IMGInit() int SDLSystem::IMGInit()
{ {
return IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG); return IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
} }
//static
void SDLSystem::IMGQuit() void SDLSystem::IMGQuit()
{ {
IMG_Quit(); IMG_Quit();
} }
//static
int SDLSystem::TTFInit() int SDLSystem::TTFInit()
{ {
return TTF_Init(); return TTF_Init();
} }
//static
void SDLSystem::TTFQuit() void SDLSystem::TTFQuit()
{ {
TTF_Quit(); TTF_Quit();
} }
//static
int SDLSystem::MixInit() int SDLSystem::MixInit()
{ {
return Mix_Init(MIX_INIT_MP3); return Mix_Init(MIX_INIT_MP3);
} }
//static
void SDLSystem::MixQuit() void SDLSystem::MixQuit()
{ {
Mix_Quit(); Mix_Quit();
} }
//static
void SDLSystem::Init() void SDLSystem::Init()
{ {
SDLInit(); SDLInit();
@ -1767,6 +1783,7 @@ namespace MiniEngine
MixInit(); MixInit();
} }
//static
void SDLSystem::Quit() void SDLSystem::Quit()
{ {
MixQuit(); MixQuit();
@ -1775,11 +1792,13 @@ namespace MiniEngine
SDLQuit(); SDLQuit();
} }
//static
void SDLSystem::Delay(int ms) void SDLSystem::Delay(int ms)
{ {
SDL_Delay(ms); SDL_Delay(ms);
} }
//static
PowerState SDLSystem::GetPowerState() PowerState SDLSystem::GetPowerState()
{ {
SDL_PowerState ret=SDL_GetPowerInfo(NULL,NULL); SDL_PowerState ret=SDL_GetPowerInfo(NULL,NULL);
@ -1800,6 +1819,7 @@ namespace MiniEngine
} }
} }
//static
int SDLSystem::GetPowerLifeLeft() int SDLSystem::GetPowerLifeLeft()
{ {
int i; int i;
@ -1807,6 +1827,7 @@ namespace MiniEngine
return i; return i;
} }
//static
int SDLSystem::GetPowerPrecentageLeft() int SDLSystem::GetPowerPrecentageLeft()
{ {
int i; int i;
@ -1814,6 +1835,7 @@ namespace MiniEngine
return i; return i;
} }
//static
Platform SDLSystem::GetPlatform() Platform SDLSystem::GetPlatform()
{ {
std::string s(SDL_GetPlatform()); std::string s(SDL_GetPlatform());
@ -1843,16 +1865,19 @@ namespace MiniEngine
} }
} }
//static
void SDLSystem::StartTextInput() void SDLSystem::StartTextInput()
{ {
SDL_StartTextInput(); SDL_StartTextInput();
} }
//static
bool SDLSystem::IsTextInputActive() bool SDLSystem::IsTextInputActive()
{ {
return SDL_IsTextInputActive()==SDL_TRUE; return SDL_IsTextInputActive()==SDL_TRUE;
} }
//static
void SDLSystem::StopTextInput() void SDLSystem::StopTextInput()
{ {
SDL_StopTextInput(); SDL_StopTextInput();
@ -1864,6 +1889,22 @@ namespace MiniEngine
return SDL_HasScreenKeyboardSupport()==SDL_TRUE; return SDL_HasScreenKeyboardSupport()==SDL_TRUE;
} }
//static
std::tuple<int,int,int> SDLSystem::getCompileVersion()
{
SDL_version ver;
SDL_VERSION(&ver);
return std::make_tuple(ver.major,ver.minor,ver.patch);
}
//static
std::tuple<int,int,int> SDLSystem::getLinkedVersion()
{
SDL_version ver;
SDL_GetVersion(&ver);
return std::make_tuple(ver.major,ver.minor,ver.patch);
}
/// Global Executor For class Timer /// Global Executor For class Timer
Uint32 _global_timer_executor(Uint32 interval,void* param) Uint32 _global_timer_executor(Uint32 interval,void* param)
{ {

View File

@ -5,6 +5,8 @@
#include <functional> #include <functional>
#include <vector> #include <vector>
#define _MINIENGINE_SDL_VERSION_ATLEAST(X,Y,Z) SDL_VERSION_ATLEAST(X,Y,Z)
namespace MiniEngine namespace MiniEngine
{ {
@ -328,6 +330,9 @@ namespace MiniEngine
void setGrab(bool); void setGrab(bool);
bool getGrab(); bool getGrab();
/// SDL2.0.5 Required.
/// If MiniEngine Runs on a lower version of SDL,
/// setOpacity() and getOpacity() always returns -1
int setOpacity(float opacity); int setOpacity(float opacity);
float getOpacity() const; float getOpacity() const;
@ -521,7 +526,10 @@ namespace MiniEngine
static bool IsTextInputActive(); static bool IsTextInputActive();
static void StopTextInput(); static void StopTextInput();
bool HasScreenKeyboardSupport(); static bool HasScreenKeyboardSupport();
static std::tuple<int,int,int> getCompileVersion();
static std::tuple<int,int,int> getLinkedVersion();
class Android class Android
{ {