text_to_lines() does not belong to show_dialog

- being more closely related to text, moved it to font
This commit is contained in:
Yann Dirson 2005-03-23 20:46:58 +00:00
parent faf6d4ec6e
commit 8f311d9d87
6 changed files with 57 additions and 56 deletions

View File

@ -2196,7 +2196,7 @@ void display::add_chat_message(const std::string& speaker, int side, const std::
msg = message;
action = false;
}
gui::text_to_lines(msg,80);
font::text_to_lines(msg,80);
int ypos = chat_message_x;
for(std::vector<chat_message>::const_iterator m = chat_messages_.begin(); m != chat_messages_.end(); ++m) {

View File

@ -1355,4 +1355,52 @@ bool load_font_config()
font::set_font_list(fontlist);
return true;
}
size_t text_to_lines(std::string& message, size_t max_length)
{
std::string starting_markup;
bool at_start = true;
size_t cur_line = 0, longest_line = 0;
for(std::string::iterator i = message.begin(); i != message.end(); ++i) {
if(at_start) {
if(font::is_format_char(*i)) {
push_back(starting_markup,*i);
} else {
at_start = false;
}
}
if(*i == '\n') {
at_start = true;
starting_markup = "";
}
if(*i == ' ' && cur_line > max_length) {
*i = '\n';
const size_t index = i - message.begin();
message.insert(index+1,starting_markup);
i = message.begin() + index + starting_markup.size();
if(cur_line > longest_line)
longest_line = cur_line;
cur_line = 0;
}
if(*i == '\n' || i+1 == message.end()) {
if(cur_line > longest_line)
longest_line = cur_line;
cur_line = 0;
} else {
++cur_line;
}
}
return longest_line;
}
}

View File

@ -188,6 +188,9 @@ void undraw_floating_labels(surface screen);
bool load_font_config();
//function to chop up one long string of text into lines
size_t text_to_lines(std::string& text, size_t max_length);
}
#endif

View File

@ -310,55 +310,6 @@ void draw_solid_tinted_rectangle(int x, int y, int w, int h,
} //end namespace gui
namespace gui
{
size_t text_to_lines(std::string& message, size_t max_length)
{
std::string starting_markup;
bool at_start = true;
size_t cur_line = 0, longest_line = 0;
for(std::string::iterator i = message.begin(); i != message.end(); ++i) {
if(at_start) {
if(font::is_format_char(*i)) {
push_back(starting_markup,*i);
} else {
at_start = false;
}
}
if(*i == '\n') {
at_start = true;
starting_markup = "";
}
if(*i == ' ' && cur_line > max_length) {
*i = '\n';
const size_t index = i - message.begin();
message.insert(index+1,starting_markup);
i = message.begin() + index + starting_markup.size();
if(cur_line > longest_line)
longest_line = cur_line;
cur_line = 0;
}
if(*i == '\n' || i+1 == message.end()) {
if(cur_line > longest_line)
longest_line = cur_line;
cur_line = 0;
} else {
++cur_line;
}
}
return longest_line;
}
namespace {
struct help_handler : public hotkey::command_executor
@ -385,6 +336,9 @@ private:
}
namespace gui
{
void show_error_message(display &disp, std::string const &message)
{
ERR_G << message << std::endl;
@ -462,7 +416,7 @@ int show_dialog(display& disp, surface image,
#endif
std::string message = msg;
text_to_lines(message,max_line_length);
font::text_to_lines(message,max_line_length);
SDL_Rect text_size = { 0, 0, 0, 0 };
if(!message.empty()) {

View File

@ -124,9 +124,6 @@ public:
virtual void set_selection(int index) = 0;
};
//function to chop up one long string of text into lines
size_t text_to_lines(std::string& text, size_t max_length);
//if a menu is given, then returns -1 if the dialog was cancelled, and the
//index of the selection otherwise. If no menu is given, returns the index
//of the button that was pressed

View File

@ -2,7 +2,6 @@
#include "font.hpp"
#include "sdl_utils.hpp"
#include "show_dialog.hpp"
#include "tooltips.hpp"
#include "video.hpp"
@ -27,7 +26,7 @@ struct tooltip
{
tooltip(const SDL_Rect& r, const std::string& msg) : rect(r), message(msg)
{
gui::text_to_lines(message,60);
font::text_to_lines(message,60);
}
SDL_Rect rect;
std::string message;