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
|
|
|
Point::Point(int X, int Y)
|
|
|
|
{
|
|
|
|
x = X;
|
|
|
|
y = Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
Point::Point()
|
|
|
|
{
|
|
|
|
x = y = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
SDL_Point Point::toSDLPoint() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
SDL_Point p;
|
|
|
|
p.x = x;
|
|
|
|
p.y = y;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
bool Point::inRect(const Rect& rect) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
auto p = toSDLPoint();
|
|
|
|
auto r = rect.toSDLRect();
|
2017-05-02 22:38:37 +08:00
|
|
|
return ( SDL_PointInRect(&p, &r) == SDL_TRUE );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
RGBA::RGBA(int R, int G, int B, int A)
|
|
|
|
{
|
|
|
|
r = R;
|
|
|
|
g = G;
|
|
|
|
b = B;
|
|
|
|
a = A;
|
|
|
|
}
|
|
|
|
|
|
|
|
RGBA::RGBA(ColorMode mode, int A)
|
|
|
|
{
|
|
|
|
r = mode.r;
|
|
|
|
g = mode.g;
|
|
|
|
b = mode.b;
|
|
|
|
a = A;
|
|
|
|
}
|
|
|
|
|
|
|
|
RGBA::RGBA()
|
|
|
|
{
|
|
|
|
r = g = b = a = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
SDL_Color RGBA::toSDLColor() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
SDL_Color c;
|
|
|
|
c.r = r;
|
|
|
|
c.g = g;
|
|
|
|
c.b = b;
|
|
|
|
c.a = a;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
ColorMode RGBA::toColorMode() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
return ColorMode(r, g, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06-05 20:43:33 +08:00
|
|
|
//private
|
|
|
|
void Texture::_set(SDL_Texture* p)
|
2017-04-12 08:40:12 +08:00
|
|
|
{
|
|
|
|
_text.reset(p,SDL_DestroyTexture);
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:52:37 +08:00
|
|
|
//private
|
|
|
|
void Texture::_set_no_delete(SDL_Texture* p)
|
|
|
|
{
|
|
|
|
_text.reset(p,[](SDL_Texture*){});
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
//private
|
|
|
|
void Texture::_clear()
|
2017-04-12 08:40:12 +08:00
|
|
|
{
|
|
|
|
_text.reset();
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
//private
|
|
|
|
SDL_Texture* Texture::_get() const
|
2017-04-12 08:40:12 +08:00
|
|
|
{
|
|
|
|
return _text.get();
|
2017-04-10 19:52:40 +08:00
|
|
|
}
|
|
|
|
|
2017-03-02 13:12:13 +08:00
|
|
|
Texture::Texture()
|
|
|
|
{
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
Rect Texture::getSize()
|
|
|
|
{
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
int Texture::getw() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
return rect.w;
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
int Texture::geth() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
return rect.h;
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
bool Texture::isReady() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return (_get() != nullptr);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Texture::setBlendMode(BlendMode mode)
|
|
|
|
{
|
2017-04-12 09:22:15 +08:00
|
|
|
return SDL_SetTextureBlendMode(_get(), _internal::getSDLBlendModeFromBlendMode(mode));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
BlendMode Texture::getBlendMode() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
SDL_BlendMode temp;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_GetTextureBlendMode(_get(), &temp);
|
2017-04-12 09:22:15 +08:00
|
|
|
return _internal::getBlendModeFromSDLBlendMode(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Alpha: 0: Transparent 255: opaque
|
|
|
|
|
|
|
|
int Texture::setAlphaMode(int alpha)
|
|
|
|
{
|
|
|
|
Uint8 temp = std::max(std::min(alpha, 255), 0);
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_SetTextureAlphaMod(_get(), temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
int Texture::getAlphaMode() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
Uint8 temp;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_GetTextureAlphaMod(_get(), &temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
ColorMode Texture::getColorMode() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
ColorMode pack;
|
|
|
|
Uint8 r, g, b;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_GetTextureColorMod(_get(), &r, &g, &b);
|
2017-02-25 09:30:05 +08:00
|
|
|
pack.r = r;
|
|
|
|
pack.g = g;
|
|
|
|
pack.b = b;
|
|
|
|
return pack;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Texture::setColorMode(ColorMode mode)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_SetTextureColorMod(_get(), mode.r, mode.g, mode.b);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 20:43:33 +08:00
|
|
|
RGBA Texture::getRGBA() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
return RGBA(getColorMode(), getAlphaMode());
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
void Texture::setRGBA(const RGBA& pack)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
setColorMode(pack.toColorMode());
|
|
|
|
setAlphaMode(pack.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// updateInfo() must be called after Texture is changed.
|
2017-06-05 20:43:33 +08:00
|
|
|
//protected
|
|
|
|
void Texture::updateInfo()
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
if(_get()==nullptr)
|
2017-03-02 13:12:13 +08:00
|
|
|
{
|
|
|
|
rect.x=rect.y=rect.w=rect.h=0;
|
|
|
|
}
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_QueryTexture(_get(), NULL, NULL, &rect.w, &rect.h);
|
2017-02-25 09:30:05 +08:00
|
|
|
rect.x = rect.y = 0;
|
|
|
|
}
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
void Texture::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:40:21 +08:00
|
|
|
//private
|
2017-04-12 08:40:12 +08:00
|
|
|
void Renderer::_set(SDL_Renderer* p)
|
|
|
|
{
|
|
|
|
_rnd.reset(p,SDL_DestroyRenderer);
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:40:21 +08:00
|
|
|
//private
|
2017-04-12 08:40:12 +08:00
|
|
|
void Renderer::_clear()
|
|
|
|
{
|
|
|
|
_rnd.reset();
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:40:21 +08:00
|
|
|
//private
|
2017-06-05 15:40:16 +08:00
|
|
|
SDL_Renderer* Renderer::_get() const
|
2017-04-12 08:40:12 +08:00
|
|
|
{
|
|
|
|
return _rnd.get();
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::setColor(const RGBA& pack)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_SetRenderDrawColor(_get(), pack.r, pack.g, pack.b, pack.a);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
RGBA Renderer::getColor() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
Uint8 r, g, b, a;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_GetRenderDrawColor(_get(), &r, &g, &b, &a);
|
2017-06-05 22:01:15 +08:00
|
|
|
return RGBA(r, g, b, a);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::setBlendMode(BlendMode mode)
|
|
|
|
{
|
2017-04-12 09:22:15 +08:00
|
|
|
return SDL_SetRenderDrawBlendMode(_get(), _internal::getSDLBlendModeFromBlendMode(mode));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
BlendMode Renderer::getBlendMode() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
SDL_BlendMode temp;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_GetRenderDrawBlendMode(_get(), &temp);
|
2017-04-12 09:22:15 +08:00
|
|
|
return _internal::getBlendModeFromSDLBlendMode(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::setTarget(Texture & t)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_SetRenderTarget(_get(), t._get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::setTarget()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_SetRenderTarget(_get(), nullptr);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-07 19:52:37 +08:00
|
|
|
Texture Renderer::getTarget()
|
|
|
|
{
|
|
|
|
Texture t;
|
|
|
|
t._set_no_delete(SDL_GetRenderTarget(_get()));
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::fillRect(const Rect& rect)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
auto inr = rect.toSDLRect();
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderFillRect(_get(), &inr);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::drawRect(const Rect& rect)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
auto inr = rect.toSDLRect();
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderDrawRect(_get(), &inr);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::drawPoint(const Point& p)
|
2017-03-14 17:29:22 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderDrawPoint(_get(),p.x,p.y);
|
2017-03-14 17:29:22 +08:00
|
|
|
}
|
|
|
|
|
2017-06-07 19:40:21 +08:00
|
|
|
int Renderer::drawLine(const Point& A,const Point& B)
|
|
|
|
{
|
|
|
|
return SDL_RenderDrawLine(_get(),A.x,A.y,B.x,B.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::fillRects(const SDL_Rect* pRectArray, int n)
|
|
|
|
{
|
|
|
|
return SDL_RenderFillRects(_get(),pRectArray,n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::drawRects(const SDL_Rect* pRectArray, int n)
|
|
|
|
{
|
|
|
|
return SDL_RenderDrawRects(_get(),pRectArray,n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::drawPoints(const SDL_Point* pPointArray, int n)
|
|
|
|
{
|
|
|
|
return SDL_RenderDrawPoints(_get(),pPointArray,n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::drawLines(const SDL_Point* pPointArray, int n)
|
|
|
|
{
|
|
|
|
return SDL_RenderDrawLines(_get(),pPointArray,n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::fillRects(const std::vector<SDL_Rect>& rectvec)
|
|
|
|
{
|
|
|
|
return fillRects(rectvec.data(),rectvec.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::drawRects(const std::vector<SDL_Rect>& rectvec)
|
|
|
|
{
|
|
|
|
return drawRects(rectvec.data(),rectvec.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::drawPoints(const std::vector<SDL_Point>& pointvec)
|
|
|
|
{
|
|
|
|
return drawPoints(pointvec.data(),pointvec.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::drawLines(const std::vector<SDL_Point>& pointvec)
|
|
|
|
{
|
|
|
|
return drawLines(pointvec.data(),pointvec.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::setScale(float scaleX, float scaleY)
|
|
|
|
{
|
|
|
|
return SDL_RenderSetScale(_get(),scaleX,scaleY);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<float,float> Renderer::getScale() const
|
|
|
|
{
|
|
|
|
float sx,sy;
|
|
|
|
SDL_RenderGetScale(_get(),&sx,&sy);
|
|
|
|
return std::make_tuple(sx,sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::setViewport(const Rect& viewport)
|
|
|
|
{
|
|
|
|
auto rect=viewport.toSDLRect();
|
|
|
|
return SDL_RenderSetViewport(_get(),&rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Renderer::getViewport() const
|
|
|
|
{
|
|
|
|
SDL_Rect rect;
|
|
|
|
SDL_RenderGetViewport(_get(),&rect);
|
|
|
|
return Rect(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::setLogicalSize(int w, int h)
|
|
|
|
{
|
|
|
|
return SDL_RenderSetLogicalSize(_get(),w,h);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Renderer::getLogicalSize() const
|
|
|
|
{
|
|
|
|
int w,h;
|
|
|
|
SDL_RenderGetLogicalSize(_get(),&w,&h);
|
|
|
|
return Rect(0,0,w,h);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::setClipRect(const Rect& cliprect)
|
|
|
|
{
|
|
|
|
auto r=cliprect.toSDLRect();
|
|
|
|
return SDL_RenderSetClipRect(_get(),&r);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Renderer::getClipRect() const
|
|
|
|
{
|
|
|
|
SDL_Rect r;
|
|
|
|
SDL_RenderGetClipRect(_get(),&r);
|
|
|
|
return Rect(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Renderer::isClipEnabled() const
|
|
|
|
{
|
|
|
|
return (SDL_RenderIsClipEnabled(_get())==SDL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Renderer::getOutputSize() const
|
|
|
|
{
|
|
|
|
int w,h;
|
|
|
|
SDL_GetRendererOutputSize(_get(),&w,&h);
|
|
|
|
return Rect(0,0,w,h);
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
int Renderer::clear()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderClear(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::update()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_RenderPresent(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::copy(const Texture& t, const Rect& src, const Rect& dst)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
SDL_Rect s = src.toSDLRect();
|
|
|
|
SDL_Rect d = dst.toSDLRect();
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderCopy(_get(), t._get(), &s, &d);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::copyTo(const Texture& t, const Rect& dst)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
SDL_Rect d = dst.toSDLRect();
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderCopy(_get(), t._get(), NULL, &d);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::copyTo(const Texture& t, const Point& lupoint)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
return copyTo(t, Rect(lupoint.x, lupoint.y, t.getw(), t.geth()));
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::copyFill(const Texture& t, const Rect& src)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
SDL_Rect s = src.toSDLRect();
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderCopy(_get(), t._get(), &s, NULL);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::copyFullFill(const Texture& t)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderCopy(_get(), t._get(), NULL, NULL);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-07 20:11:28 +08:00
|
|
|
/// ----- Super Copy Extend ----- (Begin)
|
|
|
|
int Renderer::copy(const Texture& t, const Rect& src, const Rect& dst, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
auto s=src.toSDLRect();
|
|
|
|
auto d=src.toSDLRect();
|
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),&s,&d,angle,NULL,_internal::getSDLRendererFlipFromFlipMode(mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copyTo(const Texture& t, const Rect& dst, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
auto d=dst.toSDLRect();
|
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),NULL,&d,angle,NULL,_internal::getSDLRendererFlipFromFlipMode(mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copyTo(const Texture& t, const Point& lupoint, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
return copyTo(t,Rect(lupoint.x,lupoint.y,t.getw(),t.geth()),angle,mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copyFill(const Texture& t, const Rect& src, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
auto s=src.toSDLRect();
|
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),&s,NULL,angle,NULL,_internal::getSDLRendererFlipFromFlipMode(mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copyFullFill(const Texture& t, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),NULL,NULL,angle,NULL,_internal::getSDLRendererFlipFromFlipMode(mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copy(const Texture& t, const Rect& src, const Rect& dst, const Point& centerPoint, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
auto s=src.toSDLRect();
|
|
|
|
auto d=src.toSDLRect();
|
|
|
|
auto c=centerPoint.toSDLPoint();
|
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),&s,&d,angle,&c,_internal::getSDLRendererFlipFromFlipMode(mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copyTo(const Texture& t, const Rect& dst, const Point& centerPoint, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
auto d=dst.toSDLRect();
|
|
|
|
auto c=centerPoint.toSDLPoint();
|
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),NULL,&d,angle,&c,_internal::getSDLRendererFlipFromFlipMode(mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copyTo(const Texture& t, const Point& lupoint, const Point& centerPoint, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
return copyTo(t,lupoint,centerPoint,angle,mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copyFill(const Texture& t, const Rect& src, const Point& centerPoint, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
auto s=src.toSDLRect();
|
|
|
|
auto c=centerPoint.toSDLPoint();
|
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),&s,NULL,angle,&c,_internal::getSDLRendererFlipFromFlipMode(mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::copyFullFill(const Texture& t, const Point& centerPoint, double angle, FlipMode mode)
|
|
|
|
{
|
|
|
|
auto c=centerPoint.toSDLPoint();
|
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),NULL,NULL,angle,&c,_internal::getSDLRendererFlipFromFlipMode(mode));
|
|
|
|
}
|
|
|
|
/// ----- Super Copy Extend ----- (End)
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
int Renderer::supercopy(const Texture& t,
|
|
|
|
bool srcfull,const Rect& src,bool dstfull,const Rect& dst,
|
|
|
|
double angle,
|
|
|
|
bool haspoint,const Point& center,FlipMode mode)
|
2017-03-21 17:03:03 +08:00
|
|
|
{
|
|
|
|
SDL_Rect R1,R2;
|
|
|
|
SDL_Point P;
|
|
|
|
SDL_Rect* pR1=nullptr;
|
|
|
|
SDL_Rect* pR2=nullptr;
|
|
|
|
SDL_Point* pPoint=nullptr;
|
|
|
|
SDL_RendererFlip flip;
|
|
|
|
if(srcfull)
|
|
|
|
{
|
|
|
|
R1=src.toSDLRect();
|
|
|
|
pR1=&R1;
|
|
|
|
}
|
|
|
|
if(dstfull)
|
|
|
|
{
|
|
|
|
R2=dst.toSDLRect();
|
|
|
|
pR2=&R2;
|
|
|
|
}
|
|
|
|
if(haspoint)
|
|
|
|
{
|
|
|
|
P=center.toSDLPoint();
|
|
|
|
pPoint=&P;
|
|
|
|
}
|
|
|
|
|
2017-06-07 20:11:28 +08:00
|
|
|
flip=_internal::getSDLRendererFlipFromFlipMode(mode);
|
2017-03-21 17:03:03 +08:00
|
|
|
|
2017-04-12 08:40:12 +08:00
|
|
|
return SDL_RenderCopyEx(_get(),t._get(),pR1,pR2,angle,pPoint,flip);
|
2017-03-21 17:03:03 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Renderer::render(const Surface& surf) const throw(ErrorViewer)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
Texture t;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_Texture* temp = SDL_CreateTextureFromSurface(_get(), surf._get());
|
2017-02-25 09:30:05 +08:00
|
|
|
if (temp == nullptr)
|
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
2017-04-12 08:40:12 +08:00
|
|
|
t._set(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Renderer::loadTexture(const std::string& FileName) const throw(ErrorViewer)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
Texture t;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_Texture* temp = IMG_LoadTexture(_get(), FileName.c_str());
|
2017-02-25 09:30:05 +08:00
|
|
|
if (temp == nullptr)
|
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
2017-04-12 08:40:12 +08:00
|
|
|
t._set(temp);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Renderer::loadTextureRW(const RWOP& rwop) const throw (ErrorViewer)
|
2017-04-12 08:40:12 +08:00
|
|
|
{
|
|
|
|
Texture t;
|
|
|
|
SDL_Texture* temp=IMG_LoadTexture_RW(_get(),rwop._get(),0);
|
|
|
|
if (temp == nullptr)
|
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
t._set(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Renderer::createTexture(int Width, int Height) const throw(ErrorViewer)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_Texture* temp = SDL_CreateTexture(_get(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, Width, Height);
|
2017-02-25 09:30:05 +08:00
|
|
|
if (temp == NULL)
|
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
Texture t;
|
2017-04-12 08:40:12 +08:00
|
|
|
t._set(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:40:21 +08:00
|
|
|
bool Renderer::isRenderTargetSupported() const
|
|
|
|
{
|
|
|
|
return (SDL_RenderTargetSupported(_get())==SDL_TRUE);
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
bool Renderer::isReady() const
|
2017-05-18 18:14:29 +08:00
|
|
|
{
|
|
|
|
return (_get() != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:40:21 +08:00
|
|
|
//static
|
|
|
|
int Renderer::GetDriversNum()
|
|
|
|
{
|
|
|
|
return SDL_GetNumRenderDrivers();
|
|
|
|
}
|
|
|
|
|
2017-04-21 11:25:08 +08:00
|
|
|
//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();
|
|
|
|
}
|
|
|
|
|
2017-05-22 19:17:02 +08:00
|
|
|
//private
|
2017-05-18 18:14:29 +08:00
|
|
|
void Cursor::_clear()
|
|
|
|
{
|
|
|
|
_cur.reset();
|
|
|
|
}
|
|
|
|
|
2017-05-22 19:17:02 +08:00
|
|
|
Cursor::Cursor(Surface surf,Point hotspot)
|
2017-04-21 11:25:08 +08:00
|
|
|
{
|
|
|
|
Cursor ns;
|
|
|
|
SDL_Cursor* cursor=SDL_CreateColorCursor(surf._get(),hotspot.x,hotspot.y);
|
|
|
|
ns._set(cursor);
|
|
|
|
}
|
|
|
|
|
2017-05-22 19:17:02 +08:00
|
|
|
Cursor::Cursor(SystemCursorType type)
|
2017-04-21 11:25:08 +08:00
|
|
|
{
|
|
|
|
Cursor ns;
|
|
|
|
ns._set(SDL_CreateSystemCursor(_internal::getSDLSystemCursorFromSystemCursorType(type)));
|
|
|
|
}
|
|
|
|
|
2017-04-21 22:59:25 +08:00
|
|
|
//static
|
|
|
|
Cursor Cursor::GetActiveCursor()
|
|
|
|
{
|
|
|
|
Cursor ns;
|
2017-05-22 19:17:02 +08:00
|
|
|
ns._set_no_delete(SDL_GetCursor());
|
2017-04-21 22:59:25 +08:00
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
Cursor Cursor::GetDefaultCursor()
|
|
|
|
{
|
|
|
|
Cursor ns;
|
2017-05-22 19:17:02 +08:00
|
|
|
ns._set_no_delete(SDL_GetDefaultCursor());
|
2017-04-21 22:59:25 +08:00
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
2017-04-21 11:25:08 +08:00
|
|
|
//static
|
|
|
|
bool Cursor::isShow()
|
|
|
|
{
|
|
|
|
return (SDL_ShowCursor(SDL_QUERY)==SDL_ENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
2017-05-22 19:17:02 +08:00
|
|
|
void Cursor::setShow(bool Settings)
|
2017-04-21 11:25:08 +08:00
|
|
|
{
|
|
|
|
SDL_ShowCursor(Settings?SDL_ENABLE:SDL_DISABLE);
|
|
|
|
}
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
void Cursor::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
|
|
|
|
2017-04-22 10:33:18 +08:00
|
|
|
void Cursor::activate()
|
|
|
|
{
|
2017-05-22 19:17:02 +08:00
|
|
|
if(_get()!=nullptr)
|
|
|
|
{
|
|
|
|
SDL_SetCursor(_get());
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//private
|
2017-04-12 08:40:12 +08:00
|
|
|
void Window::_set(SDL_Window* p)
|
|
|
|
{
|
|
|
|
_wnd.reset(p,SDL_DestroyWindow);
|
|
|
|
}
|
|
|
|
|
2017-06-12 13:01:28 +08:00
|
|
|
//private
|
2017-04-12 08:40:12 +08:00
|
|
|
void Window::_clear()
|
|
|
|
{
|
|
|
|
_wnd.reset();
|
|
|
|
}
|
|
|
|
|
2017-06-12 13:01:28 +08:00
|
|
|
//private
|
2017-05-31 22:17:30 +08:00
|
|
|
SDL_Window* Window::_get() const
|
2017-04-12 08:40:12 +08:00
|
|
|
{
|
|
|
|
return _wnd.get();
|
2017-03-23 14:01:06 +08:00
|
|
|
}
|
|
|
|
|
2017-05-16 22:33:21 +08:00
|
|
|
Window::Window(std::string Title, int Width, int Height,
|
|
|
|
std::initializer_list<WindowType> WindowFlags , int WindowPositionX, int WindowPositionY) throw(ErrorViewer)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-05-16 22:33:21 +08:00
|
|
|
/// Calculate Window Flags
|
|
|
|
Uint32 windowFlag=0;
|
|
|
|
for(auto v:WindowFlags)
|
|
|
|
{
|
|
|
|
windowFlag|=_internal::getSDLWindowFlagsFromWindowType(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Window* temp = SDL_CreateWindow(Title.c_str(), WindowPositionX, WindowPositionY, Width, Height, windowFlag);
|
2017-02-25 09:30:05 +08:00
|
|
|
if (temp == NULL)
|
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
2017-06-15 13:53:04 +08:00
|
|
|
|
2017-04-12 08:40:12 +08:00
|
|
|
_set(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-15 13:53:04 +08:00
|
|
|
Renderer::Renderer(Window& wnd,std::initializer_list<RendererType> RendererFlags) throw (ErrorViewer)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-06-15 13:53:04 +08:00
|
|
|
if(createRenderer(wnd,RendererFlags)!=0)
|
|
|
|
{
|
|
|
|
throw ErrorViewer();
|
|
|
|
}
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-15 13:53:04 +08:00
|
|
|
int Renderer::createRenderer(Window& wnd,std::initializer_list<RendererType> RendererFlags)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-05 11:16:44 +08:00
|
|
|
Uint32 flag = 0;
|
2017-02-25 09:30:05 +08:00
|
|
|
for (auto v : RendererFlags)
|
|
|
|
{
|
2017-06-15 13:53:04 +08:00
|
|
|
flag |= _rendertype_caster(v);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
2017-06-15 13:53:04 +08:00
|
|
|
return _createRenderer_Real(wnd,flag);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
Rect Window::getSize() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
int w, h;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_GetWindowSize(_get(), &w, &h);
|
2017-02-25 09:30:05 +08:00
|
|
|
return Rect(0, 0, w, h);
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
void Window::setSize(const Rect& sizeRect)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
setSize(sizeRect.w, sizeRect.h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setSize(int w, int h)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_SetWindowSize(_get(), w, h);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
Point Window::getPosition() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
int x, y;
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_GetWindowPosition(_get(), &x, &y);
|
2017-06-05 22:01:15 +08:00
|
|
|
return Point(x, y);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setPosition(int x, int y)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_SetWindowPosition(_get(), x, y);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
void Window::setPosition(const Point& point)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_SetWindowPosition(_get(), point.x, point.y);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
void Window::setTitle(const std::string& Title)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_SetWindowTitle(_get(), Title.c_str());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
std::string Window::getTitle() const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return std::string(SDL_GetWindowTitle(_get()));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-04-21 10:52:45 +08:00
|
|
|
void Window::setGrab(bool isGrab)
|
|
|
|
{
|
|
|
|
SDL_SetWindowGrab(_get(),isGrab?SDL_TRUE:SDL_FALSE);
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
bool Window::getGrab() const
|
2017-04-21 10:52:45 +08:00
|
|
|
{
|
|
|
|
return (SDL_GetWindowGrab(_get())==SDL_TRUE)?true:false;
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
#if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5)
|
2017-05-31 22:17:30 +08:00
|
|
|
int Window::setOpacity(float opacity)
|
|
|
|
{
|
|
|
|
return SDL_SetWindowOpacity(_get(),opacity);
|
|
|
|
}
|
|
|
|
float Window::getOpacity() const
|
|
|
|
{
|
|
|
|
float op=-1;
|
|
|
|
SDL_GetWindowOpacity(_get(),&op);
|
|
|
|
return op;
|
|
|
|
}
|
2017-06-05 22:01:15 +08:00
|
|
|
#endif /// End of SDL2 2.0.5 Require.
|
2017-05-31 22:17:30 +08:00
|
|
|
|
2017-06-05 22:01:15 +08:00
|
|
|
/// FIXME: Not Implemented.
|
2017-02-25 09:30:05 +08:00
|
|
|
void Window::setResizable(bool resizable)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
//SDL_SetWindowResizable(_get(), resizable?SDL_TRUE:SDL_FALSE);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::show()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_ShowWindow(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::hide()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_HideWindow(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::raise()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_RaiseWindow(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::minimize()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_MinimizeWindow(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::maximize()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_MaximizeWindow(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::restore()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_RestoreWindow(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_DECL_DEPRECATED Surface Window::getSurface()
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
SDL_Surface* temp = SDL_GetWindowSurface(_get());
|
2017-02-25 09:30:05 +08:00
|
|
|
Surface s;
|
|
|
|
/// Don't Free This Surface
|
2017-06-05 22:01:15 +08:00
|
|
|
s._set_no_delete(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
void Window::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
break;
|
|
|
|
case MessageBoxType::Information:
|
|
|
|
mboxdata.flags=SDL_MESSAGEBOX_INFORMATION;
|
|
|
|
break;
|
|
|
|
case MessageBoxType::Warning:
|
|
|
|
mboxdata.flags=SDL_MESSAGEBOX_WARNING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clickret=-2;
|
|
|
|
|
|
|
|
/// Call SDL2 to show MessageBox.
|
|
|
|
int ret=SDL_ShowMessageBox(&mboxdata,&clickret);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Free allocated memory
|
|
|
|
free(pButtonArr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-22 18:47:28 +08:00
|
|
|
bool Window::isScreenKeyboardShown()
|
|
|
|
{
|
|
|
|
return SDL_IsScreenKeyboardShown(_get())==SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2017-04-12 08:40:12 +08:00
|
|
|
void Font::_set(TTF_Font* p)
|
|
|
|
{
|
|
|
|
_font.reset(p,TTF_CloseFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Font::_clear()
|
|
|
|
{
|
|
|
|
_font.reset();
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
TTF_Font* Font::_get() const
|
2017-04-12 08:40:12 +08:00
|
|
|
{
|
|
|
|
return _font.get();
|
2017-03-21 13:58:48 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Font::Font(std::string FontFileName, size_t size) throw(ErrorViewer)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
if (use(FontFileName, size) != 0)
|
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
int Font::use(std::string FontFileName, size_t size)
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
TTF_Font* temp = TTF_OpenFont(FontFileName.c_str(), size);
|
|
|
|
if (temp == NULL) return -1;
|
2017-04-12 08:40:12 +08:00
|
|
|
_set(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-03-24 13:50:48 +08:00
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
bool Font::isReady() const
|
2017-03-24 10:46:33 +08:00
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return (_get() != nullptr);
|
2017-03-24 10:46:33 +08:00
|
|
|
}
|
2017-02-25 09:30:05 +08:00
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
bool Font::isNormal() const
|
2017-05-16 16:23:40 +08:00
|
|
|
{
|
|
|
|
return !(TTF_GetFontStyle(_get()));
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
bool Font::isBold() const
|
2017-05-16 16:23:40 +08:00
|
|
|
{
|
|
|
|
return (TTF_GetFontStyle(_get()) & TTF_STYLE_BOLD );
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
bool Font::isItalic() const
|
2017-05-16 16:23:40 +08:00
|
|
|
{
|
|
|
|
return (TTF_GetFontStyle(_get()) & TTF_STYLE_ITALIC );
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
bool Font::isUnderLine() const
|
2017-05-16 16:23:40 +08:00
|
|
|
{
|
|
|
|
return (TTF_GetFontStyle(_get()) & TTF_STYLE_UNDERLINE );
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
bool Font::isStrikeThrough() const
|
2017-05-16 16:23:40 +08:00
|
|
|
{
|
|
|
|
return (TTF_GetFontStyle(_get()) & TTF_STYLE_STRIKETHROUGH );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Font::setNormal()
|
|
|
|
{
|
|
|
|
_real_setFontStyle(TTF_STYLE_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Font::setBold(bool enable)
|
|
|
|
{
|
|
|
|
if( enable!=isBold() )
|
|
|
|
{
|
|
|
|
_real_setFontStyle( TTF_GetFontStyle(_get()) | (enable?TTF_STYLE_BOLD:!TTF_STYLE_BOLD) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Font::setItalic(bool enable)
|
|
|
|
{
|
|
|
|
if( enable!=isItalic() )
|
|
|
|
{
|
|
|
|
_real_setFontStyle( TTF_GetFontStyle(_get()) | (enable?TTF_STYLE_ITALIC:!TTF_STYLE_ITALIC) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Font::setUnderLine(bool enable)
|
|
|
|
{
|
|
|
|
if( enable!=isUnderLine() )
|
|
|
|
{
|
|
|
|
_real_setFontStyle( TTF_GetFontStyle(_get()) | (enable?TTF_STYLE_UNDERLINE:!TTF_STYLE_UNDERLINE) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Font::setStrikeThrough(bool enable)
|
|
|
|
{
|
|
|
|
if( enable!=isStrikeThrough() )
|
|
|
|
{
|
|
|
|
_real_setFontStyle( TTF_GetFontStyle(_get()) | (enable?TTF_STYLE_STRIKETHROUGH:!TTF_STYLE_STRIKETHROUGH) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-05 09:23:13 +08:00
|
|
|
void Font::_real_setFontStyle(int Style)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
TTF_SetFontStyle(_get(),Style);
|
2017-04-05 09:23:13 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
int Font::_style_caster(FontStyle style)
|
2017-04-05 09:23:13 +08:00
|
|
|
{
|
2017-05-16 16:23:40 +08:00
|
|
|
return _internal::getTTFFontStyleFromFontStyle(style);
|
|
|
|
}
|
2017-04-05 09:23:13 +08:00
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
std::vector<FontStyle> Font::getFontStyles() const
|
2017-05-16 16:23:40 +08:00
|
|
|
{
|
|
|
|
int styles=TTF_GetFontStyle(_get());
|
|
|
|
return _internal::getFontStyleVecFromMixedTTFFontStyle(styles);
|
2017-04-05 09:23:13 +08:00
|
|
|
}
|
|
|
|
|
2017-06-06 13:24:43 +08:00
|
|
|
int Font::getFontHeight() const
|
|
|
|
{
|
|
|
|
return TTF_FontHeight(_get());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Font::getFontAscent() const
|
|
|
|
{
|
|
|
|
return TTF_FontAscent(_get());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Font::getFontDescent() const
|
|
|
|
{
|
|
|
|
return TTF_FontDescent(_get());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Font::getFontLineSkip() const
|
|
|
|
{
|
|
|
|
return TTF_FontLineSkip(_get());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Font::isFontKerning() const
|
|
|
|
{
|
|
|
|
return (TTF_GetFontKerning(_get())!=0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Font::setFontKerning(bool enableKerning)
|
|
|
|
{
|
|
|
|
TTF_SetFontKerning(_get(),enableKerning?1:0);
|
|
|
|
}
|
|
|
|
|
|
|
|
long Font::getFontFaceNum() const
|
|
|
|
{
|
|
|
|
return TTF_FontFaces(_get());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Font::getFontFaceIsFixedWidth() const
|
|
|
|
{
|
|
|
|
return TTF_FontFaceIsFixedWidth(_get());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Font::getFontFaceFamilyName() const
|
|
|
|
{
|
|
|
|
return std::string(TTF_FontFaceFamilyName(_get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Font::getFontFaceStyleName() const
|
|
|
|
{
|
|
|
|
return std::string(TTF_FontFaceStyleName(_get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
FontHint Font::getFontHint() const
|
|
|
|
{
|
|
|
|
switch(TTF_GetFontHinting(_get()))
|
|
|
|
{
|
|
|
|
case TTF_HINTING_NORMAL:
|
|
|
|
return FontHint::Normal;
|
|
|
|
case TTF_HINTING_LIGHT:
|
|
|
|
return FontHint::Light;
|
|
|
|
case TTF_HINTING_MONO:
|
|
|
|
return FontHint::Mono;
|
|
|
|
case TTF_HINTING_NONE:
|
|
|
|
return FontHint::None;
|
|
|
|
}
|
|
|
|
/// Return Error on default.
|
|
|
|
return FontHint::Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Font::setFontHint(FontHint hint)
|
|
|
|
{
|
|
|
|
int v=0;
|
|
|
|
switch(hint)
|
|
|
|
{
|
|
|
|
case FontHint::Normal:
|
|
|
|
v=TTF_HINTING_NORMAL;
|
|
|
|
break;
|
|
|
|
case FontHint::Light:
|
|
|
|
v=TTF_HINTING_LIGHT;
|
|
|
|
break;
|
|
|
|
case FontHint::Mono:
|
|
|
|
v=TTF_HINTING_MONO;
|
|
|
|
break;
|
|
|
|
case FontHint::None:
|
|
|
|
v=TTF_HINTING_NONE;
|
|
|
|
break;
|
|
|
|
case FontHint::Error:
|
|
|
|
/// No Action on FontHint::Error.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TTF_SetFontHinting(_get(),v);
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
Rect Font::sizeText(const std::string& Text) const throw (ErrorViewer)
|
2017-05-16 15:23:34 +08:00
|
|
|
{
|
|
|
|
int w=0,h=0;
|
|
|
|
if(TTF_SizeText(_get(),Text.c_str(),&w,&h)!=0)
|
|
|
|
{
|
|
|
|
/// Something might be wrong
|
|
|
|
throw ErrorViewer();
|
|
|
|
}
|
|
|
|
return Rect(0,0,w,h);
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
Rect Font::sizeUTF8(const std::string& Text) const throw (ErrorViewer)
|
2017-05-16 15:23:34 +08:00
|
|
|
{
|
|
|
|
int w=0,h=0;
|
|
|
|
if(TTF_SizeUTF8(_get(),Text.c_str(),&w,&h)!=0)
|
|
|
|
{
|
|
|
|
/// Something might be wrong
|
|
|
|
throw ErrorViewer();
|
|
|
|
}
|
|
|
|
return Rect(0,0,w,h);
|
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
Rect Font::sizeUnicode(const uint16_t* Text) const throw (ErrorViewer)
|
|
|
|
{
|
|
|
|
int w=0,h=0;
|
|
|
|
if(TTF_SizeUNICODE(_get(),Text,&w,&h)!=0)
|
|
|
|
{
|
|
|
|
/// Something might be wrong
|
|
|
|
throw ErrorViewer();
|
|
|
|
}
|
|
|
|
return Rect(0,0,w,h);
|
|
|
|
}
|
|
|
|
|
2017-04-12 08:55:25 +08:00
|
|
|
/// rendering surfaces...
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderText(const std::string& Text,const RGBA& fg) const
|
2017-04-12 08:55:25 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderText_Blended(_get(), Text.c_str(), fg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderTextWrapped(const std::string& Text, const RGBA& fg, size_t WrapLength) const
|
2017-04-12 08:55:25 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderText_Blended_Wrapped(_get(), Text.c_str(), fg.toSDLColor(), WrapLength));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderTextShaded(const std::string& Text, const RGBA& fg,const RGBA& bg) const
|
2017-04-12 08:55:25 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderText_Shaded(_get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderTextSolid(const std::string& Text,const RGBA& fg) const
|
2017-04-12 08:55:25 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderText_Solid(_get(), Text.c_str(), fg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderUTF8(const std::string& Text,const RGBA& fg) const
|
2017-04-12 08:55:25 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderUTF8_Blended(_get(), Text.c_str(), fg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderUTF8Wrapped(const std::string& Text, const RGBA& fg, size_t WrapLength) const
|
2017-04-12 08:55:25 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderUTF8_Blended_Wrapped(_get(), Text.c_str(), fg.toSDLColor(), WrapLength));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderUTF8Shaded(const std::string& Text, const RGBA& fg,const RGBA& bg) const
|
2017-04-12 08:55:25 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderUTF8_Shaded(_get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderUTF8Solid(const std::string& Text,const RGBA& fg) const
|
2017-04-12 08:55:25 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderUTF8_Solid(_get(), Text.c_str(), fg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderUnicode(const uint16_t* Text, const RGBA& fg) const
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderUNICODE_Blended(_get(),Text,fg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderUnicodeWrapped(const uint16_t* Text, const RGBA& fg, size_t WrapLength) const
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderUNICODE_Blended_Wrapped(_get(),Text,fg.toSDLColor(),WrapLength));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderUnicodeShaded(const uint16_t* Text, const RGBA& fg, const RGBA& bg) const
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderUNICODE_Shaded(_get(),Text,fg.toSDLColor(),bg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Surface Font::renderUnicodeSolid(const uint16_t* Text, const RGBA& fg) const
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
|
|
|
Surface surf;
|
|
|
|
surf._set(TTF_RenderUNICODE_Solid(_get(),Text,fg.toSDLColor()));
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
2017-04-12 08:55:25 +08:00
|
|
|
/// rendering textures...
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderText(const Renderer& rnd, const std::string& Text, const RGBA& fg) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:55:25 +08:00
|
|
|
return rnd.render(renderText(Text,fg));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderTextWrapped(const Renderer& rnd, const std::string& Text, const RGBA& fg, size_t WrapLength) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:55:25 +08:00
|
|
|
return rnd.render(renderTextWrapped(Text,fg,WrapLength));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderTextShaded(const Renderer& rnd, const std::string& Text, const RGBA& fg, const RGBA& bg) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:55:25 +08:00
|
|
|
return rnd.render(renderTextShaded(Text,fg,bg));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderTextSolid(const Renderer& rnd, const std::string& Text, const RGBA& fg) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:55:25 +08:00
|
|
|
return rnd.render(renderTextSolid(Text,fg));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderUTF8(const Renderer& rnd, const std::string& Text, const RGBA& fg) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:55:25 +08:00
|
|
|
return rnd.render(renderUTF8(Text,fg));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderUTF8Wrapped(const Renderer& rnd, const std::string& Text, const RGBA& fg, size_t WrapLength) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:55:25 +08:00
|
|
|
return rnd.render(renderUTF8Wrapped(Text,fg,WrapLength));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderUTF8Shaded(const Renderer& rnd, const std::string& Text, const RGBA& fg, const RGBA& bg) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:55:25 +08:00
|
|
|
return rnd.render(renderUTF8Shaded(Text,fg,bg));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderUTF8Solid(const Renderer& rnd, const std::string& Text, const RGBA& fg) const
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
2017-04-12 08:55:25 +08:00
|
|
|
return rnd.render(renderUTF8Solid(Text,fg));
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 14:07:57 +08:00
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderUnicode(const Renderer& rnd, const uint16_t* Text, const RGBA& fg) const
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
|
|
|
return rnd.render(renderUnicode(Text,fg));
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderUnicodeWrapped(const Renderer& rnd, const uint16_t* Text, const RGBA& fg, size_t WrapLength) const
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
|
|
|
return rnd.render(renderUnicodeWrapped(Text,fg,WrapLength));
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderUnicodeShaded(const Renderer& rnd, const uint16_t* Text, const RGBA& fg, const RGBA& bg) const
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
|
|
|
return rnd.render(renderUnicodeShaded(Text,fg,bg));
|
|
|
|
}
|
|
|
|
|
2017-06-05 15:40:16 +08:00
|
|
|
Texture Font::renderUnicodeSolid(const Renderer& rnd, const uint16_t* Text, const RGBA& fg) const
|
2017-06-05 14:07:57 +08:00
|
|
|
{
|
|
|
|
return rnd.render(renderUnicodeSolid(Text,fg));
|
|
|
|
}
|
|
|
|
|
2017-05-18 18:14:29 +08:00
|
|
|
void Font::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
|
|
|
|
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-04-19 14:11:08 +08:00
|
|
|
/// Global Executor For class Timer
|
|
|
|
Uint32 _global_timer_executor(Uint32 interval,void* param)
|
|
|
|
{
|
|
|
|
auto p=reinterpret_cast<std::function<Uint32(Uint32 interval)>*>(param);
|
|
|
|
return (*p)(interval);
|
|
|
|
}
|
|
|
|
|
2017-04-04 20:33:41 +08:00
|
|
|
Timer::Timer()
|
|
|
|
{
|
|
|
|
_enabled=false;
|
|
|
|
_detached=false;
|
2017-04-19 14:11:08 +08:00
|
|
|
_delete_on_disable=false;
|
2017-04-04 20:33:41 +08:00
|
|
|
id=-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer::Timer(SDL_TimerCallback callback,Uint32 interval,void* param) : Timer()
|
2017-04-19 14:11:08 +08:00
|
|
|
{
|
|
|
|
_real_timer_call(callback,interval,param);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::_real_timer_call(SDL_TimerCallback callback,Uint32 interval,void* param)
|
2017-04-04 20:33:41 +08:00
|
|
|
{
|
|
|
|
_callback=callback;
|
|
|
|
_interval=interval;
|
|
|
|
_param=param;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Timer::enable()
|
|
|
|
{
|
|
|
|
if(_enabled)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id=SDL_AddTimer(_interval,_callback,_param);
|
|
|
|
if(id<0) return -2;
|
|
|
|
_enabled=true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Timer::disable()
|
|
|
|
{
|
|
|
|
if(_enabled)
|
|
|
|
{
|
|
|
|
SDL_RemoveTimer(id);
|
|
|
|
_enabled=false;
|
|
|
|
id=-1;
|
2017-04-19 14:11:08 +08:00
|
|
|
_callback=nullptr;
|
|
|
|
|
|
|
|
if(_delete_on_disable)
|
|
|
|
{
|
|
|
|
_delete_delegator(reinterpret_cast<std::function<Uint32(Uint32 interval)>*>(_param));
|
|
|
|
_delete_on_disable=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_param=nullptr;
|
2017-04-04 20:33:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::detach()
|
|
|
|
{
|
|
|
|
_detached=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer::~Timer()
|
|
|
|
{
|
|
|
|
if(!_detached)
|
|
|
|
{
|
|
|
|
disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 14:11:08 +08:00
|
|
|
//static
|
|
|
|
void Timer::_delete_delegator(std::function<Uint32(Uint32)>* param)
|
|
|
|
{
|
|
|
|
delete param;
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
AudioPlayer::AudioPlayer()
|
|
|
|
{
|
|
|
|
if (!_sysAudioCounter)
|
|
|
|
{
|
|
|
|
_sysAudio = new _Audio;
|
|
|
|
}
|
|
|
|
++_sysAudioCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioPlayer::~AudioPlayer()
|
|
|
|
{
|
|
|
|
--_sysAudioCounter;
|
|
|
|
if (!_sysAudioCounter)
|
|
|
|
{
|
|
|
|
delete _sysAudio;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioPlayer::_Audio::_Audio()
|
|
|
|
{
|
|
|
|
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioPlayer::_Audio::~_Audio()
|
|
|
|
{
|
|
|
|
Mix_CloseAudio();
|
|
|
|
}
|
|
|
|
|
2017-04-12 08:40:12 +08:00
|
|
|
void Music::_set(Mix_Music* p)//private
|
|
|
|
{
|
|
|
|
_music.reset(p,Mix_FreeMusic);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Music::_clear()//private
|
|
|
|
{
|
|
|
|
_music.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
Mix_Music* Music::_get()//private
|
|
|
|
{
|
|
|
|
return _music.get();
|
|
|
|
}
|
|
|
|
|
2017-06-06 15:50:56 +08:00
|
|
|
//static
|
|
|
|
int MusicPlayer::GetDecoderNum()
|
|
|
|
{
|
|
|
|
return Mix_GetNumMusicDecoders();
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::string MusicPlayer::GetDecoderName(int index)
|
|
|
|
{
|
|
|
|
return std::string(Mix_GetMusicDecoder(index));
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
Music MusicPlayer::loadMusic(std::string Filename) throw(ErrorViewer)
|
|
|
|
{
|
|
|
|
Mix_Music* temp = Mix_LoadMUS(Filename.c_str());
|
|
|
|
if (temp == nullptr)
|
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
Music m;
|
2017-04-12 08:40:12 +08:00
|
|
|
m._set(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::play(Music music, int loops)
|
|
|
|
{
|
|
|
|
m = music;
|
2017-04-12 08:40:12 +08:00
|
|
|
return Mix_PlayMusic(m._get(), loops);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MusicPlayer::pause()
|
|
|
|
{
|
|
|
|
Mix_PauseMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusicPlayer::resume()
|
|
|
|
{
|
|
|
|
Mix_ResumeMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusicPlayer::rewind()
|
|
|
|
{
|
|
|
|
Mix_RewindMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::stop()
|
|
|
|
{
|
|
|
|
return Mix_HaltMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::fadeIn(int loops, int ms)
|
|
|
|
{
|
2017-04-12 08:40:12 +08:00
|
|
|
return Mix_FadeInMusic(m._get(), loops, ms);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::fadeOut(int ms)
|
|
|
|
{
|
|
|
|
return Mix_FadeOutMusic(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MusicPlayer::isPlaying()
|
|
|
|
{
|
2017-05-02 22:38:37 +08:00
|
|
|
return (Mix_PlayingMusic() == 1);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MusicPlayer::isPaused()
|
|
|
|
{
|
2017-05-02 22:38:37 +08:00
|
|
|
return (Mix_PausedMusic() == 1);
|
2017-02-25 09:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::isFading()
|
|
|
|
{
|
|
|
|
switch (Mix_FadingMusic())
|
|
|
|
{
|
|
|
|
case MIX_NO_FADING:
|
|
|
|
return 0;
|
|
|
|
case MIX_FADING_IN:
|
|
|
|
return 1;
|
|
|
|
case MIX_FADING_OUT:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 18:19:04 +08:00
|
|
|
//static
|
|
|
|
int MusicPlayer::SetMusicPosition(double position)
|
|
|
|
{
|
|
|
|
return Mix_SetMusicPosition(position);
|
|
|
|
}
|
|
|
|
|
2017-04-12 08:40:12 +08:00
|
|
|
void Sound::_set(Mix_Chunk* p)
|
|
|
|
{
|
|
|
|
_sound.reset(p,Mix_FreeChunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::_clear()//private
|
|
|
|
{
|
|
|
|
_sound.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
Mix_Chunk* Sound::_get()
|
|
|
|
{
|
|
|
|
return _sound.get();
|
|
|
|
}
|
|
|
|
|
2017-06-06 15:50:56 +08:00
|
|
|
//static
|
|
|
|
int SoundPlayer::GetDecoderNum()
|
|
|
|
{
|
|
|
|
return Mix_GetNumChunkDecoders();
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::string SoundPlayer::GetDecoderName(int index)
|
|
|
|
{
|
|
|
|
return std::string(Mix_GetChunkDecoder(index));
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
SoundPlayer::SoundPlayer(int Channels)
|
|
|
|
{
|
|
|
|
Mix_AllocateChannels(Channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sound SoundPlayer::loadSound(std::string Filename) throw(ErrorViewer)
|
|
|
|
{
|
|
|
|
Mix_Chunk* temp = Mix_LoadWAV(Filename.c_str());
|
|
|
|
if (temp == NULL)
|
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
Sound s;
|
2017-04-12 08:40:12 +08:00
|
|
|
s._set(temp);
|
2017-02-25 09:30:05 +08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelID SoundPlayer::playSound(Sound sound, int loops) throw(ErrorViewer)
|
|
|
|
{
|
|
|
|
ChannelID id;
|
2017-04-12 08:40:12 +08:00
|
|
|
if (-1 == (id = Mix_PlayChannel(-1, sound._get(), loops)))
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelID SoundPlayer::fadein(Sound sound, int loops, int ms) throw(ErrorViewer)
|
|
|
|
{
|
|
|
|
ChannelID id;
|
2017-04-12 08:40:12 +08:00
|
|
|
if (-1 == (id = Mix_FadeInChannel(-1, sound._get(), loops, ms)))
|
2017-02-25 09:30:05 +08:00
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundPlayer::fadeout(ChannelID id, int ms)
|
|
|
|
{
|
|
|
|
return Mix_FadeOutChannel(id, ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundPlayer::pause(ChannelID id)
|
|
|
|
{
|
|
|
|
Mix_Pause(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundPlayer::resume(ChannelID id)
|
|
|
|
{
|
|
|
|
Mix_Resume(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundPlayer::stop(ChannelID id)
|
|
|
|
{
|
|
|
|
return Mix_HaltChannel(id);
|
|
|
|
}
|
|
|
|
|
2017-06-06 16:00:51 +08:00
|
|
|
int SoundPlayer::setPanning(ChannelID id, uint8_t left, uint8_t right)
|
|
|
|
{
|
|
|
|
return Mix_SetPanning(id,left,right);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundPlayer::setPosition(ChannelID id, int16_t angle, uint8_t distance)
|
|
|
|
{
|
|
|
|
return Mix_SetPosition(id,angle,distance);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundPlayer::setDistance(ChannelID id, uint8_t distance)
|
|
|
|
{
|
|
|
|
return Mix_SetDistance(id,distance);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundPlayer::setReverseStereo(ChannelID id, int flip)
|
|
|
|
{
|
|
|
|
return Mix_SetReverseStereo(id,flip);
|
|
|
|
}
|
|
|
|
|
2017-06-14 20:50:12 +08:00
|
|
|
int SoundPlayer::addEffect(ChannelID id,Mix_EffectFunc_t f, Mix_EffectDone_t d, void* arg)
|
|
|
|
{
|
|
|
|
return Mix_RegisterEffect(id,f,d,arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundPlayer::removeEffect(ChannelID id,Mix_EffectFunc_t f)
|
|
|
|
{
|
|
|
|
return Mix_UnregisterEffect(id,f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SoundPlayer::removeAllEffect(ChannelID id)
|
|
|
|
{
|
|
|
|
return Mix_UnregisterAllEffects(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-25 09:30:05 +08:00
|
|
|
AudioPlayer::_Audio* AudioPlayer::_sysAudio = nullptr;
|
|
|
|
int AudioPlayer::_sysAudioCounter = 0;
|
|
|
|
|
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;
|
|
|
|
}
|