The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
quit_confirmation.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2016 by the Battle for Wesnoth Project
3  <http://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 #ifndef QUIT_CONFIRMATION_HPP_INCLUDED
16 #define QUIT_CONFIRMATION_HPP_INCLUDED
17 
18 class CVideo;
19 
20 #include <cassert>
21 #include <vector>
22 
23 #include "utils/functional.hpp"
24 
25 /**
26  * Implements a quit confirmation dialog.
27  *
28  * Any object of this type will prevent the game from quitting immediately.
29  * Instead, a confirmation dialog will pop up when attempting to close.
30  */
32 {
33 public:
34  explicit quit_confirmation(const std::function<bool()>& prompt = &quit_confirmation::default_prompt)
35  : prompt_(prompt) { blockers_.push_back(this); }
36 
37  ~quit_confirmation() { blockers_.pop_back(); }
38 
39  /**
40  * Shows the quit confirmation if needed.
41  *
42  * @throws CVideo::quit If the user chooses to quit or no prompt was
43  * displayed.
44  */
45  static bool quit();
46  static void quit_to_title();
47  static void quit_to_desktop();
48 
49  static bool show_prompt(const std::string& message);
50  static bool default_prompt();
51 
52 private:
53  //noncopyable
56  static std::vector<quit_confirmation*> blockers_;
57  static bool open_;
58 
59  std::function<bool()> prompt_;
60 };
61 
62 #endif
static void quit_to_title()
Definition: video.hpp:58
static bool show_prompt(const std::string &message)
Implements a quit confirmation dialog.
quit_confirmation(const std::function< bool()> &prompt=&quit_confirmation::default_prompt)
const quit_confirmation & operator=(const quit_confirmation &)
static bool quit()
Shows the quit confirmation if needed.
static void quit_to_desktop()
static bool default_prompt()
std::function< bool()> prompt_
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
static std::vector< quit_confirmation * > blockers_
GLsizei const GLcharARB ** string
Definition: glew.h:4503