MiniEngine/include/sdl_engine.h

159 lines
3.1 KiB
C
Raw Normal View History

2017-01-03 23:32:35 +08:00
#pragma once
#include "basic_config.h"
SDL_Texture* RenderText(SDL_Renderer* rnd,TTF_Font* font,const char* Text,SDL_Color color,int* pw,int* ph);
SDL_Texture* RenderUTF8(SDL_Renderer* rnd,TTF_Font* font,const char* Text,SDL_Color color,int* pw,int* ph);
void TextureDraw(SDL_Renderer* rnd,SDL_Texture* texture,int dstx,int dsty);
bool isInRect(int x,int y,SDL_Rect rect);
bool isInRect(int x,int y,int LU_x,int LU_y,int RD_x,int RD_y);
void ClearMessageQueue();
int MyChangeDir(const char* DirName);
2017-01-04 09:50:16 +08:00
namespace Engine
{
class Rect
{
public:
Rect();
Rect(int incx,int incy,int incw,int inch);
SDL_Rect toSDLRect();
~Rect();
int x,y,w,h;
};
class RGBA
{
public:
RGBA();
RGBA(int incr,int incg,int incb,int inca);
~RGBA();
SDL_Color toSDLColor();
int r,g,b,a;
};
2017-01-04 09:50:16 +08:00
class Renderer;
class Texture;
2017-01-05 13:25:09 +08:00
class Font;
#define _SDL_ENGINE_IMPL_COPY_DECL(ClassName) \
ClassName(const ClassName&); \
ClassName(ClassName&&); \
ClassName& operator = (const ClassName&); \
ClassName& operator = (ClassName&&);
2017-01-05 13:25:09 +08:00
#define _SDL_ENGINE_IMPL \
struct impl; \
impl* pimpl;
2017-01-04 09:50:16 +08:00
2017-01-07 09:52:56 +08:00
#define DEFAULT_WIDTH 1024
#define DEFAULT_HEIGHT 768
2017-01-04 09:50:16 +08:00
class Window
{
public:
Window(int winw,int winh);
~Window();
2017-01-05 13:25:09 +08:00
_SDL_ENGINE_IMPL_COPY_DECL(Window);
2017-01-05 13:25:09 +08:00
Renderer getRenderer() const;
2017-01-07 09:52:56 +08:00
void resetRenderer();
2017-01-04 09:50:16 +08:00
Rect getSize();
2017-01-04 09:50:16 +08:00
void setSize(Rect r);
2017-01-07 09:52:56 +08:00
2017-01-04 09:50:16 +08:00
private:
_SDL_ENGINE_IMPL
2017-01-04 09:50:16 +08:00
};
class Surface
{
public:
~Surface();
2017-01-05 13:25:09 +08:00
_SDL_ENGINE_IMPL_COPY_DECL(Surface);
2017-01-04 09:50:16 +08:00
protected:
Surface();
private:
_SDL_ENGINE_IMPL
2017-01-04 09:50:16 +08:00
friend class Renderer;
2017-01-05 13:25:09 +08:00
friend class Font;
2017-01-04 09:50:16 +08:00
};
class Renderer
{
public:
virtual ~Renderer();
2017-01-05 13:25:09 +08:00
_SDL_ENGINE_IMPL_COPY_DECL(Renderer);
2017-01-04 09:50:16 +08:00
int clear();
void update();
int copy(Texture t,Rect src,Rect dst);
int copyTo(Texture t,Rect dst);
int copyFill(Texture t,Rect src);
int copyFullFill(Texture t);
Texture loadImage(const char* FileName);
Texture render(Surface surface);
2017-01-05 13:25:09 +08:00
int setColor(RGBA pack);
RGBA getColor(int* pStatus=nullptr);
int fillRect(Rect rect);
int drawRect(Rect rect);
/// Not Recommended
SDL_Renderer* getDirectRenderer();
2017-01-04 09:50:16 +08:00
protected:
Renderer();
private:
_SDL_ENGINE_IMPL
2017-01-04 09:50:16 +08:00
friend class Window;
};
class Texture
{
public:
~Texture();
int getw();
int geth();
2017-01-05 13:25:09 +08:00
_SDL_ENGINE_IMPL_COPY_DECL(Texture);
2017-01-04 09:50:16 +08:00
protected:
Texture();
private:
_SDL_ENGINE_IMPL
2017-01-04 09:50:16 +08:00
friend class Renderer;
};
class Font
{
public:
Font();
Font(const char* FontFileName,int sz);
2017-01-05 13:25:09 +08:00
int use(const char* FontFileName,int sz);
2017-01-04 09:50:16 +08:00
~Font();
2017-01-05 13:25:09 +08:00
_SDL_ENGINE_IMPL_COPY_DECL(Font);
2017-01-04 09:50:16 +08:00
Texture renderText(Renderer rnd,const char* Word,RGBA fg);
Texture renderTextShaded(Renderer rnd,const char* Word,RGBA fg,RGBA bg);
Texture renderTextSolid(Renderer rnd,const char* Word,RGBA fg);
Texture renderUTF8(Renderer rnd,const char* Word,RGBA fg);
Texture renderUTF8Shaded(Renderer rnd,const char* Word,RGBA fg,RGBA bg);
Texture renderUTF8Solid(Renderer rnd,const char* Word,RGBA fg);
private:
_SDL_ENGINE_IMPL
2017-01-04 09:50:16 +08:00
};
class SDLSystem
{
public:
static void delay(int ms);
};
2017-01-04 09:50:16 +08:00
}/// End of namespace Engine