mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 14:05:32 +02:00
Wrap text in message boxes
This commit is contained in:
parent
69a89cf87f
commit
c054b83178
2 changed files with 49 additions and 2 deletions
|
@ -45,6 +45,7 @@
|
||||||
|
|
||||||
#include "al-util.h"
|
#include "al-util.h"
|
||||||
#include "debugwriter.h"
|
#include "debugwriter.h"
|
||||||
|
#include "util/string-util.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -483,13 +484,18 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REQUEST_MESSAGEBOX :
|
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,
|
SDL_ShowSimpleMessageBox(event.user.code,
|
||||||
rtData.config.windowTitle.c_str(),
|
rtData.config.windowTitle.c_str(),
|
||||||
(const char*) event.user.data1, win);
|
message.c_str(), win);
|
||||||
free(event.user.data1);
|
free(event.user.data1);
|
||||||
msgBoxDone.set();
|
msgBoxDone.set();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case REQUEST_SETCURSORVISIBLE :
|
case REQUEST_SETCURSORVISIBLE :
|
||||||
showCursor = event.user.code;
|
showCursor = event.user.code;
|
||||||
updateCursorState(cursorInWindow, gameScreen);
|
updateCursorState(cursorInWindow, gameScreen);
|
||||||
|
|
41
src/util/string-util.h
Normal file
41
src/util/string-util.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#ifndef STRING_UTIL_H
|
||||||
|
#define STRING_UTIL_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// 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
|
Loading…
Add table
Reference in a new issue