The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
preferences_display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 /**
18  * @file
19  * Manage display-related preferences, e.g. screen-size, etc.
20  */
21 
22 #include "global.hpp"
23 #include "preferences_display.hpp"
24 
25 #include "display.hpp"
26 #include "filechooser.hpp"
27 #include "filesystem.hpp"
28 #include "formatter.hpp"
29 #include "formula/string_utils.hpp"
30 #include "game_preferences.hpp"
31 #include "gettext.hpp"
32 #include "gui/dialogs/message.hpp"
36 #include "gui/widgets/window.hpp"
37 #include "log.hpp"
38 
39 #include <boost/math/common_factor_rt.hpp>
40 
41 namespace preferences {
42 
44 {
45  set_grid(grid());
46  set_turbo(turbo());
48  set_color_cursors(preferences::get("color_cursors", true));
49 }
50 
51 void show_preferences_dialog(CVideo& video, const config& game_cfg, const DIALOG_OPEN_TO initial_view)
52 {
53  gui2::tpreferences dlg(video, game_cfg);
54 
55  switch (initial_view) {
56  case VIEW_DEFAULT:
57  // Default value (0,0) already set in tpreferences
58  break;
59  case VIEW_FRIENDS: {
60  dlg.set_selected_index(std::make_pair(4, 1));
61  break;
62  }
63  }
64 
65  dlg.show(video);
66 }
67 
68 void set_turbo(bool ison)
69 {
70  _set_turbo(ison);
71 
74  }
75 }
76 
77 void set_turbo_speed(double speed)
78 {
79  save_turbo_speed(speed);
80 
83  }
84 }
85 
86 void set_grid(bool ison)
87 {
88  _set_grid(ison);
89 
92  }
93 }
94 
96 {
97  _set_color_cursors(value);
98 
99  cursor::set();
100 }
101 
102 void set_idle_anim(bool ison) {
103  _set_idle_anim(ison);
104 
105  if(display::get_singleton()) {
107  }
108 }
109 
110 void set_idle_anim_rate(int rate) {
111  _set_idle_anim_rate(rate);
112 
113  if(display::get_singleton()) {
115  }
116 }
117 
119 {
120  std::vector<theme_info> themes = theme::get_known_themes();
121 
122  if (themes.empty()) {
124  _("No known themes. Try changing from within an existing game."));
125 
126  return false;
127  }
128 
129  gui2::ttheme_list dlg(themes);
130 
131  for (size_t k = 0; k < themes.size(); ++k) {
132  if(themes[k].id == preferences::theme()) {
133  dlg.set_selected_index(static_cast<int>(k));
134  }
135  }
136 
137  dlg.show(video);
138  const int action = dlg.selected_index();
139 
140  if (action >= 0) {
141  // FIXME: it would be preferable for the new theme to take effect
142  // immediately.
143  preferences::set_theme(themes[action].id);
144 
145  return true;
146  }
147 
148  return false;
149 }
150 
152 {
153  // Showing file_chooser so user can search the wesnothd
155  size_t offset = old_path.rfind("/");
156  if (offset != std::string::npos)
157  {
158  old_path = old_path.substr(0, offset);
159  }
160  else
161  {
162  old_path.clear();
163  }
164 #ifndef _WIN32
165 
166 #ifndef WESNOTH_PREFIX
167 #define WESNOTH_PREFIX "/usr"
168 #endif
169  const std::string filename = "wesnothd";
171  if (!filesystem::is_directory(path))
172  path = filesystem::get_cwd();
173 
174 #else
175  const std::string filename = "wesnothd.exe";
176  std::string path = filesystem::get_cwd();
177 #endif
178  if (!old_path.empty()
179  && filesystem::is_directory(old_path))
180  {
181  path = old_path;
182  }
183 
184  utils::string_map symbols;
185 
186  symbols["filename"] = filename;
187 
188  const std::string title = utils::interpolate_variables_into_string(
189  _("Find $filename server binary")
190  , &symbols);
191 
192  int res = dialogs::show_file_chooser_dialog(video, path, title, false, filename);
193  if (res == 0) {
195  }
196 }
197 
198 } // end namespace preferences
199 
void set_turbo(bool ison)
void _set_turbo(bool ison)
void set_grid(bool ison)
void _set_grid(bool ison)
void set_preference_display_settings()
void show_wesnothd_server_search(CVideo &video)
static display * get_singleton()
Returns the display object if a display object exists.
Definition: display.hpp:88
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:154
void set_selected_index(int index)
Sets the initially selected item index (-1 by default).
Definition: theme_list.hpp:41
void set_grid(const bool grid)
Determines whether a grid should be overlayed on the game board.
Definition: display.hpp:361
void _set_color_cursors(bool value)
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
Definition: dialog.cpp:34
void set_turbo(const bool turbo)
Set/Get whether 'turbo' mode is on.
Definition: display.hpp:509
void set_idle_anim_rate(int rate)
Definition: display.cpp:2645
Definition: video.hpp:58
This file contains the window object, this object is a top level container which has the event manage...
void save_turbo_speed(const double speed)
void set_selected_index(std::pair< int, int > index)
void show_transient_message(CVideo &video, const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
double turbo_speed()
bool show_theme_dialog(CVideo &video)
const config * game_cfg
Definition: help_impl.cpp:64
std::string get_cwd()
GLintptr offset
Definition: glew.h:1650
void set_mp_server_program_name(const std::string &path)
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
std::string get(const std::string &key)
GLsizei const char ** path
Definition: glew.h:4654
std::map< std::string, t_string > string_map
void set_idle_anim_rate(int rate)
void set_theme(const std::string &theme)
std::string theme()
void show_preferences_dialog(CVideo &video, const config &game_cfg, const DIALOG_OPEN_TO initial_view)
GLsizei const GLfloat * value
Definition: glew.h:1817
void set_turbo_speed(double speed)
void set_idle_anim(bool ison)
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
Modify, read and display user preferences.
int selected_index() const
Returns the selected item index after displaying.
Definition: theme_list.hpp:35
int show_file_chooser_dialog(CVideo &video, std::string &filename, std::string const &title, bool show_directory_buttons, const std::string &type_a_head, int xloc, int yloc)
Show a dialog where the user can navigate through files and select a file.
Definition: filechooser.cpp:30
map_display and display: classes which take care of displaying the map and game-data on the screen...
void set_color_cursors(bool value)
void _set_idle_anim(const bool ison)
GLuint res
Definition: glew.h:9258
std::string get_mp_server_program_name()
static std::vector< theme_info > get_known_themes()
Definition: theme.cpp:928
void set_turbo_speed(const double speed)
Definition: display.hpp:513
Declarations for File-IO.
void set_idle_anim(bool ison)
control unit idle animations and their frequency
Definition: display.hpp:516
Standard logging facilities (interface).
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void _set_idle_anim_rate(const int rate)
GLsizei const GLcharARB ** string
Definition: glew.h:4503
#define WESNOTH_PREFIX