From 6b536863831d4ca31b17d5ffc8d841215d36c772 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Fri, 7 Apr 2017 16:36:21 +0800 Subject: [PATCH] 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. --- MiniEngine.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ MiniEngine.h | 11 ++++++++++ 2 files changed, 65 insertions(+) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index e731c3f..6949751 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -25,6 +25,14 @@ namespace MiniEngine h = H; } + Rect::Rect(SDL_Rect rect) + { + x=rect.x; + y=rect.y; + w=rect.w; + h=rect.h; + } + Rect::Rect() { x = y = w = h = 0; @@ -272,6 +280,11 @@ namespace MiniEngine 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() { return SDL_RenderClear(rnd.lock().get()); @@ -410,6 +423,47 @@ namespace MiniEngine 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() { return !rnd.expired(); diff --git a/MiniEngine.h b/MiniEngine.h index cd934ba..f2b4b8c 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -20,6 +20,7 @@ namespace MiniEngine public: int x, y, w, h; Rect(int X, int Y, int W, int H); + Rect(SDL_Rect); Rect(); SDL_Rect toSDLRect(); }; @@ -147,6 +148,7 @@ namespace MiniEngine int fillRect(Rect rect); int drawRect(Rect rect); int drawPoint(Point p); + int drawLine(Point a,Point b); int clear(); void update(); @@ -164,6 +166,15 @@ namespace MiniEngine Texture loadTexture(std::string FileName) 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(); private: std::weak_ptr rnd;