summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-11-20 19:09:15 +0000
committerrubidium <rubidium@openttd.org>2011-11-20 19:09:15 +0000
commitd4b4c53a07c6271c2fe1d6b6c4527f6a489cbfc7 (patch)
tree208e6d4e8ba194f0856524f5b31f8cb9293dd8ad
parent1fde9c7f8a2ecce81b8c47e24f41bbeffecf129b (diff)
downloadopenttd-d4b4c53a07c6271c2fe1d6b6c4527f6a489cbfc7.tar.xz
(svn r23288) -Feature: use the monospace font for the NewGRF text windows
-rw-r--r--src/newgrf_gui.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index b4bc177d1..6607f4ca7 100644
--- 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 @@ enum ShowNewGRFTextfileWidgets {
};
/** 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 @@ struct NewGRFTextfileWindow : public Window {
{
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 @@ struct NewGRFTextfileWindow : public Window {
}
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 @@ struct NewGRFTextfileWindow : public Window {
}
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 @@ private:
}
}
+ 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