summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/image.cpp128
-rw-r--r--src/resources/image.h47
2 files changed, 23 insertions, 152 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 9dafc64c..854c65e8 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -34,18 +34,26 @@ Image::Image(SDL_Surface *image):
{
// Default to opaque
alpha = 1.0f;
+
+ bounds.x = 0;
+ bounds.y = 0;
+ bounds.w = image->w;
+ bounds.h = image->h;
}
#ifdef USE_OPENGL
Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight):
glimage(glimage),
- width(width),
- height(height),
texWidth(texWidth),
texHeight(texHeight)
{
// Default to opaque
alpha = 1.0f;
+
+ bounds.x = 0;
+ bounds.y = 0;
+ bounds.w = width;
+ bounds.h = height;
}
#endif
@@ -261,32 +269,12 @@ void Image::unload()
int Image::getWidth() const
{
- if (!useOpenGL) {
- if (image != NULL) {
- return image->w;
- }
- }
-#ifdef USE_OPENGL
- else {
- return width;
- }
-#endif
- return 0;
+ return bounds.w;
}
int Image::getHeight() const
{
- if (!useOpenGL) {
- if (image != NULL) {
- return image->h;
- }
- }
-#ifdef USE_OPENGL
- else {
- return height;
- }
-#endif
- return 0;
+ return bounds.h;
}
Image *Image::getSubImage(int x, int y, int width, int height)
@@ -304,65 +292,6 @@ Image *Image::getSubImage(int x, int y, int width, int height)
#endif
}
-bool Image::draw_deprecated(SDL_Surface *screen, int srcX, int srcY, int dstX, int dstY,
- int width, int height)
-{
- if (!useOpenGL) {
- // Check that preconditions for blitting are met.
- if (screen == NULL || image == NULL) return false;
-
- SDL_Rect dstRect;
- SDL_Rect srcRect;
- dstRect.x = dstX; dstRect.y = dstY;
- srcRect.x = srcX; srcRect.y = srcY;
- srcRect.w = width;
- srcRect.h = height;
-
- if (SDL_BlitSurface(image, &srcRect, screen, &dstRect) < 0) {
- return false;
- }
- }
-#ifdef USE_OPENGL
- else {
- // Find OpenGL texture coordinates
- float texX1 = srcX / (float)texWidth;
- float texY1 = srcY / (float)texHeight;
- float texX2 = (srcX + width) / (float)texWidth;
- float texY2 = (srcY + height) / (float)texHeight;
-
- glColor4f(1.0f, 1.0f, 1.0f, alpha);
- glBindTexture(GL_TEXTURE_2D, glimage);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
-
- // Draw a textured quad -- the image
- glBegin(GL_QUADS);
- glTexCoord2f(texX1, texY1);
- glVertex3i(dstX, dstY, 0);
-
- glTexCoord2f(texX2, texY1);
- glVertex3i(dstX + width, dstY, 0);
-
- glTexCoord2f(texX2, texY2);
- glVertex3i(dstX + width, dstY + height, 0);
-
- glTexCoord2f(texX1, texY2);
- glVertex3i(dstX, dstY + height, 0);
- glEnd();
-
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_BLEND);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- }
-#endif
- return true;
-}
-
-bool Image::draw_deprecated(SDL_Surface *screen, int x, int y)
-{
- return draw_deprecated(screen, 0, 0, x, y, getWidth(), getHeight());
-}
-
void Image::setAlpha(float a)
{
alpha = a;
@@ -389,10 +318,10 @@ SubImage::SubImage(Image *parent, SDL_Surface *image,
parent->incRef();
// Set up the rectangle.
- rect.x = x;
- rect.y = y;
- rect.w = width;
- rect.h = height;
+ bounds.x = x;
+ bounds.y = y;
+ bounds.w = width;
+ bounds.h = height;
}
#ifdef USE_OPENGL
@@ -403,10 +332,10 @@ SubImage::SubImage(Image *parent, GLuint image,
parent->incRef();
// Set up the rectangle.
- rect.x = x;
- rect.y = y;
- rect.w = width;
- rect.h = height;
+ bounds.x = x;
+ bounds.y = y;
+ bounds.w = width;
+ bounds.h = height;
}
#endif
@@ -418,24 +347,7 @@ SubImage::~SubImage()
parent->decRef();
}
-int SubImage::getWidth() const
-{
- return rect.w;
-}
-
-int SubImage::getHeight() const
-{
- return rect.h;
-}
-
Image *SubImage::getSubImage(int x, int y, int w, int h)
{
return NULL;
}
-
-bool SubImage::draw_deprecated(SDL_Surface *screen, int srcX, int srcY,
- int dstX, int dstY, int width, int height)
-{
- return Image::draw_deprecated(screen, rect.x + srcX, rect.y + srcY,
- dstX, dstY, width, height);
-}
diff --git a/src/resources/image.h b/src/resources/image.h
index 7d1fe3c4..85f790ba 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -36,6 +36,8 @@
*/
class Image : public Resource
{
+ friend class Graphics;
+
public:
/**
* Destructor.
@@ -83,27 +85,6 @@ class Image : public Resource
getSubImage(int x, int y, int width, int height);
/**
- * Blits the image onto the screen.
- *
- * @return <code>true</code> if the image was blitted properly
- * <code>false</code> otherwise.
- */
- virtual bool
- draw_deprecated(SDL_Surface *screen,
- int srcX, int srcY,
- int dstX, int dstY,
- int width, int height);
-
- /**
- * Blits the image onto the screen.
- *
- * @return <code>true</code> if the image was blitted properly
- * <code>false</code> otherwise.
- */
- virtual bool
- draw_deprecated(SDL_Surface *screen, int x, int y);
-
- /**
* Sets the alpha value of this image.
*/
void
@@ -125,11 +106,11 @@ class Image : public Resource
#endif
Image(SDL_Surface *image);
+ SDL_Rect bounds;
bool loaded;
#ifdef USE_OPENGL
GLuint glimage;
- int width, height;
int texWidth, texHeight;
#endif
SDL_Surface *image;
@@ -158,18 +139,6 @@ class SubImage : public Image
~SubImage();
/**
- * Returns the width of the image.
- */
- int
- getWidth() const;
-
- /**
- * Returns the height of the image.
- */
- int
- getHeight() const;
-
- /**
* Creates a new image with the desired clipping rectangle.
*
* @return <code>NULL</code> if creation failed and a valid
@@ -178,18 +147,8 @@ class SubImage : public Image
Image*
getSubImage(int x, int y, int width, int height);
- /**
- * Draws this image.
- */
- bool
- draw_deprecated(SDL_Surface *screen,
- int srcX, int srcY,
- int dstX, int dstY,
- int width, int height);
-
private:
Image *parent;
- SDL_Rect rect;
};
#endif