/* Copyright (C) 2017 - 2024 by Charles Dang Part of the Battle for Wesnoth Project https://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 "gui/dialogs/story_viewer.hpp" #include "display.hpp" #include "formula/variant.hpp" #include "sdl/point.hpp" #include "gui/core/timer.hpp" #include "gui/widgets/button.hpp" #include "gui/widgets/grid.hpp" #include "gui/widgets/image.hpp" #include "gui/widgets/label.hpp" #include "gui/widgets/scroll_label.hpp" #include "gui/widgets/settings.hpp" #include "gui/widgets/stacked_widget.hpp" #include "gui/widgets/window.hpp" #include "sound.hpp" #include "variable.hpp" namespace gui2::dialogs { // Helper function to get the canvas shape data for the shading under the title area until // I can figure out how to ensure it always stays on top of the canvas stack. static config get_title_area_decor_config() { static config cfg; cfg["x"] = 0; cfg["y"] = 0; cfg["w"] = "(screen_width)"; cfg["h"] = "(image_original_height * 2)"; cfg["name"] = "dialogs/story_title_decor.png~O(75%)"; return cfg; } // Stacked widget layer constants for the text stack. static const unsigned int LAYER_BACKGROUND = 1; static const unsigned int LAYER_TEXT = 2; REGISTER_DIALOG(story_viewer) story_viewer::story_viewer(const std::string& scenario_name, const config& cfg_parsed) : modal_dialog(window_id()) , controller_(vconfig(cfg_parsed, true), scenario_name) , part_index_(0) , current_part_(nullptr) , timer_id_(0) , next_draw_(0) , fade_step_(0) , fade_state_(NOT_FADING) { update_current_part_ptr(); } void story_viewer::clear_image_timer() { if(timer_id_ != 0) { remove_timer(timer_id_); timer_id_ = 0; } } story_viewer::~story_viewer() { clear_image_timer(); } void story_viewer::pre_show() { set_enter_disabled(true); // Special callback handle key presses connect_signal_pre_key_press(*this, std::bind(&story_viewer::key_press_callback, this, std::placeholders::_5)); connect_signal_mouse_left_click(find_widget