Android Platform APIs Supported.

This commit is contained in:
Kirigaya Kazuto 2017-03-09 18:00:19 +08:00
parent 41979ef91d
commit df4d96dfed
5 changed files with 118 additions and 6 deletions

View File

@ -611,6 +611,35 @@ namespace MiniEngine
SDL_Delay(ms);
}
Platform SDLSystem::GetPlatform()
{
std::string s(SDL_GetPlatform());
if(s=="Windows")
{
return Platform::Windows;
}
else if(s=="Mac OS X")
{
return Platform::MacOS;
}
else if(s=="Linux")
{
return Platform::Linux;
}
else if(s=="iOS")
{
return Platform::iOS;
}
else if(s=="Android")
{
return Platform::Android;
}
else
{
return Platform::Unknown;
}
}
AudioPlayer::AudioPlayer()
{
if (!_sysAudioCounter)

View File

@ -219,6 +219,8 @@ namespace MiniEngine
std::shared_ptr<TTF_Font> font;
};
enum class Platform { Unknown,Windows,MacOS,Linux,iOS,Android };
class SDLSystem
{
public:
@ -235,6 +237,19 @@ namespace MiniEngine
static void Quit();
static void Delay(int ms);
static Platform GetPlatform();
class Android
{
public:
static std::string GetInternal();
static bool ExternalAvaliable();
static bool CanReadExternal();
static bool CanWriteExternal();
static std::string GetExternal();
static void* GetJNIEnv();
};
};

71
MiniEngine_Android.cpp Normal file
View File

@ -0,0 +1,71 @@
#include "MiniEngine.h"
namespace MiniEngine
{
/// Android Device
#if defined(__ANDROID__) && __ANDROID__
std::string SDLSystem::Android::GetInternal()
{
return string(SDL_AndroidGetInternalStoragePath());
}
std::string SDLSystem::Android::GetExternal()
{
return string(SDL_AndroidGetExternalStoragePath());
}
bool SDLSystem::Android::CanReadExternal()
{
return SDL_AndroidGetExternalStorageState() & SDL_ANDROID_EXTERNAL_STORAGE_READ;
}
bool SDLSystem::Android::CanWriteExternal()
{
return SDL_AndroidGetExternalStorageState() & SDL_ANDROID_EXTERNAL_STORAGE_WRITE;
}
bool SDLSystem::Android::ExternalAvaliable()
{
return SDL_AndroidGetExternalStorageState() != 0;
}
void* SDLSystem::Android::GetJNIEnv()
{
return SDL_AndroidGetJNIEnv();
}
/// Not An Android Device
#else
std::string SDLSystem::Android::GetInternal()
{
return "";
}
std::string SDLSystem::Android::GetExternal()
{
return "";
}
bool SDLSystem::Android::CanReadExternal()
{
return false;
}
bool SDLSystem::Android::CanWriteExternal()
{
return false;
}
bool SDLSystem::Android::ExternalAvaliable()
{
return false;
}
void* SDLSystem::Android::GetJNIEnv()
{
return nullptr;
}
#endif
}///End of namespace MiniEngine

View File

@ -175,17 +175,16 @@ void ButtonBase::setRect(Rect SensorArea)
void ButtonBase::draw(Brush& brush) /// virtual
{
int ret=-1;
switch(status)
{
case 1:
ret=brush.copyTo(t1,rect);
brush.copyTo(t1,rect);
break;
case 2:
ret=brush.copyTo(t2,rect);
brush.copyTo(t2,rect);
break;
case 3:
ret=brush.copyTo(t3,rect);
brush.copyTo(t3,rect);
break;
}
}

View File

@ -41,8 +41,6 @@ public:
virtual int handle(SDL_Event e,int& running,int& update)=0;
};
class ButtonBase : public Drawable, public Interactive
{
public: