1 /*
2  * Copyright (C) 2007-2020 by the Widelands Development Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19 
20 #ifndef WL_UI_BASIC_PROGRESSWINDOW_H
21 #define WL_UI_BASIC_PROGRESSWINDOW_H
22 
23 #include "base/rect.h"
24 #include "ui_basic/fullscreen_window.h"
25 
26 class RenderTarget;
27 
28 namespace UI {
29 
30 /// Manages a progress window on the screen.
31 struct IProgressVisualization {
32 	/// perform any visualizations as needed
33 	/// if repaint is true, ensure previously painted areas are visible
34 	virtual void update(bool repaint) = 0;
35 
36 	/// Progress Window is closing, unregister and cleanup
37 	virtual void stop() = 0;
38 
~IProgressVisualizationIProgressVisualization39 	virtual ~IProgressVisualization() {
40 	}
41 };
42 
43 /// Manages a progress window on the screen.
44 struct ProgressWindow : public UI::FullscreenWindow {
45 	explicit ProgressWindow(const std::string& background = std::string());
46 	~ProgressWindow() override;
47 
48 	/// Register additional visualization (tips/hints, animation, etc)
49 	void add_visualization(IProgressVisualization* instance);
50 	void remove_visualization(IProgressVisualization* instance);
51 
52 	/// Set a picture to render in the background
53 	void set_background(const std::string& file_name);
54 
55 	/// Display a progress step description.
56 	void step(const std::string& description);
57 
58 private:
59 	using VisualizationArray = std::vector<IProgressVisualization*>;
60 
61 	Vector2i label_center_;
62 	Recti label_rectangle_;
63 	VisualizationArray visualizations_;
64 	std::string background_;
65 	const UI::ProgressbarStyleInfo& style_;
66 
67 	void draw(RenderTarget&) override;
68 	void update(bool repaint);
69 };
70 }  // namespace UI
71 
72 #endif  // end of include guard: WL_UI_BASIC_PROGRESSWINDOW_H
73