summaryrefslogtreecommitdiff
path: root/src/resources/image.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-14 12:43:28 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-14 12:43:28 +0000
commit5a1007fa3e827c03bb86db71cb26dfd4c485f28d (patch)
treea8f114d7ae6ccb1806602b89d3ea3cf6bbfe7d83 /src/resources/image.cpp
parentcfac9a371a684a3a6f37bad725094b7e2d80a7d1 (diff)
downloadmana-client-5a1007fa3e827c03bb86db71cb26dfd4c485f28d.tar.gz
mana-client-5a1007fa3e827c03bb86db71cb26dfd4c485f28d.tar.bz2
mana-client-5a1007fa3e827c03bb86db71cb26dfd4c485f28d.tar.xz
mana-client-5a1007fa3e827c03bb86db71cb26dfd4c485f28d.zip
Extended Image with methods to get width, height and draw a pattern and made
Window widget use it.
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r--src/resources/image.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 8a37a4e1..fb36f400 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -63,6 +63,23 @@ void Image::unload()
}
}
+
+int Image::getWidth()
+{
+ if (image != NULL) {
+ return image->w;
+ }
+ return 0;
+}
+
+int Image::getHeight()
+{
+ if (image != NULL) {
+ return image->h;
+ }
+ return 0;
+}
+
Image* Image::createSubImage(int x, int y, int width, int height)
{
// Create a new clipped sub-image
@@ -83,6 +100,26 @@ bool Image::draw(BITMAP *screen, int x, int y)
return true;
}
+void Image::drawPattern(BITMAP *screen, int x, int y, int w, int h)
+{
+ int iw = getWidth(); // Width of image
+ int ih = getHeight(); // Height of image
+ if (iw == 0 || ih == 0) return;
+
+ int px = 0; // X position on pattern plane
+ int py = 0; // Y position on pattern plane
+
+ while (py < h) {
+ while (px < w) {
+ draw(screen, x + px, y + py);
+ // TODO: Prevent overdraw
+ px += iw;
+ }
+ py += ih;
+ px = x;
+ }
+}
+
SubImage::SubImage(Image *parent, BITMAP *image,
int x, int y, int width, int height):
Image(create_sub_bitmap(image, x, y, width, height)),