aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base/config.cpp14
-rw-r--r--src/base/config.hpp12
-rw-r--r--src/menu/application.cpp3
-rw-r--r--src/utils/dimension_translator.hpp82
4 files changed, 110 insertions, 1 deletions
diff --git a/src/base/config.cpp b/src/base/config.cpp
index d1824187..0bcac232 100644
--- a/src/base/config.cpp
+++ b/src/base/config.cpp
@@ -31,10 +31,13 @@ namespace usdx
log4cpp::Category::getInstance("usdx.base.config");
Config::Config()
+ : graphics_resolution(800,600)
{
try {
// TODO: handling different paths
read_ini("config.ini", this->pt);
+
+ graphics_resolution = pt.get("graphics.resolution", graphics_resolution);
}
catch(...) {
log << log4cpp::Priority::ERROR << "Loading of configuration failed.";
@@ -56,4 +59,15 @@ namespace usdx
log << log4cpp::Priority::ERROR << "Saving of configuration failed.";
}
}
+
+ void Config::set_graphics_resolution(Dimension<int> value)
+ {
+ graphics_resolution = value;
+ pt.put("graphics.resolution", value);
+ }
+
+ Dimension<int> Config::get_graphics_resolution(void) const
+ {
+ return graphics_resolution;
+ }
};
diff --git a/src/base/config.hpp b/src/base/config.hpp
index 49c2e53a..a71e26c7 100644
--- a/src/base/config.hpp
+++ b/src/base/config.hpp
@@ -27,6 +27,8 @@
#include <log4cpp/Category.hh>
#include <boost/property_tree/ptree.hpp>
+#include "utils/dimension.hpp"
+#include "utils/dimension_translator.hpp"
namespace usdx
{
@@ -40,12 +42,22 @@ namespace usdx
*/
boost::property_tree::ptree pt;
+ /* Following all the available configuration options. They get filled
+ * with default or saved values within the constructor. They should be
+ * only accessible via getter/setter and setting a new value sould
+ * update the apropriate entry in the property tree instance.
+ */
+ Dimension<int> graphics_resolution;
+
public:
Config();
virtual ~Config();
/* Save the current status of the configuration items. */
void save(void) const;
+
+ void set_graphics_resolution(Dimension<int> value);
+ Dimension<int> get_graphics_resolution(void) const;
};
};
diff --git a/src/menu/application.cpp b/src/menu/application.cpp
index 45f7af0e..d0cb9926 100644
--- a/src/menu/application.cpp
+++ b/src/menu/application.cpp
@@ -41,9 +41,10 @@ namespace usdx
: Container(parent), config(NULL), display(NULL), fps_manager(NULL),
running(false), frames_per_second(50)
{
- set_size(800, 600);
log4cpp::PropertyConfigurator::configure("log4cpp.property");
config = new Config();
+
+ set_size(config->get_graphics_resolution());
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
}
diff --git a/src/utils/dimension_translator.hpp b/src/utils/dimension_translator.hpp
new file mode 100644
index 00000000..8b34df3b
--- /dev/null
+++ b/src/utils/dimension_translator.hpp
@@ -0,0 +1,82 @@
+/*
+ * UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef DIMENSION_TRANSLATOR_HPP
+#define DIMENSION_TRANSLATOR_HPP
+
+#include "dimension.hpp"
+
+#include <sstream>
+#include <string>
+#include <iostream>
+
+namespace usdx
+{
+ template <class T>
+ struct DimensionTranslator
+ {
+ typedef std::string internal_type;
+ typedef Dimension<T> external_type;
+
+ boost::optional<external_type> get_value(const internal_type& str)
+ {
+ if (!str.empty())
+ {
+ T width, height;
+ std::istringstream i(str);
+
+ i >> width;
+ i.ignore();
+ i >> height;
+ return boost::optional<external_type>(Dimension<T>(width, height));
+ }
+ else
+ return boost::optional<external_type>(boost::none);
+ }
+
+ boost::optional<internal_type> put_value(const external_type& b)
+ {
+ std::stringstream out;
+ out << b.get_width() << "x" << b.get_height();
+ return boost::optional<internal_type>(out.str());
+ }
+ };
+};
+
+namespace boost {
+ namespace property_tree {
+
+ template<typename Ch, typename Traits, typename Alloc>
+ struct translator_between<std::basic_string< Ch, Traits, Alloc >, usdx::Dimension<int> >
+ {
+ typedef usdx::DimensionTranslator<int> type;
+ };
+
+ };
+};
+
+
+#endif