The Battle for Wesnoth  1.17.0-dev
loading_screen.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2021
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
18 
19 #include "events.hpp"
20 #include "tstring.hpp"
21 
22 #include <atomic>
23 #include <chrono>
24 #include <future>
25 #include <map>
26 #include <optional>
27 #include <vector>
28 
29 namespace cursor
30 {
31  struct setter;
32 }
33 
34 /**
35  * Loading screen stage IDs.
36  * When adding new entries here, don't forget to update the stage_names
37  * map with an appropriate description.
38  */
39 enum class loading_stage
40 {
44  init_fonts,
45  init_teams,
46  init_theme,
47  load_config,
48  load_data,
49  load_level,
50  init_lua,
53  load_units,
55  start_game,
59  waiting,
60  redirect,
64  none,
65 };
66 
67 namespace gui2
68 {
69 class drawing;
70 class label;
71 class window;
72 
73 namespace dialogs
74 {
76 {
77 public:
78  loading_screen(std::function<void()> f);
79 
80  ~loading_screen();
81 
82  static void display(std::function<void()> f);
83  static bool displaying() { return singleton_ != nullptr; }
84 
85  static void progress(loading_stage stage = loading_stage::none);
86 
87 private:
88  virtual const std::string& window_id() const override;
89 
90  virtual void pre_show(window& window) override;
91 
92  virtual void post_show(window& window) override;
93 
94  /** Inherited from events::pump_monitor. */
95  virtual void process(events::pump_info&) override;
96 
97  /** Callback to handle drawing the progress animation. */
98  void draw_callback();
99 
101 
102  std::function<void()> load_func_;
103  std::future<void> worker_result_;
104  std::unique_ptr<cursor::setter> cursor_setter_;
105 
108 
109  std::optional<decltype(std::chrono::steady_clock::now())> animation_start_;
110 
111  std::atomic<loading_stage> current_stage_;
112 
113  using stage_map = std::map<loading_stage, t_string>;
115  stage_map::const_iterator current_visible_stage_;
116 };
117 
118 } // namespace dialogs
119 } // namespace gui2
stage_map::const_iterator current_visible_stage_
std::atomic< loading_stage > current_stage_
A drawing is widget with a fixed size and gives access to the canvas of the widget in the window inst...
Definition: drawing.hpp:52
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:57
Generic file dialog.
Definition: field-fwd.hpp:23
loading_stage
Loading screen stage IDs.
void process(int mousex, int mousey)
Definition: tooltips.cpp:194
std::string label
What to show in the filter&#39;s drop-down list.
Definition: manager.cpp:217
std::future< void > worker_result_
Various uncategorised dialogs.
std::optional< decltype(std::chrono::steady_clock::now())> animation_start_
std::map< loading_stage, t_string > stage_map
std::unique_ptr< cursor::setter > cursor_setter_
static loading_screen * singleton_
#define f
std::function< void()> load_func_
Abstract base class for all modal dialogs.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65