summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-13 21:38:01 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-13 21:38:01 +0300
commitaa03bdb26c736e7d506d656a5529cf6a4e9fe6b4 (patch)
tree19b7e9958b54ac138b10a606b0360c12626203af /src
parent1a6a12a8b3310400a103e0048b7ed747fc479398 (diff)
downloadplus-aa03bdb26c736e7d506d656a5529cf6a4e9fe6b4.tar.gz
plus-aa03bdb26c736e7d506d656a5529cf6a4e9fe6b4.tar.bz2
plus-aa03bdb26c736e7d506d656a5529cf6a4e9fe6b4.tar.xz
plus-aa03bdb26c736e7d506d656a5529cf6a4e9fe6b4.zip
New stack class in graphics areas stack.
Diffstat (limited to 'src')
-rw-r--r--src/render/graphics.cpp31
-rw-r--r--src/render/graphics.h5
-rw-r--r--src/resources/mstack.h7
3 files changed, 26 insertions, 17 deletions
diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp
index 17f8a6d2e..4542a33ae 100644
--- a/src/render/graphics.cpp
+++ b/src/render/graphics.cpp
@@ -102,7 +102,7 @@ Graphics::Graphics() :
mHeight(0),
mActualWidth(0),
mActualHeight(0),
- mClipStack(),
+ mClipStack(1000),
mWindow(nullptr),
#ifdef USE_SDL2
mRenderer(nullptr),
@@ -576,31 +576,36 @@ void Graphics::pushClipArea(const Rect &area)
// to the stack.
if (area.width < 0 || area.height < 0)
{
- ClipRect carea;
- mClipStack.push(carea);
+ ClipRect &carea = mClipStack.push();
+ carea.x = 0;
+ carea.y = 0;
+ carea.width = 0;
+ carea.height = 0;
+ carea.xOffset = 0;
+ carea.yOffset = 0;
return;
}
if (mClipStack.empty())
{
- ClipRect carea;
+ ClipRect &carea = mClipStack.push();
carea.x = area.x;
carea.y = area.y;
carea.width = area.width;
carea.height = area.height;
carea.xOffset = area.x;
carea.yOffset = area.y;
- mClipStack.push(carea);
return;
}
const ClipRect &top = mClipStack.top();
- ClipRect carea;
- carea = area;
- carea.xOffset = top.xOffset + carea.x;
- carea.yOffset = top.yOffset + carea.y;
- carea.x += top.xOffset;
- carea.y += top.yOffset;
+ ClipRect &carea = mClipStack.push();
+ carea.x = area.x + top.xOffset;
+ carea.y = area.y + top.yOffset;
+ carea.width = area.width;
+ carea.height = area.height;
+ carea.xOffset = top.xOffset + area.x;
+ carea.yOffset = top.yOffset + area.y;
// Clamp the pushed clip rectangle.
if (carea.x < top.x)
@@ -624,8 +629,6 @@ void Graphics::pushClipArea(const Rect &area)
if (carea.height < 0)
carea.height = 0;
}
-
- mClipStack.push(carea);
}
void Graphics::popClipArea()
@@ -641,7 +644,7 @@ const ClipRect *Graphics::getCurrentClipArea() const
if (mClipStack.empty())
return nullptr;
- return &mClipStack.top();
+ return &mClipStack.topConst();
}
#ifdef USE_OPENGL
diff --git a/src/render/graphics.h b/src/render/graphics.h
index c803b7746..c43471f66 100644
--- a/src/render/graphics.h
+++ b/src/render/graphics.h
@@ -72,9 +72,10 @@
#include "enums/render/rendertype.h"
#include "gui/color.h"
-
#include "gui/cliprect.h"
+#include "resources/mstack.h"
+
#include <SDL_video.h>
#ifdef USE_SDL2
@@ -514,7 +515,7 @@ class Graphics notfinal
/**
* Holds the clip area stack.
*/
- std::stack<ClipRect> mClipStack;
+ MStack<ClipRect> mClipStack;
SDL_Window *mWindow;
diff --git a/src/resources/mstack.h b/src/resources/mstack.h
index ba1a58eb2..2a568bc5a 100644
--- a/src/resources/mstack.h
+++ b/src/resources/mstack.h
@@ -78,7 +78,7 @@ struct MStack final
mPointer --;
}
- T &top()
+ T &top() const
{
return *mPointer;
}
@@ -93,6 +93,11 @@ struct MStack final
mPointer = mStack - 1;
}
+ bool empty() const
+ {
+ return mPointer == mStartPointer;
+ }
+
T *mStack;
size_t mMaxSize;