diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 295c60ce..bf1fbdf2 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -45,6 +45,7 @@ #include "al-util.h" #include "debugwriter.h" +#include "util/string-util.h" #include @@ -483,13 +484,18 @@ void EventThread::process(RGSSThreadData &rtData) break; case REQUEST_MESSAGEBOX : + { + std::string message; + // Try to format the message with additional newlines + copyWithNewlines((const char*) event.user.data1, + message, 70); SDL_ShowSimpleMessageBox(event.user.code, rtData.config.windowTitle.c_str(), - (const char*) event.user.data1, win); + message.c_str(), win); free(event.user.data1); msgBoxDone.set(); break; - + } case REQUEST_SETCURSORVISIBLE : showCursor = event.user.code; updateCursorState(cursorInWindow, gameScreen); diff --git a/src/util/string-util.h b/src/util/string-util.h new file mode 100644 index 00000000..f383b398 --- /dev/null +++ b/src/util/string-util.h @@ -0,0 +1,41 @@ +#ifndef STRING_UTIL_H +#define STRING_UTIL_H + +#include + +// Copies the given text with additional newlines every X characters. +// Saves the output into the given std::string object. +// Newlines are only inserted on spaces (' ') or tabs ('\t'). +void +copyWithNewlines(const char *input, std::string &output, const unsigned limit) +{ + unsigned noNewlineCount = 0; + + while (*input != '\0') + { + if ((*input == ' ' || *input == '\t') && noNewlineCount >= limit) + { + output += '\n'; + noNewlineCount = 0; + } + else + { + output += *input; + + if (*input == '\n') + noNewlineCount = 0; + else + noNewlineCount++; + } + + input++; + } +} + +void +copyWithNewlines(const std::string& input, std::string& output, const unsigned limit) +{ + copyWithNewlines(input.c_str(), output, limit); +} + +#endif // STRING_UTIL_H