Renderer::GetClipRect() now returns Optional

Also add test for clipping rect
This commit is contained in:
Dmitry Marakasov 2016-01-28 00:05:49 +03:00
parent 31e3c4df74
commit a52555b927
4 changed files with 36 additions and 4 deletions

View File

@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## 0.13.0 - unreleased
### Changed
* ```Renderer::GetClipRect``` now returns ```Optional<Rect>``` instead of (possibly empty) ```Rect```
### Removed
* Deprecated ```Renderer::GetInfo()``` variant which takes pointer (use variant which takes reference)

View File

@ -352,10 +352,14 @@ bool Renderer::TargetSupported() const {
return SDL_RenderTargetSupported(renderer_) == SDL_TRUE;
}
Rect Renderer::GetClipRect() const {
Optional<Rect> Renderer::GetClipRect() const {
SDL_Rect rect;
SDL_RenderGetClipRect(renderer_, &rect);
return rect;
if (SDL_RectEmpty(&rect))
return NullOpt;
else
return Rect(rect);
}
Point Renderer::GetLogicalSize() const {

View File

@ -648,12 +648,13 @@ public:
////////////////////////////////////////////////////////////
/// \brief Get the clip rectangle for the current target
///
/// \returns Rect representing current clipping area
/// \returns Rect representing current clipping area or
/// NullOpt if clipping is disabled
///
/// \see http://wiki.libsdl.org/SDL_RenderGetClipRect
///
////////////////////////////////////////////////////////////
Rect GetClipRect() const;
Optional<Rect> GetClipRect() const;
////////////////////////////////////////////////////////////
/// \brief Get device independent resolution for rendering

View File

@ -205,6 +205,30 @@ BEGIN_TEST(int, char*[])
SDL_Delay(1000);
}
{
// Clip rect
renderer.SetDrawColor(0, 0, 0);
renderer.Clear();
renderer.SetClipRect(Rect(1, 1, 1, 1));
renderer.SetDrawColor(255, 255, 255);
renderer.FillRect(0, 0, 10, 10);
EXPECT_TRUE(renderer.GetClipRect() && renderer.GetClipRect() == Rect(1, 1, 1, 1));
renderer.SetClipRect(NullOpt);
EXPECT_TRUE(!renderer.GetClipRect());
pixels.Retrieve(renderer);
EXPECT_TRUE(pixels.Test3x3(1, 1, 0x020, 255, 255, 255));
renderer.Present();
SDL_Delay(1000);
}
{
// Blend
renderer.SetDrawColor(0, 0, 0);