mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
159 lines
3.1 KiB
C++
159 lines
3.1 KiB
C++
#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);
|
|
|
|
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;
|
|
};
|
|
|
|
class Renderer;
|
|
class Texture;
|
|
class Font;
|
|
|
|
#define _SDL_ENGINE_IMPL_COPY_DECL(ClassName) \
|
|
ClassName(const ClassName&); \
|
|
ClassName(ClassName&&); \
|
|
ClassName& operator = (const ClassName&); \
|
|
ClassName& operator = (ClassName&&);
|
|
|
|
#define _SDL_ENGINE_IMPL \
|
|
struct impl; \
|
|
impl* pimpl;
|
|
|
|
#define DEFAULT_WIDTH 1024
|
|
#define DEFAULT_HEIGHT 768
|
|
|
|
class Window
|
|
{
|
|
public:
|
|
Window(int winw,int winh);
|
|
~Window();
|
|
|
|
_SDL_ENGINE_IMPL_COPY_DECL(Window);
|
|
|
|
Renderer getRenderer() const;
|
|
void resetRenderer();
|
|
|
|
Rect getSize();
|
|
|
|
void setSize(Rect r);
|
|
|
|
private:
|
|
_SDL_ENGINE_IMPL
|
|
};
|
|
|
|
class Surface
|
|
{
|
|
public:
|
|
~Surface();
|
|
_SDL_ENGINE_IMPL_COPY_DECL(Surface);
|
|
protected:
|
|
Surface();
|
|
private:
|
|
_SDL_ENGINE_IMPL
|
|
friend class Renderer;
|
|
friend class Font;
|
|
};
|
|
|
|
class Renderer
|
|
{
|
|
public:
|
|
virtual ~Renderer();
|
|
_SDL_ENGINE_IMPL_COPY_DECL(Renderer);
|
|
|
|
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);
|
|
|
|
int setColor(RGBA pack);
|
|
RGBA getColor(int* pStatus=nullptr);
|
|
|
|
int fillRect(Rect rect);
|
|
int drawRect(Rect rect);
|
|
|
|
/// Not Recommended
|
|
SDL_Renderer* getDirectRenderer();
|
|
protected:
|
|
Renderer();
|
|
private:
|
|
_SDL_ENGINE_IMPL
|
|
friend class Window;
|
|
};
|
|
|
|
class Texture
|
|
{
|
|
public:
|
|
~Texture();
|
|
int getw();
|
|
int geth();
|
|
_SDL_ENGINE_IMPL_COPY_DECL(Texture);
|
|
protected:
|
|
Texture();
|
|
private:
|
|
_SDL_ENGINE_IMPL
|
|
friend class Renderer;
|
|
};
|
|
|
|
class Font
|
|
{
|
|
public:
|
|
Font();
|
|
Font(const char* FontFileName,int sz);
|
|
int use(const char* FontFileName,int sz);
|
|
~Font();
|
|
|
|
_SDL_ENGINE_IMPL_COPY_DECL(Font);
|
|
|
|
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
|
|
};
|
|
|
|
class SDLSystem
|
|
{
|
|
public:
|
|
static void delay(int ms);
|
|
};
|
|
|
|
}/// End of namespace Engine
|
|
|