diff options
author | Peter Nelson <peter1138@openttd.org> | 2021-04-22 01:17:30 +0100 |
---|---|---|
committer | PeterN <peter@fuzzle.org> | 2021-04-30 17:08:15 +0100 |
commit | 2efa390a7d2091b2c2cef4aa7f986fdcb24eac2a (patch) | |
tree | 7021cf6b4568e76755d84b5d371779811664d02b | |
parent | 4f93dd95e4251e3227a55ee125838cefce173ef3 (diff) | |
download | openttd-2efa390a7d2091b2c2cef4aa7f986fdcb24eac2a.tar.xz |
Codechange: Simplify calling of DrawCharCentered()
-rw-r--r-- | src/gfx.cpp | 10 | ||||
-rw-r--r-- | src/gfx_func.h | 2 | ||||
-rw-r--r-- | src/osk_gui.cpp | 5 |
3 files changed, 8 insertions, 9 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index d540f4dfe..d3c730be1 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -891,15 +891,17 @@ const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize) /** * Draw single character horizontally centered around (x,y) * @param c Character (glyph) to draw - * @param x X position to draw character - * @param y Y position to draw character + * @param r Rectangle to draw character within * @param colour Colour to use, for details see _string_colourmap in * table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h */ -void DrawCharCentered(WChar c, int x, int y, TextColour colour) +void DrawCharCentered(WChar c, const Rect &r, TextColour colour) { SetColourRemap(colour); - GfxMainBlitter(GetGlyph(FS_NORMAL, c), x - GetCharacterWidth(FS_NORMAL, c) / 2, y, BM_COLOUR_REMAP); + GfxMainBlitter(GetGlyph(FS_NORMAL, c), + CenterBounds(r.left, r.right, GetCharacterWidth(FS_NORMAL, c)), + CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), + BM_COLOUR_REMAP); } /** diff --git a/src/gfx_func.h b/src/gfx_func.h index a4db8a045..18b1966f9 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -96,7 +96,7 @@ int DrawString(int left, int right, int top, StringID str, TextColour colour = T int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL); int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL); -void DrawCharCentered(WChar c, int x, int y, TextColour colour); +void DrawCharCentered(WChar c, const Rect &r, TextColour colour); void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE); void GfxFillPolygon(const std::vector<Point> &shape, int colour, FillRectMode mode = FILLRECT_OPAQUE); diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp index 60c9023b8..233bb1c7a 100644 --- a/src/osk_gui.cpp +++ b/src/osk_gui.cpp @@ -103,10 +103,7 @@ struct OskWindow : public Window { if (widget < WID_OSK_LETTERS) return; widget -= WID_OSK_LETTERS; - DrawCharCentered(_keyboard[this->shift][widget], - r.left + (r.right - r.left) / 2, - r.top + (r.bottom - r.top - FONT_HEIGHT_NORMAL) / 2, - TC_BLACK); + DrawCharCentered(_keyboard[this->shift][widget], r, TC_BLACK); } void OnClick(Point pt, int widget, int click_count) override |