more resizing fixes from scrawl, share an SDLWindow between the input wrapper and the engine

actorid
Jordan Milne 12 years ago
parent 9b485a86ef
commit 10a3caa504

@ -150,7 +150,6 @@ void OMW::Engine::handleSDLMessages()
switch(events[i].window.event) switch(events[i].window.event)
{ {
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
printf("Resizing window!\n");
resize = true; resize = true;
size_x = events[i].window.data1; size_x = events[i].window.data1;
size_y = events[i].window.data2; size_y = events[i].window.data2;
@ -162,12 +161,7 @@ void OMW::Engine::handleSDLMessages()
//handle window movements //handle window movements
if(resize) if(resize)
{ {
if(!mOgre->getWindow()->isFullScreen())
{
mOgre->getWindow()->windowMovedOrResized();
mOgre->getWindow()->resize(size_x, size_y); mOgre->getWindow()->resize(size_x, size_y);
mOgre->adjustViewport();
}
} }
if(SDL_PeepEvents(NULL, 1, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT) != 0) 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, mEnvironment.setInputManager (new MWInput::InputManager (*mOgre,
MWBase::Environment::get().getWorld()->getPlayer(), MWBase::Environment::get().getWorld()->getPlayer(),
*MWBase::Environment::get().getWindowManager(), mDebug, *this, keybinderUser, keybinderUserExists)); *MWBase::Environment::get().getWindowManager(), *this, keybinderUser, keybinderUserExists));
// load cell // load cell
ESM::Position pos; ESM::Position pos;

@ -31,7 +31,6 @@ namespace MWInput
InputManager::InputManager(OEngine::Render::OgreRenderer &ogre, InputManager::InputManager(OEngine::Render::OgreRenderer &ogre,
MWWorld::Player &player, MWWorld::Player &player,
MWBase::WindowManager &windows, MWBase::WindowManager &windows,
bool debug,
OMW::Engine& engine, OMW::Engine& engine,
const std::string& userFile, bool userFileExists) const std::string& userFile, bool userFileExists)
: mOgre(ogre) : mOgre(ogre)
@ -45,7 +44,7 @@ namespace MWInput
, mUserFile(userFile) , mUserFile(userFile)
, mDragDrop(false) , mDragDrop(false)
, mGuiCursorEnabled(false) , mGuiCursorEnabled(false)
, mDebug(debug) , mDebug(Settings::Manager::getBool("debug", "Engine"))
, mInvertY (Settings::Manager::getBool("invert y axis", "Input")) , mInvertY (Settings::Manager::getBool("invert y axis", "Input"))
, mCameraSensitivity (Settings::Manager::getFloat("camera sensitivity", "Input")) , mCameraSensitivity (Settings::Manager::getFloat("camera sensitivity", "Input"))
, mUISensitivity (Settings::Manager::getFloat("ui sensitivity", "Input")) , mUISensitivity (Settings::Manager::getFloat("ui sensitivity", "Input"))
@ -63,7 +62,7 @@ namespace MWInput
Ogre::RenderWindow* window = ogre.getWindow (); Ogre::RenderWindow* window = ogre.getWindow ();
mInputManager = new SFO::InputWrapper(window); mInputManager = new SFO::InputWrapper(mOgre.getSDLWindow());
mInputManager->setMouseEventCallback (this); mInputManager->setMouseEventCallback (this);
mInputManager->setKeyboardEventCallback (this); mInputManager->setKeyboardEventCallback (this);
mInputManager->setWindowEventCallback(this); mInputManager->setWindowEventCallback(this);

