From 17d1fe26c237f3608018396acb360db598170063 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 28 Sep 2022 17:16:46 +0100 Subject: [PATCH] Codechange: Helpers to allow passing a Rect to some functions. --- src/gfx_func.h | 36 ++++++++++++++++++++++++++++++++++++ src/window_gui.h | 6 ++++++ 2 files changed, 42 insertions(+) diff --git a/src/gfx_func.h b/src/gfx_func.h index c5bf12914b..c4e21792bd 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -108,6 +108,42 @@ void GfxFillPolygon(const std::vector &shape, int colour, FillRectMode mo void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0); void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); +/* Versions of DrawString/DrawStringMultiLine that accept a Rect instead of separate left, right, top and bottom parameters. */ +static inline int DrawString(const Rect &r, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL) +{ + return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize); +} + +static inline int DrawString(const Rect &r, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL) +{ + return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize); +} + +static inline int DrawString(const Rect &r, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL) +{ + return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize); +} + +static inline int DrawStringMultiLine(const Rect &r, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL) +{ + return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); +} + +static inline int DrawStringMultiLine(const Rect &r, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL) +{ + return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); +} + +static inline int DrawStringMultiLine(const Rect &r, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL) +{ + return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); +} + +static inline void GfxFillRect(const Rect &r, int colour, FillRectMode mode = FILLRECT_OPAQUE) +{ + GfxFillRect(r.left, r.top, r.right, r.bottom, colour, mode); +} + Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL); Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize = FS_NORMAL); Dimension GetStringBoundingBox(StringID strid); diff --git a/src/window_gui.h b/src/window_gui.h index 58d14a54e7..25b962f411 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -142,6 +142,12 @@ enum WidgetDrawDistances { /* widget.cpp */ void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags); + +static inline void DrawFrameRect(const Rect &r, Colours colour, FrameFlags flags) +{ + DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, flags); +} + void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align); /* window.cpp */