summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-14 15:43:26 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-14 15:43:26 +0000
commitb7170d13fd71fb624c06c4536974a7cd3f77591b (patch)
tree7f7583407e79423b08f98a50d897f6e30ac886dd /src/resources
parenta120ea5cb0a57c9d3bd8677269bd65cf79dad933 (diff)
downloadmana-client-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.gz
mana-client-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.bz2
mana-client-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.xz
mana-client-b7170d13fd71fb624c06c4536974a7cd3f77591b.zip
Rewrote Spriteset to work with Image* instead of BITMAP*
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/image.cpp43
-rw-r--r--src/resources/image.h44
2 files changed, 65 insertions, 22 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index fb36f400..b7739351 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -64,7 +64,7 @@ void Image::unload()
}
-int Image::getWidth()
+int Image::getWidth() const
{
if (image != NULL) {
return image->w;
@@ -72,7 +72,7 @@ int Image::getWidth()
return 0;
}
-int Image::getHeight()
+int Image::getHeight() const
{
if (image != NULL) {
return image->h;
@@ -80,17 +80,26 @@ int Image::getHeight()
return 0;
}
-Image* Image::createSubImage(int x, int y, int width, int height)
+Image* Image::getSubImage(int x, int y, int width, int height)
{
// Create a new clipped sub-image
return new SubImage(this, image, x, y, width, height);
}
+Image* Image::getScaledInstance(int width, int height)
+{
+ return new ScaledImage(this, image, width, height);
+}
+
bool Image::draw(BITMAP *screen, int x, int y)
{
// Check that preconditions for blitting are met.
if (screen == NULL || image == NULL) return false;
+ //SDL_Rect dst_rect;
+ //dst_rect.x = x + offset_x;
+ //dst_rect.y = y + offset_y;
+ //SDL_BlitSurface(src, NULL, dst, &dst_rect);
// Draw the image onto the screen.
draw_sprite(screen, image, x, y);
//if (SDL_BlitSurface(image, NULL, screen, &screenRect) < 0) {
@@ -120,6 +129,8 @@ void Image::drawPattern(BITMAP *screen, int x, int y, int w, int h)
}
}
+//============================================================================
+
SubImage::SubImage(Image *parent, BITMAP *image,
int x, int y, int width, int height):
Image(create_sub_bitmap(image, x, y, width, height)),
@@ -138,12 +149,10 @@ SubImage::~SubImage()
{
if (image) {
destroy_bitmap(image);
+ image = NULL;
}
- parent->decRef();
-}
-
-void SubImage::unload()
-{
+ // TODO: Enable when no longer a problem
+ //parent->decRef();
}
bool SubImage::draw(BITMAP *screen, int x, int y)
@@ -159,3 +168,21 @@ bool SubImage::draw(BITMAP *screen, int x, int y)
return true;
}
+
+//============================================================================
+
+ScaledImage::ScaledImage(Image *parent, BITMAP *bmp, int width, int height):
+ Image(create_bitmap(width, height))
+{
+ if (image) {
+ stretch_blit(bmp, image, 0, 0, bmp->w, bmp->h, 0, 0, width, height);
+ }
+}
+
+ScaledImage::~ScaledImage()
+{
+ if (image) {
+ destroy_bitmap(image);
+ image = NULL;
+ }
+}
diff --git a/src/resources/image.h b/src/resources/image.h
index 8f956324..0452cd4a 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -28,10 +28,9 @@
//#include <SDL/SDL.h>
#include <allegro.h>
-/**
- * A clipped version of a larger image.
- */
+// Forward declarations
class SubImage;
+class ScaledImage;
/**
* Defines a class for loading and storing images.
@@ -60,24 +59,29 @@ class Image : public Resource
/**
* Frees the resources created by SDL.
*/
- void unload();
+ virtual void unload();
/**
* Returns the width of the image.
*/
- int getWidth();
+ virtual int getWidth() const;
/**
* Returns the height of the image.
*/
- int getHeight();
+ virtual int getHeight() const;
/**
* Creates a new image with the desired clipping rectangle.
* @return <code>NULL</code> if creation failed and a valid
* object otherwise.
*/
- Image* createSubImage(int x, int y, int width, int height);
+ virtual Image* getSubImage(int x, int y, int width, int height);
+
+ /**
+ * Creates a scaled version of this image.
+ */
+ virtual Image* getScaledInstance(int width, int height);
/**
* Blits the internal image onto the screen.
@@ -85,12 +89,12 @@ class Image : public Resource
* @return <code>true</code> if the image was blitted properly
* <code>false</code> otherwise.
*/
- bool draw(BITMAP *screen, int x, int y);
+ virtual bool draw(BITMAP *screen, int x, int y);
/**
* Does a pattern fill on the given area.
*/
- void drawPattern(BITMAP *screen, int x, int y, int w, int h);
+ virtual void drawPattern(BITMAP *screen, int x, int y, int w, int h);
protected:
//SDL_Rect screenRect;
@@ -117,11 +121,6 @@ class SubImage : public Image
~SubImage();
/**
- * Redefines unload to not do anything.
- */
- void unload();
-
- /**
* Draws the clipped image onto the screen.
* @return <code>true</code> if drawing was succesful
* <code>false</code> otherwise.
@@ -138,4 +137,21 @@ class SubImage : public Image
//unsigned int referenceCount;
};
+/**
+ * A scaled version of an image.
+ */
+class ScaledImage : public Image
+{
+ public:
+ /**
+ * Constructor.
+ */
+ ScaledImage(Image *parent, BITMAP *image, int width, int height);
+
+ /**
+ * Destructor.
+ */
+ ~ScaledImage();
+};
+
#endif