summaryrefslogtreecommitdiff
path: root/src/gfx.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-06-27 11:45:05 +0000
committeralberth <alberth@openttd.org>2009-06-27 11:45:05 +0000
commit996e5eea471f740428f2878884363521200d6ca1 (patch)
tree85b57ba6d51e6c778938e52b73720ad2cae9d7e8 /src/gfx.cpp
parent9489490e482917a76a1675fa70fa5457565e5ca7 (diff)
downloadopenttd-996e5eea471f740428f2878884363521200d6ca1.tar.xz
(svn r16672) -Codechange: Add functions to compute size of strings and sprites.
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r--src/gfx.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 668d33c8a..c67dba176 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -831,6 +831,20 @@ Dimension GetStringBoundingBox(const char *str)
}
/**
+ * Get bounding box of a string. Uses parameters set by #DParam if needed.
+ * Has the same restrictions as #GetStringBoundingBox(const char *str).
+ * @param strid String to examine.
+ * @return Width and height of the bounding box for the string in pixels.
+ */
+Dimension GetStringBoundingBox(StringID strid)
+{
+ char buffer[DRAW_STRING_BUFFER];
+
+ GetString(buffer, strid, lastof(buffer));
+ return GetStringBoundingBox(buffer);
+}
+
+/**
* Draw single character horizontally centered around (x,y)
* @param c Character (glyph) to draw
* @param x X position to draw character
@@ -927,6 +941,22 @@ skip_cont:;
}
/**
+ * Get the size of a sprite.
+ * @param sprid Sprite to examine.
+ * @return Sprite size in pixels.
+ * @note The size assumes (0, 0) as top-left coordinate and ignores any part of the sprite drawn at the left or above that position.
+ */
+Dimension GetSpriteSize(SpriteID sprid)
+{
+ const Sprite *sprite = GetSprite(sprid, ST_NORMAL);
+
+ Dimension d;
+ d.width = max<int>(0, sprite->x_offs + sprite->width);
+ d.height = max<int>(0, sprite->y_offs + sprite->height);
+ return d;
+}
+
+/**
* Draw a sprite.
* @param img Image number to draw
* @param pal Palette to use.