Improve the way lines are split

This commit is contained in:
esteldunedain 2015-04-11 23:39:06 -03:00
parent d06e1b4a2a
commit df17df61f9
2 changed files with 22 additions and 14 deletions

View File

@ -35,7 +35,7 @@ GVAR(iconCount) = GVAR(iconCount) + 1;
if(_icon == "") then {
_icon = DEFAULT_ICON;
};
_text = format ["<img image='%1' color='%2' align='center'/><br/><t color='%3' size='0.80' align='center' shadow='1' shadowColor='#000000' shadowOffset='0.07'>%4</t>", _icon, _color, _color, _text];
_text = format ["<img image='%1' color='%2' align='center'/><br/><t color='%3' size='0.80' align='center' shadow='1' shadowColor='#000000' shadowOffset='0.07'>%4</t>", _icon, _color, _color, "ace_breakLine" callExtension _text];
_ctrl ctrlSetStructuredText (parseText _text);
_ctrl ctrlSetPosition [(_sPos select 0)-(0.125*SafeZoneW), (_sPos select 1)-(0.0095*SafeZoneW), 0.25*SafeZoneW, 0.1*SafeZoneW];
//_ctrl ctrlSetBackgroundColor [1, 0, 0, 0.1];

View File

@ -17,7 +17,7 @@
#include <vector>
#include <string>
#define MAXCHARACTERS 11
#define MAXCHARACTERS 14
static char version[] = "1.0";
@ -30,23 +30,32 @@ std::vector<std::string> splitString(std::string input) {
std::string token;
std::vector<std::string> output;
while (std::getline(ss, token, ',')) {
while (std::getline(ss, token, ' ')) {
output.push_back(token);
}
return output;
}
std::string addLineBreaks(std::string input) {
std::string addLineBreaks(const std::vector<std::string> &words) {
std::stringstream sstream;
int numChar = 0;
for ( int i = 0 ; i < input.length(); i++) {
if (numChar >= MAXCHARACTERS && input[i] == ' ') {
sstream << "<br/>";//"&lt;br/&gt;";
numChar = 0;
int i = 0;
while (i < words.size()) {
if (numChar == 0) {
sstream << words[i];
numChar += words[i].size();
i++;
} else {
sstream << input[i];
numChar++;
if (numChar + 1 + words[i].size() > MAXCHARACTERS) {
sstream << "<br/>";
numChar = 0;
} else {
sstream << " " << words[i];
numChar += 1 + words[i].size();
i++;
}
}
}
return sstream.str();
@ -57,13 +66,12 @@ std::string addLineBreaks(std::string input) {
#pragma warning( disable : 4996 )
void __stdcall RVExtension(char *output, int outputSize, const char *function) {
//strncpy(output, function, outputSize);
if (!strcmp(function, "version")) {
strncpy(output, version, outputSize);
} else {
std::vector<std::string> argStrings = splitString(function);
std::string originalString = argStrings[0];
strcpy(output, addLineBreaks(originalString).c_str());
strcpy(output, addLineBreaks(splitString(function)).c_str());
output[outputSize - 1] = '\0';
}
}