summaryrefslogtreecommitdiff
path: root/src/guichan/graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/guichan/graphics.cpp')
-rw-r--r--src/guichan/graphics.cpp62
1 files changed, 25 insertions, 37 deletions
diff --git a/src/guichan/graphics.cpp b/src/guichan/graphics.cpp
index 688362c12..7809223b7 100644
--- a/src/guichan/graphics.cpp
+++ b/src/guichan/graphics.cpp
@@ -54,9 +54,9 @@
namespace gcn
{
- Graphics::Graphics()
+ Graphics::Graphics() :
+ mFont(NULL)
{
- mFont = NULL;
}
bool Graphics::pushClipArea(Rectangle area)
@@ -70,7 +70,7 @@ namespace gcn
mClipStack.push(carea);
return true;
}
-
+
if (mClipStack.empty())
{
ClipRectangle carea;
@@ -94,39 +94,31 @@ namespace gcn
// Clamp the pushed clip rectangle.
if (carea.x < top.x)
- {
carea.x = top.x;
- }
-
+
if (carea.y < top.y)
- {
- carea.y = top.y;
- }
-
+ carea.y = top.y;
+
if (carea.x + carea.width > top.x + top.width)
{
carea.width = top.x + top.width - carea.x;
if (carea.width < 0)
- {
carea.width = 0;
- }
}
-
+
if (carea.y + carea.height > top.y + top.height)
{
carea.height = top.y + top.height - carea.y;
-
+
if (carea.height < 0)
- {
carea.height = 0;
- }
}
-
+
bool result = carea.isIntersecting(top);
-
+
mClipStack.push(carea);
-
+
return result;
}
@@ -134,9 +126,7 @@ namespace gcn
{
if (mClipStack.empty())
- {
throw GCN_EXCEPTION("Tried to pop clip area from empty stack.");
- }
mClipStack.pop();
}
@@ -144,16 +134,15 @@ namespace gcn
const ClipRectangle& Graphics::getCurrentClipArea()
{
if (mClipStack.empty())
- {
throw GCN_EXCEPTION("The clip area stack is empty.");
- }
return mClipStack.top();
}
void Graphics::drawImage(const Image* image, int dstX, int dstY)
{
- drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight());
+ drawImage(image, 0, 0, dstX, dstY,
+ image->getWidth(), image->getHeight());
}
void Graphics::setFont(Font* font)
@@ -165,23 +154,22 @@ namespace gcn
Alignment alignment)
{
if (mFont == NULL)
- {
throw GCN_EXCEPTION("No font set.");
- }
switch (alignment)
{
- case LEFT:
- mFont->drawString(this, text, x, y);
- break;
- case CENTER:
- mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y);
- break;
- case RIGHT:
- mFont->drawString(this, text, x - mFont->getWidth(text), y);
- break;
- default:
- throw GCN_EXCEPTION("Unknown alignment.");
+ case LEFT:
+ mFont->drawString(this, text, x, y);
+ break;
+ case CENTER:
+ mFont->drawString(this, text, x
+ - mFont->getWidth(text) / 2, y);
+ break;
+ case RIGHT:
+ mFont->drawString(this, text, x - mFont->getWidth(text), y);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown alignment.");
}
}
}