changeset 18444:84927a789cda draft

(svn r23288) -Feature: use the monospace font for the NewGRF text windows
author rubidium <rubidium@openttd.org>
date Sun, 20 Nov 2011 19:09:15 +0000
parents 6e0fd68bff51
children b97c4f942a33
files src/newgrf_gui.cpp
diffstat 1 files changed, 37 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -25,6 +25,7 @@
 #include "core/geometry_func.hpp"
 #include "newgrf_text.h"
 #include "fileio_func.h"
+#include "fontcache.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
@@ -473,7 +474,7 @@
 };
 
 /** Window for displaying the textfile of a NewGRF. */
-struct NewGRFTextfileWindow : public Window {
+struct NewGRFTextfileWindow : public Window, MissingGlyphSearcher {
 	const GRFConfig *grf_config;         ///< View the textfile of this GRFConfig.
 	TextfileType file_type;              ///< Type of textfile to view.
 	int line_height;                     ///< Height of a line in the display widget.
@@ -506,7 +507,7 @@
 	{
 		switch (widget) {
 			case GTW_WIDGET_BACKGROUND:
-				this->line_height = FONT_HEIGHT_NORMAL + 2;
+				this->line_height = FONT_HEIGHT_MONO + 2;
 				resize->height = this->line_height;
 
 				size->height = 4 * resize->height + TOP_SPACING + BOTTOM_SPACING; // At least 4 lines are visible.
@@ -542,7 +543,7 @@
 		}
 		int top = TOP_SPACING;
 		for (uint i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->lines.Length(); i++) {
-			DrawString(left, right, top + i * this->line_height, this->lines[i + this->vscroll->GetPosition()], TC_WHITE);
+			DrawString(left, right, top + i * this->line_height, this->lines[i + this->vscroll->GetPosition()], TC_WHITE, SA_LEFT, false, FS_MONO);
 		}
 
 		_cur_dpi = old_dpi;
@@ -555,6 +556,36 @@
 	}
 
 private:
+	uint search_iterator; ///< Iterator for the font check search.
+
+	/* virtual */ void Reset()
+	{
+		this->search_iterator = 0;
+	}
+
+	FontSize DefaultSize()
+	{
+		return FS_MONO;
+	}
+
+	const char *NextString()
+	{
+		if (this->search_iterator >= this->lines.Length()) return NULL;
+
+		return this->lines[this->search_iterator++];
+	}
+
+	/* virtual */ bool Monospace()
+	{
+		return true;
+	}
+
+	/* virtual */ void SetFontNames(FreeTypeSettings *settings, const char *font_name)
+	{
+#ifdef WITH_FREETYPE
+		strecpy(settings->mono_font, font_name, lastof(settings->mono_font));
+#endif /* WITH_FREETYPE */
+	}
 
 	/**
 	 * Load the NewGRF's textfile text from file, and setup #lines, #max_length, and both scrollbars.
@@ -600,12 +631,14 @@
 			}
 		}
 
+		CheckForMissingGlyphs(true, this);
+
 		/* Initialize scrollbars */
 		this->vscroll->SetCount(this->lines.Length());
 
 		this->max_length = 0;
 		for (uint i = 0; i < this->lines.Length(); i++) {
-			this->max_length = max(this->max_length, GetStringBoundingBox(this->lines[i]).width);
+			this->max_length = max(this->max_length, GetStringBoundingBox(this->lines[i], FS_MONO).width);
 		}
 		this->hscroll->SetCount(this->max_length + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
 		this->hscroll->SetStepSize(10); // Speed up horizontal scrollbar