[Bug Fix & Update] SDL Engine

Example code changed.
This commit is contained in:
Kirigaya Kazuto 2017-01-07 17:51:09 +08:00
parent e135eb35ac
commit 88d5a9c96b
8 changed files with 114 additions and 11 deletions

View File

@ -9,5 +9,7 @@ namespace App
{ {
Window wnd(1024,768); Window wnd(1024,768);
Renderer rnd=wnd.getRenderer(); Renderer rnd=wnd.getRenderer();
rnd.clear();
rnd.update();
} }
} }

View File

@ -71,6 +71,10 @@ public:
sWnd.reset(wnd,SDL_DestroyWindow); sWnd.reset(wnd,SDL_DestroyWindow);
rnd.pimpl->set(SDL_CreateRenderer(wnd,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_TARGETTEXTURE)); rnd.pimpl->set(SDL_CreateRenderer(wnd,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_TARGETTEXTURE));
} }
SDL_Window* getRawWindow()
{
return sWnd.get();
}
}; };
struct Texture::impl struct Texture::impl

View File

@ -30,7 +30,8 @@ class Font;
#define _SDL_ENGINE_IMPL_COPY_DECL(ClassName) \ #define _SDL_ENGINE_IMPL_COPY_DECL(ClassName) \
ClassName(const ClassName&); \ ClassName(const ClassName&); \
ClassName(ClassName&&); \ ClassName(ClassName&&); \
ClassName& operator = (const ClassName&); ClassName& operator = (const ClassName&); \
ClassName& operator = (ClassName&&);
#define _SDL_ENGINE_IMPL \ #define _SDL_ENGINE_IMPL \
struct impl; \ struct impl; \
@ -51,6 +52,7 @@ public:
void resetRenderer(); void resetRenderer();
Rect getSize(); Rect getSize();
void setSize(Rect r); void setSize(Rect r);
private: private:

View File

@ -8,6 +8,32 @@ Font::Font(const char* FontFileName,int sz) : Font()
use(FontFileName,sz); use(FontFileName,sz);
} }
Font::Font(const Font& inc) : Font()
{
*pimpl=*(inc.pimpl);
}
Font& Font::operator = (const Font& inc)
{
*pimpl=*(inc.pimpl);
return *this;
}
Font::Font(Font&& inc)
{
pimpl=inc.pimpl;
inc.pimpl=nullptr;
}
Font& Font::operator = (Font&& inc)
{
*pimpl=*(inc.pimpl);
inc.pimpl=nullptr;
return *this;
}
Font::~Font()
{
delete pimpl;
}
int Font::use(const char* FontFileName,int sz) int Font::use(const char* FontFileName,int sz)
{ {
TTF_Font* font=TTF_OpenFont(FontFileName,sz); TTF_Font* font=TTF_OpenFont(FontFileName,sz);
@ -16,10 +42,7 @@ int Font::use(const char* FontFileName,int sz)
return 0; return 0;
} }
Font::~Font()
{
delete pimpl;
}
Texture Font::renderText(Renderer rnd,const char* Word,RGBA fg) Texture Font::renderText(Renderer rnd,const char* Word,RGBA fg)
{ {

View File

@ -11,11 +11,23 @@ Renderer& Renderer::operator = (const Renderer& inc)
*pimpl=*(inc.pimpl); *pimpl=*(inc.pimpl);
return *this; return *this;
} }
Renderer::Renderer(Renderer&& inc)
{
pimpl=inc.pimpl;
inc.pimpl=nullptr;
}
Renderer& Renderer::operator = (Renderer&& inc)
{
*pimpl=*(inc.pimpl);
inc.pimpl=nullptr;
return *this;
}
Renderer::~Renderer() Renderer::~Renderer()
{ {
delete pimpl; delete pimpl;
} }
int Renderer::clear() int Renderer::clear()
{ {
return SDL_RenderClear(pimpl->sRnd.get()); return SDL_RenderClear(pimpl->sRnd.get());

View File

@ -2,11 +2,26 @@ Surface::Surface()
{ {
pimpl=new impl; pimpl=new impl;
} }
Surface::~Surface()
{
delete pimpl;
}
Surface::Surface(const Surface& inc) : Surface() Surface::Surface(const Surface& inc) : Surface()
{ {
*pimpl=*(inc.pimpl); *pimpl=*(inc.pimpl);
} }
Surface& Surface::operator = (const Surface& inc)
{
*pimpl=*(inc.pimpl);
return *this;
}
Surface::Surface(Surface&& inc)
{
pimpl=inc.pimpl;
inc.pimpl=nullptr;
}
Surface& Surface::operator = (Surface&& inc)
{
*(pimpl)=*(inc.pimpl);
return *this;
}
Surface::~Surface()
{
delete pimpl;
}

View File

@ -11,6 +11,17 @@ Texture& Texture::operator = (const Texture& inc)
*pimpl=*(inc.pimpl); *pimpl=*(inc.pimpl);
return *this; return *this;
} }
Texture::Texture(Texture&& inc)
{
pimpl=inc.pimpl;
inc.pimpl=nullptr;
}
Texture& Texture::operator = (Texture&& inc)
{
*(pimpl)=*(inc.pimpl);
inc.pimpl=nullptr;
return *this;
}
int Texture::getw() int Texture::getw()
{ {

View File

@ -5,6 +5,32 @@ Window::Window(int winw,int winh)
pimpl->set(wnd); pimpl->set(wnd);
} }
Window::Window(const Window& inc)
{
pimpl=new impl;
*pimpl=*(inc.pimpl);
}
Window& Window::operator = (const Window& inc)
{
*pimpl=*(inc.pimpl);
return *this;
}
Window::Window(Window&& inc)
{
pimpl=inc.pimpl;
inc.pimpl=nullptr;
}
Window& Window::operator = (Window&& inc)
{
*pimpl=*(inc.pimpl);
inc.pimpl=nullptr;
return *this;
}
Window::~Window() Window::~Window()
{ {
delete pimpl; delete pimpl;
@ -15,7 +41,15 @@ Renderer Window::getRenderer()
return pimpl->rnd; return pimpl->rnd;
} }
Window::Window(const Window& inc) : Window(DEFAULT_WIDTH,DEFAULT_HEIGHT) Rect Window::getSize()
{ {
*pimpl=*(inc.pimpl); int w,h;
SDL_GetWindowSize(pimpl->getRawWindow(),&w,&h);
Rect rect(0,0,w,h);
return rect;
}
void Window::setSize(Rect rect)
{
SDL_SetWindowSize(pimpl->getRawWindow(),rect.w,rect.h);
} }