Skip to content

Commit

Permalink
add "advanced graphics" preference dialog, for scaling algo options
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
cbeck88 committed Oct 24, 2014
1 parent 3f18331 commit 07b6eee
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 5 deletions.
183 changes: 183 additions & 0 deletions data/gui/default/window/advanced_graphics_options.cfg
@@ -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]

1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/game_preferences_display.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -144,6 +145,7 @@ class preferences_dialog : public gui::preview_pane
animate_map_button_,
disable_auto_move_button_,
mp_alerts_options_button_,
advanced_graphics_options_button_,

// color tab
orb_colors_defaults_,
Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
127 changes: 127 additions & 0 deletions src/gui/dialogs/advanced_graphics_options.cpp
@@ -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

0 comments on commit 07b6eee

Please sign in to comment.