Changeset - r12247:7a83d651bc47
[Not reviewed]
master
0 2 0
alberth - 15 years ago 2009-06-27 11:45:05
alberth@openttd.org
(svn r16672) -Codechange: Add functions to compute size of strings and sprites.
2 files changed with 32 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -831,6 +831,20 @@ Dimension GetStringBoundingBox(const cha
 
}
 

	
 
/**
 
 * 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.
src/gfx_func.h
Show inline comments
 
@@ -83,6 +83,7 @@ enum {
 
void RedrawScreenRect(int left, int top, int right, int bottom);
 
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
 

	
 
Dimension GetSpriteSize(SpriteID sprid);
 
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub = NULL);
 

	
 
/** How to align the to-be drawn text. */
 
@@ -106,6 +107,7 @@ void GfxDrawLine(int left, int top, int 
 
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
 

	
 
Dimension GetStringBoundingBox(const char *str);
 
Dimension GetStringBoundingBox(StringID strid);
 
uint32 FormatStringLinebreaks(char *str, int maxw);
 
int GetStringHeight(StringID str, int maxw);
 
void LoadStringWidthTable();
0 comments (0 inline, 0 general)