forked from mirror/openmw-tes3mp
more resizing fixes from scrawl, share an SDLWindow between the input wrapper and the engine
This commit is contained in:
parent
9b485a86ef
commit
10a3caa504
7 changed files with 39 additions and 37 deletions
|
@ -150,7 +150,6 @@ void OMW::Engine::handleSDLMessages()
|
|||
switch(events[i].window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
printf("Resizing window!\n");
|
||||
resize = true;
|
||||
size_x = events[i].window.data1;
|
||||
size_y = events[i].window.data2;
|
||||
|
@ -162,12 +161,7 @@ void OMW::Engine::handleSDLMessages()
|
|||
//handle window movements
|
||||
if(resize)
|
||||
{
|
||||
if(!mOgre->getWindow()->isFullScreen())
|
||||
{
|
||||
mOgre->getWindow()->windowMovedOrResized();
|
||||
mOgre->getWindow()->resize(size_x, size_y);
|
||||
mOgre->adjustViewport();
|
||||
}
|
||||
}
|
||||
|
||||
if(SDL_PeepEvents(NULL, 1, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT) != 0)
|
||||
|
@ -436,7 +430,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
|||
|
||||
mEnvironment.setInputManager (new MWInput::InputManager (*mOgre,
|
||||
MWBase::Environment::get().getWorld()->getPlayer(),
|
||||
*MWBase::Environment::get().getWindowManager(), mDebug, *this, keybinderUser, keybinderUserExists));
|
||||
*MWBase::Environment::get().getWindowManager(), *this, keybinderUser, keybinderUserExists));
|
||||
|
||||
// load cell
|
||||
ESM::Position pos;
|
||||
|
|
|
@ -31,7 +31,6 @@ namespace MWInput
|
|||
InputManager::InputManager(OEngine::Render::OgreRenderer &ogre,
|
||||
MWWorld::Player &player,
|
||||
MWBase::WindowManager &windows,
|
||||
bool debug,
|
||||
OMW::Engine& engine,
|
||||
const std::string& userFile, bool userFileExists)
|
||||
: mOgre(ogre)
|
||||
|
@ -45,7 +44,7 @@ namespace MWInput
|
|||
, mUserFile(userFile)
|
||||
, mDragDrop(false)
|
||||
, mGuiCursorEnabled(false)
|
||||
, mDebug(debug)
|
||||
, mDebug(Settings::Manager::getBool("debug", "Engine"))
|
||||
, mInvertY (Settings::Manager::getBool("invert y axis", "Input"))
|
||||
, mCameraSensitivity (Settings::Manager::getFloat("camera sensitivity", "Input"))
|
||||
, mUISensitivity (Settings::Manager::getFloat("ui sensitivity", "Input"))
|
||||
|
@ -63,7 +62,7 @@ namespace MWInput
|
|||
|
||||
Ogre::RenderWindow* window = ogre.getWindow ();
|
||||
|
||||
mInputManager = new SFO::InputWrapper(window);
|
||||
mInputManager = new SFO::InputWrapper(mOgre.getSDLWindow());
|
||||
mInputManager->setMouseEventCallback (this);
|
||||
mInputManager->setKeyboardEventCallback (this);
|
||||
mInputManager->setWindowEventCallback(this);
|
||||
|
|
|
@ -62,7 +62,6 @@ namespace MWInput
|
|||
InputManager(OEngine::Render::OgreRenderer &_ogre,
|
||||
MWWorld::Player&_player,
|
||||
MWBase::WindowManager &_windows,
|
||||
bool debug,
|
||||
OMW::Engine& engine,
|
||||
const std::string& userFile, bool userFileExists);
|
||||
|
||||
|
|
|
@ -839,7 +839,6 @@ void RenderingManager::windowResized(Ogre::RenderWindow* rw)
|
|||
Settings::Manager::setInt("resolution x", "Video", rw->getWidth());
|
||||
Settings::Manager::setInt("resolution y", "Video", rw->getHeight());
|
||||
|
||||
|
||||
mRendering.adjustViewport();
|
||||
mCompositors->recreate();
|
||||
mWater->assignTextures();
|
||||
|
|
47
extern/sdl4ogre/sdlinputwrapper.cpp
vendored
47
extern/sdl4ogre/sdlinputwrapper.cpp
vendored
|
@ -16,9 +16,9 @@ namespace SFO
|
|||
{
|
||||
/// \brief General purpose wrapper for OGRE applications around SDL's event
|
||||
/// queue, mostly used for handling input-related events.
|
||||
InputWrapper::InputWrapper(Ogre::RenderWindow *window) :
|
||||
mWindow(window),
|
||||
mSDLWindow(NULL),
|
||||
InputWrapper::InputWrapper(SDL_Window* window) :
|
||||
mSDLWindow(window),
|
||||
mOwnWindow(false),
|
||||
mWarpCompensate(false),
|
||||
mMouseRelative(false),
|
||||
mGrabPointer(false),
|
||||
|
@ -29,9 +29,27 @@ namespace SFO
|
|||
{
|
||||
_setupOISKeys();
|
||||
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
|
||||
InputWrapper::~InputWrapper()
|
||||
{
|
||||
if(mSDLWindow != NULL && mOwnWindow)
|
||||
SDL_DestroyWindow(mSDLWindow);
|
||||
mSDLWindow = NULL;
|
||||
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
|
||||
void InputWrapper::initFromRenderWindow(Ogre::RenderWindow *win)
|
||||
{
|
||||
assert(mSDLWindow == NULL);
|
||||
|
||||
mOwnWindow = true;
|
||||
|
||||
//get the HWND from ogre's renderwindow
|
||||
size_t windowHnd;
|
||||
mWindow->getCustomAttribute("WINDOW", &windowHnd);
|
||||
win->getCustomAttribute("WINDOW", &windowHnd);
|
||||
|
||||
//wrap our own event handler around ogre's
|
||||
mSDLWindow = SDL_CreateWindowFrom((void*)windowHnd);
|
||||
|
@ -42,9 +60,6 @@ namespace SFO
|
|||
//we alt-tab away.
|
||||
//SDL_SetWindowFullscreen(mSDLWindow, 0);
|
||||
|
||||
//translate our keypresses into text
|
||||
SDL_StartTextInput();
|
||||
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||
//linux-specific event-handling fixups
|
||||
//see http://bugzilla.libsdl.org/show_bug.cgi?id=730
|
||||
|
@ -78,15 +93,6 @@ namespace SFO
|
|||
#endif
|
||||
}
|
||||
|
||||
InputWrapper::~InputWrapper()
|
||||
{
|
||||
if(mSDLWindow != NULL)
|
||||
SDL_DestroyWindow(mSDLWindow);
|
||||
mSDLWindow = NULL;
|
||||
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
|
||||
void InputWrapper::capture()
|
||||
{
|
||||
SDL_Event evt;
|
||||
|
@ -158,12 +164,15 @@ namespace SFO
|
|||
|
||||
//eep, wrap the pointer manually if the input driver doesn't support
|
||||
//relative positioning natively
|
||||
SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE);
|
||||
int success = SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE);
|
||||
|
||||
if(relative)
|
||||
{
|
||||
if(success != 0)
|
||||
{
|
||||
mWrapPointer = true;
|
||||
}
|
||||
}
|
||||
|
||||
//now remove all mouse events using the old setting from the queue
|
||||
SDL_PumpEvents();
|
||||
|
@ -200,8 +209,8 @@ namespace SFO
|
|||
|
||||
SDL_GetWindowSize(mSDLWindow, &width, &height);
|
||||
|
||||
const int FUDGE_FACTOR_X = width / 4;
|
||||
const int FUDGE_FACTOR_Y = height / 4;
|
||||
const int FUDGE_FACTOR_X = width / 8;
|
||||
const int FUDGE_FACTOR_Y = height / 8;
|
||||
|
||||
//warp the mouse if it's about to go outside the window
|
||||
if(evt.x - FUDGE_FACTOR_X < 0 || evt.x + FUDGE_FACTOR_X > width
|
||||
|
|
6
extern/sdl4ogre/sdlinputwrapper.hpp
vendored
6
extern/sdl4ogre/sdlinputwrapper.hpp
vendored
|
@ -16,9 +16,11 @@ namespace SFO
|
|||
class InputWrapper
|
||||
{
|
||||
public:
|
||||
InputWrapper(Ogre::RenderWindow* window);
|
||||
InputWrapper(SDL_Window *window=NULL);
|
||||
~InputWrapper();
|
||||
|
||||
void initFromRenderWindow(Ogre::RenderWindow* win);
|
||||
|
||||
void setMouseEventCallback(MouseListener* listen) { mMouseListener = listen; }
|
||||
void setKeyboardEventCallback(KeyListener* listen) { mKeyboardListener = listen; }
|
||||
void setWindowEventCallback(WindowListener* listen) { mWindowListener = listen; }
|
||||
|
@ -62,8 +64,8 @@ namespace SFO
|
|||
Sint32 mMouseX;
|
||||
Sint32 mMouseY;
|
||||
|
||||
Ogre::RenderWindow* mWindow;
|
||||
SDL_Window* mSDLWindow;
|
||||
bool mOwnWindow;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings&
|
|||
params.insert(std::make_pair("vsync", settings.vsync ? "true" : "false"));
|
||||
|
||||
// Create an application window with the following settings:
|
||||
SDL_Window *window = SDL_CreateWindow(
|
||||
mSDLWindow = SDL_CreateWindow(
|
||||
"OpenMW", // window title
|
||||
SDL_WINDOWPOS_UNDEFINED, // initial x position
|
||||
SDL_WINDOWPOS_UNDEFINED, // initial y position
|
||||
|
@ -238,7 +238,7 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings&
|
|||
struct SDL_SysWMinfo wmInfo;
|
||||
SDL_VERSION(&wmInfo.version);
|
||||
|
||||
if(-1 == SDL_GetWindowWMInfo(window, &wmInfo))
|
||||
if(-1 == SDL_GetWindowWMInfo(mSDLWindow, &wmInfo))
|
||||
throw std::runtime_error("Couldn't get WM Info!");
|
||||
|
||||
Ogre::String winHandle;
|
||||
|
|
Loading…
Reference in a new issue