-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
quit_confirmation.hpp
62 lines (50 loc) · 1.67 KB
/
quit_confirmation.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Copyright (C) 2015 - 2016 by the Battle for Wesnoth Project
<http://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.
*/
#ifndef QUIT_CONFIRMATION_HPP_INCLUDED
#define QUIT_CONFIRMATION_HPP_INCLUDED
class CVideo;
#include <cassert>
#include <vector>
#include <boost/function.hpp>
#include <boost/bind.hpp>
/**
* Implements a quit confirmation dialog.
*
* Any object of this type will prevent the game from quitting immediately.
* Instead, a confirmation dialog will pop up when attempting to close.
*/
class quit_confirmation
{
public:
explicit quit_confirmation(const boost::function<bool()>& prompt = &quit_confirmation::default_prompt)
: prompt_(prompt) { blockers_.push_back(this); }
~quit_confirmation() { blockers_.pop_back(); }
/**
* Shows the quit confirmation if needed.
*
* @throws CVideo::quit If the user chooses to quit or no prompt was
* displayed.
*/
static bool quit();
static void quit_to_title();
static void quit_to_desktop();
static bool show_prompt(const std::string& message);
static bool default_prompt();
private:
//noncopyable
quit_confirmation( const quit_confirmation& );
const quit_confirmation& operator=( const quit_confirmation& );
static std::vector<quit_confirmation*> blockers_;
static bool open_;
boost::function<bool()> prompt_;
};
#endif