The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
helper.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project 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 GUI_DIALOGS_HELPER_HPP_INCLUDED
16 #define GUI_DIALOGS_HELPER_HPP_INCLUDED
17 
18 #include "gui/widgets/window.hpp"
19 
20 #include "utils/functional.hpp"
21 
22 namespace gui2
23 {
24 
25 /**
26  * Template for dialog callbacks. Example usage:
27  * widget->set_callback(dialog_callback<my_dialog_class,
28  * &my_dialog_class::member_function>);
29  */
30 template <class D, void (D::*fptr)(twindow&)>
31 void dialog_callback(twidget& caller)
32 {
33  D* dialog = dynamic_cast<D*>(caller.dialog());
34  assert(dialog);
35  twindow* window = caller.get_window();
36  assert(window);
37  (dialog->*fptr)(*window);
38 }
39 
40 typedef std::function<void(twindow &)> dialog_member_func_type;
41 
42 inline void make_dialog_callback_helper(const dialog_member_func_type & t,
43  twidget & caller)
44 {
45  twindow * window = caller.get_window();
46  assert(window);
47  t(*window);
48 }
49 
50 inline std::function<void(twidget &)> make_dialog_callback(
51  dialog_member_func_type func)
52 {
53  return std::bind(make_dialog_callback_helper, func, _1);
54 }
55 
56 } // namespace gui2
57 
58 #endif
void make_dialog_callback_helper(const dialog_member_func_type &t, twidget &caller)
Definition: helper.hpp:42
This file contains the window object, this object is a top level container which has the event manage...
std::function< void(twidget &)> make_dialog_callback(dialog_member_func_type func)
Definition: helper.hpp:50
GLdouble GLdouble t
Definition: glew.h:1366
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
tdialog * dialog()
Returns the top-level dialogue.
Definition: widget.cpp:144
std::function< void(twindow &)> dialog_member_func_type
Definition: helper.hpp:40
Base class for all widgets.
Definition: widget.hpp:49
twindow * get_window()
Get the parent window.
Definition: widget.cpp:116
void dialog_callback(twidget &caller)
Template for dialog callbacks.
Definition: helper.hpp:31