From 88d8b9c933572bf9f661e074aae1217593099c3a Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Tue, 20 Mar 2018 21:07:59 +1100 Subject: [PATCH] Removed a whole bunch of GUI1 stuff This almost completely removes GUI1, save for the button widget (will remove once I get all the Theme handling sorted out) and the editor's own GUI1 widgets. This includes the GUI1 textbox, scrollbar, scrollarea, and menu widgets, as well as the dialog_frame and dialog_manager classes. I've also removed floating_textbox. It was only kept around for reference (it's unused as of the inclusion of the GUI2 command console). gui::in_dialog has been replaced by GUI2's is_in_dialog directly now that we have no more GUI1 dialogs. \o/ --- source_lists/libwesnoth | 6 - source_lists/wesnoth | 1 - src/controller_base.cpp | 18 +- src/display.cpp | 1 - src/floating_textbox.cpp | 146 ---- src/floating_textbox.hpp | 57 -- src/help/help.cpp | 1 - src/hotkey/command_executor.cpp | 1 - src/show_dialog.cpp | 367 --------- src/show_dialog.hpp | 115 --- src/widgets/button.cpp | 592 --------------- src/widgets/button.hpp | 97 --- src/widgets/menu.cpp | 1248 ------------------------------- src/widgets/menu.hpp | 317 -------- src/widgets/menu_style.cpp | 243 ------ src/widgets/scrollarea.cpp | 171 ----- src/widgets/scrollarea.hpp | 67 -- src/widgets/scrollbar.cpp | 396 ---------- src/widgets/scrollbar.hpp | 103 --- src/widgets/textbox.cpp | 730 ------------------ src/widgets/textbox.hpp | 122 --- src/widgets/widget.cpp | 358 --------- src/widgets/widget.hpp | 133 ---- 23 files changed, 14 insertions(+), 5276 deletions(-) delete mode 100644 src/floating_textbox.cpp delete mode 100644 src/floating_textbox.hpp delete mode 100644 src/show_dialog.cpp delete mode 100644 src/show_dialog.hpp delete mode 100644 src/widgets/button.cpp delete mode 100644 src/widgets/button.hpp delete mode 100644 src/widgets/menu.cpp delete mode 100644 src/widgets/menu.hpp delete mode 100644 src/widgets/menu_style.cpp delete mode 100644 src/widgets/scrollarea.cpp delete mode 100644 src/widgets/scrollarea.hpp delete mode 100644 src/widgets/scrollbar.cpp delete mode 100644 src/widgets/scrollbar.hpp delete mode 100644 src/widgets/textbox.cpp delete mode 100644 src/widgets/textbox.hpp delete mode 100644 src/widgets/widget.cpp delete mode 100644 src/widgets/widget.hpp diff --git a/source_lists/libwesnoth b/source_lists/libwesnoth index c758d34996aa..59624679b604 100644 --- a/source_lists/libwesnoth +++ b/source_lists/libwesnoth @@ -41,7 +41,6 @@ pathfind/astarsearch.cpp pathutils.cpp quit_confirmation.cpp reports.cpp -show_dialog.cpp sound.cpp sound_music_track.cpp soundsource.cpp @@ -54,10 +53,5 @@ tooltips.cpp utils/make_enum.cpp video.cpp widgets/button.cpp -widgets/menu.cpp -widgets/menu_style.cpp -widgets/scrollarea.cpp -widgets/scrollbar.cpp -widgets/textbox.cpp widgets/widget.cpp wml_exception.cpp diff --git a/source_lists/wesnoth b/source_lists/wesnoth index be1203bcc621..f7c2c853bd26 100644 --- a/source_lists/wesnoth +++ b/source_lists/wesnoth @@ -103,7 +103,6 @@ editor/toolkit/editor_toolkit.cpp fake_unit_manager.cpp fake_unit_ptr.cpp filesystem_sdl.cpp -floating_textbox.cpp formula/callable_objects.cpp formula/debugger.cpp formula/debugger_fwd.cpp diff --git a/src/controller_base.cpp b/src/controller_base.cpp index b0606efba272..01c527dc7d0d 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -18,6 +18,8 @@ #include "display.hpp" #include "events.hpp" #include "game_config_manager.hpp" +#include "gui/core/event/handler.hpp" // gui2::is_in_dialog +#include "gui/dialogs/loading_screen.hpp" #include "hotkey/command_executor.hpp" #include "hotkey/hotkey_command.hpp" #include "log.hpp" @@ -25,8 +27,6 @@ #include "mouse_handler_base.hpp" #include "preferences/game.hpp" #include "scripting/plugins/context.hpp" -#include "show_dialog.hpp" //gui::in_dialog -#include "gui/core/event/handler.hpp" // gui2::is_in_dialog #include "soundsource.hpp" static lg::log_domain log_display("display"); #define ERR_DP LOG_STREAM(err, log_display) @@ -50,7 +50,17 @@ controller_base::~controller_base() void controller_base::handle_event(const SDL_Event& event) { - if(gui::in_dialog()) { + /* TODO: since GUI2 and the main game are now part of the same event context, there is some conflict + * between the GUI2 and event handlers such as these. By design, the GUI2 sdl handler is always on top + * of the handler queue, so its events are handled last. This means events here have a chance to fire + * first. have_keyboard_focus currently returns false if a dialog open, but this is just as stopgap + * measure. We need to figure out a better way to filter out events. + */ + //if(gui2::is_in_dialog()) { + // return; + //} + + if(gui2::dialogs::loading_screen::displaying()) { return; } @@ -162,7 +172,7 @@ void controller_base::keyup_listener::handle_event(const SDL_Event& event) bool controller_base::have_keyboard_focus() { - return true; + return !gui2::is_in_dialog(); } bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, double x_axis, double y_axis) diff --git a/src/display.cpp b/src/display.cpp index 23120c5af38b..d121d8a1c6bb 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -48,7 +48,6 @@ #include "units/animation_component.hpp" #include "units/drawer.hpp" #include "whiteboard/manager.hpp" -#include "show_dialog.hpp" #include "gui/dialogs/loading_screen.hpp" #include diff --git a/src/floating_textbox.cpp b/src/floating_textbox.cpp deleted file mode 100644 index 900c6025f7b0..000000000000 --- a/src/floating_textbox.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - Copyright (C) 2006 - 2018 by Joerg Hinrichs - wesnoth playturn Copyright (C) 2003 by David White - Part of the Battle for Wesnoth Project http://www.wesnoth.org/ - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. - - See the COPYING file for more details. -*/ - -#include "floating_textbox.hpp" - -#include "display_chat_manager.hpp" -#include "floating_label.hpp" -#include "font/standard_colors.hpp" -#include "game_display.hpp" -#include "preferences/game.hpp" -#include "log.hpp" - -#include - -static lg::log_domain log_display("display"); -#define ERR_DP LOG_STREAM(err, log_display) - -namespace gui{ - floating_textbox::floating_textbox() : - box_(nullptr), - check_(nullptr), - mode_(TEXTBOX_NONE), - label_string_(), - label_(0) - {} - - void floating_textbox::close(game_display& gui) - { - if(!active()) { - return; - } - if(check_ != nullptr) { - if(mode_ == TEXTBOX_MESSAGE) { - preferences::set_message_private(check_->checked()); - } - } - box_.reset(nullptr); - check_.reset(nullptr); - font::remove_floating_label(label_); - mode_ = TEXTBOX_NONE; - gui.invalidate_all(); - } - - void floating_textbox::update_location(game_display& gui) - { - if (box_ == nullptr) - return; - - const SDL_Rect& area = gui.map_outside_area(); - - const int border_size = 10; - - const int ypos = area.y+area.h-30 - (check_ != nullptr ? check_->height() + border_size : 0); - - if (label_ != 0) - font::remove_floating_label(label_); - - font::floating_label flabel(label_string_); - flabel.set_color(font::YELLOW_COLOR); - flabel.set_position(area.x + border_size, ypos); - flabel.set_alignment(font::LEFT_ALIGN); - flabel.set_clip_rect(area); - - label_ = font::add_floating_label(flabel); - - if (label_ == 0) - return; - - const SDL_Rect& label_area = font::get_floating_label_rect(label_); - const int textbox_width = area.w - label_area.w - border_size*3; - - if(textbox_width <= 0) { - font::remove_floating_label(label_); - return; - } - - if(box_ != nullptr) { - box_->set_volatile(true); - const SDL_Rect rect { - area.x + label_area.w + border_size * 2 - , ypos - , textbox_width - , box_->height() - }; - - box_->set_location(rect); - } - - if(check_ != nullptr) { - check_->set_volatile(true); - check_->set_location(box_->location().x,box_->location().y + box_->location().h + border_size); - } - } - - void floating_textbox::show(gui::TEXTBOX_MODE mode, const std::string& label, - const std::string& check_label, bool checked, game_display& gui) - { - close(gui); - - label_string_ = label; - mode_ = mode; - - if(!check_label.empty()) { - check_.reset(new gui::button(gui.video(),check_label,gui::button::TYPE_CHECK)); - check_->set_check(checked); - } - - - box_.reset(new gui::textbox(gui.video(),100,"",true,256,font::SIZE_PLUS,0.8,0.6)); - - update_location(gui); - } - - void floating_textbox::tab(const std::set& dictionary) - { - if(active() == false) { - return; - } - - std::string text = box_->text(); - std::vector matches(dictionary.begin(), dictionary.end()); - const bool line_start = utils::word_completion(text, matches); - - if (matches.empty()) return; - if (matches.size() == 1 && mode_ == gui::TEXTBOX_MESSAGE) { - text.append(line_start ? ": " : " "); - } else if (matches.size() > 1) { - std::string completion_list = utils::join(matches, " "); - game_display::get_singleton()->get_chat_manager().add_chat_message(time(nullptr), "", 0, completion_list, - events::chat_handler::MESSAGE_PRIVATE, false); - } - box_->set_text(text); - } -} diff --git a/src/floating_textbox.hpp b/src/floating_textbox.hpp deleted file mode 100644 index f25336fb0ad1..000000000000 --- a/src/floating_textbox.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (C) 2006 - 2018 by Joerg Hinrichs - wesnoth playturn Copyright (C) 2003 by David White - Part of the Battle for Wesnoth Project http://www.wesnoth.org/ - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. - - See the COPYING file for more details. -*/ - -#pragma once - -// Scoped_resource can't use a pointer to an incomplete pointer with MSVC. -#include "widgets/textbox.hpp" - -#include -#include - -class game_display; - -namespace gui{ - - class button; - - enum TEXTBOX_MODE { TEXTBOX_NONE, TEXTBOX_SEARCH, TEXTBOX_MESSAGE, - TEXTBOX_COMMAND, TEXTBOX_AI }; - - class floating_textbox{ - public: - floating_textbox(); - - TEXTBOX_MODE mode() const { return mode_; } - const std::unique_ptr& check() const { return check_; } - const std::unique_ptr& box() const { return box_; } - - void close(game_display& gui); - void update_location(game_display& gui); - void show(gui::TEXTBOX_MODE mode, const std::string& label, - const std::string& check_label, bool checked, game_display& gui); - void tab(const std::set& dictionary); - bool active() const { return box_.get() != nullptr; } - - private: - std::unique_ptr box_; - std::unique_ptr check_; - - TEXTBOX_MODE mode_; - - std::string label_string_; - int label_; - }; -} diff --git a/src/help/help.cpp b/src/help/help.cpp index d29c4e052820..4d79e587ea15 100644 --- a/src/help/help.cpp +++ b/src/help/help.cpp @@ -33,7 +33,6 @@ #include "key.hpp" // for CKey #include "log.hpp" // for LOG_STREAM, log_domain #include "sdl/surface.hpp" // for surface -#include "show_dialog.hpp" // for dialog_frame, etc #include "terrain/terrain.hpp" // for terrain_type #include "units/unit.hpp" // for unit #include "units/types.hpp" // for unit_type, unit_type_data, etc diff --git a/src/hotkey/command_executor.cpp b/src/hotkey/command_executor.cpp index d8d30f121bd0..fd77f50c78f4 100644 --- a/src/hotkey/command_executor.cpp +++ b/src/hotkey/command_executor.cpp @@ -29,7 +29,6 @@ #include "display.hpp" #include "quit_confirmation.hpp" #include "sdl/surface.hpp" -#include "show_dialog.hpp" #include "../resources.hpp" #include "../playmp_controller.hpp" diff --git a/src/show_dialog.cpp b/src/show_dialog.cpp deleted file mode 100644 index a53d8d06ad36..000000000000 --- a/src/show_dialog.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/* - Copyright (C) 2003 - 2018 by David White - Part of the Battle for Wesnoth Project http://www.wesnoth.org/ - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. - - See the COPYING file for more details. -*/ - -#define GETTEXT_DOMAIN "wesnoth-lib" - -#include "show_dialog.hpp" - -#include "floating_label.hpp" -#include "font/sdl_ttf.hpp" -#include "picture.hpp" -#include "gettext.hpp" -#include "gui/core/event/handler.hpp" -#include "help/help.hpp" -#include "hotkey/command_executor.hpp" -#include "log.hpp" -#include "font/marked-up_text.hpp" -#include "font/standard_colors.hpp" -#include "sdl/rect.hpp" - -static lg::log_domain log_display("display"); -#define ERR_DP LOG_STREAM(err, log_display) -#define ERR_G LOG_STREAM(err, lg::general) - -namespace { -bool is_in_dialog = false; -} - -namespace gui { - -//static initialization -const int ButtonHPadding = 10; -const int ButtonVPadding = 10; - -//note: style names are directly related to the panel image file names -const dialog_frame::style dialog_frame::default_style("opaque", 0); -const dialog_frame::style dialog_frame::message_style("translucent65", 3); -const dialog_frame::style dialog_frame::preview_style("../dialogs/selection", 0); -const dialog_frame::style dialog_frame::titlescreen_style("translucent54", 1); - -const int dialog_frame::title_border_w = 10; -const int dialog_frame::title_border_h = 5; - - - -bool in_dialog() -{ - return is_in_dialog || gui2::is_in_dialog(); -} - -dialog_manager::dialog_manager() : cursor::setter(cursor::NORMAL), reset_to(is_in_dialog) -{ - is_in_dialog = true; -} - -dialog_manager::~dialog_manager() -{ - is_in_dialog = reset_to; - int mousex, mousey; - SDL_GetMouseState(&mousex, &mousey); - SDL_Event pb_event; - pb_event.type = SDL_MOUSEMOTION; - pb_event.motion.state = 0; - pb_event.motion.x = mousex; - pb_event.motion.y = mousey; - pb_event.motion.xrel = 0; - pb_event.motion.yrel = 0; - SDL_PushEvent(&pb_event); -} - -dialog_frame::dialog_frame(CVideo& video, const std::string& title, - const style& style, bool auto_restore, - std::vector* buttons, button* help_button) : - title_(title), - video_(video), - dialog_style_(style), - buttons_(buttons), - help_button_(help_button), - restorer_(nullptr), - auto_restore_(auto_restore), - dim_(), - top_(image::get_image("dialogs/" + dialog_style_.panel + "-border-top.png")), - bot_(image::get_image("dialogs/" + dialog_style_.panel + "-border-bottom.png")), - left_(image::get_image("dialogs/" + dialog_style_.panel + "-border-left.png")), - right_(image::get_image("dialogs/" + dialog_style_.panel + "-border-right.png")), - top_left_(image::get_image("dialogs/" + dialog_style_.panel + "-border-topleft.png")), - bot_left_(image::get_image("dialogs/" + dialog_style_.panel + "-border-botleft.png")), - top_right_(image::get_image("dialogs/" + dialog_style_.panel + "-border-topright.png")), - bot_right_(image::get_image("dialogs/" + dialog_style_.panel + "-border-botright.png")), - bg_(image::get_image("dialogs/" + dialog_style_.panel + "-background.png")), - have_border_(top_ != nullptr && bot_ != nullptr && left_ != nullptr && right_ != nullptr), - dirty_(true) -{ -} - -dialog_frame::~dialog_frame() -{ - delete restorer_; -} - -dialog_frame::dimension_measurements::dimension_measurements() : - interior(sdl::empty_rect), exterior(sdl::empty_rect), title(sdl::empty_rect), button_row(sdl::empty_rect) -{} - -dialog_frame::dimension_measurements dialog_frame::layout(const SDL_Rect& rect) { - return layout(rect.x, rect.y, rect.w, rect.h); -} - -int dialog_frame::top_padding() const { - int padding = 0; - if(have_border_) { - padding += top_->h; - } - if(!title_.empty()) { - padding += font::get_max_height(font::SIZE_TITLE) + 2*dialog_frame::title_border_h; - } - return padding; -} - -void dialog_frame::set_dirty(bool dirty) { - dirty_ = dirty; -} - -void dialog_frame::handle_window_event(const SDL_Event& event) { - - if (event.type == SDL_WINDOWEVENT) { - switch (event.window.event) { - case SDL_WINDOWEVENT_RESIZED: - case SDL_WINDOWEVENT_RESTORED: - case SDL_WINDOWEVENT_SHOWN: - case SDL_WINDOWEVENT_EXPOSED: - set_dirty(); - } - } -} - -void dialog_frame::handle_event(const SDL_Event& event) { - - if (event.type == DRAW_ALL_EVENT) { - set_dirty(); - - if (buttons_) { - for(std::vector