2017-01-03 23:32:35 +08:00
|
|
|
#include "sdl_engine.h"
|
|
|
|
#include "unistd.h"
|
2017-01-04 09:50:16 +08:00
|
|
|
#include <memory>
|
|
|
|
using namespace std;
|
2017-01-03 23:32:35 +08:00
|
|
|
|
|
|
|
SDL_Texture* RenderUTF8(SDL_Renderer* rnd,TTF_Font* font,const char* Text,SDL_Color color,int* pw,int* ph)
|
|
|
|
{
|
|
|
|
SDL_Surface* surf=TTF_RenderUTF8_Blended(font,Text,color);
|
|
|
|
if(surf==NULL) return NULL;
|
|
|
|
SDL_Texture* texture=SDL_CreateTextureFromSurface(rnd,surf);
|
|
|
|
SDL_FreeSurface(surf);
|
|
|
|
if(pw&&ph) SDL_QueryTexture(texture,NULL,NULL,pw,ph);
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInRect(int x,int y,SDL_Rect rect)
|
|
|
|
{
|
|
|
|
return ((x>=rect.x&&x<=rect.x+rect.w)&&(y>=rect.y&&y<=rect.y+rect.h));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInRect(int x,int y,int LU_x,int LU_y,int RD_x,int RD_y)
|
|
|
|
{
|
|
|
|
return ((x>=LU_x&&x<=RD_x)&&(y>=LU_y&&y<=RD_y));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearMessageQueue()
|
|
|
|
{
|
|
|
|
/// Clear Message Queue
|
|
|
|
while(SDL_PeepEvents(NULL,1,SDL_GETEVENT,SDL_FIRSTEVENT,SDL_LASTEVENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Color color_white { 255,255,255 };
|
|
|
|
SDL_Color color_black { 0,0,0 };
|
|
|
|
|
|
|
|
int MyChangeDir(const char* DirName)
|
|
|
|
{
|
|
|
|
mlog("Change Dir to \"%s\"",DirName);
|
|
|
|
int ret=chdir(DirName);
|
|
|
|
mlog("Change Dir returns %d",ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-01-04 09:50:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
namespace Engine
|
|
|
|
{
|
|
|
|
|
2017-01-05 13:25:09 +08:00
|
|
|
/// Rect
|
|
|
|
#include "sdl_engine_rect.hpp"
|
2017-01-04 09:50:16 +08:00
|
|
|
|
|
|
|
struct Window::impl
|
|
|
|
{
|
|
|
|
shared_ptr<SDL_Window> sWnd;
|
|
|
|
Renderer rnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Renderer::impl
|
|
|
|
{
|
|
|
|
shared_ptr<SDL_Renderer> sRnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Texture::impl
|
|
|
|
{
|
|
|
|
shared_ptr<SDL_Texture> sText;
|
|
|
|
int w,h;
|
|
|
|
};
|
|
|
|
|
2017-01-05 13:25:09 +08:00
|
|
|
struct Surface::impl
|
2017-01-04 09:50:16 +08:00
|
|
|
{
|
2017-01-05 13:25:09 +08:00
|
|
|
shared_ptr<SDL_Surface> sSurf;
|
|
|
|
};
|
2017-01-04 09:50:16 +08:00
|
|
|
|
|
|
|
struct Font::impl
|
|
|
|
{
|
|
|
|
shared_ptr<TTF_Font> sTTF;
|
|
|
|
};
|
|
|
|
|
2017-01-05 13:25:09 +08:00
|
|
|
/// Window
|
|
|
|
#include "sdl_engine_window.hpp"
|
|
|
|
/// Renderer
|
|
|
|
#include "sdl_engine_renderer.hpp"
|
|
|
|
/// Surface
|
|
|
|
#include "sdl_engine_surface.hpp"
|
|
|
|
/// Texture
|
|
|
|
#include "sdl_engine_texture.hpp"
|
|
|
|
/// RGBA
|
|
|
|
#include "sdl_engine_rgba.hpp"
|
|
|
|
/// Font
|
|
|
|
#include "sdl_engine_font.hpp"
|
2017-01-04 09:50:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}/// End of namespace Engine
|