@ -62,7 +62,6 @@ namespace MWInput
InputManager(OEngine::Render::OgreRenderer &_ogre, InputManager(OEngine::Render::OgreRenderer &_ogre,
MWWorld::Player&_player, MWWorld::Player&_player,
MWBase::WindowManager &_windows, MWBase::WindowManager &_windows,
bool debug,
OMW::Engine& engine, OMW::Engine& engine,
const std::string& userFile, bool userFileExists); 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 x", "Video", rw->getWidth());
Settings::Manager::setInt("resolution y", "Video", rw->getHeight()); Settings::Manager::setInt("resolution y", "Video", rw->getHeight());
mRendering.adjustViewport(); mRendering.adjustViewport();
mCompositors->recreate(); mCompositors->recreate();
mWater->assignTextures(); mWater->assignTextures();

@ -16,9 +16,9 @@ namespace SFO
{ {
/// \brief General purpose wrapper for OGRE applications around SDL's event /// \brief General purpose wrapper for OGRE applications around SDL's event
/// queue, mostly used for handling input-related events. /// queue, mostly used for handling input-related events.
InputWrapper::InputWrapper(Ogre::RenderWindow *window) : InputWrapper::InputWrapper(SDL_Window* window) :
mWindow(window), mSDLWindow(window),
mSDLWindow(NULL), mOwnWindow(false),
mWarpCompensate(false), mWarpCompensate(false),
mMouseRelative(false), mMouseRelative(false),
mGrabPointer(false), mGrabPointer(false),
@ -29,9 +29,27 @@ namespace SFO
{ {
_setupOISKeys(); _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 //get the HWND from ogre's renderwindow
size_t windowHnd; size_t windowHnd;
mWindow->getCustomAttribute("WINDOW", &windowHnd); win->getCustomAttribute("WINDOW", &windowHnd);
//wrap our own event handler around ogre's //wrap our own event handler around ogre's
mSDLWindow = SDL_CreateWindowFrom((void*)windowHnd); mSDLWindow = SDL_CreateWindowFrom((void*)windowHnd);
@ -42,9 +60,6 @@ namespace SFO
//we alt-tab away. //we alt-tab away.
//SDL_SetWindowFullscreen(mSDLWindow, 0); //SDL_SetWindowFullscreen(mSDLWindow, 0);
//translate our keypresses into text
SDL_StartTextInput();
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
//linux-specific event-handling fixups //linux-specific event-handling fixups
//see http://bugzilla.libsdl.org/show_bug.cgi?id=730 //see http://bugzilla.libsdl.org/show_bug.cgi?id=730
@ -78,15 +93,6 @@ namespace SFO
#endif #endif
} }
InputWrapper::~InputWrapper()
{
if(mSDLWindow != NULL)
SDL_DestroyWindow(mSDLWindow);
mSDLWindow = NULL;
SDL_StopTextInput();
}
void InputWrapper::capture() void InputWrapper::capture()
{ {
SDL_Event evt; SDL_Event evt;
@ -158,12 +164,15 @@ namespace SFO
//eep, wrap the pointer manually if the input driver doesn't support //eep, wrap the pointer manually if the input driver doesn't support
//relative positioning natively //relative positioning natively
SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE); int success = SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE);
if(relative) if(relative)
{
if(success != 0)
{ {
mWrapPointer = true; mWrapPointer = true;
} }
}
//now remove all mouse events using the old setting from the queue //now remove all mouse events using the old setting from the queue
SDL_PumpEvents(); SDL_PumpEvents();
@ -200,8 +209,8 @@ namespace SFO
SDL_GetWindowSize(mSDLWindow, &width, &height); SDL_GetWindowSize(mSDLWindow, &width, &height);
const int FUDGE_FACTOR_X = width / 4; const int FUDGE_FACTOR_X = width / 8;
const int FUDGE_FACTOR_Y = height / 4; const int FUDGE_FACTOR_Y = height / 8;
//warp the mouse if it's about to go outside the window //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 if(evt.x - FUDGE_FACTOR_X < 0 || evt.x + FUDGE_FACTOR_X > width

@ -16,9 +16,11 @@ namespace SFO
class InputWrapper class InputWrapper
{ {
public: public:
InputWrapper(Ogre::RenderWindow* window); InputWrapper(SDL_Window *window=NULL);
~InputWrapper(); ~InputWrapper();
void initFromRenderWindow(Ogre::RenderWindow* win);
void setMouseEventCallback(MouseListener* listen) { mMouseListener = listen; } void setMouseEventCallback(MouseListener* listen) { mMouseListener = listen; }
void setKeyboardEventCallback(KeyListener* listen) { mKeyboardListener = listen; } void setKeyboardEventCallback(KeyListener* listen) { mKeyboardListener = listen; }
void setWindowEventCallback(WindowListener* listen) { mWindowListener = listen; } void setWindowEventCallback(WindowListener* listen) { mWindowListener = listen; }
@ -62,8 +64,8 @@ namespace SFO
Sint32 mMouseX; Sint32 mMouseX;
Sint32 mMouseY; Sint32 mMouseY;
Ogre::RenderWindow* mWindow;
SDL_Window* mSDLWindow; 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")); params.insert(std::make_pair("vsync", settings.vsync ? "true" : "false"));
// Create an application window with the following settings: // Create an application window with the following settings:
SDL_Window *window = SDL_CreateWindow( mSDLWindow = SDL_CreateWindow(
"OpenMW", // window title "OpenMW", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position SDL_WINDOWPOS_UNDEFINED, // initial y position
@ -238,7 +238,7 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings&
struct SDL_SysWMinfo wmInfo; struct SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version); 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!"); throw std::runtime_error("Couldn't get WM Info!");
Ogre::String winHandle; Ogre::String winHandle;

Loading…
Cancel
Save