The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
theme_list.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Ignacio Riquelme Morelle <[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 
16 
18 #ifdef GUI2_EXPERIMENTAL_LISTBOX
19 #include "gui/widgets/list.hpp"
20 #else
21 #include "gui/widgets/listbox.hpp"
22 #endif
23 #include "gui/widgets/settings.hpp"
24 #include "gui/widgets/window.hpp"
25 #include "theme.hpp"
26 
27 namespace gui2
28 {
29 
30 /*WIKI
31  * @page = GUIWindowDefinitionWML
32  * @order = 2_theme_list
33  *
34  * == Theme list ==
35  *
36  * Dialog for selecting a GUI theme.
37  *
38  * @begin{table}{dialog_widgets}
39  *
40  * themes & & listbox & m &
41  * Listbox displaying user choices. $
42  *
43  * -name & & control & m &
44  * Widget which shows a theme item name. $
45  *
46  * -description & & control & m &
47  * Widget which shows a theme item description. $
48  *
49  * @end{table}
50  */
51 
52 REGISTER_DIALOG(theme_list)
53 
54 ttheme_list::ttheme_list(const std::vector<theme_info>& themes, int selection)
55  : index_(selection), themes_(themes)
56 {
57 }
58 
60 {
61  tlistbox& list = find_widget<tlistbox>(&window, "themes", false);
62  window.keyboard_capture(&list);
63 
64  for(const auto & t : themes_)
65  {
66  std::map<std::string, string_map> data;
68 
69  std::string theme_name = t.name;
70  if(theme_name.empty()) {
71  theme_name = t.id;
72  }
73 
74  column["label"] = theme_name;
75  data.insert(std::make_pair("name", column));
76  column["label"] = t.description;
77  data.insert(std::make_pair("description", column));
78 
79  list.add_row(data);
80  }
81 
82  if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) {
83  list.select_row(index_);
84  }
85 
86  index_ = -1;
87 }
88 
90 {
91  if(get_retval() != twindow::OK) {
92  return;
93  }
94 
95  tlistbox& list = find_widget<tlistbox>(&window, "themes", false);
96  index_ = list.get_selected_row();
97 }
98 }
int get_retval() const
Definition: dialog.hpp:161
This file contains the window object, this object is a top level container which has the event manage...
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
Definition: listbox.cpp:228
REGISTER_DIALOG(label_settings)
STL namespace.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
GLdouble GLdouble t
Definition: glew.h:1366
void post_show(twindow &window)
Inherited from tdialog.
Definition: theme_list.cpp:89
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
Dialog is closed with ok button.
Definition: window.hpp:125
This file contains the settings handling of the widget library.
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:138
void add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:74
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
GLenum GLenum GLvoid GLvoid * column
Definition: glew.h:3805
void pre_show(twindow &window)
Inherited from tdialog.
Definition: theme_list.cpp:59
The listbox class.
Definition: listbox.hpp:39
Definitions related to theme-support.
std::vector< theme_info > themes_
Definition: theme_list.hpp:49
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:237
GLsizei const GLcharARB ** string
Definition: glew.h:4503