diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-08-25 19:24:56 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-08-25 19:24:56 +0000 |
commit | 7cd9c0d02d148cdbacbca6624d8749a344ddbfe0 (patch) | |
tree | 8b8b61611584fe45c1f0908fb9b468559468d858 | |
parent | 2c7d0b3518d72a7ab0726b72f7d2137e5944f049 (diff) | |
download | mana-client-7cd9c0d02d148cdbacbca6624d8749a344ddbfe0.tar.gz mana-client-7cd9c0d02d148cdbacbca6624d8749a344ddbfe0.tar.bz2 mana-client-7cd9c0d02d148cdbacbca6624d8749a344ddbfe0.tar.xz mana-client-7cd9c0d02d148cdbacbca6624d8749a344ddbfe0.zip |
Reduce code duplication.
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/openglgraphics.cpp | 52 | ||||
-rw-r--r-- | src/openglgraphics.h | 6 |
3 files changed, 23 insertions, 36 deletions
@@ -8,6 +8,7 @@ 2005-08-25 Björn Steinbrink <B.Steinbrink@gmx.de> + * src/openglgraphics.cpp, src/openglgraphics.h: Reduce code duplication. * src/configuration.cpp: Fix compilation errors. * src/graphics.cpp, src/openglgraphics.cpp, src/gui/button.cpp, src/gui/checkbox.cpp, src/gui/equipmentwindow.cpp, diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 883672bb..e15c8c15 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -25,7 +25,6 @@ #include "openglgraphics.h" -#include <iostream> #include <SDL.h> #include "log.h" @@ -351,7 +350,7 @@ void OpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) glEnd(); } -void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rectangle) +void OpenGLGraphics::_drawRectangle(const gcn::Rectangle& rect, bool filled) { if (mAlpha && !mColorAlpha) { glDisable(GL_BLEND); @@ -366,43 +365,28 @@ void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rectangle) mTexture = false; } - glBegin(GL_LINE_LOOP); - glVertex3f(rectangle.x + mClipStack.top().xOffset + 0.5f, - rectangle.y + mClipStack.top().yOffset + 0.5f, 0); - glVertex3f(rectangle.x + rectangle.width - 0.5f + mClipStack.top().xOffset, - rectangle.y + mClipStack.top().yOffset + 0.5f, 0); - glVertex3f(rectangle.x + rectangle.width - 0.5f + mClipStack.top().xOffset, - rectangle.y + rectangle.height + mClipStack.top().yOffset - 0.5f, 0); - glVertex3f(rectangle.x + mClipStack.top().xOffset + 0.5f, - rectangle.y + rectangle.height + mClipStack.top().yOffset - 0.5f, 0); + float offset = filled ? 0 : 0.5f; + + glBegin(filled ? GL_QUADS : GL_LINE_LOOP); + glVertex3f(rect.x + mClipStack.top().xOffset + offset, + rect.y + mClipStack.top().yOffset + offset, 0); + glVertex3f(rect.x + rect.width + mClipStack.top().xOffset - offset, + rect.y + mClipStack.top().yOffset + offset, 0); + glVertex3f(rect.x + rect.width + mClipStack.top().xOffset - offset, + rect.y + rect.height + mClipStack.top().yOffset - offset, 0); + glVertex3f(rect.x + mClipStack.top().xOffset + offset, + rect.y + rect.height + mClipStack.top().yOffset - offset, 0); glEnd(); } -void OpenGLGraphics::fillRectangle(const gcn::Rectangle& rectangle) +void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rect) { - if (mAlpha && !mColorAlpha) { - glDisable(GL_BLEND); - mAlpha = false; - } else if (!mAlpha && mColorAlpha) { - glEnable(GL_BLEND); - mAlpha = true; - } - - if (mTexture) { - glDisable(GL_TEXTURE_2D); - mTexture = false; - } + _drawRectangle(rect, false); +} - glBegin(GL_QUADS); - glVertex3i(rectangle.x + mClipStack.top().xOffset, - rectangle.y + mClipStack.top().yOffset, 0); - glVertex3i(rectangle.x + rectangle.width + mClipStack.top().xOffset, - rectangle.y + mClipStack.top().yOffset, 0); - glVertex3i(rectangle.x + rectangle.width + mClipStack.top().xOffset, - rectangle.y + rectangle.height + mClipStack.top().yOffset, 0); - glVertex3i(rectangle.x + mClipStack.top().xOffset, - rectangle.y + rectangle.height + mClipStack.top().yOffset, 0); - glEnd(); +void OpenGLGraphics::fillRectangle(const gcn::Rectangle& rect) +{ + _drawRectangle(rect, true); } void OpenGLGraphics::setTargetPlane(int width, int height) diff --git a/src/openglgraphics.h b/src/openglgraphics.h index 434999bb..e303c803 100644 --- a/src/openglgraphics.h +++ b/src/openglgraphics.h @@ -54,9 +54,11 @@ class OpenGLGraphics : public Graphics void drawLine(int x1, int y1, int x2, int y2); - void drawRectangle(const gcn::Rectangle& rectangle); + void _drawRectangle(const gcn::Rectangle &rect, bool filled); - void fillRectangle(const gcn::Rectangle &rectangle); + void drawRectangle(const gcn::Rectangle &rect); + + void fillRectangle(const gcn::Rectangle &rect); void setTargetPlane(int width, int height); |