mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 07:15:36 +00:00
Implement UI scaling factor
This commit is contained in:
parent
842ff4d874
commit
49df07ea7f
9 changed files with 61 additions and 74 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "windowbase.hpp"
|
||||
|
||||
#include <MyGUI_InputManager.h>
|
||||
#include <MyGUI_RenderManager.h>
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
|
@ -48,11 +49,7 @@ void WindowBase::center()
|
|||
{
|
||||
// Centre dialog
|
||||
|
||||
// MyGUI::IntSize gameWindowSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
// Note by scrawl: The following works more reliably in the case when the window was _just_
|
||||
// resized and MyGUI RenderManager doesn't know about the new size yet
|
||||
MyGUI::IntSize gameWindowSize = MyGUI::IntSize(Settings::Manager::getInt("resolution x", "Video"),
|
||||
Settings::Manager::getInt("resolution y", "Video"));
|
||||
MyGUI::IntSize gameWindowSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
|
||||
MyGUI::IntCoord coord = mMainWidget->getCoord();
|
||||
coord.left = (gameWindowSize.width - coord.width)/2;
|
||||
|
|
|
@ -182,7 +182,8 @@ namespace MWGui
|
|||
, mFPS(0.0f)
|
||||
, mFallbackMap(fallbackMap)
|
||||
{
|
||||
mGuiPlatform = new osgMyGUI::Platform(viewer, guiRoot, resourceSystem->getTextureManager());
|
||||
float uiScale = Settings::Manager::getFloat("scaling factor", "GUI");
|
||||
mGuiPlatform = new osgMyGUI::Platform(viewer, guiRoot, resourceSystem->getTextureManager(), uiScale);
|
||||
mGuiPlatform->initialise(resourcePath, logpath);
|
||||
|
||||
mGui = new MyGUI::Gui;
|
||||
|
@ -1104,6 +1105,13 @@ namespace MWGui
|
|||
|
||||
void WindowManager::windowResized(int x, int y)
|
||||
{
|
||||
mGuiPlatform->getRenderManagerPtr()->setViewSize(x, y);
|
||||
|
||||
// scaled size
|
||||
const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
x = viewSize.width;
|
||||
y = viewSize.height;
|
||||
|
||||
sizeVideo(x, y);
|
||||
|
||||
if (!mHud)
|
||||
|
|
|
@ -123,8 +123,8 @@ namespace MWInput
|
|||
, mGuiCursorEnabled(true)
|
||||
, mDetectingKeyboard(false)
|
||||
, mOverencumberedMessageDelay(0.f)
|
||||
, mMouseX(0)
|
||||
, mMouseY(0)
|
||||
, mGuiCursorX(0)
|
||||
, mGuiCursorY(0)
|
||||
, mMouseWheel(0)
|
||||
, mUserFileExists(userFileExists)
|
||||
, mAlwaysRunActive(Settings::Manager::getBool("always run", "Input"))
|
||||
|
@ -132,13 +132,8 @@ namespace MWInput
|
|||
, mSneaking(false)
|
||||
, mAttemptJump(false)
|
||||
, mFakeDeviceID(1)
|
||||
, mInvUiScalingFactor(1.f)
|
||||
{
|
||||
int w,h;
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
|
||||
mMouseX = w / 2.f;
|
||||
mMouseY = h / 2.f;
|
||||
|
||||
mInputManager = new SDLUtil::InputWrapper(window, viewer, grab);
|
||||
mInputManager->setMouseEventCallback (this);
|
||||
mInputManager->setKeyboardEventCallback (this);
|
||||
|
@ -193,6 +188,16 @@ namespace MWInput
|
|||
//ICS_LOG(std::string("Unusable controller plugged in: ")+SDL_JoystickNameForIndex(i));
|
||||
}
|
||||
}
|
||||
|
||||
float uiScale = Settings::Manager::getFloat("scaling factor", "GUI");
|
||||
if (uiScale != 0.f)
|
||||
mInvUiScalingFactor = 1.f / uiScale;
|
||||
|
||||
int w,h;
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
|
||||
mGuiCursorX = mInvUiScalingFactor * w / 2.f;
|
||||
mGuiCursorY = mInvUiScalingFactor * h / 2.f;
|
||||
}
|
||||
|
||||
void InputManager::clear()
|
||||
|
@ -394,7 +399,7 @@ namespace MWInput
|
|||
//cursor is
|
||||
if( !is_relative && was_relative != is_relative )
|
||||
{
|
||||
mInputManager->warpMouse(static_cast<int>(mMouseX), static_cast<int>(mMouseY));
|
||||
mInputManager->warpMouse(static_cast<int>(mGuiCursorX/mInvUiScalingFactor), static_cast<int>(mGuiCursorY/mInvUiScalingFactor));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -406,7 +411,7 @@ namespace MWInput
|
|||
|
||||
mInputManager->capture(disableEvents);
|
||||
// inject some fake mouse movement to force updating MyGUI's widget states
|
||||
MyGUI::InputManager::getInstance().injectMouseMove( int(mMouseX), int(mMouseY), mMouseWheel);
|
||||
MyGUI::InputManager::getInstance().injectMouseMove( int(mGuiCursorX), int(mGuiCursorY), mMouseWheel);
|
||||
|
||||
if (mControlsDisabled)
|
||||
{
|
||||
|
@ -430,15 +435,15 @@ namespace MWInput
|
|||
|
||||
// We keep track of our own mouse position, so that moving the mouse while in
|
||||
// game mode does not move the position of the GUI cursor
|
||||
mMouseX += xAxis * dt * 1500.0f;
|
||||
mMouseY += yAxis * dt * 1500.0f;
|
||||
mGuiCursorX += xAxis * dt * 1500.0f * mInvUiScalingFactor;
|
||||
mGuiCursorY += yAxis * dt * 1500.0f * mInvUiScalingFactor;
|
||||
mMouseWheel -= static_cast<int>(zAxis * dt * 1500.0f);
|
||||
|
||||
mMouseX = std::max(0.f, std::min(mMouseX, float(viewSize.width)));
|
||||
mMouseY = std::max(0.f, std::min(mMouseY, float(viewSize.height)));
|
||||
mGuiCursorX = std::max(0.f, std::min(mGuiCursorX, float(viewSize.width)));
|
||||
mGuiCursorY = std::max(0.f, std::min(mGuiCursorY, float(viewSize.height)));
|
||||
|
||||
MyGUI::InputManager::getInstance().injectMouseMove(static_cast<int>(mMouseX), static_cast<int>(mMouseY), mMouseWheel);
|
||||
mInputManager->warpMouse(static_cast<int>(mMouseX), static_cast<int>(mMouseY));
|
||||
MyGUI::InputManager::getInstance().injectMouseMove(static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY), mMouseWheel);
|
||||
mInputManager->warpMouse(static_cast<int>(mGuiCursorX/mInvUiScalingFactor), static_cast<int>(mGuiCursorY/mInvUiScalingFactor));
|
||||
}
|
||||
if (mMouseLookEnabled)
|
||||
{
|
||||
|
@ -741,7 +746,7 @@ namespace MWInput
|
|||
if (id == SDL_BUTTON_LEFT || id == SDL_BUTTON_RIGHT) // MyGUI only uses these mouse events
|
||||
{
|
||||
guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
||||
guiMode = MyGUI::InputManager::getInstance().injectMousePress(static_cast<int>(mMouseX), static_cast<int>(mMouseY), sdlButtonToMyGUI(id)) && guiMode;
|
||||
guiMode = MyGUI::InputManager::getInstance().injectMousePress(static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY), sdlButtonToMyGUI(id)) && guiMode;
|
||||
if (MyGUI::InputManager::getInstance ().getMouseFocusWidget () != 0)
|
||||
{
|
||||
MyGUI::Button* b = MyGUI::InputManager::getInstance ().getMouseFocusWidget ()->castType<MyGUI::Button>(false);
|
||||
|
@ -768,7 +773,7 @@ namespace MWInput
|
|||
mInputBinder->mouseReleased (arg, id);
|
||||
} else {
|
||||
bool guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
||||
guiMode = MyGUI::InputManager::getInstance().injectMouseRelease(static_cast<int>(mMouseX), static_cast<int>(mMouseY), sdlButtonToMyGUI(id)) && guiMode;
|
||||
guiMode = MyGUI::InputManager::getInstance().injectMouseRelease(static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY), sdlButtonToMyGUI(id)) && guiMode;
|
||||
|
||||
if(mInputBinder->detectingBindingState()) return; // don't allow same mouseup to bind as initiated bind
|
||||
|
||||
|
@ -786,19 +791,14 @@ namespace MWInput
|
|||
|
||||
if (mGuiCursorEnabled)
|
||||
{
|
||||
const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
|
||||
// We keep track of our own mouse position, so that moving the mouse while in
|
||||
// game mode does not move the position of the GUI cursor
|
||||
mMouseX = static_cast<float>(arg.x);
|
||||
mMouseY = static_cast<float>(arg.y);
|
||||
|
||||
mMouseX = std::max(0.f, std::min(mMouseX, float(viewSize.width)));
|
||||
mMouseY = std::max(0.f, std::min(mMouseY, float(viewSize.height)));
|
||||
mGuiCursorX = static_cast<float>(arg.x) * mInvUiScalingFactor;
|
||||
mGuiCursorY = static_cast<float>(arg.y) * mInvUiScalingFactor;
|
||||
|
||||
mMouseWheel = int(arg.z);
|
||||
|
||||
MyGUI::InputManager::getInstance().injectMouseMove( int(mMouseX), int(mMouseY), mMouseWheel);
|
||||
MyGUI::InputManager::getInstance().injectMouseMove( int(mGuiCursorX), int(mGuiCursorY), mMouseWheel);
|
||||
}
|
||||
|
||||
if (mMouseLookEnabled && !mControlsDisabled)
|
||||
|
@ -840,7 +840,7 @@ namespace MWInput
|
|||
guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
||||
if(!mInputBinder->detectingBindingState())
|
||||
{
|
||||
guiMode = MyGUI::InputManager::getInstance().injectMousePress(static_cast<int>(mMouseX), static_cast<int>(mMouseY),
|
||||
guiMode = MyGUI::InputManager::getInstance().injectMousePress(static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY),
|
||||
sdlButtonToMyGUI((arg.button == SDL_CONTROLLER_BUTTON_B) ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT)) && guiMode;
|
||||
if (MyGUI::InputManager::getInstance ().getMouseFocusWidget () != 0)
|
||||
{
|
||||
|
@ -872,7 +872,7 @@ namespace MWInput
|
|||
else if(arg.button == SDL_CONTROLLER_BUTTON_A || arg.button == SDL_CONTROLLER_BUTTON_B)
|
||||
{
|
||||
bool guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
||||
guiMode = MyGUI::InputManager::getInstance().injectMouseRelease(static_cast<int>(mMouseX), static_cast<int>(mMouseY), sdlButtonToMyGUI((arg.button == SDL_CONTROLLER_BUTTON_B) ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT)) && guiMode;
|
||||
guiMode = MyGUI::InputManager::getInstance().injectMouseRelease(static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY), sdlButtonToMyGUI((arg.button == SDL_CONTROLLER_BUTTON_B) ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT)) && guiMode;
|
||||
|
||||
if(mInputBinder->detectingBindingState()) return; // don't allow same mouseup to bind as initiated bind
|
||||
|
||||
|
|
|
@ -187,8 +187,8 @@ namespace MWInput
|
|||
|
||||
float mOverencumberedMessageDelay;
|
||||
|
||||
float mMouseX;
|
||||
float mMouseY;
|
||||
float mGuiCursorX;
|
||||
float mGuiCursorY;
|
||||
int mMouseWheel;
|
||||
bool mUserFileExists;
|
||||
bool mAlwaysRunActive;
|
||||
|
@ -198,7 +198,11 @@ namespace MWInput
|
|||
|
||||
std::map<std::string, bool> mControlSwitch;
|
||||
|
||||
float mInvUiScalingFactor;
|
||||
|
||||
private:
|
||||
void convertMousePosForMyGUI(int& x, int& y);
|
||||
|
||||
MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button);
|
||||
|
||||
virtual std::string sdlControllerAxisToString(int axis);
|
||||
|
|
|
@ -14,14 +14,14 @@ namespace osgMyGUI
|
|||
class Platform
|
||||
{
|
||||
public:
|
||||
Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager)
|
||||
Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager, float uiScalingFactor)
|
||||
: mRenderManager(nullptr)
|
||||
, mDataManager(nullptr)
|
||||
, mLogManager(nullptr)
|
||||
, mLogFacility(nullptr)
|
||||
{
|
||||
mLogManager = new MyGUI::LogManager();
|
||||
mRenderManager = new RenderManager(viewer, guiRoot, textureManager);
|
||||
mRenderManager = new RenderManager(viewer, guiRoot, textureManager, uiScalingFactor);
|
||||
mDataManager = new DataManager();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,37 +40,6 @@
|
|||
} \
|
||||
} while(0)
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Proxy to forward an OSG resize event to RenderManager::setViewSize
|
||||
class ResizeHandler : public osgGA::GUIEventHandler {
|
||||
osgMyGUI::RenderManager *mParent;
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
|
||||
{
|
||||
if(ea.getEventType() == osgGA::GUIEventAdapter::RESIZE)
|
||||
{
|
||||
int width = ea.getWindowWidth();
|
||||
int height = ea.getWindowHeight();
|
||||
mParent->setViewSize(width, height);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
ResizeHandler(osgMyGUI::RenderManager *parent=nullptr) : mParent(parent) { }
|
||||
ResizeHandler(const ResizeHandler ©, const osg::CopyOp ©op=osg::CopyOp::SHALLOW_COPY)
|
||||
: osg::Object(copy, copyop), osgGA::GUIEventHandler(copy, copyop)
|
||||
, mParent(copy.mParent)
|
||||
{ }
|
||||
|
||||
META_Object(osgMyGUI, ResizeHandler)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace osgMyGUI
|
||||
{
|
||||
|
||||
|
@ -322,13 +291,16 @@ void OSGVertexBuffer::create()
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
RenderManager::RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::TextureManager* textureManager)
|
||||
RenderManager::RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::TextureManager* textureManager, float scalingFactor)
|
||||
: mViewer(viewer)
|
||||
, mSceneRoot(sceneroot)
|
||||
, mTextureManager(textureManager)
|
||||
, mUpdate(false)
|
||||
, mIsInitialise(false)
|
||||
, mInvScalingFactor(1.f)
|
||||
{
|
||||
if (scalingFactor != 0.f)
|
||||
mInvScalingFactor = 1.f / scalingFactor;
|
||||
}
|
||||
|
||||
RenderManager::~RenderManager()
|
||||
|
@ -380,7 +352,6 @@ void RenderManager::initialise()
|
|||
|
||||
mGuiRoot = camera;
|
||||
mSceneRoot->addChild(mGuiRoot.get());
|
||||
mViewer->addEventHandler(new ResizeHandler(this));
|
||||
|
||||
osg::ref_ptr<osg::Viewport> vp = mViewer->getCamera()->getViewport();
|
||||
setViewSize(vp->width(), vp->height());
|
||||
|
@ -458,7 +429,8 @@ void RenderManager::setViewSize(int width, int height)
|
|||
if(height < 1) height = 1;
|
||||
|
||||
mGuiRoot->setViewport(0, 0, width, height);
|
||||
mViewSize.set(width, height);
|
||||
|
||||
mViewSize.set(width * mInvScalingFactor, height * mInvScalingFactor);
|
||||
|
||||
mInfo.maximumDepth = 1;
|
||||
mInfo.hOffset = 0;
|
||||
|
|
|
@ -46,15 +46,19 @@ class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
|
|||
|
||||
osg::ref_ptr<osg::Camera> mGuiRoot;
|
||||
|
||||
float mInvScalingFactor;
|
||||
|
||||
void destroyAllResources();
|
||||
|
||||
public:
|
||||
RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::TextureManager* textureManager);
|
||||
RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::TextureManager* textureManager, float scalingFactor);
|
||||
virtual ~RenderManager();
|
||||
|
||||
void initialise();
|
||||
void shutdown();
|
||||
|
||||
void setScalingFactor(float factor);
|
||||
|
||||
static RenderManager& getInstance() { return *getInstancePtr(); }
|
||||
static RenderManager* getInstancePtr()
|
||||
{ return static_cast<RenderManager*>(MyGUI::RenderManager::getInstancePtr()); }
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace osgMyGUI
|
|||
if (!mTextureManager)
|
||||
throw std::runtime_error("No texturemanager set");
|
||||
|
||||
mTexture = mTextureManager->getTexture2D(fname, osg::Texture2D::CLAMP, osg::Texture2D::CLAMP);
|
||||
mTexture = mTextureManager->getTexture2D(fname, osg::Texture2D::REPEAT, osg::Texture2D::REPEAT);
|
||||
|
||||
// FIXME
|
||||
mFormat = MyGUI::PixelFormat::R8G8B8;
|
||||
|
|
|
@ -21,6 +21,8 @@ gamma = 1.00
|
|||
contrast = 1.00
|
||||
|
||||
[GUI]
|
||||
scaling factor = 1.0
|
||||
|
||||
# 1 is fully opaque
|
||||
menu transparency = 0.84
|
||||
|
||||
|
|
Loading…
Reference in a new issue