Made it possible in show_dialog to specify the maximum length of the
text widget.

show_dialog invocation really is cluttered. Maybe we should replace it, using
the "named parameter idiom" ?
This commit is contained in:
Philippe Plantier 2004-10-27 19:28:07 +00:00
parent 483c369e7e
commit 04555a3bbd
8 changed files with 33 additions and 20 deletions

View file

@ -209,7 +209,7 @@ gui::dialog_button_action::RESULT delete_save::button_pressed(int menu_selection
options.push_back(gui::check_item(_("Don't ask me again!"),false));
const int res = gui::show_dialog(disp_,NULL,"",_("Do you really want to delete this game?"),gui::YES_NO,
NULL,NULL,"",NULL,NULL,&options);
NULL,NULL,"",NULL,-1,NULL,&options);
//see if the user doesn't want to be asked this again
assert(options.empty() == false);
@ -448,7 +448,7 @@ std::string load_game_dialog(display& disp, const config& game_config, const gam
std::vector<gui::check_item> options;
options.push_back(gui::check_item(_("Don't ask me again!"),false));
const int res = gui::show_dialog(disp,NULL,_(caption),_(message),
gui::YES_NO,NULL,NULL,"",NULL,NULL,&options);
gui::YES_NO,NULL,NULL,"",NULL,-1,NULL,&options);
generate_summaries = res == 0;
if(options.front().checked) {
@ -517,7 +517,7 @@ std::string load_game_dialog(display& disp, const config& game_config, const gam
const int res = gui::show_dialog(disp,NULL,
_("Load Game"),
_("Choose the game to load"),
gui::OK_CANCEL,&items,&preview_panes,"",NULL,NULL,&options,-1,-1,NULL,&buttons);
gui::OK_CANCEL,&items,&preview_panes,"",NULL,-1,NULL,&options,-1,-1,NULL,&buttons);
if(res == -1)
return "";

View file

@ -3,6 +3,10 @@
#include "language.hpp"
#include "map_label.hpp"
namespace {
const size_t max_label_size = 32;
}
map_labels::map_labels(const display& disp, const gamemap& map) : disp_(disp), map_(map)
{}
@ -42,6 +46,10 @@ const std::string& map_labels::get_label(int index) const {
return font::get_floating_label_text(index);
}
int map_labels::get_max_chars() {
return max_label_size;
}
const std::string& map_labels::get_label(const gamemap::location& loc) const
{
const label_map::const_iterator itor = labels_.find(loc);
@ -55,7 +63,6 @@ const std::string& map_labels::get_label(const gamemap::location& loc) const
void map_labels::set_label(const gamemap::location& loc, const std::string& str)
{
const size_t max_label_size = 32;
std::string text = str;
if(text.size() > max_label_size) {
text.resize(max_label_size);

View file

@ -20,6 +20,8 @@ public:
void write(config& res) const;
void read(const config& cfg);
static int get_max_chars();
const std::string& get_label(const gamemap::location& loc) const;
void set_label(const gamemap::location& loc, const std::string& text);
void clear();

View file

@ -642,9 +642,9 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
preview_panes.push_back(&defender_preview);
res = gui::show_dialog(gui_,NULL,_("Attack Enemy"),
_("Choose weapon")+std::string(":\n"),
gui::OK_CANCEL,&items,&preview_panes,"",NULL,NULL,NULL,-1,-1,
NULL,&buttons);
_("Choose weapon")+std::string(":\n"),
gui::OK_CANCEL,&items,&preview_panes,"",NULL,-1,NULL,NULL,-1,-1,
NULL,&buttons);
}
cursor::set(cursor::NORMAL);
@ -1040,7 +1040,7 @@ void turn_info::show_menu(const std::vector<std::string>& items_arg, int xloc, i
static const std::string style = "menu2";
const int res = gui::show_dialog(gui_,NULL,"","",
gui::MESSAGE,&menu,NULL,"",NULL,NULL,NULL,xloc,yloc,&style);
gui::MESSAGE,&menu,NULL,"",NULL,-1,NULL,NULL,xloc,yloc,&style);
if(res < 0 || res >= items.size())
return;
@ -1640,9 +1640,9 @@ void turn_info::recruit()
preview_panes.push_back(&unit_preview);
recruit_res = gui::show_dialog(gui_,NULL,_("Recruit"),
_("Select unit") + std::string(":\n"),
gui::OK_CANCEL,&items,&preview_panes,"",NULL,NULL,NULL,-1,-1,
NULL,NULL,"recruit_and_recall");
_("Select unit") + std::string(":\n"),
gui::OK_CANCEL,&items,&preview_panes,"",NULL,-1,NULL,NULL,-1,-1,
NULL,NULL,"recruit_and_recall");
}
if(recruit_res != -1) {
@ -1819,10 +1819,10 @@ void turn_info::recall()
preview_panes.push_back(&unit_preview);
res = gui::show_dialog(gui_,NULL,_("Recall"),
_("Select unit") + std::string(":\n"),
gui::OK_CANCEL,&options,
&preview_panes,"",NULL,
NULL,NULL,-1,-1,NULL,&buttons);
_("Select unit") + std::string(":\n"),
gui::OK_CANCEL,&options,
&preview_panes,"",NULL,-1,
NULL,NULL,-1,-1,NULL,&buttons);
}
if(res >= 0) {
@ -2295,7 +2295,8 @@ void turn_info::label_terrain()
std::string label = gui_.labels().get_label(last_hex_);
const int res = gui::show_dialog(gui_,NULL,_("Place Label"),"",gui::OK_CANCEL,
NULL,NULL,_("Label") + std::string(":"),&label);
NULL,NULL,_("Label") + std::string(":"),&label,
map_labels::get_max_chars());
if(res == 0) {
gui_.labels().set_label(last_hex_,label);
recorder.add_label(label,last_hex_);

View file

@ -384,6 +384,7 @@ int show_dialog(display& disp, surface image,
const std::vector<preview_pane*>* preview_panes,
const std::string& text_widget_label,
std::string* text_widget_text,
int text_widget_max_chars,
dialog_action* action, std::vector<check_item>* options, int xloc, int yloc,
const std::string* dialog_style, std::vector<dialog_button>* action_buttons,
const std::string& help_topic)
@ -420,7 +421,7 @@ int show_dialog(display& disp, surface image,
static const std::string default_text_string = "";
const unsigned int text_box_width = 350;
textbox text_widget(disp,text_box_width,
use_textbox ? *text_widget_text : default_text_string, editable_textbox);
use_textbox ? *text_widget_text : default_text_string, editable_textbox, text_widget_max_chars);
int text_widget_width = 0;
int text_widget_height = 0;
@ -954,7 +955,7 @@ network::connection network_data_dialog(display& disp, const std::string& msg, c
}
dialog_action_receive_network receiver(connection_num,cfg,stats);
const int res = show_dialog(disp,NULL,"",str.str(),CANCEL_ONLY,NULL,NULL,"",NULL,&receiver);
const int res = show_dialog(disp,NULL,"",str.str(),CANCEL_ONLY,NULL,NULL,"",NULL,-1,&receiver);
if(res != int(dialog_action_receive_network::CONNECTION_CONTINUING)) {
return receiver.result();
}

View file

@ -138,6 +138,7 @@ int show_dialog(display& screen, surface image,
const std::vector<preview_pane*>* preview_panes=NULL,
const std::string& text_widget_label="",
std::string* text_widget_text=NULL,
const int text_widget_max_chars = 256,
dialog_action* action=NULL,
std::vector<check_item>* options=NULL, int xloc=-1, int yloc=-1,
const std::string* dialog_style=NULL,

View file

@ -78,7 +78,7 @@ bool combo::process(int x, int y, bool button)
if(button_.process(x,y,button)) {
const SDL_Rect rect = button_.location();
set_selected(gui::show_dialog(*display_,NULL,"","",
gui::MESSAGE,&items_,NULL,"",NULL,NULL,NULL,
gui::MESSAGE,&items_,NULL,"",NULL,-1,NULL,NULL,
rect.x,rect.y+rect.h));
button_.draw();

View file

@ -39,7 +39,8 @@ textbox::textbox(display& d, int width, const std::string& text, bool editable,
scroll_bottom_(false), wrap_(false), line_height_(0), yscroll_(0)
{
static const SDL_Rect area = d.screen_area();
const int height = font::draw_text(NULL,area,font_size,font::NORMAL_COLOUR,"ABCD",0,0).h;
// const int height = font::draw_text(NULL,area,font_size,font::NORMAL_COLOUR,"ABCD",0,0).h;
const int height = font::get_max_height(font_size);
const SDL_Rect starting_rect = {0,0,width,height};
set_location(starting_rect);
update_text_cache(true);