enginesettings.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 // Standard C++ library includes
00023 #include <algorithm>
00024 #include <string>
00025 
00026 // 3rd party library includes
00027 #include <SDL.h>
00028 
00029 // FIFE includes
00030 // These includes are split up in two parts, separated by one empty line
00031 // First block: files included from the FIFE root src directory
00032 // Second block: files included from the same folder
00033 #include "util/base/exception.h"
00034 
00035 #include "enginesettings.h"
00036 
00037 namespace FIFE {
00038     const float MAXIMUM_VOLUME = 10.0;
00039 
00040     EngineSettings::EngineSettings():
00041         m_bitsperpixel(0),
00042         m_fullscreen(false),
00043         m_initialvolume(MAXIMUM_VOLUME / 2),
00044         m_renderbackend("SDL"),
00045         m_sldremovefakealpha(false),
00046         m_screenwidth(800),
00047         m_screenheight(600),
00048         m_windowtitle("FIFE"),
00049         m_windowicon(""),
00050         m_defaultfontpath(""),
00051         m_defaultfontsize(8),
00052         m_defaultfontglyphs(""),
00053         m_image_chunking_size(256),
00054         m_iscolorkeyenabled(false) {
00055             m_colorkey.r = 255;
00056             m_colorkey.g = 0;
00057             m_colorkey.b = 255;
00058     }
00059     
00060     EngineSettings::~EngineSettings() {
00061     }
00062     
00063     void EngineSettings::validate() const {
00064         if (m_defaultfontpath == "") {
00065             throw NotSet("Path for default font is not set");
00066         }
00067         std::string::size_type loc = m_defaultfontpath.find(".ttf", 0);
00068         if ((loc == std::string::npos) && (m_defaultfontglyphs == "")) {
00069             throw NotSet("Glyphs for default font are not set");
00070         }
00071     }
00072 
00073     std::vector<std::pair<unsigned int, unsigned int> > EngineSettings::getPossibleResolutions() const {
00074         SDL_Rect **modes = SDL_ListModes(NULL, ((getRenderBackend() != "SDL") ? (SDL_OPENGL | SDL_HWPALETTE | SDL_HWACCEL) : 0) | (isFullScreen() ? SDL_FULLSCREEN : 0));
00075         if(modes == (SDL_Rect **)0)
00076             throw NotFound("No VideoMode Found");
00077 
00078         std::vector<std::pair<unsigned int, unsigned int> > result;
00079         if(modes != (SDL_Rect **)-1)
00080             for(unsigned int i = 0; modes[i]; ++i)
00081                 result.push_back(std::pair<unsigned int, unsigned int>(modes[i]->w, modes[i]->h));
00082         return result;
00083     }
00084 
00085     void EngineSettings::setBitsPerPixel(unsigned int bitsperpixel) {
00086         std::vector<unsigned int> pv = getPossibleBitsPerPixel();
00087         std::vector<unsigned int>::iterator i = std::find(pv.begin(), pv.end(), bitsperpixel);
00088         if (i != pv.end()) {
00089             m_bitsperpixel = bitsperpixel;
00090             return;
00091         }
00092         throw NotSupported("Given bits per pixel value is not supported");
00093     }
00094     
00095     std::vector<unsigned int> EngineSettings::getPossibleBitsPerPixel() const {
00096         std::vector<unsigned int> tmp;
00097         tmp.push_back(0);
00098         tmp.push_back(16);
00099         tmp.push_back(24);
00100         tmp.push_back(32);
00101         return tmp;
00102     }
00103     
00104     void EngineSettings::setInitialVolume(float volume) {
00105         if (volume > getMaxVolume()) {
00106             throw NotSupported("Given volume exceeds maximum volume");
00107         }
00108         if (volume < 0) {
00109             throw NotSupported("Given volume is below 0");
00110         }
00111         m_initialvolume = volume;
00112     }
00113     
00114     float EngineSettings::getMaxVolume() const {
00115         return MAXIMUM_VOLUME;
00116     }
00117     
00118     void EngineSettings::setRenderBackend(const std::string& renderbackend) {
00119         std::vector<std::string> pv = getPossibleRenderBackends();
00120         std::vector<std::string>::iterator i = std::find(pv.begin(), pv.end(), renderbackend);
00121         if (i != pv.end()) {
00122             m_renderbackend = renderbackend;
00123             return;
00124         }
00125         throw NotSupported("Given render backend is not supported");
00126     }
00127     
00128     std::vector<std::string> EngineSettings::getPossibleRenderBackends() {
00129         std::vector<std::string> tmp;
00130         tmp.push_back("SDL");
00131         tmp.push_back("OpenGL");
00132         return tmp;
00133     }
00134     
00135     void EngineSettings::setSDLRemoveFakeAlpha(bool sldremovefakealpha) {
00136         m_sldremovefakealpha = sldremovefakealpha;
00137     }
00138     
00139     void EngineSettings::setScreenWidth(unsigned int screenwidth) {
00140         m_screenwidth = screenwidth;
00141     }
00142     
00143     void EngineSettings::setScreenHeight(unsigned int screenheight) {
00144         m_screenheight = screenheight;
00145     }
00146     
00147     void EngineSettings::setDefaultFontPath(const std::string& defaultfontpath) {
00148         m_defaultfontpath = defaultfontpath;
00149     }
00150     
00151     void EngineSettings::setDefaultFontSize(const unsigned int defaultfontsize) {
00152         m_defaultfontsize = defaultfontsize;
00153     }
00154     
00155     void EngineSettings::setDefaultFontGlyphs(const std::string& defaultfontglyphs) {
00156         m_defaultfontglyphs = defaultfontglyphs;
00157     }
00158     
00159     void EngineSettings::setWindowTitle(const std::string& title) {
00160         m_windowtitle = title;
00161     }
00162     
00163     void EngineSettings::setWindowIcon(const std::string& icon) {
00164         m_windowicon = icon;
00165     }
00166 
00167     void EngineSettings::setColorKeyEnabled(bool colorkeyenable) {
00168         m_iscolorkeyenabled = colorkeyenable;
00169     }
00170 
00171     bool EngineSettings::isColorKeyEnabled() const {
00172         return m_iscolorkeyenabled;
00173     }
00174 
00175     void EngineSettings::setColorKey(Uint8 r, Uint8 g, Uint8 b) {
00176         m_colorkey.r = r;
00177         m_colorkey.g = g;
00178         m_colorkey.b = b;
00179     }
00180 
00181     const SDL_Color& EngineSettings::getColorKey() const {
00182         return m_colorkey;
00183     }
00184 }
00185 
Generated by  doxygen 1.6.2-20100208