summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-08-25 22:42:55 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-08-25 22:42:55 +0000
commitfd1b18db1716144e556a4867bcd59e92edecdc58 (patch)
tree09ada126a486ffed1a8e7e39add862772c5cf07d /src
parentba5c32ee9c5c57613ec678d47c3871e9ea312402 (diff)
downloadmana-fd1b18db1716144e556a4867bcd59e92edecdc58.tar.gz
mana-fd1b18db1716144e556a4867bcd59e92edecdc58.tar.bz2
mana-fd1b18db1716144e556a4867bcd59e92edecdc58.tar.xz
mana-fd1b18db1716144e556a4867bcd59e92edecdc58.zip
Use OpenGL's translation capabilites. Small cleanups.
Diffstat (limited to 'src')
-rw-r--r--src/graphics.cpp37
-rw-r--r--src/openglgraphics.cpp45
2 files changed, 41 insertions, 41 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 47414ff0..a3299650 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -23,10 +23,6 @@
#include "graphics.h"
-#ifdef USE_OPENGL
-#include <guichan/imagefont.hpp>
-#endif
-
#include "log.h"
#include "graphic/imagerect.h"
@@ -184,37 +180,40 @@ void Graphics::drawImageRect(
Image *bottom, Image *left,
Image *center)
{
+ pushClipArea(gcn::Rectangle(x, y, w, h));
+
// Draw the center area
drawImagePattern(center,
- x + topLeft->getWidth(), y + topLeft->getHeight(),
+ topLeft->getWidth(), topLeft->getHeight(),
w - topLeft->getWidth() - topRight->getWidth(),
h - topLeft->getHeight() - bottomLeft->getHeight());
// Draw the sides
drawImagePattern(top,
- x + topLeft->getWidth(), y,
- w - topLeft->getWidth() - topRight->getWidth(), top->getHeight());
+ left->getWidth(), 0,
+ w - left->getWidth() - right->getWidth(), top->getHeight());
drawImagePattern(bottom,
- x + bottomLeft->getWidth(), y + h - bottom->getHeight(),
- w - bottomLeft->getWidth() - bottomRight->getWidth(),
+ left->getWidth(), h - bottom->getHeight(),
+ w - left->getWidth() - right->getWidth(),
bottom->getHeight());
drawImagePattern(left,
- x, y + topLeft->getHeight(),
+ 0, top->getHeight(),
left->getWidth(),
- h - topLeft->getHeight() - bottomLeft->getHeight());
+ h - top->getHeight() - bottom->getHeight());
drawImagePattern(right,
- x + w - right->getWidth(), y + topRight->getHeight(),
+ w - right->getWidth(), top->getHeight(),
right->getWidth(),
- h - topRight->getHeight() - bottomRight->getHeight());
+ h - top->getHeight() - bottom->getHeight());
// Draw the corners
- drawImage(topLeft, x, y);
- drawImage(topLeft, x, y);
- drawImage(topRight, x + w - topRight->getWidth(), y);
- drawImage(bottomLeft, x, y + h - bottomLeft->getHeight());
+ drawImage(topLeft, 0, 0);
+ drawImage(topRight, w - topRight->getWidth(), 0);
+ drawImage(bottomLeft, 0, h - bottomLeft->getHeight());
drawImage(bottomRight,
- x + w - bottomRight->getWidth(),
- y + h - bottomRight->getHeight());
+ w - bottomRight->getWidth(),
+ h - bottomRight->getHeight());
+
+ popClipArea();
}
void Graphics::drawImageRect(
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 6fdbc79a..c73bcdff 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -73,9 +73,6 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
int dstX, int dstY, int width, int height)
{
- dstX += mClipStack.top().xOffset;
- dstY += mClipStack.top().yOffset;
-
srcX += image->bounds.x;
srcY += image->bounds.y;
@@ -179,8 +176,20 @@ void OpenGLGraphics::_endDraw()
bool OpenGLGraphics::pushClipArea(gcn::Rectangle area)
{
+ int transX = 0;
+ int transY = 0;
+
+ if (!mClipStack.empty()) {
+ transX = -mClipStack.top().x;
+ transY = -mClipStack.top().y;
+ }
+
bool result = gcn::Graphics::pushClipArea(area);
+ transX += mClipStack.top().x;
+ transY += mClipStack.top().y;
+
+ glTranslated(transX, transY, 0);
glScissor(mClipStack.top().x,
mScreen->h - mClipStack.top().y - mClipStack.top().height,
mClipStack.top().width,
@@ -191,6 +200,9 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area)
void OpenGLGraphics::popClipArea()
{
+ int transX = -mClipStack.top().x;
+ int transY = -mClipStack.top().y;
+
gcn::Graphics::popClipArea();
if (mClipStack.empty())
@@ -198,6 +210,10 @@ void OpenGLGraphics::popClipArea()
return;
}
+ transX += mClipStack.top().x;
+ transY += mClipStack.top().y;
+
+ glTranslated(transX, transY, 0);
glScissor(mClipStack.top().x,
mScreen->h - mClipStack.top().y - mClipStack.top().height,
mClipStack.top().width,
@@ -218,9 +234,6 @@ void OpenGLGraphics::setColor(const gcn::Color& color)
void OpenGLGraphics::drawImage(const gcn::Image* image, int srcX, int srcY,
int dstX, int dstY, int width, int height)
{
- dstX += mClipStack.top().xOffset;
- dstY += mClipStack.top().yOffset;
-
// The following code finds the real width and height of the texture.
// OpenGL only supports texture sizes that are powers of two
int realImageWidth = 1;
@@ -249,9 +262,6 @@ void OpenGLGraphics::drawImage(const gcn::Image* image, int srcX, int srcY,
void OpenGLGraphics::drawPoint(int x, int y)
{
- x += mClipStack.top().xOffset;
- y += mClipStack.top().yOffset;
-
setTexturingAndBlending(false);
glBegin(GL_POINTS);
@@ -261,11 +271,6 @@ void OpenGLGraphics::drawPoint(int x, int y)
void OpenGLGraphics::drawLine(int x1, int y1, int x2, int y2)
{
- x1 += mClipStack.top().xOffset;
- y1 += mClipStack.top().yOffset;
- x2 += mClipStack.top().xOffset;
- y2 += mClipStack.top().yOffset;
-
setTexturingAndBlending(false);
glBegin(GL_LINES);
@@ -328,14 +333,10 @@ void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled)
setTexturingAndBlending(false);
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);
+ glVertex3f(rect.x + offset, rect.y + offset, 0);
+ glVertex3f(rect.x + rect.width - offset, rect.y + offset, 0);
+ glVertex3f(rect.x + rect.width - offset, rect.y + rect.height - offset, 0);
+ glVertex3f(rect.x + offset, rect.y + rect.height - offset, 0);
glEnd();
}