2017-02-25 09:30:05 +08:00
|
|
|
#include "MiniEngine.h"
|
|
|
|
#include <algorithm>
|
2017-02-25 13:39:41 +08:00
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
2017-03-09 18:53:18 +08:00
|
|
|
#include <fstream>
|
|
|
|
|
2017-03-23 18:47:51 +08:00
|
|
|
#ifdef _MSC_VER /// Visual Studio
|
|
|
|
#define _MINIENGINE_HAS_UNISTD 0
|
|
|
|
#else
|
|
|
|
#define _MINIENGINE_HAS_UNISTD 1
|
2017-03-09 18:53:18 +08:00
|
|
|
#include <unistd.h>
|
2017-03-23 18:47:51 +08:00
|
|
|
#endif
|
|
|
|
|
2017-03-09 18:53:18 +08:00
|
|
|
#include "rapidxml/rapidxml.hpp"
|
|
|
|
#include "rapidxml/rapidxml_print.hpp"
|
|
|
|
#include "rapidxml/rapidxml_utils.hpp"
|
2017-02-25 09:30:05 +08:00
|
|
|
|
|
|
|
namespace MiniEngine
|
|
|
|
{
|
2017-04-12 09:22:15 +08:00
|
|
|
namespace _internal
|
|
|
|
{
|
|
|
|
BlendMode getBlendModeFromSDLBlendMode(SDL_BlendMode mode)
|
|
|
|
{
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case SDL_BLENDMODE_ADD:
|
|
|
|
return BlendMode::Add;
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
|
|
|
return BlendMode::Blend;
|
|
|
|
case SDL_BLENDMODE_MOD:
|
|
|
|
return BlendMode::Mod;
|
|
|
|
case SDL_BLENDMODE_NONE:
|
|
|
|
default:/// return BlendMode::None on default.
|
|
|
|
return BlendMode::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_BlendMode getSDLBlendModeFromBlendMode(BlendMode mode)
|
|
|
|
{
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case BlendMode::Add:
|
|
|
|
return SDL_BLENDMODE_ADD;
|
|
|
|
case BlendMode::Blend:
|
|
|
|
return SDL_BLENDMODE_BLEND;
|
|
|
|
case BlendMode::Mod:
|
|
|
|
return SDL_BLENDMODE_MOD;
|
|
|
|
case BlendMode::None:
|
|
|
|
default:/// return SDL_BLENDMODE_NONE on default.
|
|
|
|
return SDL_BLENDMODE_NONE;
|
|
|
|
}
|
|
|
|
}
|
2017-04-21 11:25:08 +08:00
|
|
|
|
2017-05-16 22:33:21 +08:00
|
|
|
/// FIXME: return SDL_WindowFlags or Uint32 ?
|
|
|
|
Uint32 getSDLWindowFlagsFromWindowType(WindowType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case WindowType::FullScreen:
|
|
|
|
return SDL_WINDOW_FULLSCREEN;
|
|
|
|
case WindowType::OpenGL:
|
|
|
|
return SDL_WINDOW_OPENGL;
|
|
|
|
case WindowType::Shown:
|
|
|
|
return SDL_WINDOW_SHOWN;
|
|
|
|
case WindowType::Hidden:
|
|
|
|
return SDL_WINDOW_HIDDEN;
|
|
|
|
case WindowType::Borderless:
|
|
|
|
return SDL_WINDOW_BORDERLESS;
|
|
|
|
case WindowType::Resizable:
|
|
|
|
return SDL_WINDOW_RESIZABLE;
|
|
|
|
case WindowType::Minimized:
|
|
|
|
return SDL_WINDOW_MINIMIZED;
|
|
|
|
case WindowType::Maximized:
|
|
|
|
return SDL_WINDOW_MAXIMIZED;
|
|
|
|
case WindowType::InputGrabbed:
|
|
|
|
return SDL_WINDOW_INPUT_GRABBED;
|
|
|
|
case WindowType::InputFocus:
|
|
|
|
return SDL_WINDOW_INPUT_FOCUS;
|
|
|
|
case WindowType::MouseFocus:
|
|
|
|
return SDL_WINDOW_MOUSE_FOCUS;
|
|
|
|
case WindowType::FullScreenDesktop:
|
|
|
|
return SDL_WINDOW_FULLSCREEN_DESKTOP;
|
|
|
|
case WindowType::Foreign:
|
|
|
|
return SDL_WINDOW_FOREIGN;
|
|
|
|
case WindowType::AllowHighDPI:
|
|
|
|
return SDL_WINDOW_ALLOW_HIGHDPI;
|
|
|
|
case WindowType::MouseCapture:
|
|
|
|
return SDL_WINDOW_MOUSE_CAPTURE;
|
2017-05-24 03:09:27 +08:00
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
#if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5) /// SDL 2.0.5 Required
|
2017-05-16 22:33:21 +08:00
|
|
|
case WindowType::AlwaysOnTop:
|
|
|
|
return SDL_WINDOW_ALWAYS_ON_TOP;
|
|
|
|
case WindowType::SkipTaskBar:
|
|
|
|
return SDL_WINDOW_SKIP_TASKBAR;
|
|
|
|
case WindowType::Utility:
|
|
|
|
return SDL_WINDOW_UTILITY;
|
|
|
|
case WindowType::ToolTip:
|
|
|
|
return SDL_WINDOW_TOOLTIP;
|
|
|
|
case WindowType::PopUpMenu:
|
|
|
|
return SDL_WINDOW_POPUP_MENU;
|
2017-06-01 22:50:17 +08:00
|
|
|
#endif // End of SDL2.0.5 Require
|
2017-05-24 03:09:27 +08:00
|
|
|
|
2017-05-16 22:33:21 +08:00
|
|
|
default:
|
|
|
|
return 0;/// Return 0 on default.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 11:25:08 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2017-05-16 16:23:40 +08:00
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
int getTTFFontStyleFromFontStyle(FontStyle style)
|
2017-05-16 16:23:40 +08:00
|
|
|
{
|
|
|
|
switch(style)
|
|
|
|
{
|
2017-06-05 14:07:57 +08:00
|
|
|
case FontStyle::Bold:
|
2017-05-16 16:23:40 +08:00
|
|
|
return TTF_STYLE_BOLD;
|
2017-06-05 14:07:57 +08:00
|
|
|
case FontStyle::Italic:
|
2017-05-16 16:23:40 +08:00
|
|
|
return TTF_STYLE_ITALIC;
|
2017-06-05 14:07:57 +08:00
|
|
|
case FontStyle::Normal:
|
2017-05-16 16:23:40 +08:00
|
|
|
return TTF_STYLE_NORMAL;
|
2017-06-05 14:07:57 +08:00
|
|
|
case FontStyle::StrikeThrough:
|
2017-05-16 16:23:40 +08:00
|
|
|
return TTF_STYLE_STRIKETHROUGH;
|
2017-06-05 14:07:57 +08:00
|
|
|
case FontStyle::UnderLine:
|
2017-05-16 16:23:40 +08:00
|
|
|
return TTF_STYLE_UNDERLINE;
|
|
|
|
default:
|
|
|
|
return TTF_STYLE_NORMAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
std::vector<FontStyle> getFontStyleVecFromMixedTTFFontStyle(int Mixed_TTF_Font_Style)
|
2017-05-16 16:23:40 +08:00
|
|
|
{
|
2017-06-05 14:07:57 +08:00
|
|
|
std::vector<FontStyle> vec;
|
2017-05-16 16:23:40 +08:00
|
|
|
if(Mixed_TTF_Font_Style&TTF_STYLE_BOLD)
|
|
|
|
{
|
2017-06-05 14:07:57 +08:00
|
|
|
vec.push_back(FontStyle::Bold);
|
2017-05-16 16:23:40 +08:00
|
|
|
}
|
|
|
|
if(Mixed_TTF_Font_Style&TTF_STYLE_ITALIC)
|
|
|
|
{
|
2017-06-05 14:07:57 +08:00
|
|
|
vec.push_back(FontStyle::Italic);
|
2017-05-16 16:23:40 +08:00
|
|
|
}
|
|
|
|
if(Mixed_TTF_Font_Style&TTF_STYLE_STRIKETHROUGH)
|
|
|
|
{
|
2017-06-05 14:07:57 +08:00
|
|
|
vec.push_back(FontStyle::StrikeThrough);
|
2017-05-16 16:23:40 +08:00
|
|
|
}
|
|
|
|
if(Mixed_TTF_Font_Style&TTF_STYLE_UNDERLINE)
|
|
|
|
{
|
2017-06-05 14:07:57 +08:00
|
|
|
vec.push_back(FontStyle::UnderLine);
|
2017-05-16 16:23:40 +08:00
|
|
|
}
|
|
|
|
if(vec.empty())
|
|
|
|
{
|
2017-06-05 14:07:57 +08:00
|
|
|
vec.push_back(FontStyle::Normal);
|
2017-05-16 16:23:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
2017-06-07 20:11:28 +08:00
|
|
|
|
|
|
|
SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode)
|
|
|
|
{
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case FlipMode::None:
|
|
|
|
return SDL_FLIP_NONE;
|
|
|
|
case FlipMode::Horizontal:
|
|
|
|
return SDL_FLIP_HORIZONTAL;
|
|
|
|
case FlipMode::Vertical:
|
|
|
|
return SDL_FLIP_VERTICAL;
|
|
|
|
default:
|
|
|
|
/// return non-flip mode on default.
|
|
|
|
return SDL_FLIP_NONE;
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 09:22:15 +08:00
|
|
|
}/// End of namespace _internal
|
|
|
|
|
2017-05-09 10:53:02 +08:00
|
|
|
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
ColorMode::ColorMode(int R, int G, int B)
|
|
|
|
{
|
|
|
|
r = R;
|
|
|
|
g = G;
|
|
|
|
b = B;
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorMode::ColorMode()
|
|
|
|
{
|
|
|
|
r = g = b = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ErrorViewer::fetch()
|
|
|
|
{
|
|
|
|
str = SDL_GetError();
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
std::string ErrorViewer::getError() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * ErrorViewer::what() const throw()
|
|
|
|
{
|
|
|
|
return str.c_str();
|
|
|
|
}
|
|
|
|
|
2017-04-12 08:40:12 +08:00
|
|
|
// private
|
|
|
|
void RWOP::_set(SDL_RWops* p)
|
|
|
|
{
|
|
|
|
_op.reset(p,[](SDL_RWops* p){SDL_RWclose(p);});
|
|
|
|
}
|
|
|
|
|
|
|
|
// private
|
2017-05-23 13:05:09 +08:00
|
|
|
SDL_RWops* RWOP::_get() const
|
2017-04-12 08:40:12 +08:00
|
|
|
{
|
|
|
|
return _op.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RWOP::_clear()
|
|
|
|
{
|
|
|
|
_op.reset();
|
|
|
|
}
|
|
|
|
|
2017-04-10 15:27:24 +08:00
|
|
|
RWOP::RWOP(FILE* fp,bool autoclose)
|
|
|
|
{
|
|
|
|
SDL_bool b=autoclose?SDL_TRUE:SDL_FALSE;
|
2017-04-12 08:40:12 +08:00
|
|
|
_set(SDL_RWFromFP(fp,b));
|
2017-04-10 15:27:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RWOP::RWOP(const std::string& filename,const std::string& openmode)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
_set(SDL_RWFromFile(filename.c_str(),openmode.c_str()));
|
2017-04-10 15:27:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RWOP::RWOP(const void* mem,int size)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
_set(SDL_RWFromConstMem(mem,size));
|
2017-04-10 15:27:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RWOP::RWOP(void* mem,int size)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
_set(SDL_RWFromMem(mem,size));
|
|
|
|
}
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
void RWOP::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
|
|
|
|
2017-05-25 18:34:59 +08:00
|
|
|
|
2017-05-23 13:05:09 +08:00
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
|
2017-04-12 08:40:12 +08:00
|
|
|
|
2017-06-07 19:40:21 +08:00
|
|
|
|
2017-04-21 11:25:08 +08:00
|
|
|
|
2017-04-22 10:33:18 +08:00
|
|
|
|
2017-06-12 13:01:28 +08:00
|
|
|
WindowMessageBoxButton::WindowMessageBoxButton()
|
|
|
|
{
|
|
|
|
_hitoption=0;
|
|
|
|
text="Button";
|
|
|
|
callback=[](){};
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowMessageBoxButton::WindowMessageBoxButton(const std::string& ButtonText,const std::function<void()>& CallbackFunc) : text(ButtonText)
|
|
|
|
{
|
|
|
|
_hitoption=0;
|
|
|
|
callback=CallbackFunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowMessageBoxButton::setHitAsEscape(bool enable)
|
|
|
|
{
|
|
|
|
_hitoption=enable?1:0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowMessageBoxButton::setHitAsReturn(bool enable)
|
|
|
|
{
|
|
|
|
_hitoption=enable?2:0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowMessageBoxButton::isHitAsEscape() const
|
|
|
|
{
|
|
|
|
return _hitoption==1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowMessageBoxButton::isHitAsReturn() const
|
|
|
|
{
|
|
|
|
return _hitoption==2;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowMessageBox::WindowMessageBox()
|
|
|
|
{
|
|
|
|
boxtype=MessageBoxType::Information;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowMessageBox::WindowMessageBox(const std::string& Title,const std::string& Text,MessageBoxType BoxType,const std::function<void()>& DefaultCallback) : title(Title), text(Text)
|
|
|
|
{
|
|
|
|
boxtype=BoxType;
|
|
|
|
defaultcallback=DefaultCallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowMessageBox::addButton(const WindowMessageBoxButton& button)
|
|
|
|
{
|
|
|
|
_vec.push_back(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
int WindowMessageBox::getButtonNum() const
|
|
|
|
{
|
|
|
|
return _vec.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowMessageBoxButton& WindowMessageBox::getButton(int index)
|
|
|
|
{
|
|
|
|
return _vec.at(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
const WindowMessageBoxButton& WindowMessageBox::getButtonConst(int index) const
|
|
|
|
{
|
|
|
|
return _vec.at(index);
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
|
|
|
|
// private
|
2017-06-15 13:53:04 +08:00
|
|
|
Uint32 Renderer::_rendertype_caster(RendererType Type)
|
2017-04-05 11:16:44 +08:00
|
|
|
{
|
|
|
|
switch(Type)
|
|
|
|
{
|
|
|
|
case RendererType::Accelerated:
|
|
|
|
return SDL_RENDERER_ACCELERATED;
|
|
|
|
case RendererType::PresentSync:
|
|
|
|
return SDL_RENDERER_PRESENTVSYNC;
|
|
|
|
case RendererType::Software:
|
|
|
|
return SDL_RENDERER_SOFTWARE;
|
|
|
|
case RendererType::TargetTexture:
|
|
|
|
return SDL_RENDERER_TARGETTEXTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// If an error occurs, return 0 by default.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
// private
|
2017-06-15 13:53:04 +08:00
|
|
|
int Renderer::_createRenderer_Real(Window& wnd,Uint32 flags)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-06-15 13:53:04 +08:00
|
|
|
SDL_Renderer* pSDLRnd=SDL_CreateRenderer(wnd._get(), -1, flags);
|
|
|
|
if(pSDLRnd!=nullptr)
|
|
|
|
{
|
|
|
|
_set(pSDLRnd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Window::showSimpleMessageBox(MessageBoxType type,const std::string& Title,const std::string& Message) const
|
2017-03-21 13:58:48 +08:00
|
|
|
{
|
|
|
|
Uint32 flags=0;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case MessageBoxType::Error:
|
|
|
|
flags=SDL_MESSAGEBOX_ERROR;
|
|
|
|
break;
|
|
|
|
case MessageBoxType::Information:
|
|
|
|
flags=SDL_MESSAGEBOX_INFORMATION;
|
|
|
|
break;
|
|
|
|
case MessageBoxType::Warning:
|
|
|
|
flags=SDL_MESSAGEBOX_WARNING;
|
|
|
|
break;
|
|
|
|
}
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_ShowSimpleMessageBox(flags,Title.c_str(),Message.c_str(),_get());
|
|
|
|
}
|
|
|
|
|
2017-06-12 13:01:28 +08:00
|
|
|
int Window::showMessageBox(const WindowMessageBox& box) const
|
|
|
|
{
|
|
|
|
SDL_MessageBoxData mboxdata;
|
|
|
|
mboxdata.title=box.title.c_str();
|
|
|
|
mboxdata.message=box.text.c_str();
|
|
|
|
mboxdata.window=_get();
|
|
|
|
mboxdata.colorScheme=nullptr;
|
|
|
|
mboxdata.numbuttons=box.getButtonNum();
|
|
|
|
SDL_MessageBoxButtonData* pButtonArr=(SDL_MessageBoxButtonData*)malloc(sizeof(SDL_MessageBoxButtonData)*(mboxdata.numbuttons));
|
|
|
|
if(pButtonArr==nullptr)
|
|
|
|
{
|
|
|
|
/// Failed to malloc
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
for(int i=0;i<mboxdata.numbuttons;i++)
|
|
|
|
{
|
|
|
|
pButtonArr[i].buttonid=i+1;
|
|
|
|
pButtonArr[i].text=box.getButtonConst(i).text.c_str();
|
|
|
|
pButtonArr[i].flags=
|
|
|
|
(box.getButtonConst(i).isHitAsEscape()) ? SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
|
|
|
|
:(
|
|
|
|
(box.getButtonConst(i).isHitAsReturn()) ?SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
|
|
|
|
:0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
mboxdata.buttons=pButtonArr;
|
|
|
|
switch(box.boxtype)
|
|
|
|
{
|
|
|
|
case MessageBoxType::Error:
|
|
|
|
mboxdata.flags=SDL_MESSAGEBOX_ERROR;
|
2017-06-18 17:36:13 +08:00
|
|
|
break;
|
|
|
|
case MessageBoxType::Information:
|
|
|
|
mboxdata.flags=SDL_MESSAGEBOX_INFORMATION;
|
|
|
|
break;
|
|
|
|
case MessageBoxType::Warning:
|
|
|
|
mboxdata.flags=SDL_MESSAGEBOX_WARNING;
|
|
|
|
break;
|
|
|
|
}
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-06-18 17:36:13 +08:00
|
|
|
int clickret=-2;
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-06-18 17:36:13 +08:00
|
|
|
/// Call SDL2 to show MessageBox.
|
|
|
|
int ret=SDL_ShowMessageBox(&mboxdata,&clickret);
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-06-18 17:36:13 +08:00
|
|
|
if(ret==0)
|
|
|
|
{
|
|
|
|
/// Success.
|
|
|
|
if(clickret>=1)
|
|
|
|
{
|
|
|
|
/// If any button is clicked, call the callback function associated with it.
|
|
|
|
if(box.getButtonConst(clickret-1).callback)
|
|
|
|
{
|
|
|
|
box.getButtonConst(clickret-1).callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/// ... else, call the default callback
|
|
|
|
if(box.defaultcallback) box.defaultcallback();
|
|
|
|
}
|
|
|
|
}
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-06-18 17:36:13 +08:00
|
|
|
/// Free allocated memory
|
|
|
|
free(pButtonArr);
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-06-18 17:36:13 +08:00
|
|
|
return ret;
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-18 17:36:13 +08:00
|
|
|
bool Window::isScreenKeyboardShown()
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
2017-06-18 17:36:13 +08:00
|
|
|
return SDL_IsScreenKeyboardShown(_get())==SDL_TRUE;
|
2017-06-05 14:07:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
|
2017-03-24 13:50:48 +08:00
|
|
|
void LogSystem::d(const char* fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap,fmt);
|
|
|
|
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_DEBUG,fmt,ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogSystem::v(const char* fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap,fmt);
|
|
|
|
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_VERBOSE,fmt,ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogSystem::e(const char* fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap,fmt);
|
|
|
|
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_ERROR,fmt,ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogSystem::i(const char* fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap,fmt);
|
|
|
|
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,fmt,ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogSystem::w(const char* fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap,fmt);
|
|
|
|
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_WARN,fmt,ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogSystem::critical(const char* fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap,fmt);
|
|
|
|
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_CRITICAL,fmt,ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
2017-05-11 11:53:26 +08:00
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
//private
|
|
|
|
void* SharedLibrary::_get() const
|
2017-05-18 18:14:29 +08:00
|
|
|
{
|
|
|
|
return _obj.get();
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
//private
|
2017-05-18 18:14:29 +08:00
|
|
|
void SharedLibrary::_set(void* ptr)
|
|
|
|
{
|
|
|
|
_obj.reset(ptr,SDL_UnloadObject);
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
//private
|
2017-05-18 18:14:29 +08:00
|
|
|
void SharedLibrary::_clear()
|
|
|
|
{
|
|
|
|
_obj.reset();
|
|
|
|
}
|
|
|
|
|
2017-05-11 11:53:26 +08:00
|
|
|
SharedLibrary::SharedLibrary()
|
|
|
|
{
|
|
|
|
_obj=nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedLibrary::SharedLibrary(const std::string& Filename)
|
|
|
|
{
|
|
|
|
_obj=nullptr;
|
|
|
|
load(Filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SharedLibrary::load(const std::string& Filename)
|
|
|
|
{
|
2017-05-18 18:14:29 +08:00
|
|
|
if(_get()!=nullptr) return -1; /// Loaded
|
2017-05-11 11:53:26 +08:00
|
|
|
else
|
|
|
|
{
|
2017-05-18 18:14:29 +08:00
|
|
|
void* ptr=SDL_LoadObject(Filename.c_str());
|
|
|
|
if(ptr)
|
|
|
|
{
|
|
|
|
_set(ptr);
|
|
|
|
return 0; /// Success
|
|
|
|
}
|
|
|
|
else return -2; /// Failed to load
|
2017-05-11 11:53:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int SharedLibrary::unload()
|
|
|
|
{
|
2017-05-18 18:14:29 +08:00
|
|
|
if(_get()!=nullptr)
|
2017-05-11 11:53:26 +08:00
|
|
|
{
|
2017-05-18 18:14:29 +08:00
|
|
|
_clear();
|
|
|
|
return 0; /// Success to unload
|
2017-05-11 11:53:26 +08:00
|
|
|
}
|
2017-05-18 18:14:29 +08:00
|
|
|
else return -1; /// Not Loaded.
|
2017-05-11 11:53:26 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
void* SharedLibrary::get(const std::string& FunctionName) const
|
2017-05-11 11:53:26 +08:00
|
|
|
{
|
2017-05-18 18:14:29 +08:00
|
|
|
if(_get()==nullptr) return nullptr;
|
|
|
|
else return SDL_LoadFunction(_get(),FunctionName.c_str());
|
2017-05-11 11:53:26 +08:00
|
|
|
}
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
void SharedLibrary::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
2017-03-24 13:50:48 +08:00
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
int SDLSystem::SDLInit()
|
|
|
|
{
|
|
|
|
return SDL_Init(SDL_INIT_EVERYTHING);
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
void SDLSystem::SDLQuit()
|
|
|
|
{
|
|
|
|
SDL_Quit();
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
int SDLSystem::IMGInit()
|
|
|
|
{
|
|
|
|
return IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
void SDLSystem::IMGQuit()
|
|
|
|
{
|
|
|
|
IMG_Quit();
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
int SDLSystem::TTFInit()
|
|
|
|
{
|
|
|
|
return TTF_Init();
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
void SDLSystem::TTFQuit()
|
|
|
|
{
|
|
|
|
TTF_Quit();
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
int SDLSystem::MixInit()
|
|
|
|
{
|
|
|
|
return Mix_Init(MIX_INIT_MP3);
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
void SDLSystem::MixQuit()
|
|
|
|
{
|
|
|
|
Mix_Quit();
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
void SDLSystem::Init()
|
|
|
|
{
|
|
|
|
SDLInit();
|
|
|
|
IMGInit();
|
|
|
|
TTFInit();
|
|
|
|
MixInit();
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
void SDLSystem::Quit()
|
|
|
|
{
|
|
|
|
MixQuit();
|
|
|
|
TTFQuit();
|
|
|
|
IMGQuit();
|
|
|
|
SDLQuit();
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-02-25 09:30:05 +08:00
|
|
|
void SDLSystem::Delay(int ms)
|
|
|
|
{
|
|
|
|
SDL_Delay(ms);
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-03-21 12:30:29 +08:00
|
|
|
PowerState SDLSystem::GetPowerState()
|
|
|
|
{
|
|
|
|
SDL_PowerState ret=SDL_GetPowerInfo(NULL,NULL);
|
|
|
|
switch(ret)
|
|
|
|
{
|
|
|
|
case SDL_POWERSTATE_ON_BATTERY:
|
|
|
|
return PowerState::OnBattery;
|
|
|
|
case SDL_POWERSTATE_NO_BATTERY:
|
|
|
|
return PowerState::NoBattery;
|
|
|
|
case SDL_POWERSTATE_CHARGING:
|
|
|
|
return PowerState::Charging;
|
|
|
|
case SDL_POWERSTATE_CHARGED:
|
|
|
|
return PowerState::Charged;
|
|
|
|
|
|
|
|
case SDL_POWERSTATE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
return PowerState::Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-04-12 09:26:03 +08:00
|
|
|
int SDLSystem::GetPowerLifeLeft()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
SDL_GetPowerInfo(&i,NULL);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-04-12 09:26:03 +08:00
|
|
|
int SDLSystem::GetPowerPrecentageLeft()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
SDL_GetPowerInfo(NULL,&i);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-03-09 18:00:19 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-03-24 11:07:27 +08:00
|
|
|
void SDLSystem::StartTextInput()
|
|
|
|
{
|
|
|
|
SDL_StartTextInput();
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-05-22 18:47:28 +08:00
|
|
|
bool SDLSystem::IsTextInputActive()
|
|
|
|
{
|
|
|
|
return SDL_IsTextInputActive()==SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-03-24 11:07:27 +08:00
|
|
|
void SDLSystem::StopTextInput()
|
|
|
|
{
|
|
|
|
SDL_StopTextInput();
|
|
|
|
}
|
|
|
|
|
2017-05-22 18:47:28 +08:00
|
|
|
//static
|
|
|
|
bool SDLSystem::HasScreenKeyboardSupport()
|
|
|
|
{
|
|
|
|
return SDL_HasScreenKeyboardSupport()==SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2017-06-01 22:50:17 +08:00
|
|
|
//static
|
2017-06-06 22:56:07 +08:00
|
|
|
std::tuple<int,int,int> SDLSystem::GetSDLCompileVersion()
|
2017-06-01 22:50:17 +08:00
|
|
|
{
|
|
|
|
SDL_version ver;
|
|
|
|
SDL_VERSION(&ver);
|
|
|
|
return std::make_tuple(ver.major,ver.minor,ver.patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
2017-06-06 22:56:07 +08:00
|
|
|
std::tuple<int,int,int> SDLSystem::GetSDLLinkedVersion()
|
2017-06-01 22:50:17 +08:00
|
|
|
{
|
|
|
|
SDL_version ver;
|
|
|
|
SDL_GetVersion(&ver);
|
|
|
|
return std::make_tuple(ver.major,ver.minor,ver.patch);
|
|
|
|
}
|
2017-06-06 22:56:07 +08:00
|
|
|
//static
|
|
|
|
std::tuple<int,int,int> SDLSystem::GetIMGCompileVersion()
|
|
|
|
{
|
|
|
|
SDL_version ver;
|
|
|
|
SDL_IMAGE_VERSION(&ver);
|
|
|
|
return std::make_tuple(ver.major,ver.minor,ver.patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::tuple<int,int,int> SDLSystem::GetIMGLinkedVersion()
|
|
|
|
{
|
|
|
|
const SDL_version* ptr=IMG_Linked_Version();
|
2017-06-07 12:17:36 +08:00
|
|
|
return std::make_tuple(ptr->major,ptr->minor,ptr->patch);
|
2017-06-06 22:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::tuple<int,int,int> SDLSystem::GetMixCompileVersion()
|
|
|
|
{
|
|
|
|
SDL_version ver;
|
|
|
|
SDL_MIXER_VERSION(&ver);
|
|
|
|
return std::make_tuple(ver.major,ver.minor,ver.patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::tuple<int,int,int> SDLSystem::GetMixLinkedVersion()
|
|
|
|
{
|
|
|
|
const SDL_version* ptr=Mix_Linked_Version();
|
|
|
|
return std::make_tuple(ptr->major,ptr->minor,ptr->patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::tuple<int,int,int> SDLSystem::GetTTFCompileVersion()
|
|
|
|
{
|
|
|
|
SDL_version ver;
|
|
|
|
SDL_TTF_VERSION(&ver);
|
|
|
|
return std::make_tuple(ver.major,ver.minor,ver.patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::tuple<int,int,int> SDLSystem::GetTTFLinkedVersion()
|
|
|
|
{
|
|
|
|
const SDL_version* ptr=TTF_Linked_Version();
|
|
|
|
return std::make_tuple(ptr->major,ptr->minor,ptr->patch);
|
|
|
|
}
|
2017-06-01 22:50:17 +08:00
|
|
|
|
2017-06-07 20:37:54 +08:00
|
|
|
//static
|
|
|
|
int SDLSystem::GetCPUCount()
|
|
|
|
{
|
|
|
|
return SDL_GetCPUCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
int SDLSystem::GetCPUCacheLineSize()
|
|
|
|
{
|
|
|
|
return SDL_GetCPUCacheLineSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
int SDLSystem::GetSystemRAM()
|
|
|
|
{
|
|
|
|
return SDL_GetSystemRAM();
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-06-14 20:50:12 +08:00
|
|
|
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-03-09 18:53:18 +08:00
|
|
|
struct StringEngine::impl
|
|
|
|
{
|
|
|
|
rapidxml::xml_document<> doc;
|
|
|
|
rapidxml::xml_node<>* root;
|
|
|
|
bool status;
|
|
|
|
};
|
|
|
|
|
|
|
|
StringEngine::StringEngine(std::string StringFile,std::string LanguageTag)
|
|
|
|
{
|
|
|
|
pimpl=new impl;
|
|
|
|
pimpl->status=false;
|
2017-05-18 13:04:20 +08:00
|
|
|
|
2017-03-09 18:53:18 +08:00
|
|
|
std::ifstream ifs(StringFile);
|
|
|
|
if(!ifs) return;
|
|
|
|
rapidxml::file<> strFile(ifs);
|
|
|
|
pimpl->doc.parse<0>(strFile.data());
|
|
|
|
pimpl->root=pimpl->doc.first_node(LanguageTag.c_str());
|
|
|
|
if(pimpl->root==nullptr) return;
|
|
|
|
|
|
|
|
pimpl->status=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StringEngine::ready()
|
|
|
|
{
|
|
|
|
return pimpl->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int StringEngine::useLanaguage(std::string LanguageTag)
|
|
|
|
{
|
|
|
|
pimpl->root=pimpl->doc.first_node(LanguageTag.c_str());
|
|
|
|
if(pimpl->root==nullptr)
|
|
|
|
{
|
|
|
|
pimpl->status=false;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pimpl->status=true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string StringEngine::getString(std::string Tag)
|
|
|
|
{
|
2017-05-18 13:04:20 +08:00
|
|
|
if(!ready()) return "(StringEngine::STRING_NOT_FOUND)";
|
|
|
|
rapidxml::xml_node<>* pnode=pimpl->root->first_node(Tag.c_str());
|
|
|
|
if(pnode==nullptr) return "(StringEngine::STRING_NOT_FOUND)";
|
|
|
|
char* context=pnode->value();
|
|
|
|
if(context==nullptr) return "";/// Empty String.
|
2017-03-09 18:53:18 +08:00
|
|
|
else return std::string(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringEngine::~StringEngine()
|
|
|
|
{
|
|
|
|
delete pimpl;
|
|
|
|
}
|
|
|
|
|
2017-05-22 18:27:56 +08:00
|
|
|
int SetClipboardText(const std::string& str)
|
|
|
|
{
|
|
|
|
return SDL_SetClipboardText(str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetClipboardText()
|
|
|
|
{
|
|
|
|
char* pstr=SDL_GetClipboardText();
|
|
|
|
if(pstr==nullptr)
|
|
|
|
{
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string s(pstr);
|
|
|
|
SDL_free(pstr);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasClipboardText()
|
|
|
|
{
|
|
|
|
return SDL_HasClipboardText()==SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2017-05-22 18:47:28 +08:00
|
|
|
bool GetScanKeyState(SDL_Scancode code)
|
|
|
|
{
|
|
|
|
return SDL_GetKeyboardState(NULL)[code];
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
}/// End of namespace MiniEngine
|
|
|
|
|
2017-03-23 12:22:02 +08:00
|
|
|
/// The Following Functions are not avaliable in Visual Studio
|
2017-03-23 18:47:51 +08:00
|
|
|
#if (_MINIENGINE_HAS_UNISTD == 1)
|
2017-03-09 18:53:18 +08:00
|
|
|
bool isexist(std::string Path)
|
|
|
|
{
|
|
|
|
return access(Path.c_str(),F_OK)==0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canread(std::string Path)
|
|
|
|
{
|
|
|
|
return access(Path.c_str(),R_OK)==0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canwrite(std::string Path)
|
|
|
|
{
|
|
|
|
return access(Path.c_str(),W_OK)==0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canexecute(std::string Path)
|
|
|
|
{
|
|
|
|
return access(Path.c_str(),X_OK)==0;
|
|
|
|
}
|
2017-03-23 19:28:06 +08:00
|
|
|
#else /// _MINIENGINE_HAS_UNISTD == 0
|
2017-03-23 18:47:51 +08:00
|
|
|
/// File Functions will be implied in platform specific source file.
|
|
|
|
#endif
|
2017-03-09 18:53:18 +08:00
|
|
|
|
2017-03-30 11:16:57 +08:00
|
|
|
int _miniengine_argc;
|
|
|
|
char** _miniengine_argv;
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
/// Default Setup Code
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2017-03-30 11:16:57 +08:00
|
|
|
_miniengine_argc=argc;
|
|
|
|
_miniengine_argv=argv;
|
2017-02-25 09:30:05 +08:00
|
|
|
MiniEngine::SDLSystem::Init();
|
|
|
|
int ret = AppMain();
|
|
|
|
MiniEngine::SDLSystem::Quit();
|
|
|
|
return ret;
|
|
|
|
}
|
2017-04-12 08:44:58 +08:00
|
|
|
|
|
|
|
int GetArgc()
|
|
|
|
{
|
|
|
|
return _miniengine_argc;
|
|
|
|
}
|
|
|
|
|
|
|
|
char** GetArgv()
|
|
|
|
{
|
|
|
|
return _miniengine_argv;
|
|
|
|
}
|