add "advanced graphics" preference dialog, for scaling algo options

This commit also gives the smart enums in src/make_enum.hpp
introspective capabilities, by giving them a static const size_t
which tells how many possible values they may take (hence the range
of the enum.) It was convenient for the dialog implementation
to have this.

Note that, I had to make use of __attribute__((unused)) to compile
this. I apply this using a macro which adds it for gcc, clang, and
mingw which I know respond to this attribute. I don't know what is
the equivalent MSVC device, or if it is even necessary, so its
possible that this commit needs to be fixed up.

We also disable unit tests for the new advanced graphics dialog,
there are no tests for it right now...
This commit is contained in:
Chris Beck 2014-10-22 01:14:08 -04:00
parent 3f18331a08
commit 07b6eeedb2
9 changed files with 423 additions and 5 deletions

View file

@ -0,0 +1,183 @@
#textdomain wesnoth-lib
#define _GUI_COLUMN_LABEL LABEL TOOLTIP
[row]
grow_factor=0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = {LABEL}
tooltip = {TOOLTIP}
[/label]
[/column]
[/row]
#enddef
#define _GUI_SCALE_OPTION ID LABEL TOOLTIP
[row]
grow_factor=0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[toggle_button]
id = "scale_"+{ID}
definition = "radio"
label = {LABEL}
tooltip = {TOOLTIP}
[/toggle_button]
[/column]
[/row]
#enddef
#define _GUI_SCALE_ALGO_OPTIONS CASE
{_GUI_SCALE_OPTION ({CASE}+"_linear") _"Linear" _"Bilinear intepolation scaling (legacy wesnoth option)"}
{_GUI_SCALE_OPTION ({CASE}+"_nn") _"Nearest Neighbor" _"Nearest Neighbor scaling (fastest)"}
{_GUI_SCALE_OPTION ({CASE}+"_xbrzlin") _"xBRZ + linear" _"xBRZ followed by Bilinear interpolation"}
{_GUI_SCALE_OPTION ({CASE}+"_xbrznn") _"xBRZ + NN" _"xBRZ followed by Nearest Neighbor (recommended)"}
#enddef
#define _GUI_SCALE_CHOICE CASE LABEL TOOLTIP
[grid]
{_GUI_COLUMN_LABEL {LABEL} {TOOLTIP}}
{_GUI_SCALE_ALGO_OPTIONS {CASE}}
[/grid]
#enddef
[window]
id = "advanced_graphics_options"
description = "Advanced options to control what image processing algorithms are used."
[resolution]
definition = "default"
#click_dismiss = "true"
maximum_width = 800
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
[linked_group]
id = "algorithm"
fixed_width = "true"
[/linked_group]
[tooltip]
id = "tooltip_large"
[/tooltip]
[helptip]
id = "tooltip_large"
[/helptip]
[grid]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Advanced Graphics Options"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Images will be scaled using the following algorithms:"
wrap = "true"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
[grid]
[row]
grow_factor = 0
[column]
horizontal_grow = "true"
vertical_grow = "true"
border = "top"
border_size = 5
{_GUI_SCALE_CHOICE zoom _"Scaled to zoom" _"All units, haloes, border hexes"}
[/column]
[column]
horizontal_grow = "true"
vertical_grow = "true"
border = "top"
border_size = 5
{_GUI_SCALE_CHOICE hex _"Scaled to hex" _"Everything else"}
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
grow_factor = 0
[column]
horizontal_alignment = "right"
[grid]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "ok"
definition = "default"
label = _ "Close"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -787,6 +787,7 @@ set(wesnoth-main_SRC
gui/dialogs/addon/uninstall_list.cpp
gui/dialogs/addon_connect.cpp
gui/dialogs/addon_list.cpp
gui/dialogs/advanced_graphics_options.cpp
gui/dialogs/campaign_difficulty.cpp
gui/dialogs/campaign_selection.cpp
gui/dialogs/campaign_settings.cpp

View file

@ -370,6 +370,7 @@ wesnoth_sources = Split("""
gui/dialogs/addon/uninstall_list.cpp
gui/dialogs/addon_connect.cpp
gui/dialogs/addon_list.cpp
gui/dialogs/advanced_graphics_options.cpp
gui/dialogs/campaign_difficulty.cpp
gui/dialogs/campaign_selection.cpp
gui/dialogs/campaign_settings.cpp

View file

@ -21,6 +21,7 @@
#include "filechooser.hpp"
#include "game_preferences.hpp"
#include "gettext.hpp"
#include "gui/dialogs/advanced_graphics_options.hpp"
#include "gui/dialogs/game_cache_options.hpp"
#include "gui/dialogs/game_paths.hpp"
#include "gui/dialogs/mp_alerts_options.hpp"
@ -144,6 +145,7 @@ private:
animate_map_button_,
disable_auto_move_button_,
mp_alerts_options_button_,
advanced_graphics_options_button_,
// color tab
orb_colors_defaults_,
@ -246,6 +248,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
animate_map_button_(disp.video(), _("Animate map"), gui::button::TYPE_CHECK),
disable_auto_move_button_(disp.video(), _("Disable automatic moves"), gui::button::TYPE_CHECK),
mp_alerts_options_button_(disp.video(), _("Alerts")),
advanced_graphics_options_button_(disp.video(), _("Advanced")),
// Colors tab buttons
orb_colors_defaults_(disp.video(), _("Defaults")),
@ -609,6 +612,7 @@ handler_vector preferences_dialog::handler_members()
h.push_back(&friends_);
h.push_back(&disable_auto_move_button_);
h.push_back(&mp_alerts_options_button_);
h.push_back(&advanced_graphics_options_button_);
// Colors tab
for (unsigned i = 0; i < color_ids_.size(); i++) {
@ -706,6 +710,7 @@ void preferences_dialog::update_location(SDL_Rect const &rect)
bottom_row_y - theme_button_.height());
colors_button_.set_location(rect.x + video_mode_button_.width() + theme_button_.width() + 20, bottom_row_y - colors_button_.height());
advanced_graphics_options_button_.set_location(rect.x, bottom_row_y - video_mode_button_.height() - advanced_graphics_options_button_.height() - 10);
// Color tab
const int width = 28; // orb_colors_ally_buttons_[0].width();
@ -1002,6 +1007,9 @@ void preferences_dialog::process_event()
if (colors_button_.pressed())
set_selection(COLOR_TAB);
if (advanced_graphics_options_button_.pressed())
show_advanced_graphics_dialog(disp_);
return;
}
@ -1606,6 +1614,7 @@ void preferences_dialog::set_selection(int index)
show_team_colors_button_.hide(hide_display);
show_grid_button_.hide(hide_display);
colors_button_.hide(hide_display);
advanced_graphics_options_button_.hide(hide_display);
const bool hide_colors = tab_ != COLOR_TAB;
orb_colors_ally_toggle_.hide(hide_colors);
@ -1774,6 +1783,11 @@ void show_mp_alerts_dialog(display & disp)
gui2::tmp_alerts_options::display(disp.video());
}
void show_advanced_graphics_dialog(display & disp)
{
gui2::tadvanced_graphics_options::display(disp.video());
}
std::string show_wesnothd_server_search(display& disp)
{
// Showing file_chooser so user can search the wesnothd

View file

@ -0,0 +1,127 @@
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
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/advanced_graphics_options.hpp"
#include "desktop/notifications.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/dialogs/message.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
#include "preferences.hpp"
#include "formula_string_utils.hpp"
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>
#include "gettext.hpp"
namespace gui2
{
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_mp_alerts_options
*
* == Lobby sounds options ==
*
* A Preferences subdialog permitting to configure the sounds and notifications
* generated in response to various mp lobby / game events.
*
* @begin{table}{dialog_widgets}
*
* _label & & label & m &
* Item name. $
*
* _sound & & toggle_button & m &
* Toggles whether to play the item sound. $
*
* _notif & & toggle_button & m &
* Toggles whether to give a notification. $
*
* _lobby & & toggle_button & m &
* Toggles whether to take actions for this item when in the lobby. $
*
* @end{table}
*/
REGISTER_DIALOG(advanced_graphics_options)
const std::vector<std::string> tadvanced_graphics_options::scale_cases = boost::assign::list_of("zoom")("hex");
void tadvanced_graphics_options::setup_scale_button(const std::string & case_id, SCALING_ALGORITHM button, twindow & window )
{
std::string pref_id = "scale_" + case_id;
tadvanced_graphics_options::SCALING_ALGORITHM algo = tadvanced_graphics_options::LINEAR;
try {
algo = string_to_SCALING_ALGORITHM(preferences::get(pref_id));
} catch (bad_enum_cast &) {
preferences::set(pref_id, SCALING_ALGORITHM_to_string(algo));
}
// algo is now synced with preference, and default value of linear if something went wrong
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM_to_string(button), false);
b->set_value(algo == button);
connect_signal_mouse_left_click(*b, boost::bind(&tadvanced_graphics_options::scale_button_callback, this, pref_id, button, boost::ref(window)));
}
void tadvanced_graphics_options::scale_button_callback(std::string pref_id, SCALING_ALGORITHM me, twindow & window)
{
preferences::set(pref_id, SCALING_ALGORITHM_to_string(me));
for (size_t x = 0; x < SCALING_ALGORITHM_COUNT; ++x) {
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM_to_string(static_cast<SCALING_ALGORITHM>(x)), false);
b->set_value(x == me);
}
}
void tadvanced_graphics_options::setup_scale_case(const std::string & i, twindow & window)
{
for (size_t x = 0; x < SCALING_ALGORITHM_COUNT; ++x) {
setup_scale_button(i, static_cast<SCALING_ALGORITHM>(x), window);
}
}
tadvanced_graphics_options::tadvanced_graphics_options()
{
}
void tadvanced_graphics_options::pre_show(CVideo& /*video*/, twindow& window)
{
BOOST_FOREACH(const std::string & i, scale_cases) {
setup_scale_case(i, window);
}
/*
tbutton * defaults;
defaults = &find_widget<tbutton>(&window,"revert_to_defaults", false);
connect_signal_mouse_left_click(*defaults, boost::bind(&revert_to_default_pref_values, boost::ref(window)));
*/
}
void tadvanced_graphics_options::post_show(twindow& /*window*/)
{
}
} // end namespace gui2

View file

@ -0,0 +1,72 @@
/*
Copyright (C) 2012 - 2014 by Chris Beck <render787@gmail.com>
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.
*/
#ifndef GUI_DIALOGS_ADVANCED_GRAPHICS_OPTIONS_HPP_INCLUDED
#define GUI_DIALOGS_ADVANCED_GRAPHICS_OPTIONS_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "make_enum.hpp"
namespace gui2
{
class tlabel;
class ttoggle_button;
class tadvanced_graphics_options : public tdialog
{
public:
/** Constructor. */
tadvanced_graphics_options();
/**
* The display function.
*
* See @ref tdialog for more information.
*/
static void display(CVideo& video)
{
tadvanced_graphics_options().show(video);
}
// These names must match the infixes of the widget ids in advanced_graphics_options.cfg
static const std::vector<std::string> scale_cases;
// These names must match the suffixes of the widget ids in advanced_graphics_options.cfg
MAKE_ENUM(SCALING_ALGORITHM,
(LINEAR, "linear")
(NEAREST_NEIGHBOR, "nn")
(XBRZ_LIN, "xbrzlin")
(XBRZ_NN, "xbrznn")
)
private:
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
void setup_scale_case(const std::string &, twindow &);
void setup_scale_button(const std::string &, SCALING_ALGORITHM, twindow &);
void scale_button_callback(std::string, SCALING_ALGORITHM, twindow &);
};
MAKE_ENUM_STREAM_OPS2(tadvanced_graphics_options, SCALING_ALGORITHM)
} // end namespace gui2
#endif

View file

@ -61,6 +61,7 @@ MAKE_ENUM_STREAM_OPS2(bar , another)
* What it does:
*
* generates an enum foo::enumname, with functions to convert to and from string
* const size_t foo::enumname_COUNT, which counts the number of possible values,
*
*
* foo::string_to_enumname(std::string); //throws bad_enum_cast
@ -129,6 +130,13 @@ private:
const std::string message;
};
// Add compiler directive suppressing unused variable warning
#if defined(__GNUCC__) || defined(__clang__) || defined(__MINGW32__)
#define ATTR_UNUSED( x ) __attribute__((unused)) x
#else
#define ATTR_UNUSED( x ) x
#endif
#define CAT2( A, B ) A ## B
#define CAT3( A, B, C ) A ## B ## C
@ -152,6 +160,9 @@ private:
#define EXPANDENUMFUNCTIONREVRETURN( a, b ) if ( val == a ) return b;
#define EXPANDENUMFUNCTIONREV( r, data, elem ) EXPANDENUMFUNCTIONREVRETURN elem
#define EXPANDENUMFUNCTIONCOUNTRETURN( a, b ) 1+
#define EXPANDENUMFUNCTIONCOUNT( r, data, elem ) EXPANDENUMFUNCTIONCOUNTRETURN elem
#define ADD_PAREN_1( A, B ) ((A, B)) ADD_PAREN_2
#define ADD_PAREN_2( A, B ) ((A, B)) ADD_PAREN_1
#define ADD_PAREN_1_END
@ -161,10 +172,10 @@ private:
#define MAKEENUMTYPE( NAME, CONTENT ) \
enum NAME { \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMTYPE, , MAKEPAIRS(CONTENT)) \
}; \
};
#define MAKEENUMCAST( NAME, PREFIX, CONTENT ) \
#define MAKEENUMCAST( NAME, PREFIX, CONTENT, COUNT_VAR ) \
PREFIX NAME CAT3(string_to_, NAME, _default) (const std::string& str, NAME def) \
{ \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMFUNCTION, , MAKEPAIRS(CONTENT)) \
@ -180,13 +191,16 @@ PREFIX std::string CAT2(NAME,_to_string) (NAME val) \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMFUNCTIONREV, , MAKEPAIRS(CONTENT)) \
assert(false && "Corrupted enum found with identifier NAME"); \
throw 42; \
}
} \
\
PREFIX const size_t ATTR_UNUSED( COUNT_VAR ) = \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMFUNCTIONCOUNT, , MAKEPAIRS(CONTENT)) \
0;
#define MAKE_ENUM( NAME, CONTENT ) \
MAKEENUMTYPE( NAME, CONTENT ) \
MAKEENUMCAST( NAME, static , CONTENT )
MAKEENUMCAST( NAME, static , CONTENT, CAT2(NAME,_COUNT) )
#define MAKE_ENUM_STREAM_OPS1( NAME ) \
inline std::ostream& operator<< (std::ostream & os, NAME val) \

View file

@ -79,6 +79,7 @@ namespace preferences {
bool show_theme_dialog(display& disp);
void show_paths_dialog(display& disp);
void show_mp_alerts_dialog(display& disp);
void show_advanced_graphics_dialog(display & disp);
// If prefs is non-null, save the hotkeys in that config
// instead of the default.

View file

@ -446,6 +446,11 @@ BOOST_AUTO_TEST_CASE(test_gui2)
std::remove(list.begin(), list.end(), "mp_alerts_options")
, list.end());
// No test for this right now
list.erase(
std::remove(list.begin(), list.end(), "advanced_graphics_options")
, list.end());
// Test size() instead of empty() to get the number of offenders
BOOST_CHECK_EQUAL(list.size(), 0);
BOOST_FOREACH(const std::string& id, list) {