mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Add support for Viewport and ClipRect setting.
New Method in class Renderer: setViewport/getViewport , setClipRect/getClipRect... , drawLine class Rect can be initialized from SDL_Rect now.
This commit is contained in:
parent
fb6bee96a7
commit
6b53686383
|
@ -25,6 +25,14 @@ namespace MiniEngine
|
||||||
h = H;
|
h = H;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect::Rect(SDL_Rect rect)
|
||||||
|
{
|
||||||
|
x=rect.x;
|
||||||
|
y=rect.y;
|
||||||
|
w=rect.w;
|
||||||
|
h=rect.h;
|
||||||
|
}
|
||||||
|
|
||||||
Rect::Rect()
|
Rect::Rect()
|
||||||
{
|
{
|
||||||
x = y = w = h = 0;
|
x = y = w = h = 0;
|
||||||
|
@ -272,6 +280,11 @@ namespace MiniEngine
|
||||||
return SDL_RenderDrawPoint(rnd.lock().get(),p.x,p.y);
|
return SDL_RenderDrawPoint(rnd.lock().get(),p.x,p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Renderer::drawLine(Point a,Point b)
|
||||||
|
{
|
||||||
|
return SDL_RenderDrawLine(rnd.lock().get(),a.x,a.y,b.x,b.y);
|
||||||
|
}
|
||||||
|
|
||||||
int Renderer::clear()
|
int Renderer::clear()
|
||||||
{
|
{
|
||||||
return SDL_RenderClear(rnd.lock().get());
|
return SDL_RenderClear(rnd.lock().get());
|
||||||
|
@ -410,6 +423,47 @@ namespace MiniEngine
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Renderer::setViewport(Rect viewPort)
|
||||||
|
{
|
||||||
|
SDL_Rect rect=viewPort.toSDLRect();
|
||||||
|
return SDL_RenderSetViewport(rnd.lock().get(),&rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Renderer::setViewport()
|
||||||
|
{
|
||||||
|
return SDL_RenderSetViewport(rnd.lock().get(),NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect Renderer::getViewport()
|
||||||
|
{
|
||||||
|
SDL_Rect rect;
|
||||||
|
SDL_RenderGetViewport(rnd.lock().get(),&rect);
|
||||||
|
return Rect(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Renderer::setClipRect(Rect cliparea)
|
||||||
|
{
|
||||||
|
SDL_Rect rect=cliparea.toSDLRect();
|
||||||
|
return SDL_RenderSetClipRect(rnd.lock().get(),&rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect Renderer::getClipRect()
|
||||||
|
{
|
||||||
|
SDL_Rect rect;
|
||||||
|
SDL_RenderGetClipRect(rnd.lock().get(),&rect);
|
||||||
|
return Rect(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Renderer::isClipEnabled()
|
||||||
|
{
|
||||||
|
return SDL_RenderIsClipEnabled(rnd.lock().get())==SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::disableClip()
|
||||||
|
{
|
||||||
|
SDL_RenderSetClipRect(rnd.lock().get(),NULL);
|
||||||
|
}
|
||||||
|
|
||||||
bool Renderer::isReady()
|
bool Renderer::isReady()
|
||||||
{
|
{
|
||||||
return !rnd.expired();
|
return !rnd.expired();
|
||||||
|
|
11
MiniEngine.h
11
MiniEngine.h
|
@ -20,6 +20,7 @@ namespace MiniEngine
|
||||||
public:
|
public:
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
Rect(int X, int Y, int W, int H);
|
Rect(int X, int Y, int W, int H);
|
||||||
|
Rect(SDL_Rect);
|
||||||
Rect();
|
Rect();
|
||||||
SDL_Rect toSDLRect();
|
SDL_Rect toSDLRect();
|
||||||
};
|
};
|
||||||
|
@ -147,6 +148,7 @@ namespace MiniEngine
|
||||||
int fillRect(Rect rect);
|
int fillRect(Rect rect);
|
||||||
int drawRect(Rect rect);
|
int drawRect(Rect rect);
|
||||||
int drawPoint(Point p);
|
int drawPoint(Point p);
|
||||||
|
int drawLine(Point a,Point b);
|
||||||
|
|
||||||
int clear();
|
int clear();
|
||||||
void update();
|
void update();
|
||||||
|
@ -164,6 +166,15 @@ namespace MiniEngine
|
||||||
Texture loadTexture(std::string FileName) throw(ErrorViewer);
|
Texture loadTexture(std::string FileName) throw(ErrorViewer);
|
||||||
Texture createTexture(int Width, int Height) throw(ErrorViewer);
|
Texture createTexture(int Width, int Height) throw(ErrorViewer);
|
||||||
|
|
||||||
|
int setViewport(Rect viewport);
|
||||||
|
int setViewport();
|
||||||
|
Rect getViewport();
|
||||||
|
|
||||||
|
int setClipRect(Rect cliprect);
|
||||||
|
Rect getClipRect();
|
||||||
|
bool isClipEnabled();
|
||||||
|
void disableClip();
|
||||||
|
|
||||||
bool isReady();
|
bool isReady();
|
||||||
private:
|
private:
|
||||||
std::weak_ptr<SDL_Renderer> rnd;
|
std::weak_ptr<SDL_Renderer> rnd;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user