Skip to content

Commit

Permalink
Pass CVideo arguments directly preferences-related functions
Browse files Browse the repository at this point in the history
This isn't perfect, and it still calls display::get_singleton in some unsafe areas
Additionally, fullscreen toggling seems to break - maximized state isn't remembered
  • Loading branch information
Vultraz committed Jan 12, 2016
1 parent aff6c1b commit 5e6f0e1
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 191 deletions.
2 changes: 1 addition & 1 deletion src/editor/controller/editor_controller.cpp
Expand Up @@ -1072,7 +1072,7 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
void editor_controller::preferences()
{
gui_->video().clear_all_help_strings();
preferences::show_preferences_dialog(*gui_, game_config_);
preferences::show_preferences_dialog(gui_->video(), game_config_);

gui_->redraw_everything();
}
Expand Down
10 changes: 5 additions & 5 deletions src/editor/map/context_manager.cpp
Expand Up @@ -190,7 +190,7 @@ void context_manager::load_map_dialog(bool force_same_context /* = false */)
if (fn.empty()) {
fn = default_dir_;
}
int res = dialogs::show_file_chooser_dialog(gui_, fn, _("Choose a File to Open"));
int res = dialogs::show_file_chooser_dialog(gui_.video(), fn, _("Choose a File to Open"));
if (res == 0) {
load_map(fn, !force_same_context);
}
Expand Down Expand Up @@ -464,7 +464,7 @@ void context_manager::apply_mask_dialog()
if (fn.empty()) {
fn = default_dir_;
}
int res = dialogs::show_file_chooser_dialog(gui_, fn, _("Choose a Mask to Apply"));
int res = dialogs::show_file_chooser_dialog(gui_.video(), fn, _("Choose a Mask to Apply"));
if (res == 0) {
try {
map_context mask(game_config_, fn, gui_);
Expand Down Expand Up @@ -501,7 +501,7 @@ void context_manager::create_mask_to_dialog()
if (fn.empty()) {
fn = default_dir_;
}
int res = dialogs::show_file_chooser_dialog(gui_, fn, _("Choose Target Map"));
int res = dialogs::show_file_chooser_dialog(gui_.video(), fn, _("Choose Target Map"));
if (res == 0) {
try {
map_context map(game_config_, fn, gui_);
Expand Down Expand Up @@ -625,7 +625,7 @@ void context_manager::save_map_as_dialog()
int overwrite_res = 1;
do {
input_name = old_input_name;
int res = dialogs::show_file_chooser_dialog_save(gui_, input_name, _("Save the Map As"), ".map");
int res = dialogs::show_file_chooser_dialog_save(gui_.video(), input_name, _("Save the Map As"), ".map");
if (res == 0) {
if (filesystem::file_exists(input_name)) {
res = gui2::show_message(gui_.video(), "",
Expand Down Expand Up @@ -653,7 +653,7 @@ void context_manager::save_scenario_as_dialog()
int overwrite_res = 1;
do {
input_name = old_input_name;
int res = dialogs::show_file_chooser_dialog_save(gui_, input_name, _("Save the Scenario As"), ".cfg");
int res = dialogs::show_file_chooser_dialog_save(gui_.video(), input_name, _("Save the Scenario As"), ".cfg");
if (res == 0) {
if (filesystem::file_exists(input_name)) {
res = gui2::show_message(gui_.video(), "",
Expand Down
22 changes: 11 additions & 11 deletions src/filechooser.cpp
Expand Up @@ -27,12 +27,12 @@
namespace dialogs
{

int show_file_chooser_dialog(display &disp, std::string &filename,
int show_file_chooser_dialog(CVideo& video, std::string &filename,
std::string const &title, bool show_directory_buttons,
const std::string& type_a_head,
int xloc, int yloc) {

file_dialog d(disp, filename, title, "", show_directory_buttons);
file_dialog d(video, filename, title, "", show_directory_buttons);
if (!type_a_head.empty())
d.select_file(type_a_head);
if(d.show(xloc, yloc) >= 0) {
Expand All @@ -41,14 +41,14 @@ int show_file_chooser_dialog(display &disp, std::string &filename,
return d.result();
}

int show_file_chooser_dialog_save(display &disp, std::string &filename,
int show_file_chooser_dialog_save(CVideo& video, std::string &filename,
std::string const &title,
const std::string& default_file_name,
bool show_directory_buttons,
const std::string& type_a_head,
int xloc, int yloc) {

file_dialog d(disp, filename, title, default_file_name, show_directory_buttons);
file_dialog d(video, filename, title, default_file_name, show_directory_buttons);
d.set_autocomplete(false);
if (!type_a_head.empty())
d.select_file(type_a_head);
Expand All @@ -58,20 +58,20 @@ int show_file_chooser_dialog_save(display &disp, std::string &filename,
return d.result();
}

file_dialog::file_dialog(display &disp, const std::string& file_path,
file_dialog::file_dialog(CVideo& video, const std::string& file_path,
const std::string& title, const std::string& default_file_name,
bool show_directory_buttons) :
gui::dialog(disp.video(), title, file_path, gui::OK_CANCEL),
gui::dialog(video, title, file_path, gui::OK_CANCEL),
show_directory_buttons_(show_directory_buttons),
files_list_(NULL),
last_selection_(-1),
last_textbox_text_(),
chosen_file_(".."),
autocomplete_(true)
{
files_list_ = new gui::file_menu(disp.video(), file_path);
const unsigned file_list_height = (disp.h() / 2);
const unsigned file_list_width = std::min<unsigned>(files_list_->width(), (disp.w() / 4));
files_list_ = new gui::file_menu(video, file_path);
const unsigned file_list_height = (display::get_singleton()->h() / 2);
const unsigned file_list_width = std::min<unsigned>(files_list_->width(), (display::get_singleton()->w() / 4));
files_list_->set_measurements(file_list_width, file_list_height);
files_list_->set_max_height(file_list_height);
set_menu(files_list_);
Expand All @@ -80,9 +80,9 @@ file_dialog::file_dialog(display &disp, const std::string& file_path,
set_textbox(_("File: "), format_filename(file_path), 100);
if (show_directory_buttons_)
{
add_button( new gui::dialog_button(disp.video(), _("Delete File"),
add_button( new gui::dialog_button(video, _("Delete File"),
gui::button::TYPE_PRESS, gui::DELETE_ITEM), dialog::BUTTON_EXTRA);
add_button( new gui::dialog_button(disp.video(), _("New Folder"),
add_button( new gui::dialog_button(video, _("New Folder"),
gui::button::TYPE_PRESS, gui::CREATE_ITEM), dialog::BUTTON_EXTRA_LEFT);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/filechooser.hpp
Expand Up @@ -29,7 +29,7 @@ namespace dialogs

class file_dialog : public gui::dialog {
public:
file_dialog(display &disp, const std::string& file_path, const std::string& title, const std::string& default_file_name, bool show_directory_buttons);
file_dialog(CVideo& video, const std::string& file_path, const std::string& title, const std::string& default_file_name, bool show_directory_buttons);

virtual gui::dialog::dimension_measurements layout(int xloc=-1, int yloc=-1);

Expand Down Expand Up @@ -62,14 +62,14 @@ class file_dialog : public gui::dialog {
/// contains the chosen file when the function returns. Return the
/// index of the button pressed, or -1 if the dialog was canceled
/// through keypress.
int show_file_chooser_dialog(display &displ, std::string &filename,
int show_file_chooser_dialog(CVideo& videol, std::string &filename,
std::string const &title, bool show_directory_buttons = true,
const std::string& file_to_search = "",
int xloc = -1, int yloc = -1);

/// Show a filechooser dialog in a "save" mode, that is, without relying
/// on autocomplete to allow saving under any filename
int show_file_chooser_dialog_save(display &displ, std::string &filename,
int show_file_chooser_dialog_save(CVideo& video, std::string &filename,
std::string const &title,
const std::string& default_file_name = "",
bool show_directory_buttons = true,
Expand Down
2 changes: 1 addition & 1 deletion src/game_initialization/multiplayer.cpp
Expand Up @@ -641,7 +641,7 @@ static void do_preferences_dialog(game_display& disp, const config& game_config)
{
DBG_MP << "displaying preferences dialog" << std::endl;
const preferences::display_manager disp_manager(&disp);
preferences::show_preferences_dialog(disp,game_config);
preferences::show_preferences_dialog(disp.video(),game_config);

/**
* The screen size might have changed force an update of the size.
Expand Down
4 changes: 2 additions & 2 deletions src/game_launcher.cpp
Expand Up @@ -956,7 +956,7 @@ bool game_launcher::play_multiplayer()
start_wesnothd();
} catch(game::mp_server_error&)
{
std::string path = preferences::show_wesnothd_server_search(disp());
std::string path = preferences::show_wesnothd_server_search(disp().video());

if (!path.empty())
{
Expand Down Expand Up @@ -1076,7 +1076,7 @@ bool game_launcher::change_language()
void game_launcher::show_preferences()
{
const preferences::display_manager disp_manager(&disp());
preferences::show_preferences_dialog(disp(),
preferences::show_preferences_dialog(disp().video(),
game_config_manager::get()->game_config());

disp().redraw_everything();
Expand Down

0 comments on commit 5e6f0e1

Please sign in to comment.