From a953848dda1305de6672ba0396784022eb92fcf6 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Tue, 12 Jan 2016 23:10:01 +0100 Subject: [PATCH] remove display dependency from show_help() help_button still needs a display& for regierting it in the hotkey code. --- src/dialogs.cpp | 4 +- src/editor/controller/editor_controller.cpp | 8 +-- src/editor/controller/editor_controller.hpp | 2 +- src/gui/dialogs/addon_connect.cpp | 6 +-- src/gui/dialogs/unit_attack.cpp | 2 +- src/gui/dialogs/unit_create.cpp | 2 +- src/help/help.cpp | 55 ++++++++++----------- src/help/help.hpp | 18 +++---- src/help/help_browser.cpp | 19 +++---- src/help/help_browser.hpp | 5 +- src/help/help_button.cpp | 2 +- src/menu_events.cpp | 6 +-- src/scripting/game_lua_kernel.cpp | 2 +- src/show_dialog.cpp | 2 +- src/tooltips.cpp | 2 +- src/wesnoth.cpp | 2 +- 16 files changed, 67 insertions(+), 70 deletions(-) diff --git a/src/dialogs.cpp b/src/dialogs.cpp index 5fd5a2f4f70..b2b103d3ab1 100644 --- a/src/dialogs.cpp +++ b/src/dialogs.cpp @@ -1058,7 +1058,7 @@ const unit_preview_pane::details units_list_preview_pane::get_details() const void units_list_preview_pane::process_event() { if (details_button_.pressed() && index_ >= 0 && index_ < int(size())) { - help::show_unit_description(*units_->at(index_)); + help::show_unit_description(CVideo::get_singleton(), *units_->at(index_)); } } @@ -1146,7 +1146,7 @@ void unit_types_preview_pane::process_event() if (details_button_.pressed() && index_ >= 0 && index_ < int(size())) { const unit_type* type = (*unit_types_)[index_]; if (type != NULL) - help::show_unit_description(*type); + help::show_unit_description(CVideo::get_singleton(), *type); } } diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index 7dac79c291d..5ed428c946b 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -979,7 +979,7 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i void editor_controller::show_help() { - help::show_help(*gui_, "..editor"); + help::show_help(gui_->video(), "..editor"); } void editor_controller::show_menu(const std::vector& items_arg, int xloc, int yloc, bool context_menu, display& disp) @@ -1089,9 +1089,9 @@ void editor_controller::unit_description() const unit_map & units = context_manager_->get_map_context().get_units(); const unit_map::const_unit_iterator un = units.find(loc); if(un != units.end()) { - help::show_unit_help(*gui_, un->type_id(), un->type().show_variations_in_help(), false); + help::show_unit_help(gui_->video(), un->type_id(), un->type().show_variations_in_help(), false); } else { - help::show_help(*gui_, "..units"); + help::show_help(gui_->video(), "..units"); } } @@ -1343,7 +1343,7 @@ void editor_controller::terrain_description() return; const terrain_type& type = context_manager_->get_map().get_terrain_info(loc); - help::show_terrain_description(type); + help::show_terrain_description(gui().video(), type); } void editor_controller::process_keyup_event(const SDL_Event& event) diff --git a/src/editor/controller/editor_controller.hpp b/src/editor/controller/editor_controller.hpp index eebdaf8fede..a413f253a35 100644 --- a/src/editor/controller/editor_controller.hpp +++ b/src/editor/controller/editor_controller.hpp @@ -167,7 +167,7 @@ class editor_controller : public controller_base, /* controller_base overrides */ void process_keyup_event(const SDL_Event& event); mouse_handler_base& get_mouse_handler_base() { return *this; } - editor_display& get_display() {return *gui_;} + editor_display& get_display() { return *gui_; } /** Get the current mouse action */ mouse_action* get_mouse_action(); diff --git a/src/gui/dialogs/addon_connect.cpp b/src/gui/dialogs/addon_connect.cpp index 2af8578ea6a..4904a38edca 100644 --- a/src/gui/dialogs/addon_connect.cpp +++ b/src/gui/dialogs/addon_connect.cpp @@ -61,11 +61,9 @@ taddon_connect::taddon_connect(std::string& host_name, register_text("host_name", false, host_name, true); } -void taddon_connect::help_button_callback(twindow& /*window*/) +void taddon_connect::help_button_callback(twindow& window) { - if(disp_) { - help::show_help(*disp_, "installing_addons"); - } + help::show_help(window.video(), "installing_addons"); } void taddon_connect::pre_show(CVideo& /*video*/, twindow& window) diff --git a/src/gui/dialogs/unit_attack.cpp b/src/gui/dialogs/unit_attack.cpp index f94405f4427..9a7077acf2b 100644 --- a/src/gui/dialogs/unit_attack.cpp +++ b/src/gui/dialogs/unit_attack.cpp @@ -261,7 +261,7 @@ void tunit_attack::profile_button_callback(const std::string& type) return; } - help::show_unit_help(*disp_, type); + help::show_unit_help(disp_->video(), type); } void tunit_attack::damage_calc_callback(twindow& window) diff --git a/src/gui/dialogs/unit_create.cpp b/src/gui/dialogs/unit_create.cpp index 9e7a0384ebb..efc49cb9e02 100644 --- a/src/gui/dialogs/unit_create.cpp +++ b/src/gui/dialogs/unit_create.cpp @@ -436,7 +436,7 @@ void tunit_create::profile_button_callback(twindow& window) const int selected_row = find_widget(&window, "unit_type_list", false).get_selected_row(); - help::show_unit_help(*disp_, + help::show_unit_help(disp_->video(), units_[selected_row]->id(), units_[selected_row]->show_variations_in_help(), false); } diff --git a/src/help/help.cpp b/src/help/help.cpp index 27c78e441a1..049113ecb64 100644 --- a/src/help/help.cpp +++ b/src/help/help.cpp @@ -23,7 +23,6 @@ #include "help.hpp" #include "config.hpp" // for config, etc -#include "display.hpp" // for display #include "events.hpp" // for raise_draw_event, pump, etc #include "font.hpp" // for relative_size #include "game_preferences.hpp" @@ -58,17 +57,17 @@ static lg::log_domain log_help("help"); namespace help { -void show_unit_description(const unit &u) +void show_unit_description(CVideo& video, const unit &u) { - help::show_unit_description(u.type()); + help::show_unit_description(video, u.type()); } -void show_terrain_description(const terrain_type &t) +void show_terrain_description(CVideo& video, const terrain_type &t) { - help::show_terrain_help(*display::get_singleton(), t.id(), t.hide_in_editor() || t.is_combined()); + help::show_terrain_help(video, t.id(), t.hide_in_editor() || t.is_combined()); } -void show_unit_description(const unit_type &t) +void show_unit_description(CVideo& video, const unit_type &t) { std::string var_id = t.get_cfg()["variation_id"].str(); if (var_id.empty()) @@ -86,9 +85,9 @@ void show_unit_description(const unit_type &t) } if (use_variation) - help::show_variation_help(*display::get_singleton(), t.id(), var_id, hide_help); + help::show_variation_help(video, t.id(), var_id, hide_help); else - help::show_unit_help(*display::get_singleton(), t.id(), t.show_variations_in_help(), hide_help); + help::show_unit_help(video, t.id(), t.show_variations_in_help(), hide_help); } help_manager::help_manager(const config *cfg) //, gamemap *_map) @@ -114,10 +113,10 @@ help_manager::~help_manager() * * If show_topic is the empty string, the default topic will be shown. */ -void show_help(display &disp, const std::string& show_topic, int xloc, int yloc) +void show_help(CVideo& video, const std::string& show_topic, int xloc, int yloc) { - show_help(disp, toplevel, show_topic, xloc, yloc); - disp.redraw_everything(); + show_help(video, toplevel, show_topic, xloc, yloc); + video.flip(); } /** @@ -125,11 +124,11 @@ void show_help(display &disp, const std::string& show_topic, int xloc, int yloc) * * If show_topic is the empty string, the default topic will be shown. */ -void show_unit_help(display &disp, const std::string& show_topic, bool has_variations, bool hidden, int xloc, int yloc) +void show_unit_help(CVideo& video, const std::string& show_topic, bool has_variations, bool hidden, int xloc, int yloc) { - show_help(disp, toplevel, + show_help(video, toplevel, hidden_symbol(hidden) + (has_variations ? ".." : "") + unit_prefix + show_topic, xloc, yloc); - disp.redraw_everything(); + video.flip(); } /** @@ -137,10 +136,10 @@ void show_unit_help(display &disp, const std::string& show_topic, bool has_varia * * If show_topic is the empty string, the default topic will be shown. */ -void show_terrain_help(display &disp, const std::string& show_topic, bool hidden, int xloc, int yloc) +void show_terrain_help(CVideo& video, const std::string& show_topic, bool hidden, int xloc, int yloc) { - show_help(disp, toplevel, hidden_symbol(hidden) + terrain_prefix + show_topic, xloc, yloc); - disp.redraw_everything(); + show_help(video, toplevel, hidden_symbol(hidden) + terrain_prefix + show_topic, xloc, yloc); + video.flip(); } @@ -148,10 +147,10 @@ void show_terrain_help(display &disp, const std::string& show_topic, bool hidden /** * Open the help browser, show the variation of the unit matching. */ -void show_variation_help(display &disp, const std::string& unit, const std::string &variation, bool hidden, int xloc, int yloc) +void show_variation_help(CVideo& video, const std::string& unit, const std::string &variation, bool hidden, int xloc, int yloc) { - show_help(disp, toplevel, hidden_symbol(hidden) + variation_prefix + unit + "_" + variation, xloc, yloc); - disp.redraw_everything(); + show_help(video, toplevel, hidden_symbol(hidden) + variation_prefix + unit + "_" + variation, xloc, yloc); + video.flip(); } /** @@ -160,7 +159,7 @@ void show_variation_help(display &disp, const std::string& unit, const std::stri * This allows for complete customization of the contents, although not in a * very easy way. */ -void show_help(display &disp, const section &toplevel_sec, +void show_help(CVideo& video, const section &toplevel_sec, const std::string& show_topic, int xloc, int yloc) { @@ -168,7 +167,7 @@ void show_help(display &disp, const section &toplevel_sec, const gui::dialog_manager manager; const resize_lock prevent_resizing; - CVideo& screen = disp.video(); + CVideo& screen = video; const surface& scr = screen.getSurface(); const int width = std::min(font::relative_size(1250), scr->w - font::relative_size(20)); @@ -185,10 +184,10 @@ void show_help(display &disp, const section &toplevel_sec, yloc = scr->h / 2 - height / 2; } std::vector buttons_ptr; - gui::button close_button_(disp.video(), _("Close")); + gui::button close_button_(video, _("Close")); buttons_ptr.push_back(&close_button_); - gui::dialog_frame f(disp.video(), _("The Battle for Wesnoth Help"), gui::dialog_frame::default_style, + gui::dialog_frame f(video, _("The Battle for Wesnoth Help"), gui::dialog_frame::default_style, true, &buttons_ptr); f.layout(xloc, yloc, width, height); f.draw(); @@ -208,7 +207,7 @@ void show_help(display &disp, const section &toplevel_sec, generate_contents(); } try { - help_browser hb(disp, toplevel_sec); + help_browser hb(video, toplevel_sec); hb.set_location(xloc + left_padding, yloc + top_padding); hb.set_width(width - left_padding - right_padding); hb.set_height(height - top_padding - bot_padding); @@ -220,7 +219,7 @@ void show_help(display &disp, const section &toplevel_sec, } hb.set_dirty(true); events::raise_draw_event(); - disp.video().flip(); + video.flip(); CKey key; for (;;) { events::pump(); @@ -238,14 +237,14 @@ void show_help(display &disp, const section &toplevel_sec, return; } } - disp.video().flip(); + video.flip(); CVideo::delay(10); } } catch (parse_error& e) { std::stringstream msg; msg << _("Parse error when parsing help text: ") << "'" << e.message << "'"; - gui2::show_transient_message(disp.video(), "", msg.str()); + gui2::show_transient_message(video, "", msg.str()); } } diff --git a/src/help/help.hpp b/src/help/help.hpp index 24b3d220882..b126a4715ea 100644 --- a/src/help/help.hpp +++ b/src/help/help.hpp @@ -19,7 +19,7 @@ class display; class terrain_type; class unit; class unit_type; - +class CVideo; #include namespace help { @@ -33,29 +33,29 @@ struct section; /// Open a help dialog using a toplevel other than the default. This /// allows for complete customization of the contents, although not in a /// very easy way. -void show_help(display &disp, const section &toplevel, const std::string& show_topic="", +void show_help(CVideo& video, const section &toplevel, const std::string& show_topic="", int xloc=-1, int yloc=-1); /// Open the help browser. The help browser will have the topic with id /// show_topic open if it is not the empty string. The default topic /// will be shown if show_topic is the empty string. -void show_help(display &disp, const std::string& show_topic="", int xloc=-1, int yloc=-1); +void show_help(CVideo& video, const std::string& show_topic="", int xloc=-1, int yloc=-1); /// wrapper to add unit prefix and hiding symbol -void show_unit_help(display &disp, const std::string& unit_id, bool has_variations=false, +void show_unit_help(CVideo& video, const std::string& unit_id, bool has_variations=false, bool hidden = false, int xloc=-1, int yloc=-1); /// wrapper to add variation prefix and hiding symbol -void show_variation_help(display &disp, const std::string &unit_id, const std::string &variation, +void show_variation_help(CVideo& video, const std::string &unit_id, const std::string &variation, bool hidden = false, int xloc=-1, int yloc=-1); /// wrapper to add terrain prefix and hiding symbol -void show_terrain_help(display &disp, const std::string& unit_id, bool hidden = false, +void show_terrain_help(CVideo& video, const std::string& unit_id, bool hidden = false, int xloc = -1, int yloc = -1); -void show_unit_description(const unit_type &t); -void show_unit_description(const unit &u); -void show_terrain_description(const terrain_type& t); +void show_unit_description(CVideo& video, const unit_type &t); +void show_unit_description(CVideo& video, const unit &u); +void show_terrain_description(CVideo& video, const terrain_type& t); } // End namespace help. diff --git a/src/help/help_browser.cpp b/src/help/help_browser.cpp index c5231557db6..6dbf9baa438 100644 --- a/src/help/help_browser.cpp +++ b/src/help/help_browser.cpp @@ -17,7 +17,6 @@ #include // for operator<<, basic_ostream, etc #include "SDL_mouse.h" // for SDL_GetMouseState, etc #include "cursor.hpp" // for set, CURSOR_TYPE::HYPERLINK, etc -#include "display.hpp" // for display #include "font.hpp" // for relative_size #include "gettext.hpp" // for _ #include "gui/dialogs/transient_message.hpp" @@ -25,21 +24,23 @@ #include "help_impl.hpp" // for find_topic, hidden_symbol, etc #include "key.hpp" // for CKey #include "log.hpp" // for log_scope +#include "sdl/rect.hpp" +#include "video.hpp" + struct SDL_Rect; namespace help { -help_browser::help_browser(display &disp, const section &toplevel) : - gui::widget(disp.video()), - disp_(disp), - menu_(disp.video(), +help_browser::help_browser(CVideo& video, const section &toplevel) : + gui::widget(video), + menu_(video, toplevel), - text_area_(disp.video(), toplevel), toplevel_(toplevel), + text_area_(video, toplevel), toplevel_(toplevel), ref_cursor_(false), back_topics_(), forward_topics_(), - back_button_(disp.video(), "", gui::button::TYPE_PRESS, "button_normal/button_small_H22", gui::button::DEFAULT_SPACE, true, "icons/arrows/long_arrow_ornate_left"), - forward_button_(disp.video(), "", gui::button::TYPE_PRESS, "button_normal/button_small_H22", gui::button::DEFAULT_SPACE, true, "icons/arrows/long_arrow_ornate_right"), + back_button_(video, "", gui::button::TYPE_PRESS, "button_normal/button_small_H22", gui::button::DEFAULT_SPACE, true, "icons/arrows/long_arrow_ornate_left"), + forward_button_(video, "", gui::button::TYPE_PRESS, "button_normal/button_small_H22", gui::button::DEFAULT_SPACE, true, "icons/arrows/long_arrow_ornate_right"), shown_topic_(NULL) { // Hide the buttons at first since we do not have any forward or @@ -150,7 +151,7 @@ void help_browser::handle_event(const SDL_Event &event) if (t == NULL) { std::stringstream msg; msg << _("Reference to unknown topic: ") << "'" << ref << "'."; - gui2::show_transient_message(disp_.video(), "", msg.str()); + gui2::show_transient_message(CVideo::get_singleton(), "", msg.str()); update_cursor(); } else { diff --git a/src/help/help_browser.hpp b/src/help/help_browser.hpp index a469e960ec0..24a7bc02800 100644 --- a/src/help/help_browser.hpp +++ b/src/help/help_browser.hpp @@ -22,7 +22,7 @@ #include "help_text_area.hpp" // for help_text_area #include "widgets/button.hpp" // for button #include "widgets/widget.hpp" // for widget -class display; // lines 18-18 +class CVideo; // lines 18-18 struct SDL_Rect; namespace help { @@ -31,7 +31,7 @@ namespace help { class help_browser : public gui::widget { public: - help_browser(display &disp, const section &toplevel); + help_browser(CVideo& video, const section &toplevel); void adjust_layout(); @@ -54,7 +54,6 @@ private: /// it in to. Pop at the fronts if the maximum number of elements is /// exceeded. void move_in_history(std::deque &from, std::deque &to); - display &disp_; help_menu menu_; help_text_area text_area_; const section &toplevel_; diff --git a/src/help/help_button.cpp b/src/help/help_button.cpp index 570b5bebb2e..0f54e21f1d2 100644 --- a/src/help/help_button.cpp +++ b/src/help/help_button.cpp @@ -44,7 +44,7 @@ int help_button::action(gui::dialog_process_info &info) { void help_button::show_help() { - help::show_help(disp_, topic_); + help::show_help(disp_.video(), topic_); } bool help_button::can_execute_command(const hotkey::hotkey_command& cmd, int/*index*/) const diff --git a/src/menu_events.cpp b/src/menu_events.cpp index 413ef5f9cd8..a3c2b464f3d 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -482,7 +482,7 @@ void menu_handler::show_chat_log() void menu_handler::show_help() { - help::show_help(*gui_); + help::show_help(gui_->video()); } void menu_handler::speak() @@ -861,7 +861,7 @@ void menu_handler::unit_description() { const unit_map::const_iterator un = current_unit(); if(un != units().end()) { - help::show_unit_description(*un); + help::show_unit_description(pc_.get_display().video(), *un); } } @@ -874,7 +874,7 @@ void menu_handler::terrain_description(mouse_handler& mousehandler) const terrain_type& type = map().get_terrain_info(loc); //const terrain_type& info = board().map().get_terrain_info(terrain); - help::show_terrain_description(type); + help::show_terrain_description(pc_.get_display().video(), type); } void menu_handler::rename_unit() diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 2ae6cc1b40f..e2e9a06e8a1 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -1648,7 +1648,7 @@ int game_lua_kernel::intf_message(lua_State *L) int game_lua_kernel::intf_open_help(lua_State *L) { if (game_display_) { - help::show_help(*game_display_, luaL_checkstring(L, 1)); + help::show_help(game_display_->video(), luaL_checkstring(L, 1)); } return 0; } diff --git a/src/show_dialog.cpp b/src/show_dialog.cpp index a85dca19852..a204f57f3ed 100644 --- a/src/show_dialog.cpp +++ b/src/show_dialog.cpp @@ -437,7 +437,7 @@ private: void show_help() { if(topic_.empty() == false) { - help::show_help(disp_,topic_); + help::show_help(disp_.video(),topic_); } } diff --git a/src/tooltips.cpp b/src/tooltips.cpp index 572ce8a9b17..d90a72fe47a 100644 --- a/src/tooltips.cpp +++ b/src/tooltips.cpp @@ -220,7 +220,7 @@ bool click(int mousex, int mousey) for(std::map::const_iterator i = tips.begin(); i != tips.end(); ++i) { if(!i->second.action.empty() && sdl::point_in_rect(mousex, mousey, i->second.rect)) { display* disp = resources::screen; - help::show_help(*disp, i->second.action); + help::show_help(disp->video(), i->second.action); return true; } } diff --git a/src/wesnoth.cpp b/src/wesnoth.cpp index bd99305d599..ba33fef28bc 100644 --- a/src/wesnoth.cpp +++ b/src/wesnoth.cpp @@ -824,7 +824,7 @@ static int do_gameloop(const std::vector& args) continue; } else if(res == gui2::ttitle_screen::SHOW_HELP) { help::help_manager help_manager(&config_manager.game_config()); - help::show_help(game->disp()); + help::show_help(game->video()); continue; } else if(res == gui2::ttitle_screen::GET_ADDONS) { // NOTE: we need the help_manager to get access to the Add-ons