The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
loadscreen.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 by the Battle for Wesnoth Project http://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 
16 #include "gui/dialogs/dialog.hpp"
17 #include "gui/widgets/label.hpp"
18 #include "tstring.hpp"
19 
20 
21 #include <boost/scoped_ptr.hpp>
22 #include <map>
23 #include <vector>
24 #include <atomic>
25 
26 class CVideo;
27 namespace boost
28 {
29  class thread;
30 }
31 namespace cursor
32 {
33  struct setter;
34 }
35 namespace gui2
36 {
37 
38 class twindow;
39 
40 class tloadscreen : public tdialog
41 {
42 public:
43 
44  tloadscreen(std::function<void()> f);
45 
46  ~tloadscreen();
47 
48  static void display(CVideo& video, std::function<void()> f);
49  static bool displaying() { return current_load != nullptr; }
50 
51  static void progress(const char* stage_name = nullptr);
52 
53  /**
54  * Hides the window.
55  *
56  * The hiding also destroys the window. It is safe to call the function
57  * when the window is not shown.
58  */
59  void close();
60 private:
62  size_t timer_id_;
64  std::function<void()> work_;
65  boost::scoped_ptr<boost::thread> worker_;
66  boost::scoped_ptr<cursor::setter> cursor_setter_;
67 
68  twindow* build_window(CVideo& video) const;
69 
70  virtual const std::string& window_id() const;
71 
72  void timer_callback(twindow& window);
73 
74  /** Inherited from tdialog. */
75  void pre_show(twindow& window);
76 
77  /** Inherited from tdialog. */
78  void post_show(twindow& window);
79 
83 
84 #if defined(_MSC_VER) && _MSC_VER < 1900
85  // std::atomic is buggy in MSVC 2013 - doesn't work for cv types
86  const char* current_stage_;
87 #else
88  std::atomic<const char*> current_stage_;
89 #endif
90  std::map<std::string, t_string> visible_stages_;
91  std::vector<t_string> animation_stages_;
92  std::map<std::string, t_string>::const_iterator current_visible_stage_;
93 };
94 
95 } // namespace gui2
tloadscreen(std::function< void()> f)
Definition: loadscreen.cpp:67
twindow * build_window(CVideo &video) const
Definition: loadscreen.cpp:102
void pre_show(twindow &window)
Inherited from tdialog.
Definition: loadscreen.cpp:107
tlabel * animation_label_
Definition: loadscreen.hpp:81
Definition: video.hpp:58
Label showing a text.
Definition: label.hpp:29
std::map< std::string, t_string > visible_stages_
Definition: loadscreen.hpp:90
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
tlabel * progress_stage_label_
Definition: loadscreen.hpp:80
void timer_callback(twindow &window)
Definition: loadscreen.cpp:145
Abstract base class for all dialogs.
Definition: dialog.hpp:121
twindow * window_
Definition: loadscreen.hpp:61
static tloadscreen * current_load
Definition: loadscreen.hpp:82
static bool displaying()
Definition: loadscreen.hpp:49
boost::scoped_ptr< cursor::setter > cursor_setter_
Definition: loadscreen.hpp:66
static void display(CVideo &video, std::function< void()> f)
Definition: loadscreen.cpp:181
static void progress(const char *stage_name=nullptr)
Definition: loadscreen.cpp:128
std::atomic< const char * > current_stage_
Definition: loadscreen.hpp:88
std::map< std::string, t_string >::const_iterator current_visible_stage_
Definition: loadscreen.hpp:92
void post_show(twindow &window)
Inherited from tdialog.
Definition: loadscreen.cpp:121
boost::scoped_ptr< boost::thread > worker_
Definition: loadscreen.hpp:65
virtual const std::string & window_id() const
The id of the window to build.
std::function< void()> work_
Definition: loadscreen.hpp:64
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void close()
Hides the window.
Definition: loadscreen.cpp:93
std::vector< t_string > animation_stages_
Definition: loadscreen.hpp:91
GLclampf f
Definition: glew.h:3024