2017-02-25 09:29:34 +08:00
|
|
|
#pragma once
|
2017-05-16 16:27:35 +08:00
|
|
|
#include "MiniEngine_Config.h"
|
2017-02-25 09:29:34 +08:00
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2017-03-23 12:22:02 +08:00
|
|
|
#include <functional>
|
2017-05-16 16:23:40 +08:00
|
|
|
#include <vector>
|
2017-02-25 09:29:34 +08:00
|
|
|
|
|
|
|
namespace MiniEngine
|
|
|
|
{
|
|
|
|
|
|
|
|
class Rect
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int x, y, w, h;
|
|
|
|
Rect(int X, int Y, int W, int H);
|
2017-05-09 10:53:02 +08:00
|
|
|
Rect(const SDL_Rect&);
|
2017-02-25 09:29:34 +08:00
|
|
|
Rect();
|
2017-05-09 10:53:02 +08:00
|
|
|
SDL_Rect toSDLRect() const;
|
|
|
|
bool isEmpty();
|
|
|
|
bool operator == (const Rect&) const;
|
|
|
|
bool hasIntersection(const Rect&);
|
|
|
|
Rect getIntersection(const Rect&);
|
|
|
|
Rect getUnion(const Rect&);
|
2017-02-25 09:29:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Point
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int x, y;
|
|
|
|
Point(int X, int Y);
|
|
|
|
Point();
|
|
|
|
SDL_Point toSDLPoint();
|
|
|
|
bool inRect(Rect rect);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ColorMode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int r, g, b;
|
|
|
|
ColorMode(int R, int G, int B);
|
|
|
|
ColorMode();
|
|
|
|
};
|
|
|
|
|
|
|
|
class RGBA
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int r, g, b, a;
|
|
|
|
RGBA(int R, int G, int B, int A);
|
|
|
|
RGBA(ColorMode mode, int A);
|
|
|
|
RGBA();
|
|
|
|
SDL_Color toSDLColor();
|
|
|
|
ColorMode toColorMode();
|
|
|
|
};
|
|
|
|
|
|
|
|
class NonCopyable
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
NonCopyable() = default;
|
|
|
|
~NonCopyable() = default;
|
|
|
|
NonCopyable(const NonCopyable&) = delete;
|
|
|
|
NonCopyable& operator = (const NonCopyable&) = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ErrorViewer : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void fetch();
|
|
|
|
std::string getError();
|
|
|
|
const char* what() const throw() override;
|
|
|
|
private:
|
|
|
|
std::string str;
|
|
|
|
};
|
|
|
|
|
2017-04-10 15:27:24 +08:00
|
|
|
class RWOP
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RWOP(FILE* fp,bool autoclose);
|
|
|
|
RWOP(const std::string& filename,const std::string& openmode);
|
|
|
|
RWOP(const void* mem,int size);
|
|
|
|
RWOP(void* mem,int size);
|
|
|
|
RWOP()=default;
|
|
|
|
~RWOP()=default;
|
|
|
|
private:
|
2017-04-12 08:40:12 +08:00
|
|
|
std::shared_ptr<SDL_RWops> _op;
|
|
|
|
SDL_RWops* _get();
|
|
|
|
void _clear();
|
|
|
|
void _set(SDL_RWops*);
|
|
|
|
friend class Renderer;
|
2017-04-10 15:27:24 +08:00
|
|
|
};
|
|
|
|
|
2017-04-12 09:22:15 +08:00
|
|
|
enum class BlendMode { None,Blend,Add,Mod };
|
2017-02-25 09:29:34 +08:00
|
|
|
|
|
|
|
class Surface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~Surface() = default;
|
2017-04-10 19:52:40 +08:00
|
|
|
int savePNG(const std::string& filename);
|
2017-04-12 09:03:03 +08:00
|
|
|
int getw();
|
|
|
|
int geth();
|
2017-04-12 09:22:15 +08:00
|
|
|
BlendMode getBlendMode();
|
|
|
|
int setBlendMode(BlendMode mode);
|
2017-04-12 09:50:12 +08:00
|
|
|
|
|
|
|
int blit(Surface s,Rect src,Rect dst);
|
|
|
|
int blitTo(Surface t, Rect dst);
|
|
|
|
int blitTo(Surface t, Point lupoint);
|
|
|
|
int blitFill(Surface t, Rect src);
|
|
|
|
int blitFullFill(Surface t);
|
2017-04-13 09:03:44 +08:00
|
|
|
|
2017-04-14 20:46:07 +08:00
|
|
|
int blitScaled(Surface s,Rect src,Rect dst);
|
|
|
|
int blitScaledTo(Surface t, Rect dst);
|
|
|
|
int blitScaledTo(Surface t, Point lupoint);
|
|
|
|
int blitScaledFill(Surface t, Rect src);
|
|
|
|
int blitScaledFullFill(Surface t);
|
|
|
|
|
2017-04-13 09:03:44 +08:00
|
|
|
int setAlphaMode(int alpha);
|
|
|
|
int getAlphaMode();
|
|
|
|
|
|
|
|
ColorMode getColorMode();
|
|
|
|
int setColorMode(ColorMode mode);
|
|
|
|
RGBA getRGBA();
|
|
|
|
void setRGBA(RGBA pack);
|
|
|
|
|
|
|
|
bool mustlock();
|
|
|
|
int lock();
|
|
|
|
void unlock();
|
|
|
|
|
|
|
|
static Surface createSurface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer);
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
protected:
|
|
|
|
Surface() = default;
|
|
|
|
private:
|
2017-04-12 08:40:12 +08:00
|
|
|
std::shared_ptr<SDL_Surface> _surf;
|
|
|
|
void _set(SDL_Surface*);
|
|
|
|
void _clear();
|
|
|
|
SDL_Surface* _get();
|
|
|
|
std::shared_ptr<SDL_Surface>& _getex();
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
friend class Window;
|
|
|
|
friend class Renderer;
|
|
|
|
friend class Font;
|
2017-04-21 11:25:08 +08:00
|
|
|
friend class Cursor;
|
2017-02-25 09:29:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Texture
|
|
|
|
{
|
|
|
|
public:
|
2017-03-02 13:11:50 +08:00
|
|
|
Texture();
|
2017-02-25 09:29:34 +08:00
|
|
|
~Texture() = default;
|
|
|
|
Rect getSize();
|
|
|
|
int getw();
|
|
|
|
int geth();
|
|
|
|
bool isReady();
|
|
|
|
int setBlendMode(BlendMode mode);
|
|
|
|
BlendMode getBlendMode();
|
|
|
|
/// Alpha: 0: Transparent 255: opaque
|
|
|
|
int setAlphaMode(int alpha);
|
|
|
|
int getAlphaMode();
|
|
|
|
|
|
|
|
ColorMode getColorMode();
|
|
|
|
int setColorMode(ColorMode mode);
|
|
|
|
RGBA getRGBA();
|
|
|
|
void setRGBA(RGBA pack);
|
2017-03-02 13:11:50 +08:00
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
protected:
|
|
|
|
/// updateInfo() must be called after Texture is changed.
|
|
|
|
void updateInfo();
|
|
|
|
private:
|
2017-04-12 08:40:12 +08:00
|
|
|
std::shared_ptr<SDL_Texture> _text;
|
|
|
|
void _set(SDL_Texture*);
|
|
|
|
void _clear();
|
|
|
|
SDL_Texture* _get();
|
2017-02-25 09:29:34 +08:00
|
|
|
Rect rect;
|
|
|
|
friend class Renderer;
|
|
|
|
};
|
|
|
|
|
2017-04-12 09:22:15 +08:00
|
|
|
enum class RendererType { Software, Accelerated, PresentSync, TargetTexture };
|
2017-02-25 09:29:34 +08:00
|
|
|
|
2017-03-21 17:03:03 +08:00
|
|
|
enum class FlipMode { None, Horizontal, Vertical };
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
class Renderer
|
|
|
|
{
|
|
|
|
public:
|
2017-04-05 11:43:01 +08:00
|
|
|
Renderer() = default;
|
2017-02-25 09:29:34 +08:00
|
|
|
int setColor(RGBA pack);
|
|
|
|
RGBA getColor();
|
|
|
|
int setBlendMode(BlendMode mode);
|
|
|
|
BlendMode getBlendMode();
|
|
|
|
|
|
|
|
int setTarget(Texture& t);
|
|
|
|
int setTarget();
|
|
|
|
|
|
|
|
int fillRect(Rect rect);
|
|
|
|
int drawRect(Rect rect);
|
2017-03-14 17:29:22 +08:00
|
|
|
int drawPoint(Point p);
|
2017-03-21 17:03:03 +08:00
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
int clear();
|
|
|
|
void update();
|
2017-03-21 17:03:03 +08:00
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
int copy(Texture t, Rect src, Rect dst);
|
|
|
|
int copyTo(Texture t, Rect dst);
|
|
|
|
int copyTo(Texture t, Point lupoint);
|
|
|
|
int copyFill(Texture t, Rect src);
|
|
|
|
int copyFullFill(Texture t);
|
2017-03-21 17:03:03 +08:00
|
|
|
|
|
|
|
int supercopy(Texture t,bool srcfull,Rect src,bool dstfull,Rect dst,double angle,bool haspoint,Point center,FlipMode mode);
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
Surface loadSurface(std::string FileName) throw(ErrorViewer);
|
2017-04-12 08:40:12 +08:00
|
|
|
Surface loadSurfaceRW(RWOP rwop) throw(ErrorViewer);
|
2017-02-25 09:29:34 +08:00
|
|
|
Texture render(Surface surf) throw (ErrorViewer);
|
|
|
|
Texture loadTexture(std::string FileName) throw(ErrorViewer);
|
2017-04-12 08:40:12 +08:00
|
|
|
Texture loadTextureRW(RWOP rwop) throw(ErrorViewer);
|
2017-02-25 09:29:34 +08:00
|
|
|
Texture createTexture(int Width, int Height) throw(ErrorViewer);
|
|
|
|
|
2017-03-23 14:01:06 +08:00
|
|
|
bool isReady();
|
2017-02-25 09:29:34 +08:00
|
|
|
private:
|
2017-04-12 08:40:12 +08:00
|
|
|
std::shared_ptr<SDL_Renderer> _rnd;
|
|
|
|
void _set(SDL_Renderer*);
|
|
|
|
void _clear();
|
|
|
|
SDL_Renderer* _get();
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
friend class Window;
|
|
|
|
};
|
|
|
|
|
2017-04-21 11:25:08 +08:00
|
|
|
enum class SystemCursorType
|
|
|
|
{
|
|
|
|
Arrow, Ibeam, CrossHair,
|
|
|
|
Wait, WaitArrow,
|
|
|
|
SizeNWSE, SizeNESW, SizeWE, SizeNS, SizeAll,
|
|
|
|
No, Hand
|
|
|
|
};
|
|
|
|
|
|
|
|
class Cursor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static Cursor CreateSystemCursor(SystemCursorType);
|
|
|
|
static Cursor CreateCursor(Surface surf,Point hotspot={0,0});
|
|
|
|
|
|
|
|
static Cursor GetActiveCursor();
|
|
|
|
static Cursor GetDefaultCursor();
|
|
|
|
|
|
|
|
static void show(bool);
|
|
|
|
static bool isShow();
|
2017-04-22 10:33:18 +08:00
|
|
|
|
|
|
|
void activate();
|
2017-04-21 11:25:08 +08:00
|
|
|
private:
|
|
|
|
std::shared_ptr<SDL_Cursor> _cur;
|
|
|
|
void _set(SDL_Cursor*);
|
|
|
|
void _set_no_delete(SDL_Cursor*);
|
|
|
|
SDL_Cursor* _get();
|
|
|
|
void _clear();
|
|
|
|
};
|
|
|
|
|
2017-04-12 09:22:15 +08:00
|
|
|
enum class MessageBoxType { Error, Warning, Information };
|
2017-03-21 13:58:48 +08:00
|
|
|
|
2017-05-16 22:33:21 +08:00
|
|
|
enum class WindowType
|
|
|
|
{
|
|
|
|
FullScreen, OpenGL, Shown, Hidden,
|
|
|
|
Borderless, Resizable, Minimized, Maximized,
|
|
|
|
InputGrabbed, InputFocus, MouseFocus,
|
|
|
|
FullScreenDesktop, Foreign, AllowHighDPI,
|
|
|
|
MouseCapture, AlwaysOnTop, SkipTaskBar,
|
|
|
|
Utility, ToolTip, PopUpMenu
|
|
|
|
};
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
class Window
|
|
|
|
{
|
|
|
|
public:
|
2017-05-16 22:33:21 +08:00
|
|
|
Window(std::string Title, int Width, int Height,
|
|
|
|
std::initializer_list<RendererType> RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture },
|
|
|
|
std::initializer_list<WindowType> WindowFlags = {WindowType::Shown} ,
|
|
|
|
int WindowPositionX=SDL_WINDOWPOS_CENTERED, int WindowPositionY=SDL_WINDOWPOS_CENTERED) throw(ErrorViewer);
|
2017-02-25 09:29:34 +08:00
|
|
|
Renderer getRenderer() const;
|
|
|
|
|
2017-04-05 11:16:44 +08:00
|
|
|
void setRenderer(RendererType Type)
|
|
|
|
{
|
|
|
|
_internal_rndflagcalc=0;
|
|
|
|
_setRenderer(Type);
|
|
|
|
}
|
|
|
|
|
2017-04-05 11:43:01 +08:00
|
|
|
template<typename... Args>
|
|
|
|
void setRenderer(RendererType Type,Args&&... args)
|
|
|
|
{
|
|
|
|
_internal_rndflagcalc=0;
|
|
|
|
_setRenderer(Type,std::forward<RendererType>(args...));
|
|
|
|
}
|
|
|
|
|
2017-04-05 11:16:44 +08:00
|
|
|
void setRenderer(std::initializer_list<RendererType>);
|
2017-02-25 09:29:34 +08:00
|
|
|
|
|
|
|
Rect getSize();
|
|
|
|
void setSize(Rect sizeRect);
|
|
|
|
void setSize(int w, int h);
|
|
|
|
|
|
|
|
Rect getPosition();
|
|
|
|
void setPosition(int x, int y);
|
|
|
|
/// FIXME: Use class Point or class Rect ?
|
|
|
|
void setPosition(Point point);
|
|
|
|
|
|
|
|
|
|
|
|
void setTitle(std::string Title);
|
|
|
|
std::string getTitle();
|
|
|
|
|
2017-04-21 10:52:45 +08:00
|
|
|
void setGrab(bool);
|
|
|
|
bool getGrab();
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
void setResizable(bool resizable);
|
|
|
|
|
2017-03-21 13:58:48 +08:00
|
|
|
/// Use UTF8 in Title and Message please.
|
|
|
|
int showSimpleMessageBox(MessageBoxType type,std::string Title,std::string Message);
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
void show();
|
|
|
|
void hide();
|
|
|
|
void raise();
|
|
|
|
void minimize();
|
|
|
|
void maximize();
|
|
|
|
void restore();
|
|
|
|
|
|
|
|
|
|
|
|
_DECL_DEPRECATED Surface getSurface();
|
2017-04-05 11:16:44 +08:00
|
|
|
protected:
|
|
|
|
template<typename... Args>
|
|
|
|
void _setRenderer(RendererType Type,Args&&... args)
|
|
|
|
{
|
|
|
|
_internal_rndflagcalc|=_render_caster(Type);
|
|
|
|
_setRenderer(args...);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _setRenderer(RendererType Type)
|
|
|
|
{
|
|
|
|
_internal_rndflagcalc|=_render_caster(Type);
|
|
|
|
_setRenderer_Real(_internal_rndflagcalc);
|
|
|
|
}
|
2017-02-25 09:29:34 +08:00
|
|
|
private:
|
|
|
|
void _setRenderer_Real(Uint32 flags);
|
2017-04-05 11:16:44 +08:00
|
|
|
Uint32 _internal_rndflagcalc;
|
|
|
|
Uint32 _render_caster(RendererType);
|
2017-04-12 08:40:12 +08:00
|
|
|
|
|
|
|
std::shared_ptr<SDL_Window> _wnd;
|
|
|
|
void _set(SDL_Window*);
|
|
|
|
void _clear();
|
|
|
|
SDL_Window* _get();
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
Renderer winrnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Font
|
|
|
|
{
|
|
|
|
public:
|
2017-04-05 09:23:13 +08:00
|
|
|
enum class Style { Normal, Bold, Italic, UnderLine, StrikeThrough };
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
Font() = default;
|
|
|
|
Font(std::string FontFileName, int size) throw(ErrorViewer);
|
|
|
|
int use(std::string FontFileName, int size);
|
2017-03-24 10:46:33 +08:00
|
|
|
bool isReady();
|
2017-04-05 09:23:13 +08:00
|
|
|
|
2017-05-16 16:23:40 +08:00
|
|
|
bool isNormal();
|
|
|
|
bool isBold();
|
|
|
|
bool isItalic();
|
|
|
|
bool isUnderLine();
|
|
|
|
bool isStrikeThrough();
|
|
|
|
|
|
|
|
void setNormal();
|
|
|
|
void setBold(bool);
|
|
|
|
void setItalic(bool);
|
|
|
|
void setUnderLine(bool);
|
|
|
|
void setStrikeThrough(bool);
|
|
|
|
|
2017-04-05 09:23:13 +08:00
|
|
|
template<typename... Args>
|
|
|
|
void setFontStyle(Style style,Args&&... args)
|
|
|
|
{
|
2017-05-16 15:52:00 +08:00
|
|
|
int fontcalc=0;
|
|
|
|
_setFontStyle(fontcalc,style,args...);
|
2017-04-05 09:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setFontStyle(Style style)
|
|
|
|
{
|
2017-05-16 15:52:00 +08:00
|
|
|
int fontcalc=0;
|
|
|
|
_setFontStyle(fontcalc,style);
|
2017-04-05 09:23:13 +08:00
|
|
|
}
|
|
|
|
|
2017-05-16 16:23:40 +08:00
|
|
|
std::vector<Style> getFontStyles();
|
2017-04-05 09:23:13 +08:00
|
|
|
|
2017-05-16 15:23:34 +08:00
|
|
|
Rect sizeText(const std::string& Text) throw (ErrorViewer);
|
|
|
|
Rect sizeUTF8(const std::string& Text) throw (ErrorViewer);
|
|
|
|
|
2017-04-12 08:55:25 +08:00
|
|
|
Surface renderText(std::string Text, RGBA fg);
|
|
|
|
Surface renderTextWrapped(std::string Text, RGBA fg, int WrapLength);
|
|
|
|
Surface renderTextShaded(std::string Text, RGBA fg, RGBA bg);
|
|
|
|
Surface renderTextSolid(std::string Text, RGBA fg);
|
|
|
|
|
|
|
|
Surface renderUTF8(std::string Text, RGBA fg);
|
|
|
|
Surface renderUTF8Wrapped(std::string Text, RGBA fg, int WrapLength);
|
|
|
|
Surface renderUTF8Shaded(std::string Text, RGBA fg, RGBA bg);
|
|
|
|
Surface renderUTF8Solid(std::string Text, RGBA fg);
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
Texture renderText(Renderer rnd, std::string Text, RGBA fg);
|
|
|
|
Texture renderTextWrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength);
|
|
|
|
Texture renderTextShaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg);
|
|
|
|
Texture renderTextSolid(Renderer rnd, std::string Text, RGBA fg);
|
|
|
|
|
|
|
|
Texture renderUTF8(Renderer rnd, std::string Text, RGBA fg);
|
|
|
|
Texture renderUTF8Wrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength);
|
|
|
|
Texture renderUTF8Shaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg);
|
|
|
|
Texture renderUTF8Solid(Renderer rnd, std::string Text, RGBA fg);
|
2017-04-05 09:23:13 +08:00
|
|
|
protected:
|
|
|
|
template<typename... Args>
|
2017-05-16 15:52:00 +08:00
|
|
|
void _setFontStyle(int& fontcalc,Style style,Args&&... args)
|
2017-04-05 09:23:13 +08:00
|
|
|
{
|
2017-05-16 15:52:00 +08:00
|
|
|
fontcalc|=_style_caster(style);
|
|
|
|
_setFontStyle(fontcalc,args...);
|
2017-04-05 09:23:13 +08:00
|
|
|
}
|
|
|
|
|
2017-05-16 15:52:00 +08:00
|
|
|
void _setFontStyle(int& fontcalc,Style style)
|
2017-04-05 09:23:13 +08:00
|
|
|
{
|
2017-05-16 15:52:00 +08:00
|
|
|
fontcalc|=_style_caster(style);
|
|
|
|
_real_setFontStyle(fontcalc);
|
2017-04-05 09:23:13 +08:00
|
|
|
}
|
2017-02-25 09:29:34 +08:00
|
|
|
private:
|
2017-04-05 09:23:13 +08:00
|
|
|
void _real_setFontStyle(int);
|
|
|
|
int _style_caster(Style);
|
2017-04-12 08:40:12 +08:00
|
|
|
|
|
|
|
std::shared_ptr<TTF_Font> _font;
|
|
|
|
void _set(TTF_Font*);
|
|
|
|
void _clear();
|
|
|
|
TTF_Font* _get();
|
2017-02-25 09:29:34 +08:00
|
|
|
};
|
|
|
|
|
2017-03-09 18:00:19 +08:00
|
|
|
enum class Platform { Unknown,Windows,MacOS,Linux,iOS,Android };
|
2017-03-21 12:30:29 +08:00
|
|
|
enum class PowerState { Unknown,OnBattery,NoBattery,Charging,Charged };
|
2017-03-09 18:00:19 +08:00
|
|
|
|
2017-03-24 13:50:48 +08:00
|
|
|
class LogSystem
|
|
|
|
{
|
|
|
|
static void v(const char* fmt,...);/// Verbose
|
|
|
|
static void d(const char* fmt,...);/// Debug
|
|
|
|
static void i(const char* fmt,...);/// Information
|
|
|
|
static void w(const char* fmt,...);/// Warning
|
|
|
|
static void e(const char* fmt,...);/// Error
|
|
|
|
static void critical(const char* fmt,...);/// Critical
|
|
|
|
};
|
|
|
|
|
2017-05-11 11:53:26 +08:00
|
|
|
class SharedLibrary
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SharedLibrary();
|
|
|
|
SharedLibrary(const std::string& Filename);
|
|
|
|
~SharedLibrary();
|
|
|
|
int load(const std::string& Filename);
|
|
|
|
int unload();
|
|
|
|
void* get(const std::string& FunctionName);
|
|
|
|
private:
|
|
|
|
void* _obj;
|
|
|
|
};
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
class SDLSystem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static int SDLInit();
|
|
|
|
static void SDLQuit();
|
|
|
|
static int IMGInit();
|
|
|
|
static void IMGQuit();
|
|
|
|
static int TTFInit();
|
|
|
|
static void TTFQuit();
|
|
|
|
static int MixInit();
|
|
|
|
static void MixQuit();
|
|
|
|
|
|
|
|
static void Init();
|
|
|
|
static void Quit();
|
|
|
|
|
|
|
|
static void Delay(int ms);
|
2017-03-09 18:00:19 +08:00
|
|
|
|
2017-03-21 12:30:29 +08:00
|
|
|
static PowerState GetPowerState();
|
2017-04-12 09:26:03 +08:00
|
|
|
static int GetPowerLifeLeft();
|
|
|
|
static int GetPowerPrecentageLeft();
|
2017-03-21 12:30:29 +08:00
|
|
|
|
2017-03-09 18:00:19 +08:00
|
|
|
static Platform GetPlatform();
|
|
|
|
|
2017-03-24 11:07:27 +08:00
|
|
|
static void StartTextInput();
|
|
|
|
static void StopTextInput();
|
|
|
|
|
2017-03-09 18:00:19 +08:00
|
|
|
class Android
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static std::string GetInternal();
|
|
|
|
static bool ExternalAvaliable();
|
|
|
|
static bool CanReadExternal();
|
|
|
|
static bool CanWriteExternal();
|
|
|
|
static std::string GetExternal();
|
|
|
|
static void* GetJNIEnv();
|
|
|
|
};
|
2017-02-25 09:29:34 +08:00
|
|
|
};
|
|
|
|
|
2017-04-19 14:11:08 +08:00
|
|
|
Uint32 _global_timer_executor(Uint32 interval,void* param);
|
|
|
|
|
2017-04-04 20:33:41 +08:00
|
|
|
class Timer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Timer();
|
2017-05-05 09:02:39 +08:00
|
|
|
|
|
|
|
/// void func(Uint32,...)
|
|
|
|
template<typename VoidCallable,typename... Args>
|
|
|
|
Timer(Uint32 interval,VoidCallable&& vcallable,Args&&... args) : Timer()
|
|
|
|
{
|
|
|
|
auto realCall=[&](Uint32 ims)->Uint32{vcallable(ims,args...);return interval;};
|
|
|
|
auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall);
|
|
|
|
_real_timer_call(_global_timer_executor,interval,pfunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Uint32 func(Uint32,...)
|
2017-04-19 14:11:08 +08:00
|
|
|
template<typename Callable,typename... Args>
|
|
|
|
Timer(Callable&& callable,Uint32 interval,Args&&... args) : Timer()
|
|
|
|
{
|
2017-05-05 09:02:39 +08:00
|
|
|
auto realCall=[&](Uint32 ims)->Uint32{return callable(ims,args...);};
|
2017-04-19 14:11:08 +08:00
|
|
|
auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall);
|
|
|
|
_real_timer_call(_global_timer_executor,interval,pfunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Restore For Capability
|
2017-04-04 20:33:41 +08:00
|
|
|
Timer(SDL_TimerCallback callback,Uint32 interval,void* param);
|
2017-04-19 14:11:08 +08:00
|
|
|
|
2017-04-04 20:33:41 +08:00
|
|
|
int enable();
|
|
|
|
int disable();
|
|
|
|
bool isenable();
|
|
|
|
void detach();
|
|
|
|
~Timer();
|
2017-04-19 14:11:08 +08:00
|
|
|
|
|
|
|
static void _delete_delegator(std::function<Uint32(Uint32)>* Delegator);
|
2017-04-04 20:33:41 +08:00
|
|
|
private:
|
2017-04-19 14:11:08 +08:00
|
|
|
|
|
|
|
void _real_timer_call(SDL_TimerCallback callback,Uint32 interval,void* param);
|
|
|
|
|
2017-04-04 20:33:41 +08:00
|
|
|
SDL_TimerCallback _callback;
|
|
|
|
Uint32 _interval;
|
|
|
|
void* _param;
|
|
|
|
SDL_TimerID id;
|
|
|
|
bool _enabled;
|
|
|
|
bool _detached;
|
2017-04-19 14:11:08 +08:00
|
|
|
/// Reserved Variable For Template variable Parameter
|
|
|
|
bool _delete_on_disable;
|
2017-04-04 20:33:41 +08:00
|
|
|
};
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
class AudioPlayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AudioPlayer();
|
|
|
|
~AudioPlayer();
|
|
|
|
private:
|
|
|
|
class _Audio
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
_Audio();
|
|
|
|
~_Audio();
|
|
|
|
};
|
|
|
|
|
|
|
|
static _Audio* _sysAudio;
|
|
|
|
static int _sysAudioCounter;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Forward Declaration
|
|
|
|
class Music
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Music() = default;
|
|
|
|
private:
|
2017-04-12 08:40:12 +08:00
|
|
|
std::shared_ptr<Mix_Music> _music;
|
|
|
|
void _set(Mix_Music*);
|
|
|
|
void _clear();
|
|
|
|
Mix_Music* _get();
|
2017-02-25 09:29:34 +08:00
|
|
|
friend class MusicPlayer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MusicPlayer : public AudioPlayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Music loadMusic(std::string Filename) throw (ErrorViewer);
|
|
|
|
|
|
|
|
int play(Music music, int loops);
|
|
|
|
void pause();
|
|
|
|
void resume();
|
|
|
|
void rewind();
|
|
|
|
int stop();
|
|
|
|
int fadeIn(int loops, int ms);
|
|
|
|
int fadeOut(int ms);
|
|
|
|
|
|
|
|
bool isPlaying();
|
|
|
|
bool isPaused();
|
|
|
|
int isFading();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Music m;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Sound
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
protected:
|
|
|
|
Sound() = default;
|
|
|
|
private:
|
2017-04-12 08:40:12 +08:00
|
|
|
std::shared_ptr<Mix_Chunk> _sound;
|
|
|
|
void _set(Mix_Chunk*);
|
|
|
|
void _clear();
|
|
|
|
Mix_Chunk* _get();
|
2017-02-25 09:29:34 +08:00
|
|
|
friend class SoundPlayer;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int ChannelID;
|
|
|
|
|
|
|
|
class SoundPlayer : public AudioPlayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SoundPlayer(int Channels = 16);
|
|
|
|
Sound loadSound(std::string Filename) throw (ErrorViewer);
|
|
|
|
ChannelID playSound(Sound sound, int loops) throw (ErrorViewer);
|
|
|
|
ChannelID fadein(Sound sound, int loops, int ms) throw (ErrorViewer);
|
|
|
|
int fadeout(ChannelID id, int ms);
|
|
|
|
void pause(ChannelID id);
|
|
|
|
void resume(ChannelID id);
|
|
|
|
int stop(ChannelID id);
|
|
|
|
};
|
|
|
|
|
2017-03-09 18:52:57 +08:00
|
|
|
class StringEngine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StringEngine(std::string StringFile,std::string LanguageTag);
|
|
|
|
|
|
|
|
StringEngine(StringEngine& )=delete;
|
|
|
|
StringEngine& operator = (StringEngine& )=delete;
|
|
|
|
|
|
|
|
int useLanaguage(std::string LanguageTag);
|
|
|
|
bool ready();
|
|
|
|
std::string getString(std::string Tag);
|
|
|
|
~StringEngine();
|
|
|
|
private:
|
|
|
|
struct impl;
|
|
|
|
impl* pimpl;
|
|
|
|
};
|
|
|
|
|
2017-02-25 09:29:34 +08:00
|
|
|
}/// End of namespace MiniEngine
|
|
|
|
|
2017-02-25 22:40:48 +08:00
|
|
|
std::string UTF8ToGBK(std::string UTF8String);
|
|
|
|
std::string GBKToUTF8(std::string GBKString);
|
2017-03-09 18:52:57 +08:00
|
|
|
bool canread(std::string Path);
|
|
|
|
bool canwrite(std::string Path);
|
|
|
|
bool isexist(std::string Path);
|
|
|
|
bool canexecute(std::string Path);
|
2017-02-25 09:29:34 +08:00
|
|
|
|
|
|
|
/// Your Program Should Start Here
|
|
|
|
int AppMain();
|
|
|
|
|
2017-02-25 22:40:48 +08:00
|
|
|
/// MiniEngine Provides main
|
|
|
|
int main(int argc,char* argv[]);
|
2017-03-30 11:16:57 +08:00
|
|
|
|
|
|
|
/// MiniEngine Provided API: Get Start Parameters
|
|
|
|
int GetArgc();
|
|
|
|
char** GetArgv();
|