From 4ecac31752cb59082817921cd6e74812d435f7b8 Mon Sep 17 00:00:00 2001 From: Ragora Date: Fri, 12 Sep 2014 05:16:33 -0400 Subject: [PATCH] Map keeps focus on wherever it was last moved when resizing map window --- apps/openmw/mwgui/mapwindow.cpp | 21 +++++++++++++++++++++ apps/openmw/mwgui/mapwindow.hpp | 1 + 2 files changed, 22 insertions(+) diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 1968181ce..17e084767 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -14,6 +14,9 @@ #include "../mwrender/globalmap.hpp" +#include "../mwgui/container.hpp" +#include "../mwgui/itemview.hpp" + #include "../components/esm/globalmap.hpp" #include "widgets.hpp" @@ -537,6 +540,9 @@ namespace MWGui getWidget(mPlayerArrowLocal, "CompassLocal"); getWidget(mPlayerArrowGlobal, "CompassGlobal"); + // Seems to be called when the map window is resized at all regardless of local or world map view + mLocalMap->eventChangeCoord += MyGUI::newDelegate(this, &MapWindow::onChangeCoord); + mGlobalMap->setVisible (false); getWidget(mButton, "WorldButton"); @@ -632,6 +638,21 @@ namespace MWGui mEditNoteDialog.setText(""); } + void MapWindow::onChangeCoord(MyGUI::Widget* sender) + { + static MyGUI::IntCoord lastCoordinates = sender->getCoord(); + MyGUI::IntCoord currentCoordinates = sender->getCoord(); + + MyGUI::IntPoint currentViewPortCenter = MyGUI::IntPoint(currentCoordinates.width / 2, currentCoordinates.height / 2); + MyGUI::IntPoint lastViewPortCenter = MyGUI::IntPoint(lastCoordinates.width / 2, lastCoordinates.height / 2); + MyGUI::IntPoint viewPortCenterDiff = currentViewPortCenter - lastViewPortCenter; + + mLocalMap->setViewOffset(mLocalMap->getViewOffset() + viewPortCenterDiff); + mGlobalMap->setViewOffset(mGlobalMap->getViewOffset() + viewPortCenterDiff); + + lastCoordinates = currentCoordinates; + } + void MapWindow::renderGlobalMap(Loading::Listener* loadingListener) { mGlobalMapRender = new MWRender::GlobalMap(""); diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index a9edbe0b1..d1e9f95c6 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -200,6 +200,7 @@ namespace MWGui void onNoteEditDelete(); void onNoteEditDeleteConfirm(); void onNoteDoubleClicked(MyGUI::Widget* sender); + void onChangeCoord(MyGUI::Widget* sender); void globalMapUpdatePlayer(); MyGUI::ScrollView* mGlobalMap;