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