From 656a8f1be9fd3cf181de8140ba343778851e49c3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 23 May 2012 01:32:36 +0200 Subject: [PATCH] working menu transparency slider --- apps/openmw/mwgui/settingswindow.cpp | 38 ++++++++++++++++ apps/openmw/mwgui/settingswindow.hpp | 4 ++ apps/openmw/mwrender/renderingmanager.cpp | 24 ++++++++++ apps/openmw/mwrender/renderingmanager.hpp | 6 +++ apps/openmw/mwworld/world.cpp | 5 ++ apps/openmw/mwworld/world.hpp | 3 ++ files/mygui/CMakeLists.txt | 1 - files/mygui/openmw_list.skin.xml | 23 ++++++++++ files/mygui/openmw_resources.xml | 2 +- files/mygui/openmw_settings_window_layout.xml | 43 ++++++++++++++++-- files/mygui/transparent.png | Bin 150 -> 0 bytes files/settings-default.cfg | 4 ++ libs/openengine/ogre/renderer.cpp | 15 ++++++ libs/openengine/ogre/renderer.hpp | 4 ++ 14 files changed, 166 insertions(+), 6 deletions(-) delete mode 100644 files/mygui/transparent.png diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 3641a63a4..af909ea8c 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -1,5 +1,13 @@ #include "settingswindow.hpp" +#include +#include + +#include + +#include "../mwbase/environment.hpp" +#include "../mwworld/world.hpp" + #include "window_manager.hpp" namespace MWGui @@ -8,18 +16,48 @@ namespace MWGui WindowBase("openmw_settings_window_layout.xml", parWindowManager) { getWidget(mOkButton, "OkButton"); + getWidget(mResolutionList, "ResolutionList"); + getWidget(mMenuTransparencySlider, "MenuTransparencySlider"); + getWidget(mViewDistanceSlider, "ViewDistanceSlider"); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked); + mMenuTransparencySlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); + mViewDistanceSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); center(); int okSize = mOkButton->getTextSize().width + 24; mOkButton->setCoord(mMainWidget->getWidth()-16-okSize, mOkButton->getTop(), okSize, mOkButton->getHeight()); + + // fill resolution list + Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem(); + const Ogre::StringVector& videoModes = rs->getConfigOptions()["Video Mode"].possibleValues; + for (Ogre::StringVector::const_iterator it=videoModes.begin(); + it!=videoModes.end(); ++it) + { + mResolutionList->addItem(*it); + } + + // read settings + int menu_transparency = (mMenuTransparencySlider->getScrollRange()-1) * Settings::Manager::getFloat("menu transparency", "GUI"); + mMenuTransparencySlider->setScrollPosition(menu_transparency); + onSliderChangePosition(mMenuTransparencySlider, menu_transparency); } void SettingsWindow::onOkButtonClicked(MyGUI::Widget* _sender) { mWindowManager.setGuiMode(GM_Game); } + + void SettingsWindow::onSliderChangePosition(MyGUI::ScrollBar* scroller, size_t pos) + { + float val = pos / float(scroller->getScrollRange()-1); + if (scroller == mMenuTransparencySlider) + { + Settings::Manager::setFloat("menu transparency", "GUI", val); + } + + MWBase::Environment::get().getWorld()->processChangedSettings(Settings::Manager::apply()); + } } diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index e37c00f7e..597f8dec1 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -17,8 +17,12 @@ namespace MWGui protected: MyGUI::Button* mOkButton; + MyGUI::ListBox* mResolutionList; + MyGUI::ScrollBar* mMenuTransparencySlider; + MyGUI::ScrollBar* mViewDistanceSlider; void onOkButtonClicked(MyGUI::Widget* _sender); + void onSliderChangePosition(MyGUI::ScrollBar* scroller, size_t pos); }; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 6d0b1b21c..86c1f752c 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -114,6 +114,8 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const mDebugging = new Debugging(mMwRoot, engine); mLocalMap = new MWRender::LocalMap(&mRendering, this); + + setMenuTransparency(Settings::Manager::getFloat("menu transparency", "GUI")); } RenderingManager::~RenderingManager () @@ -563,4 +565,26 @@ Compositors* RenderingManager::getCompositors() return mCompositors; } +void RenderingManager::processChangedSettings(const Settings::CategorySettingVector& settings) +{ + for (Settings::CategorySettingVector::const_iterator it=settings.begin(); + it != settings.end(); ++it) + { + if (it->second == "menu transparency" && it->first == "GUI") + { + setMenuTransparency(Settings::Manager::getFloat("menu transparency", "GUI")); + } + } +} + +void RenderingManager::setMenuTransparency(float val) +{ + Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().getByName("transparent.png"); + std::vector buffer; + buffer.resize(1); + buffer[0] = (int(255*val) << 24); + memcpy(tex->getBuffer()->lock(Ogre::HardwareBuffer::HBL_DISCARD), &buffer[0], 1*4); + tex->getBuffer()->unlock(); +} + } // namespace diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 5ef43a2e2..edee193f3 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -13,6 +13,8 @@ #include #include +#include + #include #include @@ -157,10 +159,14 @@ class RenderingManager: private RenderingInterface { ///< transform the specified bounding box (in world coordinates) into screen coordinates. /// @return packed vector4 (min_x, min_y, max_x, max_y) + void processChangedSettings(const Settings::CategorySettingVector& settings); + private: void setAmbientMode(); + void setMenuTransparency(float val); + bool mSunEnabled; SkyManager* mSkyManager; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index c0107d9af..772dc71cb 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -1024,4 +1024,9 @@ namespace MWWorld mWorldScene->insertObject(object, cell); } + + void World::processChangedSettings(const Settings::CategorySettingVector& settings) + { + mRendering->processChangedSettings(settings); + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 1b0ad7fd8..e8391773b 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -7,6 +7,7 @@ #include #include +#include #include "../mwrender/debugging.hpp" #include "../mwrender/renderingmanager.hpp" @@ -279,6 +280,8 @@ namespace MWWorld bool canPlaceObject(float cursorX, float cursorY); ///< @return true if it is possible to place on object at specified cursor location + + void processChangedSettings(const Settings::CategorySettingVector& settings); }; } diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 9f43f2d89..90a0c1fce 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -60,7 +60,6 @@ configure_file("${SDIR}/openmw_trade_window_layout.xml" "${DDIR}/openmw_trade_wi configure_file("${SDIR}/openmw_settings_window_layout.xml" "${DDIR}/openmw_settings_window_layout.xml" COPYONLY) configure_file("${SDIR}/atlas1.cfg" "${DDIR}/atlas1.cfg" COPYONLY) configure_file("${SDIR}/smallbars.png" "${DDIR}/smallbars.png" COPYONLY) -configure_file("${SDIR}/transparent.png" "${DDIR}/transparent.png" COPYONLY) configure_file("${SDIR}/EBGaramond-Regular.ttf" "${DDIR}/EBGaramond-Regular.ttf" COPYONLY) configure_file("${SDIR}/Obliviontt.zip" "${DDIR}/Obliviontt.zip" COPYONLY) configure_file("${SDIR}/VeraMono.ttf" "${DDIR}/VeraMono.ttf" COPYONLY) diff --git a/files/mygui/openmw_list.skin.xml b/files/mygui/openmw_list.skin.xml index e1fbc49b6..64435451a 100644 --- a/files/mygui/openmw_list.skin.xml +++ b/files/mygui/openmw_list.skin.xml @@ -151,6 +151,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -170,6 +192,7 @@ + diff --git a/files/mygui/openmw_resources.xml b/files/mygui/openmw_resources.xml index b47de005d..e96aeb918 100644 --- a/files/mygui/openmw_resources.xml +++ b/files/mygui/openmw_resources.xml @@ -130,7 +130,7 @@ - + diff --git a/files/mygui/openmw_settings_window_layout.xml b/files/mygui/openmw_settings_window_layout.xml index 387a8587e..9c6716ff0 100644 --- a/files/mygui/openmw_settings_window_layout.xml +++ b/files/mygui/openmw_settings_window_layout.xml @@ -6,17 +6,52 @@ - + + + + + + + + + + + + + + + + - + - + - + + + + + + + + + + + + + + + + + + + + + diff --git a/files/mygui/transparent.png b/files/mygui/transparent.png deleted file mode 100644 index 32d2ed1975611dbfc9baf5550b92118fee2d73b8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPggaCRPzfaZ{P!_CO&qPZ!4!iOb0; m2?-I$8rTgC1sD!HGcs&^z_3mHan=i<3I @@ -107,6 +110,18 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings& params.insert(std::make_pair("vsync", settings.vsync ? "true" : "false")); mWindow = mRoot->createRenderWindow(title, settings.window_x, settings.window_y, settings.fullscreen, ¶ms); + + // create the semi-transparent black background texture used by the GUI. + // has to be created in code with TU_DYNAMIC_WRITE_ONLY_DISCARDABLE param + // so that it can be modified at runtime. + mTransparentBGTexture = Ogre::TextureManager::getSingleton().createManual( + "transparent.png", + Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + Ogre::TEX_TYPE_2D, + 1, 1, + 0, + Ogre::PF_A8R8G8B8, + Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); } void OgreRenderer::createScene(const std::string camName, float fov, float nearClip) diff --git a/libs/openengine/ogre/renderer.hpp b/libs/openengine/ogre/renderer.hpp index 7dc539e27..50fe64015 100644 --- a/libs/openengine/ogre/renderer.hpp +++ b/libs/openengine/ogre/renderer.hpp @@ -24,6 +24,8 @@ # include "OgreD3D9Plugin.h" #endif +#include "OgreTexture.h" + namespace Ogre { class Root; @@ -71,6 +73,8 @@ namespace OEngine Fader* mFader; bool logging; + Ogre::TexturePtr mTransparentBGTexture; + public: OgreRenderer() : mRoot(NULL)