/
drop_down_list.cpp
101 lines (89 loc) · 3.09 KB
/
drop_down_list.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
Copyright (C) 2008 - 2016 by Mark de Wever <koraq@xs4all.nl>
Part of 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.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/drop_down_list.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/dialogs/dialog.hpp"
#include "gui/widgets/integer_selector.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/settings.hpp"
#include "utils/foreach.tpp"
namespace gui2
{
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_mp_method_selection
*
* == MP method selection ==
*
* This shows the dialog to select the kind of MP game the user wants to play.
*
* @begin{table}{dialog_widgets}
*
* user_name & & text_box & m &
* This text contains the name the user on the MP server. This widget
* will get a fixed maximum length by the engine. $
*
* method_list & & listbox & m &
* The list with possible game methods. $
*
* @end{table}
*/
REGISTER_DIALOG(drop_down_list)
namespace {
void click_callback(twindow& window, bool& handled, bool& halt, tpoint coordinate)
{
SDL_Rect rect = window.get_rectangle();
if(coordinate.x < rect.x || coordinate.x > rect.x + rect.w || coordinate.y < rect.y || coordinate.y > rect.y + rect.h ) {
halt = handled = true;
window.set_retval(twindow::CANCEL);
window.close();
}
}
void resize_callback(twindow& window)
{
window.set_retval(twindow::CANCEL);
window.close();
SDL_Rect rect = window.get_rectangle();
}
}
void tdrop_down_list::pre_show(CVideo& /*video*/, twindow& window)
{
window.set_variable("button_x", variant(button_pos_.x));
window.set_variable("button_y", variant(button_pos_.y));
window.set_variable("button_w", variant(button_pos_.w));
window.set_variable("button_h", variant(button_pos_.h));
tlistbox& list = find_widget<tlistbox>(&window, "list", true);
std::map<std::string, string_map> data;
t_string& label = data["label"]["label"];
FOREACH(const AUTO& str, items_) {
label = str;
list.add_row(data);
}
list.select_row(selected_item_);
list.set_callback_item_change(boost::bind(&tdrop_down_list::item_change_callback, this, boost::ref(window), _1));
//Dismiss on click outside the window
window.connect_signal<event::SDL_LEFT_BUTTON_UP>(boost::bind(&click_callback, boost::ref(window), _3, _4, _5), event::tdispatcher::front_child);
//Dismiss on resize
window.connect_signal<event::SDL_VIDEO_RESIZE>(boost::bind(&resize_callback, boost::ref(window)), event::tdispatcher::front_child);
}
void tdrop_down_list::item_change_callback(twindow& window, size_t item)
{
selected_item_ = item;
window.set_retval(twindow::OK);
window.close();
}
void tdrop_down_list::post_show(twindow&)
{
}
} // namespace gui2