From fa3315b5207098e25844def9192f61a26001d099 Mon Sep 17 00:00:00 2001 From: Tommy Date: Sun, 17 Jul 2022 00:39:43 +1200 Subject: [PATCH] GUI1: Remove CVideo from widget constructor --- src/display.cpp | 4 ++-- src/editor/palette/common_palette.hpp | 7 +++---- src/editor/palette/editor_palettes.cpp | 2 +- src/editor/palette/editor_palettes.hpp | 2 +- src/editor/palette/empty_palette.hpp | 2 +- src/editor/palette/location_palette.cpp | 18 +++++++++--------- src/editor/palette/palette_manager.cpp | 2 +- src/editor/palette/tristate_button.cpp | 5 ++--- src/editor/palette/tristate_button.hpp | 2 +- src/floating_textbox.cpp | 4 ++-- src/help/help.cpp | 12 +++++------- src/help/help.hpp | 1 - src/help/help_browser.cpp | 14 ++++++-------- src/help/help_browser.hpp | 4 ++-- src/help/help_menu.cpp | 6 ++---- src/help/help_menu.hpp | 4 +--- src/help/help_text_area.cpp | 5 ++--- src/help/help_text_area.hpp | 4 ++-- src/help/help_topic_generators.cpp | 2 +- src/show_dialog.cpp | 7 ++++--- src/show_dialog.hpp | 5 +++-- src/widgets/button.cpp | 6 +++--- src/widgets/button.hpp | 2 +- src/widgets/menu.cpp | 4 ++-- src/widgets/menu.hpp | 2 +- src/widgets/scrollarea.cpp | 6 +++--- src/widgets/scrollarea.hpp | 2 +- src/widgets/scrollbar.cpp | 5 ++--- src/widgets/scrollbar.hpp | 2 +- src/widgets/textbox.cpp | 6 +++--- src/widgets/textbox.hpp | 2 +- src/widgets/widget.cpp | 10 ++++++++-- src/widgets/widget.hpp | 5 ++--- 33 files changed, 79 insertions(+), 85 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 17c4beaa6e5..db4fa64f7e4 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -891,7 +891,7 @@ void display::create_buttons() continue; } - auto b = std::make_shared(screen_, menu.title(), gui::button::TYPE_PRESS, menu.image(), + auto b = std::make_shared(menu.title(), gui::button::TYPE_PRESS, menu.image(), gui::button::DEFAULT_SPACE, true, menu.overlay(), font::SIZE_BUTTON_SMALL); DBG_DP << "drawing button " << menu.get_id(); @@ -909,7 +909,7 @@ void display::create_buttons() DBG_DP << "creating action buttons..."; for(const auto& action : theme_.actions()) { - auto b = std::make_shared(screen_, action.title(), string_to_button_type(action.type()), + auto b = std::make_shared(action.title(), string_to_button_type(action.type()), action.image(), gui::button::DEFAULT_SPACE, true, action.overlay(), font::SIZE_BUTTON_SMALL); DBG_DP << "drawing button " << action.get_id(); diff --git a/src/editor/palette/common_palette.hpp b/src/editor/palette/common_palette.hpp index 3ff1dea15cc..1a02384acd3 100644 --- a/src/editor/palette/common_palette.hpp +++ b/src/editor/palette/common_palette.hpp @@ -20,7 +20,6 @@ #include "widgets/widget.hpp" struct SDL_Rect; -class CVideo; namespace editor { @@ -47,7 +46,7 @@ class common_palette : public gui::widget { public: - common_palette(CVideo& video) : gui::widget(video, true) {} + common_palette() : gui::widget(true) {} virtual ~common_palette() {} @@ -91,8 +90,8 @@ public: class tristate_palette : public common_palette { public: - tristate_palette(CVideo& video) - : common_palette(video) + tristate_palette() + : common_palette() { } virtual void select_fg_item(const std::string& item_id) = 0; diff --git a/src/editor/palette/editor_palettes.cpp b/src/editor/palette/editor_palettes.cpp index 1ff52d64782..0230dfecd9d 100644 --- a/src/editor/palette/editor_palettes.cpp +++ b/src/editor/palette/editor_palettes.cpp @@ -173,7 +173,7 @@ void editor_palette::adjust_size(const SDL_Rect& target) if(items_fitting > 0) { const auto buttons_needed = static_cast(items_fitting); if(buttons_.size() != buttons_needed) { - buttons_.resize(buttons_needed, gui::tristate_button(gui_.video(), this)); + buttons_.resize(buttons_needed, gui::tristate_button(this)); } } diff --git a/src/editor/palette/editor_palettes.hpp b/src/editor/palette/editor_palettes.hpp index 03cdfd0311e..772914975c0 100644 --- a/src/editor/palette/editor_palettes.hpp +++ b/src/editor/palette/editor_palettes.hpp @@ -30,7 +30,7 @@ public: editor_palette(editor_display &gui, const game_config_view& /*cfg*/ , std::size_t item_size, std::size_t columns, editor_toolkit &toolkit) - : tristate_palette(gui.video()) + : tristate_palette() , groups_() , gui_(gui) , item_size_(item_size) diff --git a/src/editor/palette/empty_palette.hpp b/src/editor/palette/empty_palette.hpp index d66454c7644..a717d7fc19e 100644 --- a/src/editor/palette/empty_palette.hpp +++ b/src/editor/palette/empty_palette.hpp @@ -29,7 +29,7 @@ class empty_palette : public common_palette { public: empty_palette(display& gui) : - common_palette(gui.video()), + common_palette(), gui_(gui) {} //event handling diff --git a/src/editor/palette/location_palette.cpp b/src/editor/palette/location_palette.cpp index ce4b90d2978..fad2ed5fc2a 100644 --- a/src/editor/palette/location_palette.cpp +++ b/src/editor/palette/location_palette.cpp @@ -50,8 +50,8 @@ public: } }; - location_palette_item(CVideo& video, editor::location_palette* parent) - : gui::widget(video, true) + location_palette_item(editor::location_palette* parent) + : gui::widget(true) , parent_(parent) { } @@ -137,8 +137,8 @@ private: class location_palette_button : public gui::button { public: - location_palette_button(CVideo& video, const SDL_Rect& location, const std::string& text, const std::function& callback) - : gui::button(video, text) + location_palette_button(const SDL_Rect& location, const std::string& text, const std::function& callback) + : gui::button(text) , callback_(callback) { this->set_location(location.x, location.y); @@ -160,7 +160,7 @@ protected: namespace editor { location_palette::location_palette(editor_display &gui, const game_config_view& /*cfg*/, editor_toolkit &toolkit) - : common_palette(gui.video()) + : common_palette() , item_size_(20) //TODO avoid magic number , item_space_(20 + 3) @@ -247,14 +247,14 @@ void location_palette::adjust_size(const SDL_Rect& target) const int button_y = 30; int bottom = target.y + target.h; if (!button_goto_) { - button_goto_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Go To"), [this]() { + button_goto_.reset(new location_palette_button(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Go To"), [this]() { //static_cast(toolkit_.get_mouse_action()). ?? map_location pos = disp_.get_map().special_location(selected_item_); if (pos.valid()) { disp_.scroll_to_tile(pos, display::WARP); } })); - button_add_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Add"), [this]() { + button_add_.reset(new location_palette_button(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Add"), [this]() { std::string newid; if (gui2::dialogs::edit_text::execute(_("New Location Identifier"), "", newid)) { static const boost::regex valid_id("[a-zA-Z0-9_]+"); @@ -271,7 +271,7 @@ void location_palette::adjust_size(const SDL_Rect& target) } } })); - button_delete_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Delete"), nullptr)); + button_delete_.reset(new location_palette_button(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Delete"), nullptr)); } else { button_goto_->set_location(SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }); @@ -290,7 +290,7 @@ void location_palette::adjust_size(const SDL_Rect& target) // This simplifies the scrolling code in add_item. const std::size_t buttons_needed = items_fitting; if(buttons_.size() != buttons_needed) { - location_palette_item lpi(disp_.video(), this); + location_palette_item lpi(this); buttons_.resize(buttons_needed, lpi); } } diff --git a/src/editor/palette/palette_manager.cpp b/src/editor/palette/palette_manager.cpp index 69af6d82dbb..a86d8e0ee24 100644 --- a/src/editor/palette/palette_manager.cpp +++ b/src/editor/palette/palette_manager.cpp @@ -25,7 +25,7 @@ namespace editor { palette_manager::palette_manager(editor_display& gui, const game_config_view& cfg , editor_toolkit& toolkit) - : gui::widget(gui.video()), + : gui::widget(), gui_(gui), palette_start_(0), toolkit_(toolkit), diff --git a/src/editor/palette/tristate_button.cpp b/src/editor/palette/tristate_button.cpp index a54c7c9fcf1..6150eb508ec 100644 --- a/src/editor/palette/tristate_button.cpp +++ b/src/editor/palette/tristate_button.cpp @@ -23,18 +23,17 @@ #include "log.hpp" #include "sdl/rect.hpp" #include "sound.hpp" -#include "video.hpp" // TODO: highdpi - only needed for widget constructor static lg::log_domain log_display("display"); #define ERR_DP LOG_STREAM(err, log_display) namespace gui { -tristate_button::tristate_button(CVideo& video, +tristate_button::tristate_button( editor::tristate_palette* palette, std::string button_image_name, const bool auto_join) - : widget(video, auto_join) + : widget(auto_join) , baseImage_() , touchedBaseImage_() , activeBaseImage_() diff --git a/src/editor/palette/tristate_button.hpp b/src/editor/palette/tristate_button.hpp index a279ae93955..78bc882f94c 100644 --- a/src/editor/palette/tristate_button.hpp +++ b/src/editor/palette/tristate_button.hpp @@ -37,7 +37,7 @@ public: enum PRESSED_STATE { LEFT, RIGHT, BOTH, NONE }; - tristate_button(CVideo& video, + tristate_button( editor::tristate_palette* palette, std::string button_image="", const bool auto_join=true); diff --git a/src/floating_textbox.cpp b/src/floating_textbox.cpp index 24df603f769..167655fd660 100644 --- a/src/floating_textbox.cpp +++ b/src/floating_textbox.cpp @@ -112,12 +112,12 @@ namespace gui{ mode_ = mode; if(!check_label.empty()) { - check_.reset(new gui::button(gui.video(),check_label,gui::button::TYPE_CHECK)); + check_.reset(new gui::button(check_label,gui::button::TYPE_CHECK)); check_->set_check(checked); } - box_.reset(new gui::textbox(gui.video(),100,"",true,256,font::SIZE_NORMAL,0.8,0.6)); + box_.reset(new gui::textbox(100,"",true,256,font::SIZE_NORMAL,0.8,0.6)); update_location(gui); } diff --git a/src/help/help.cpp b/src/help/help.cpp index b06e1fbe122..18cd1f02c21 100644 --- a/src/help/help.cpp +++ b/src/help/help.cpp @@ -38,7 +38,7 @@ #include "terrain/terrain.hpp" // for terrain_type #include "units/unit.hpp" // for unit #include "units/types.hpp" // for unit_type, unit_type_data, etc -#include "video.hpp" // for CVideo, resize_lock +#include "video.hpp" // TODO: draw_manager - only for draw_area #include "widgets/button.hpp" // for button #include // for assert @@ -189,12 +189,10 @@ void show_with_toplevel(const section &toplevel_sec, const std::string& show_topic, int xloc, int yloc) { - CVideo& video = CVideo::get_singleton(); - const events::event_context dialog_events_context; const gui::dialog_manager manager; - SDL_Rect draw_area = video.draw_area(); + SDL_Rect draw_area = CVideo::get_singleton().draw_area(); const int width = std::min(font::relative_size(1200), draw_area.w - font::relative_size(20)); const int height = std::min(font::relative_size(850), draw_area.h - font::relative_size(150)); @@ -210,11 +208,11 @@ void show_with_toplevel(const section &toplevel_sec, yloc = draw_area.h / 2 - height / 2; } std::vector buttons_ptr; - gui::button close_button_(video, _("Close")); + gui::button close_button_(_("Close")); buttons_ptr.push_back(&close_button_); gui::dialog_frame f( - video, _("Help"), gui::dialog_frame::default_style, &buttons_ptr + _("Help"), gui::dialog_frame::default_style, &buttons_ptr ); f.layout(xloc, yloc, width, height); @@ -234,7 +232,7 @@ void show_with_toplevel(const section &toplevel_sec, generate_contents(); } try { - help_browser hb(video, toplevel_sec); + help_browser hb(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); diff --git a/src/help/help.hpp b/src/help/help.hpp index 15a50e2af5b..c5fe1e1bd3b 100644 --- a/src/help/help.hpp +++ b/src/help/help.hpp @@ -19,7 +19,6 @@ class config; class terrain_type; class unit; class unit_type; -class CVideo; class game_config_view; #include diff --git a/src/help/help_browser.cpp b/src/help/help_browser.cpp index 7d12c54b005..3e6c81f6aed 100644 --- a/src/help/help_browser.cpp +++ b/src/help/help_browser.cpp @@ -25,21 +25,19 @@ #include "sdl/rect.hpp" #include "sdl/input.hpp" // for get_mouse_state -class CVideo; struct SDL_Rect; namespace help { -help_browser::help_browser(CVideo& video, const section &toplevel) : - gui::widget(video), - menu_(video, - toplevel), - text_area_(video, toplevel), toplevel_(toplevel), +help_browser::help_browser(const section &toplevel) : + gui::widget(), + menu_(toplevel), + text_area_(toplevel), toplevel_(toplevel), ref_cursor_(false), back_topics_(), forward_topics_(), - 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"), + back_button_("", gui::button::TYPE_PRESS, "button_normal/button_small_H22", gui::button::DEFAULT_SPACE, true, "icons/arrows/long_arrow_ornate_left"), + forward_button_("", gui::button::TYPE_PRESS, "button_normal/button_small_H22", gui::button::DEFAULT_SPACE, true, "icons/arrows/long_arrow_ornate_right"), shown_topic_(nullptr) { // Hide the buttons at first since we do not have any forward or diff --git a/src/help/help_browser.hpp b/src/help/help_browser.hpp index a3838ebe99a..b8d3d8a40fa 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 CVideo; // lines 18-18 + struct SDL_Rect; namespace help { @@ -31,7 +31,7 @@ namespace help { class help_browser : public gui::widget { public: - help_browser(CVideo& video, const section &toplevel); + help_browser(const section &toplevel); void adjust_layout(); diff --git a/src/help/help_menu.cpp b/src/help/help_menu.cpp index de433413054..fce49fd9aa6 100644 --- a/src/help/help_menu.cpp +++ b/src/help/help_menu.cpp @@ -26,12 +26,10 @@ #include // for pair #include -class CVideo; // lines 56-56 - namespace help { -help_menu::help_menu(CVideo &video, const section& toplevel, int max_height) : - gui::menu(video, empty_string_vector, true, max_height, -1, nullptr, &gui::menu::bluebg_style), +help_menu::help_menu(const section& toplevel, int max_height) : + gui::menu(empty_string_vector, true, max_height, -1, nullptr, &gui::menu::bluebg_style), visible_items_(), toplevel_(toplevel), expanded_(), diff --git a/src/help/help_menu.hpp b/src/help/help_menu.hpp index 388ab1dba1e..d01ab69b95e 100644 --- a/src/help/help_menu.hpp +++ b/src/help/help_menu.hpp @@ -20,8 +20,6 @@ #include // for vector #include "widgets/menu.hpp" // for menu -class CVideo; - namespace help { struct section; } namespace help { struct topic; } @@ -34,7 +32,7 @@ namespace help { class help_menu : public gui::menu { public: - help_menu(CVideo &video, const section &toplevel, int max_height=-1); + help_menu(const section &toplevel, int max_height=-1); int process(); /** diff --git a/src/help/help_text_area.cpp b/src/help/help_text_area.cpp index 9ab0f0b62a7..3d2aab3a129 100644 --- a/src/help/help_text_area.cpp +++ b/src/help/help_text_area.cpp @@ -27,7 +27,6 @@ #include "sdl/rect.hpp" // for draw_rectangle, etc #include "sdl/texture.hpp" // for texture #include "serialization/parser.hpp" // for read, write -#include "video.hpp" // for CVideo #include // for max, min, find_if #include // for operator<<, stringstream, etc @@ -43,8 +42,8 @@ static lg::log_domain log_help("help"); namespace help { -help_text_area::help_text_area(CVideo &video, const section &toplevel) : - gui::scrollarea(video), +help_text_area::help_text_area(const section &toplevel) : + gui::scrollarea(), items_(), last_row_(), toplevel_(toplevel), diff --git a/src/help/help_text_area.hpp b/src/help/help_text_area.hpp index 6adbf51eaa5..0acab924503 100644 --- a/src/help/help_text_area.hpp +++ b/src/help/help_text_area.hpp @@ -21,7 +21,7 @@ #include "font/standard_colors.hpp" // for NORMAL_COLOR #include "sdl/texture.hpp" // for texture #include "widgets/scrollarea.hpp" // for scrollarea -class CVideo; + class config; namespace help { struct section; } namespace help { struct topic; } @@ -33,7 +33,7 @@ namespace help { class help_text_area : public gui::scrollarea { public: - help_text_area(CVideo &video, const section &toplevel); + help_text_area(const section &toplevel); /** Display the topic. */ void show_topic(const topic &t); diff --git a/src/help/help_topic_generators.cpp b/src/help/help_topic_generators.cpp index 13c23929449..a87d9f642de 100644 --- a/src/help/help_topic_generators.cpp +++ b/src/help/help_topic_generators.cpp @@ -32,7 +32,7 @@ #include "tstring.hpp" // for t_string, operator<< #include "units/helper.hpp" // for resistance_color #include "units/types.hpp" // for unit_type, unit_type_data, etc -#include "video.hpp" // fore current_resolution +#include "video.hpp" // TODO: draw_manager - only draw_area #include // for map, etc #include diff --git a/src/show_dialog.cpp b/src/show_dialog.cpp index d8f40ec74f1..a4645976472 100644 --- a/src/show_dialog.cpp +++ b/src/show_dialog.cpp @@ -31,6 +31,7 @@ #include "sdl/rect.hpp" #include "sdl/input.hpp" // get_mouse_state #include "sdl/utils.hpp" // blur_surface +#include "video.hpp" static lg::log_domain log_display("display"); #define ERR_DP LOG_STREAM(err, log_display) @@ -81,11 +82,11 @@ dialog_manager::~dialog_manager() SDL_PushEvent(&pb_event); } -dialog_frame::dialog_frame(CVideo& video, const std::string& title, +dialog_frame::dialog_frame(const std::string& title, const style& style, std::vector* buttons, button* help_button) : title_(title), - video_(video), + video_(CVideo::get_singleton()), dialog_style_(style), buttons_(buttons), help_button_(help_button), @@ -316,7 +317,7 @@ void dialog_frame::draw_background() SDL_Rect dialog_frame::draw_title(CVideo* video) { - SDL_Rect rect = CVideo::get_singleton().draw_area(); + SDL_Rect rect = video_.draw_area(); return font::pango_draw_text(video, rect, font::SIZE_TITLE, font::TITLE_COLOR, title_, dim_.title.x, dim_.title.y, false, font::pango_text::STYLE_NORMAL); } diff --git a/src/show_dialog.hpp b/src/show_dialog.hpp index bbebfc59caf..6ad2c995cc7 100644 --- a/src/show_dialog.hpp +++ b/src/show_dialog.hpp @@ -21,9 +21,10 @@ class surface; #include "floating_label.hpp" #include "gui/core/top_level_drawable.hpp" #include "tooltips.hpp" -#include "video.hpp" #include "widgets/button.hpp" +class CVideo; + namespace gui { @@ -67,7 +68,7 @@ public: static const int title_border_w, title_border_h; static const style default_style; - dialog_frame(CVideo &video, const std::string& title="", + dialog_frame(const std::string& title="", const style& dialog_style=default_style, std::vector* buttons=nullptr, button* help_button=nullptr); diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index e9ae382741a..8598ed3c311 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -28,7 +28,7 @@ #include "sdl/rect.hpp" #include "serialization/string_utils.hpp" #include "sound.hpp" -#include "video.hpp" +#include "video.hpp" // TODO: draw_manager - only needed for draw_area() #include "wml_separators.hpp" #include @@ -40,10 +40,10 @@ namespace gui { const int default_font_size = font::SIZE_BUTTON; -button::button(CVideo& video, const std::string& label, button::TYPE type, +button::button(const std::string& label, button::TYPE type, std::string button_image_name, SPACE_CONSUMPTION spacing, const bool auto_join, std::string overlay_image, int font_size) - : widget(video, auto_join), type_(type), + : widget(auto_join), type_(type), label_text_(label), image_(nullptr), pressedImage_(nullptr), activeImage_(nullptr), pressedActiveImage_(nullptr), disabledImage_(nullptr), pressedDisabledImage_(nullptr), diff --git a/src/widgets/button.hpp b/src/widgets/button.hpp index 3c20ec45736..8f6045be6a7 100644 --- a/src/widgets/button.hpp +++ b/src/widgets/button.hpp @@ -62,7 +62,7 @@ public: enum SPACE_CONSUMPTION { DEFAULT_SPACE, MINIMUM_SPACE }; - button(CVideo& video, const std::string& label, TYPE type=TYPE_PRESS, + button(const std::string& label, TYPE type=TYPE_PRESS, std::string button_image="", SPACE_CONSUMPTION spacing=DEFAULT_SPACE, const bool auto_join=true, std::string overlay_image="", int font_size = -1); diff --git a/src/widgets/menu.cpp b/src/widgets/menu.cpp index 083abd0976b..06627584e6f 100644 --- a/src/widgets/menu.cpp +++ b/src/widgets/menu.cpp @@ -147,10 +147,10 @@ bool menu::basic_sorter::less(int column, const item& row1, const item& row2) co return false; } -menu::menu(CVideo& video, const std::vector& items, +menu::menu(const std::vector& items, bool click_selects, int max_height, int max_width, const sorter* sorter_obj, style *menu_style, const bool auto_join) -: scrollarea(video, auto_join), silent_(false), +: scrollarea(auto_join), silent_(false), max_height_(max_height), max_width_(max_width), max_items_(-1), item_height_(-1), heading_height_(-1), diff --git a/src/widgets/menu.hpp b/src/widgets/menu.hpp index 6eb2c7796c5..f0b34d54d5d 100644 --- a/src/widgets/menu.hpp +++ b/src/widgets/menu.hpp @@ -137,7 +137,7 @@ public: std::map> pos_sort_; }; - menu(CVideo& video, const std::vector& items, + menu(const std::vector& items, bool click_selects=false, int max_height=-1, int max_width=-1, const sorter* sorter_obj=nullptr, style *menu_style=nullptr, const bool auto_join=true); diff --git a/src/widgets/scrollarea.cpp b/src/widgets/scrollarea.cpp index 2a63eb2a3e1..203665d7a02 100644 --- a/src/widgets/scrollarea.cpp +++ b/src/widgets/scrollarea.cpp @@ -17,13 +17,13 @@ #include "widgets/scrollarea.hpp" #include "sdl/rect.hpp" -#include "video.hpp" +#include "video.hpp" // TODO: draw_manager - only needed for draw_area() #include "sdl/input.hpp" // get_mouse_state namespace gui { -scrollarea::scrollarea(CVideo &video, const bool auto_join) - : widget(video, auto_join), scrollbar_(video), +scrollarea::scrollarea(const bool auto_join) + : widget(auto_join), scrollbar_(), old_position_(0), recursive_(false), shown_scrollbar_(false), shown_size_(0), full_size_(0), swipe_dy_(0) { diff --git a/src/widgets/scrollarea.hpp b/src/widgets/scrollarea.hpp index d5e22f8da26..c32ef16ba70 100644 --- a/src/widgets/scrollarea.hpp +++ b/src/widgets/scrollarea.hpp @@ -28,7 +28,7 @@ public: */ //- \param d the display object //- \param pane the widget where wheel events take place - scrollarea(CVideo &video, bool auto_join=true); + scrollarea(bool auto_join=true); virtual void hide(bool value = true); diff --git a/src/widgets/scrollbar.cpp b/src/widgets/scrollbar.cpp index a9c2afc812b..b98c9e8453a 100644 --- a/src/widgets/scrollbar.cpp +++ b/src/widgets/scrollbar.cpp @@ -24,7 +24,6 @@ #include "sdl/rect.hpp" #include "sdl/texture.hpp" #include "sdl/utils.hpp" -#include "video.hpp" namespace { @@ -44,8 +43,8 @@ const std::string scrollbar_mid_pressed = "buttons/scrollbars/scrollmid-pressed. namespace gui { -scrollbar::scrollbar(CVideo &video) - : widget(video) +scrollbar::scrollbar() + : widget() , state_(NORMAL) , minimum_grip_height_(0) , mousey_on_grip_(0) diff --git a/src/widgets/scrollbar.hpp b/src/widgets/scrollbar.hpp index 232cb20ec64..98a617c4c0b 100644 --- a/src/widgets/scrollbar.hpp +++ b/src/widgets/scrollbar.hpp @@ -33,7 +33,7 @@ public: //- @param d the display object //- @param pane the widget where wheel events take place //- @param callback a callback interface for warning that the grip has been moved - scrollbar(CVideo &video); + scrollbar(); /** * Determine where the scrollbar is. diff --git a/src/widgets/textbox.cpp b/src/widgets/textbox.cpp index 68750f7be58..f62b1f79bca 100644 --- a/src/widgets/textbox.cpp +++ b/src/widgets/textbox.cpp @@ -24,7 +24,7 @@ #include "log.hpp" #include "sdl/rect.hpp" #include "serialization/string_utils.hpp" -#include "video.hpp" +#include "video.hpp" // TODO: draw_manager - only needed for pixel scale #include "sdl/input.hpp" // get_mouse_state static lg::log_domain log_display("display"); @@ -33,8 +33,8 @@ static lg::log_domain log_display("display"); namespace gui { -textbox::textbox(CVideo &video, int width, const std::string& text, bool editable, std::size_t max_size, int font_size, double alpha, double alpha_focus, const bool auto_join) - : scrollarea(video, auto_join), max_size_(max_size), font_size_(font_size), text_(unicode_cast(text)), +textbox::textbox(int width, const std::string& text, bool editable, std::size_t max_size, int font_size, double alpha, double alpha_focus, const bool auto_join) + : scrollarea(auto_join), max_size_(max_size), font_size_(font_size), text_(unicode_cast(text)), cursor_(text_.size()), selstart_(-1), selend_(-1), grabmouse_(false), text_pos_(0), editable_(editable), show_cursor_(true), show_cursor_at_(0), text_image_(nullptr), diff --git a/src/widgets/textbox.hpp b/src/widgets/textbox.hpp index 0318abd1217..562de7e7f4e 100644 --- a/src/widgets/textbox.hpp +++ b/src/widgets/textbox.hpp @@ -26,7 +26,7 @@ namespace gui { class textbox : public scrollarea { public: - textbox(CVideo &video, int width, const std::string& text="", bool editable=true, std::size_t max_size = 256, int font_size = font::SIZE_PLUS, double alpha = 0.4, double alpha_focus = 0.2, const bool auto_join = true); + textbox(int width, const std::string& text="", bool editable=true, std::size_t max_size = 256, int font_size = font::SIZE_PLUS, double alpha = 0.4, double alpha_focus = 0.2, const bool auto_join = true); virtual ~textbox(); const std::string text() const; diff --git a/src/widgets/widget.cpp b/src/widgets/widget.cpp index d73989d29c9..2135506d252 100644 --- a/src/widgets/widget.cpp +++ b/src/widgets/widget.cpp @@ -31,8 +31,8 @@ namespace gui { bool widget::mouse_lock_ = false; -widget::widget(CVideo& video, const bool auto_join) - : events::sdl_handler(auto_join), focus_(true), video_(&video), rect_(EmptyRect), needs_restore_(false), +widget::widget(const bool auto_join) + : events::sdl_handler(auto_join), focus_(true), rect_(EmptyRect), needs_restore_(false), state_(UNINIT), hidden_override_(false), enabled_(true), clip_(false), clip_rect_(EmptyRect), help_string_(0), mouse_lock_local_(false) { @@ -68,6 +68,12 @@ bool widget::mouse_locked() const return mouse_lock_ && !mouse_lock_local_; } +// TODO: draw_manager - overhaul CVideo interface +CVideo& widget::video() const +{ + return CVideo::get_singleton(); +} + // TODO: draw_manager - kill surface restorers void widget::bg_cancel() { diff --git a/src/widgets/widget.hpp b/src/widgets/widget.hpp index 74024a09d52..00abc51bb0e 100644 --- a/src/widgets/widget.hpp +++ b/src/widgets/widget.hpp @@ -69,7 +69,7 @@ public: virtual void process_tooltip_string(int mousex, int mousey) override; protected: - widget(CVideo& video, const bool auto_join=true); + widget(const bool auto_join=true); virtual ~widget(); // During each relocation, this function should be called to register @@ -80,7 +80,7 @@ protected: void bg_update(); // TODO: draw_manager - remove void bg_cancel(); // TODO: draw_manager - remove - CVideo& video() const { return *video_; } + CVideo& video() const; public: /* draw_manager interface */ @@ -111,7 +111,6 @@ protected: private: void hide_override(bool value = true); - CVideo* video_; std::vector restorer_; rect rect_; mutable bool needs_restore_; // Have we drawn ourselves, so that if moved, we need to restore the background?