Ejemplo n.º 1
0
void Setup_Video::apply()
{
    const std::string mode = mModeListModel->getElementAt(mModeList->getSelected());

    if (mode.find("x") != std::string::npos)
    {
        const int width = atoi(mode.substr(0, mode.find("x")).c_str());
        const int height = atoi(mode.substr(mode.find("x") + 1).c_str());

        gui->resize(width, height);
    }

    // Full screen changes
    bool fullscreen = mFsCheckBox->isSelected();
    if (fullscreen != (config.getValue("screen", false) == 1))
    {
        /* The OpenGL test is only necessary on Windows, since switching
         * to/from full screen works fine on Linux. On Windows we'd have to
         * reinitialize the OpenGL state and reload all textures.
         *
         * See http://libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode
         */

#ifdef WIN32
        // checks for opengl usage
        if (!(config.getValue("opengl", false) == 1))
        {
#endif
            if (!graphics->setFullscreen(fullscreen))
            {
                fullscreen = !fullscreen;
                if (!graphics->setFullscreen(fullscreen))
                {
                    std::stringstream error;
                    error << _("Failed to switch to ") <<
                        (fullscreen ? _("windowed") : _("fullscreen")) <<
                        _("mode and restoration of old mode also failed!") <<
                        std::endl;
                    logger->error(error.str());
                }
            }
#ifdef WIN32
        }
        else
        {
            new OkDialog(_("Switching to full screen"),
                         _("Restart needed for changes to take effect."));
        }
#endif
        config.setValue("screen", fullscreen ? true : false);
    }

    // OpenGL change
    if (mOpenGLCheckBox->isSelected() != mOpenGLEnabled)
    {
        config.setValue("opengl", mOpenGLCheckBox->isSelected() ? true : false);

        // OpenGL can currently only be changed by restarting, notify user.
        new OkDialog(_("Changing OpenGL"),
                     _("Applying change to OpenGL requires restart."));
    }

    if ((int) mFontSizeSlider->getValue() != mFontSize)
    {
        const int val = (int) mFontSizeSlider->getValue();

        gui->changeFontSize(val);

        Widgets widgets = windowContainer->getWidgetList();
        WidgetIterator iter;

        for (iter = widgets.begin(); iter != widgets.end(); ++iter)
        {
            Popup* popup = dynamic_cast<Popup*>(*iter);

            if (popup)
            {
                popup->adaptToNewSize();
                continue;
            }
        }

        if (state != GAME_STATE && desktop)
            desktop->resize();

        config.setValue("fontSize", val);
    }

    mFps = (mFpsCheckBox->isSelected()) ? (int) mFpsSlider->getValue() : 0;

    mFpsSlider->setEnabled(mFps > 0);

    // FPS change
    config.setValue("fpslimit", mFps);

    // We sync old and new values at apply time
    mFullScreenEnabled = config.getValue("screen", false);
    mOpenGLEnabled = config.getValue("opengl", false);
    mCustomCursorEnabled = config.getValue("customcursor", true);
    mNameEnabled = config.getValue("showownname", false);
    mPickupChatEnabled = config.getValue("showpickupchat", true);
    mPickupParticleEnabled = config.getValue("showpickupparticle", false);
    mSpeechMode = (int) config.getValue("speech", 3);
    mOpacity = config.getValue("guialpha", 0.8);
    mMouseOpacity = config.getValue("mousealpha", 0.7);
    mScreenWidth = (int) config.getValue("screenwidth", 800);
    mScreenHeight = (int) config.getValue("screenheight", 600);
    mFontSize = (int) config.getValue("fontSize", 11);
    mOverlayDetail = (int) config.getValue("OverlayDetail", 2);
    mParticleDetail = 3 - (int) config.getValue("particleEmitterSkip", 1);
    config.setValue("particleeffects", mParticleDetail != -1);
}