summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDizzyEggg <jajkodizzy@wp.pl>2017-10-09 15:40:08 +0200
committerDizzyEggg <jajkodizzy@wp.pl>2017-10-09 15:40:08 +0200
commit9d4acb9635b3b74d5ae4edee70d673f49c0aab74 (patch)
tree9da34e51216504406058b09e4a6fe311c7cbeac5 /src
parent96c5966ff3676eb1b3463808b83b42e13e1591fd (diff)
some work on international string util
Diffstat (limited to 'src')
-rw-r--r--src/coins.c2
-rw-r--r--src/international_string_util.c57
2 files changed, 58 insertions, 1 deletions
diff --git a/src/coins.c b/src/coins.c
index 4ee601b22..9c2d35168 100644
--- a/src/coins.c
+++ b/src/coins.c
@@ -5,12 +5,12 @@
#include "text_window.h"
#include "string_util.h"
#include "menu.h"
+#include "international_string_util.h"
#define MAX_COINS 9999
EWRAM_DATA u8 sCoinsWindowId = 0;
-extern s32 GetStringRightAlignXOffset(u8 fontId, u8 *str, s32 totalWidth);
extern void sub_819746C(u8 windowId, bool8 copyToVram);
extern const u8 gText_Coins[];
diff --git a/src/international_string_util.c b/src/international_string_util.c
new file mode 100644
index 000000000..c77b4f8ff
--- /dev/null
+++ b/src/international_string_util.c
@@ -0,0 +1,57 @@
+#include "global.h"
+#include "international_string_util.h"
+#include "text.h"
+
+extern s32 convert_pixel_width_to_tile_width(s32 a0); // script menu
+
+s32 GetStringCenterAlignXOffset(s32 fontId, const u8 *str, s32 totalWidth)
+{
+ return GetStringCenterAlignXOffsetWithLetterSpacing(fontId, str, totalWidth, 0);
+}
+
+s32 GetStringRightAlignXOffset(s32 fontId, const u8 *str, s32 totalWidth)
+{
+ return GetStringWidthDifference(fontId, str, totalWidth, 0);
+}
+
+s32 GetStringCenterAlignXOffsetWithLetterSpacing(s32 fontId, const u8 *str, s32 totalWidth, s32 letterSpacing)
+{
+ return GetStringWidthDifference(fontId, str, totalWidth, letterSpacing) / 2;
+}
+
+s32 GetStringWidthDifference(s32 fontId, const u8 *str, s32 totalWidth, s32 letterSpacing)
+{
+ s32 stringWidth = GetStringWidth(fontId, str, letterSpacing);
+ if (totalWidth > stringWidth)
+ return totalWidth - stringWidth;
+ else
+ return 0;
+}
+
+s32 GetMaxWidthInMenuTable(const u8 **str, s32 arg1)
+{
+ s32 i, var;
+
+ for (var = 0, i = 0; i < arg1; i++)
+ {
+ s32 stringWidth = GetStringWidth(1, str[i * 2], 0);
+ if (stringWidth > var)
+ var = stringWidth;
+ }
+
+ return convert_pixel_width_to_tile_width(var);
+}
+
+s32 sub_81DB3D8(const u8 **str, u8* arg1, s32 arg2)
+{
+ s32 i, var;
+
+ for (var = 0, i = 0; i < arg2; i++)
+ {
+ s32 stringWidth = GetStringWidth(1, str[arg1[i] * 2], 0);
+ if (stringWidth > var)
+ var = stringWidth;
+ }
+
+ return convert_pixel_width_to_tile_width(var);
+}