The Battle for Wesnoth  1.15.1+dev
advanced_graphics_options.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
3  Part of the Battle for Wesnoth Project https://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 
20 #include "gui/widgets/settings.hpp"
22 #include "gui/widgets/window.hpp"
23 
24 #include "picture.hpp"
25 
26 #include "utils/functional.hpp"
27 
28 #include "gettext.hpp"
29 
30 namespace gui2
31 {
32 namespace dialogs
33 {
34 
35 REGISTER_DIALOG(advanced_graphics_options)
36 
37 const std::vector<std::string> advanced_graphics_options::scale_cases {"zoom", "hex"};
38 
40  : groups_()
41 {
42 }
43 
45 {
46  for(const std::string& i : scale_cases) {
47  setup_scale_case(i, window);
48  }
49 }
50 
52 {
54 
55  try {
56  algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
57  } catch(const bad_enum_cast&) {
58  preferences::set(pref_id, algo.to_string());
59  }
60 
61  // algo is now synced with preference, and default value set if something went wrong
62  return algo;
63 }
64 
65 void advanced_graphics_options::setup_scale_case(const std::string& case_id, window& window)
66 {
67  const std::string pref_id = "scale_" + case_id;
69 
70  for(std::size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
71  SCALING_ALGORITHM scale = SCALING_ALGORITHM::from_int(x);
72 
73  // The widget ids in advanced_graphics_options.cfg must match the enum string values for this to work.
74  toggle_button* button = find_widget<toggle_button>(&window, pref_id + "_" + scale.to_string(), false, true);
75  VALIDATE(button, _("No matching widget found for scaling option") + " " + scale.to_string());
76 
77  group.add_member(button, scale);
78  }
79 
80  group.set_member_states(get_scale_pref(pref_id));
81 }
82 
83 void advanced_graphics_options::update_scale_case(const std::string& case_id)
84 {
85  const std::string pref_id = "scale_" + case_id;
86  SCALING_ALGORITHM new_val = groups_[case_id].get_active_member_value();
87 
88  if(new_val != get_scale_pref(pref_id)) {
90  }
91 
92  preferences::set(pref_id, new_val.to_string());
93 }
94 
96 {
97  if(get_retval() == retval::OK) {
98  for(const std::string& i : scale_cases) {
100  }
101 
103  }
104 }
105 
106 } // namespace dialogs
107 } // namespace gui2
const SCALING_ALGORITHM default_scaling_algorithm
Definition: general.cpp:74
This file contains the window object, this object is a top level container which has the event manage...
void set(const std::string &key, bool value)
Definition: general.cpp:180
virtual void pre_show(window &window) override
Inherited from modal_dialog.
void flush_cache()
Definition: picture.cpp:231
Generic file dialog.
Definition: field-fwd.hpp:22
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
std::string get(const std::string &key)
Definition: general.cpp:228
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
Definition: xbrz.cpp:1190
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
This file contains the settings handling of the widget library.
Various uncategorised dialogs.
void add_member(selectable_item *w, const T &value)
Adds a widget/value pair to the group map.
Definition: group.hpp:41
std::size_t i
Definition: function.cpp:933
static const std::vector< std::string > scale_cases
The display function.
void setup_scale_case(const std::string &, window &)
Simple push button.
Definition: button.hpp:35
std::map< std::string, group< SCALING_ALGORITHM > > groups_
SCALING_ALGORITHM get_scale_pref(const std::string &pref_id)
bool update_from_preferences()
initialize any private data, e.g. algorithm choices from preferences
Definition: picture.cpp:1181
Dialog was closed with the OK button.
Definition: retval.hpp:34
virtual void post_show(window &window) override
Inherited from modal_dialog.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63
Class for a toggle button.
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:110