The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
advanced_graphics_options.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[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 
18 
21 #include "gui/dialogs/message.hpp"
22 #include "gui/widgets/button.hpp"
23 #include "gui/widgets/label.hpp"
24 #include "gui/widgets/settings.hpp"
26 #include "gui/widgets/window.hpp"
27 
28 #include "image.hpp"
29 #include "preferences.hpp"
30 #include "formula/string_utils.hpp"
31 
32 #include "utils/functional.hpp"
33 
34 #include "gettext.hpp"
35 
36 namespace gui2
37 {
38 
39 REGISTER_DIALOG(advanced_graphics_options)
40 
41 const std::vector<std::string> tadvanced_graphics_options::scale_cases = {"zoom", "hex"};
42 
43 tadvanced_graphics_options::SCALING_ALGORITHM tadvanced_graphics_options::get_scale_pref(const std::string& pref_id)
44 {
45  SCALING_ALGORITHM algo = SCALING_ALGORITHM::LINEAR;
46  try {
47  algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
48  } catch (bad_enum_cast &) {
49  preferences::set(pref_id, algo.to_string());
50  }
51  // algo is now synced with preference, and default value of linear if something went wrong
52  return algo;
53 }
54 
56 {
57  std::string pref_id = "scale_" + case_id;
59  for (size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
60  SCALING_ALGORITHM scale = SCALING_ALGORITHM::from_int(x);
61  ttoggle_button* button = &find_widget<ttoggle_button>(&window, pref_id + "_" + scale.to_string(), false);
62  group.add_member(button, scale);
63  }
64  group.set_member_states(get_scale_pref(pref_id));
65 }
66 
68 {
69  std::string pref_id = "scale_" + case_id;
70  SCALING_ALGORITHM new_val = groups_[case_id].get_active_member_value();
71  if(new_val != get_scale_pref(pref_id)) {
73  }
74  preferences::set(pref_id, new_val.to_string());
75 }
76 
78 {
79 }
80 
82 {
83  for(const std::string & i : scale_cases) {
84  setup_scale_case(i, window);
85  }
86 
87  /*
88  tbutton * defaults;
89  defaults = &find_widget<tbutton>(&window,"revert_to_defaults", false);
90  connect_signal_mouse_left_click(*defaults, std::bind(&revert_to_default_pref_values, std::ref(window)));
91  */
92 }
93 
95 {
96  if(get_retval() == twindow::OK) {
97  for(const std::string & i : scale_cases) {
99  }
101  }
102 }
103 
104 } // end namespace gui2
static const std::vector< std::string > scale_cases
SCALING_ALGORITHM get_scale_pref(const std::string &pref_id)
GLenum GLenum GLenum GLenum GLenum scale
Definition: glew.h:10669
int get_retval() const
Definition: dialog.hpp:161
void setup_scale_case(const std::string &, twindow &)
MAKE_ENUM(SCALING_ALGORITHM,(LINEAR,"linear")(NEAREST_NEIGHBOR,"nn")(XBRZ_LIN,"xbrzlin")(XBRZ_NN,"xbrznn")) private void pre_show(twindow &window)
Inherited from tdialog, implemented by REGISTER_DIALOG.
This file contains the window object, this object is a top level container which has the event manage...
std::map< std::string, tgroup< SCALING_ALGORITHM > > groups_
REGISTER_DIALOG(label_settings)
void set(const std::string &key, bool value)
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
void flush_cache()
Definition: image.cpp:191
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
std::string get(const std::string &key)
Dialog is closed with ok button.
Definition: window.hpp:125
This file contains the settings handling of the widget library.
GLuint GLuint GLsizei count
Definition: glew.h:1221
size_t i
Definition: function.cpp:1057
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
GLboolean GLuint group
Definition: glew.h:2589
void post_show(twindow &window)
Inherited from tdialog.
void add_member(tselectable_ *widget, const T &value)
Adds a widget/value pair to the group vector.
Definition: group.hpp:43
bool update_from_preferences()
initialize any private data, e.g. algorithm choices from preferences
Definition: image.cpp:1274
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void set_member_states(const T &value)
Sets the toggle values for all widgets besides the one associated with the specified value to false...
Definition: group.hpp:113