tFunction added to display a centred string. This uses the actual width of the … | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit b4c9032023e7a52edd98b6223ed1fabc91210514 | |
parent 2b187d1cd09162f12318d323d308ab1f54e9a6ca | |
Author: Ben Webb <[email protected]> | |
Date: Mon, 24 Jun 2002 11:04:47 +0000 | |
Function added to display a centred string. This uses the actual width of | |
tthe display window (rather than using a hard-coded value of 80) and deals | |
properly with the case where the string is longer than the width (previously | |
tthis would result in a negative x-coordinate, and curses would refuse to | |
display the string at all, causing problems with the nn translation). | |
Diffstat: | |
M src/curses_client/curses_client.c | 20 ++++++++++++++++---- | |
1 file changed, 16 insertions(+), 4 deletions(-) | |
--- | |
diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_clien… | |
t@@ -181,6 +181,18 @@ static void LogMessage(const gchar *log_domain, GLogLevel… | |
clear_bottom(); | |
} | |
+/* | |
+ * Displays a string, horizontally centred on the given row | |
+ */ | |
+static void mvaddcentstr(const int row, const gchar *str) | |
+{ | |
+ int col; | |
+ | |
+ col = (Width - strlen(str)) / 2; | |
+ col = MAX(col, 0); | |
+ mvaddstr(row, col, str); | |
+} | |
+ | |
/* | |
* Displays a dopewars introduction screen. | |
*/ | |
t@@ -1306,7 +1318,7 @@ void GunShop(Player *Play) | |
text = _("Will you B>uy, S>ell, or L>eave? "); | |
attrset(PromptAttr); | |
clear_line(22); | |
- mvaddstr(22, 40 - strlen(text) / 2, text); | |
+ mvaddcentstr(22, text); | |
attrset(TextAttr); | |
/* Translate these three keys in line with the above options, keeping | |
t@@ -2140,7 +2152,7 @@ static void Curses_DoGame(Player *Play) | |
g_string_append(text, _(", J>et")); | |
} | |
g_string_append(text, _(", or Q>uit? ")); | |
- mvaddstr(22, 40 - strlen(text->str) / 2, text->str); | |
+ mvaddcentstr(22, text->str); | |
attrset(TextAttr); | |
curs_set(1); | |
break; | |
t@@ -2162,7 +2174,7 @@ static void Curses_DoGame(Player *Play) | |
/* (%tde = "drugs" by default here) */ | |
dpg_string_sprintfa(text, _("D>eal %tde, "), Names.Drugs); | |
g_string_append(text, _("or Q>uit? ")); | |
- mvaddstr(22, 40 - strlen(text->str) / 2, text->str); | |
+ mvaddcentstr(22, text->str); | |
attrset(TextAttr); | |
curs_set(1); | |
break; | |
t@@ -2175,7 +2187,7 @@ static void Curses_DoGame(Player *Play) | |
g_string_append(text, Names.Drugs); | |
g_string_append(text, ", or Q>uit? "); | |
attrset(PromptAttr); | |
- mvaddstr(22, 40 - strlen(text->str) / 2, text->str); | |
+ mvaddcentstr(22, text->str); | |
attrset(TextAttr); | |
curs_set(1); | |
break; |