this change shortens the width of the MP dialog on the titlescreen,

...and makes it easier to change dialog dimension measurements
generally. also moved around a few constants to avoid redefinition
conflict.
This commit is contained in:
Patrick Parker 2006-07-23 11:31:37 +00:00
parent bda6efd1cc
commit 15f1c253c2
10 changed files with 66 additions and 64 deletions

View file

@ -71,6 +71,8 @@ const size_t dialog::bottom_padding = font::relative_size(10);
namespace {
std::vector<std::string> empty_string_vector;
struct help_handler : public hotkey::command_executor
{
help_handler(display& disp, const std::string& topic) : disp_(disp), topic_(topic)
@ -213,7 +215,13 @@ void dialog::set_textbox(const std::string& text_widget_label,
text_widget_->set_wrap(!editable_textbox);
}
menu *dialog::get_menu()
void dialog::set_menu(const std::vector<std::string> &menu_items)
{
set_menu(new gui::menu(disp_.video(), menu_items, (type_==MESSAGE), -1,
dialog::max_menu_width, NULL, &menu::default_style, false));
}
menu& dialog::get_menu() const
{
if(menu_ == NULL)
{
@ -221,12 +229,18 @@ menu *dialog::get_menu()
empty_menu = new gui::menu(disp_.video(),empty_string_vector,false,-1,-1,NULL,&menu::simple_style);
empty_menu->leave();
}
menu_ = empty_menu;
menu_ = empty_menu; //no menu, so fake it
}
return menu_;
return *menu_;
}
int dialog::show(int xloc, int yloc)
{
dimension_measurements dim = layout(xloc, yloc);
return show(dim);
}
int dialog::show(const dimension_measurements &dim)
{
if(disp_.update_locked())
return CLOSE_DIALOG;
@ -241,12 +255,6 @@ int dialog::show(int xloc, int yloc)
help_handler helper(disp_,help_button_.topic());
hotkey::basic_handler help_dispatcher(&disp_,&helper);
//create an empty menu, if none exists
get_menu();
//layout
dimension_measurements dim = layout(xloc, yloc);
//draw
draw_frame(dim);
update_widget_positions(dim);
@ -319,7 +327,7 @@ void dialog::update_widget_positions(const dimension_measurements &dim)
text_widget_->caption()->set_location(dim.caption_x, dim.caption_y);
}
}
if(get_menu()->height() > 0) {
if(get_menu().height() > 0) {
menu_->join();
menu_->set_numeric_keypress_selection(text_widget_ == NULL);
menu_->set_width( dim.menu_width );
@ -374,7 +382,7 @@ dialog::dimension_measurements dialog::layout(int xloc, int yloc) const
text_widget_height = dim.textbox.h + message_font_size;
}
const bool use_menu = (menu_->height() > 0);
const bool use_menu = (get_menu().height() > 0);
if(!message_.empty()) {
dim.message = font::draw_text(NULL, clipRect, message_font_size,
font::NORMAL_COLOUR, message_, 0, 0);
@ -606,7 +614,7 @@ int dialog::process(dialog_process_info &info)
const bool new_left_button = (mouse_flags&SDL_BUTTON_LMASK) != 0;
const bool new_key_down = info.key[SDLK_SPACE] || info.key[SDLK_RETURN] ||
info.key[SDLK_ESCAPE];
const bool use_menu = (get_menu()->height() > 0);
const bool use_menu = (get_menu().height() > 0);
if((!info.key_down && info.key[SDLK_RETURN] || menu_->double_clicked()) &&
(type_ == YES_NO || type_ == OK_CANCEL || type_ == OK_ONLY || type_ == CLOSE_ONLY)) {
@ -690,8 +698,8 @@ int dialog::process(dialog_process_info &info)
int dialog_button::action(dialog_process_info &info) {
if(handler_ != NULL) {
menu &menu = *(parent_->get_menu());
dialog_button_action::RESULT res = handler_->button_pressed(menu.selection());
menu &menu_ref = parent_->get_menu();
dialog_button_action::RESULT res = handler_->button_pressed(menu_ref.selection());
if(res == DELETE_ITEM || res == CLOSE_DIALOG) {
return res;
@ -711,9 +719,9 @@ void dialog::action(dialog_process_info& info)
{
//default way of handling a "delete item" request
if(result() == DELETE_ITEM) {
menu &m = *(get_menu());
m.erase_item(m.selection());
if(m.nitems() == 0) {
menu &menu_ref = get_menu();
menu_ref.erase_item(menu_ref.selection());
if(menu_ref.nitems() == 0) {
set_result(CLOSE_DIALOG);
} else {
set_result(CONTINUE_DIALOG);
@ -732,10 +740,10 @@ int standard_dialog_button::action(dialog_process_info &/*info*/) {
//button pressed, otherwise return the index of the menu
//item selected if the last button is not pressed, and
//cancel (-1) otherwise
if(dialog()->get_menu()->height() <= 0) {
if(dialog()->get_menu().height() <= 0) {
return simple_result_;
} else if((simple_result_ == 0 && is_last_) || !is_last_) {
return (dialog()->get_menu()->selection());
return (dialog()->get_menu().selection());
}
return CLOSE_DIALOG;
}

View file

@ -23,12 +23,6 @@
#include "key.hpp"
#include "sdl_utils.hpp"
namespace {
static std::vector<std::string> empty_string_vector;
SDL_Rect empty_rect = { 0, 0, 0, 0 };
}
namespace gui {
struct dialog_process_info
@ -128,7 +122,19 @@ private:
class dialog {
public:
enum BUTTON_LOCATION { BUTTON_STANDARD, BUTTON_EXTRA, BUTTON_CHECKBOX, BUTTON_CHECKBOX_LEFT };
struct dimension_measurements {
dimension_measurements() : x(-1), y(-1),
frame(empty_rect), message(empty_rect), textbox(empty_rect)
{}
int x, y;
SDL_Rect frame, message, textbox;
unsigned int menu_width;
std::map<preview_pane *const, SDL_Rect > panes;
int label_x, label_y;
int menu_x, menu_y;
int image_x, image_y, caption_x, caption_y;
std::map<dialog_button *const, std::pair<int,int> > buttons;
};
private:
typedef std::vector<preview_pane *>::iterator pp_iterator;
typedef std::vector<preview_pane *>::const_iterator pp_const_iterator;
@ -164,7 +170,9 @@ public:
void set_image(dialog_image *const img) { delete image_; image_ = img; }
void set_image(surface surf, const std::string &caption="");
void set_menu(menu *const m) { if(menu_ != empty_menu) delete menu_; menu_ = m; }
void set_menu(const std::vector<std::string> & menu_items);
//add_pane - preview panes are not currently memory managed (for backwards compat)
void add_pane(preview_pane *const pp) { preview_panes_.push_back(pp); }
void set_textbox(dialog_textbox *const box) {
delete text_widget_;
@ -177,13 +185,18 @@ public:
void add_button(dialog_button *const btn, BUTTON_LOCATION loc);
void add_button(dialog_button_info btn_info, BUTTON_LOCATION loc=BUTTON_EXTRA);
//Specific preparations
//layout - determines dialog measurements based on all components
dimension_measurements layout(int xloc=-1, int yloc=-1) const;
//Launching the dialog
//show - the return value of this method should be the same as result()
int show(int xloc=-1, int yloc=-1);
int show(const dimension_measurements &dim);
//Results
int result() const { return result_; }
menu *get_menu(); //creates an empty menu if one doesn't exist
menu &get_menu() const;
bool done() const { return (result_ != CONTINUE_DIALOG); }
const std::string textbox_text() const { return text_widget_->text();}
const bool option_checked(unsigned int option_index=0);
@ -203,22 +216,8 @@ protected:
void refresh();
private:
struct dimension_measurements {
dimension_measurements() : x(-1), y(-1),
frame(empty_rect), message(empty_rect), textbox(empty_rect)
{}
int x, y;
SDL_Rect frame, message, textbox;
unsigned int menu_width;
std::map<preview_pane *const, SDL_Rect > panes;
int label_x, label_y;
int menu_x, menu_y;
int image_x, image_y, caption_x, caption_y;
std::map<dialog_button *const, std::pair<int,int> > buttons;
};
//layout - prepare components for display and draw the frame
dimension_measurements layout(int xloc, int yloc) const;
// enum INIT_STATE { STATE_UNINIT, STATE_CONTEXT_STARTED, STATE_FRAME_DRAWN, STATE_WIDGETS_JOINED, STATE_READY };
// void start_context();
void draw_frame(const dimension_measurements &dim);
void update_widget_positions(const dimension_measurements &dim);
void draw_contents(const dimension_measurements &dim);
@ -242,7 +241,7 @@ private:
const std::string title_, style_;
std::string message_;
const DIALOG_TYPE type_;
gui::menu *menu_;
mutable gui::menu *menu_;
std::vector<preview_pane*> preview_panes_;
std::vector< std::pair<dialog_button*,BUTTON_LOCATION> > button_pool_;
std::vector<dialog_button*> standard_buttons_;
@ -252,6 +251,7 @@ private:
dialog_action *action_;
surface_restorer *bg_restore_;
int result_;
// INIT_STATE state_;
};
} //end namespace gui

View file

@ -71,8 +71,6 @@ namespace {
const size_t SideBarGameStatus_x = 16;
const size_t SideBarGameStatus_y = 220;
const SDL_Rect empty_rect = {0,0,0,0};
}
display::display(unit_map& units, CVideo& video, const gamemap& map,

View file

@ -17,6 +17,7 @@
#include "about.hpp"
#include "config.hpp"
#include "construct_dialog.hpp"
#include "cursor.hpp"
#include "dialogs.hpp"
#include "display.hpp"
@ -1161,14 +1162,13 @@ bool game_controller::play_multiplayer()
std::string login = preferences::login();
int res;
do {
res = gui::show_dialog2(disp(), NULL, _("Multiplayer"), "",
gui::OK_CANCEL, &host_or_join, NULL,
_("Login: "), &login);
if(login.size() > 18) {
gui::show_error_message(disp(), _("The login name you chose is too long, please use a login with less than 18 characters"));
}
}while(login.size() > 18) ;
{
gui::dialog d(disp(), _("Multiplayer"), "", gui::OK_CANCEL);
d.set_menu(host_or_join);
d.set_textbox(_("Login: "), login, 18, font::relative_size(250));
res = d.show();
login = d.textbox_text();
}
if (res < 0)
return false;

View file

@ -26,6 +26,7 @@
#include "sound.hpp"
namespace {
std::vector<std::string> empty_string_vector;
std::string games_menu_heading()
{

View file

@ -29,10 +29,6 @@
class display;
struct game_state;
namespace {
static std::vector<std::string> empty_string_vector;
}
namespace mp {
enum controller { CNTR_NETWORK = 0, CNTR_LOCAL, CNTR_COMPUTER, CNTR_EMPTY, CNTR_LAST };

View file

@ -1122,10 +1122,6 @@ void pixel_data::read(const config& cfg) {
b = atoi(blue.c_str());
}
namespace {
const SDL_Rect empty_rect = {0,0,0,0};
}
surface_restorer::surface_restorer() : target_(NULL), rect_(empty_rect), surface_(NULL)
{
}

View file

@ -35,6 +35,10 @@
#define SDL_BUTTON_WHEELDOWN 5
#endif
namespace {
const SDL_Rect empty_rect = { 0, 0, 0, 0 };
}
SDLKey sdl_keysym_from_name(std::string const &keyname);
bool point_in_rect(int x, int y, const SDL_Rect& rect);

View file

@ -336,7 +336,7 @@ int show_dialog(display& screen, surface image,
d.set_image(image, caption);
}
if(menu_items) {
d.set_menu( new gui::menu(disp,*menu_items,type == MESSAGE,-1,dialog::max_menu_width,sorter,menu_style,false));;
d.set_menu( new gui::menu(disp,*menu_items,type == MESSAGE,-1,dialog::max_menu_width,sorter,menu_style,false));
}
if(preview_panes) {
for(int i=0; i < preview_panes->size(); ++i) {

View file

@ -29,7 +29,6 @@
#define LOG_DP LOG_STREAM(info, display)
namespace {
const SDL_Rect empty_rect = {0,0,0,0};
const int XDim = 1024;
const int YDim = 768;