changeset 17828:111bcb2076f3 draft

(svn r22619) -Fix [FS#4662]: Consider the size of the vehicle sprite for the lineheight in the company GUI. This also makes the widget containing the sprite not skip drawing it, if the bounds of the widget are outside of the drawing area though the sprite actually needs drawing.
author frosch <frosch@openttd.org>
date Sat, 02 Jul 2011 14:37:03 +0000
parents 808fd7d57d64
children 3c9a83a23782
files src/company_gui.cpp src/gfx.cpp src/gfx_func.h
diffstat 3 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/company_gui.cpp
+++ b/src/company_gui.cpp
@@ -1824,6 +1824,15 @@
 	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 	{
 		switch (widget) {
+			case CW_WIDGET_DESC_COLOUR_SCHEME_EXAMPLE: {
+				Point offset;
+				Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
+				d.width -= offset.x;
+				d.height -= offset.y;
+				*size = maxdim(*size, d);
+				break;
+			}
+
 			case CW_WIDGET_DESC_COMPANY_VALUE:
 				SetDParam(0, INT64_MAX); // Arguably the maximum company value
 				size->width = GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE).width;
@@ -1869,9 +1878,13 @@
 				DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, TC_FROMSTRING, SA_CENTER);
 				break;
 
-			case CW_WIDGET_DESC_COLOUR_SCHEME_EXAMPLE:
-				DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->index), (r.left + r.right) / 2, r.top + FONT_HEIGHT_NORMAL / 10);
+			case CW_WIDGET_DESC_COLOUR_SCHEME_EXAMPLE: {
+				Point offset;
+				Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset);
+				d.height -= offset.y;
+				DrawSprite(SPR_VEH_BUS_SW_VIEW, COMPANY_SPRITE_COLOUR(c->index), r.left - offset.x, (r.top + r.bottom - d.height) / 2 - offset.y);
 				break;
+			}
 
 			case CW_WIDGET_DESC_VEHICLE_COUNTS: {
 				uint amounts[4];
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -1116,13 +1116,19 @@
 /**
  * Get the size of a sprite.
  * @param sprid Sprite to examine.
+ * @param [out] offset Optionally returns the sprite position offset.
  * @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)
+Dimension GetSpriteSize(SpriteID sprid, Point *offset)
 {
 	const Sprite *sprite = GetSprite(sprid, ST_NORMAL);
 
+	if (offset != NULL) {
+		offset->x = sprite->x_offs;
+		offset->y = sprite->y_offs;
+	}
+
 	Dimension d;
 	d.width  = max<int>(0, sprite->x_offs + sprite->width);
 	d.height = max<int>(0, sprite->y_offs + sprite->height);
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -88,7 +88,7 @@
 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);
+Dimension GetSpriteSize(SpriteID sprid, Point *offset = NULL);
 void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = NULL);
 
 /** How to align the to-be drawn text. */