Skip to content

Commit 63b8e63

Browse files
committed
Merge branch 'screenspacesummit' into 'master'
Stick focused object tooltip to slightly above its top (#4710) Closes #4710 See merge request OpenMW/openmw!4489
2 parents 69c4a68 + efdea0f commit 63b8e63

9 files changed

+31
-42
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Bug #4508: Can't stack enchantment buffs from different instances of the same self-cast generic magic apparel
1212
Bug #4610: Casting a Bound Weapon spell cancels the casting animation by equipping the weapon prematurely
1313
Bug #4683: Disposition decrease when player commits crime is not implemented properly
14+
Bug #4710: Object tooltips don't always stick to the top of the object
1415
Bug #4742: Actors with wander never stop walking after Loopgroup Walkforward
1516
Bug #4743: PlayGroup doesn't play non-looping animations correctly
1617
Bug #4754: Stack of ammunition cannot be equipped partially

apps/openmw/mwbase/windowmanager.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace MWBase
184184
///< change the active cell
185185

186186
virtual void setFocusObject(const MWWorld::Ptr& focus) = 0;
187-
virtual void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y) = 0;
187+
virtual void setFocusObjectScreenCoords(float x, float y) = 0;
188188

189189
virtual void setCursorVisible(bool visible) = 0;
190190
virtual void setCursorActive(bool active) = 0;

apps/openmw/mwgui/tooltips.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ namespace MWGui
308308
{
309309
MyGUI::IntSize tooltipSize = getToolTipViaPtr(mFocusObject.getCellRef().getCount(), true, checkOwned());
310310

311-
setCoord(viewSize.width / 2 - tooltipSize.width / 2,
312-
std::max(0, int(mFocusToolTipY * viewSize.height - tooltipSize.height)), tooltipSize.width,
313-
tooltipSize.height);
311+
const int left = viewSize.width / 2 - tooltipSize.width / 2;
312+
const int top = std::max(0, int(mFocusToolTipY * viewSize.height - tooltipSize.height - 20));
313+
setCoord(left, top, tooltipSize.width, tooltipSize.height);
314314

315315
mDynamicToolTipBox->setVisible(true);
316316
}
@@ -818,10 +818,10 @@ namespace MWGui
818818
return mFullHelp;
819819
}
820820

821-
void ToolTips::setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y)
821+
void ToolTips::setFocusObjectScreenCoords(float x, float y)
822822
{
823-
mFocusToolTipX = (min_x + max_x) / 2;
824-
mFocusToolTipY = min_y;
823+
mFocusToolTipX = x;
824+
mFocusToolTipY = y;
825825
}
826826

827827
void ToolTips::createSkillToolTip(MyGUI::Widget* widget, ESM::RefId skillId)

apps/openmw/mwgui/tooltips.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace MWGui
6464
void clear();
6565

6666
void setFocusObject(const MWWorld::Ptr& focus);
67-
void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y);
67+
void setFocusObjectScreenCoords(float x, float y);
6868
///< set the screen-space position of the tooltip for focused object
6969

7070
static std::string getWeightString(const float weight, const std::string& prefix);

apps/openmw/mwgui/windowmanagerimp.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1038,9 +1038,9 @@ namespace MWGui
10381038
}
10391039
}
10401040

1041-
void WindowManager::setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y)
1041+
void WindowManager::setFocusObjectScreenCoords(float x, float y)
10421042
{
1043-
mToolTips->setFocusObjectScreenCoords(min_x, min_y, max_x, max_y);
1043+
mToolTips->setFocusObjectScreenCoords(x, y);
10441044
}
10451045

10461046
bool WindowManager::toggleFullHelp()

apps/openmw/mwgui/windowmanagerimp.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ namespace MWGui
204204
void changeCell(const MWWorld::CellStore* cell) override; ///< change the active cell
205205

206206
void setFocusObject(const MWWorld::Ptr& focus) override;
207-
void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y) override;
207+
void setFocusObjectScreenCoords(float x, float y) override;
208208

209209
void getMousePosition(int& x, int& y) override;
210210
void getMousePosition(float& x, float& y) override;

apps/openmw/mwrender/renderingmanager.cpp

+14-24
Original file line numberDiff line numberDiff line change
@@ -1013,34 +1013,24 @@ namespace MWRender
10131013
mScreenshotManager->screenshot(image, w, h);
10141014
}
10151015

1016-
osg::Vec4f RenderingManager::getScreenBounds(const osg::BoundingBox& worldbb)
1016+
osg::Vec2f RenderingManager::getScreenCoords(const osg::BoundingBox& bb)
10171017
{
1018-
if (!worldbb.valid())
1019-
return osg::Vec4f();
1020-
osg::Matrix viewProj = mViewer->getCamera()->getViewMatrix() * mViewer->getCamera()->getProjectionMatrix();
1021-
float min_x = 1.0f, max_x = 0.0f, min_y = 1.0f, max_y = 0.0f;
1022-
for (int i = 0; i < 8; ++i)
1018+
if (bb.valid())
10231019
{
1024-
osg::Vec3f corner = worldbb.corner(i);
1025-
corner = corner * viewProj;
1026-
1027-
float x = (corner.x() + 1.f) * 0.5f;
1028-
float y = (corner.y() - 1.f) * (-0.5f);
1029-
1030-
if (x < min_x)
1031-
min_x = x;
1032-
1033-
if (x > max_x)
1034-
max_x = x;
1035-
1036-
if (y < min_y)
1037-
min_y = y;
1038-
1039-
if (y > max_y)
1040-
max_y = y;
1020+
const osg::Matrix viewProj
1021+
= mViewer->getCamera()->getViewMatrix() * mViewer->getCamera()->getProjectionMatrix();
1022+
const osg::Vec3f worldPoint((bb.xMin() + bb.xMax()) * 0.5f, (bb.yMin() + bb.yMax()) * 0.5f, bb.zMax());
1023+
const osg::Vec4f clipPoint = osg::Vec4f(worldPoint, 1.0f) * viewProj;
1024+
if (clipPoint.w() > 0.f)
1025+
{
1026+
const float screenPointX = (clipPoint.x() / clipPoint.w() + 1.f) * 0.5f;
1027+
const float screenPointY = (clipPoint.y() / clipPoint.w() - 1.f) * (-0.5f);
1028+
if (screenPointX >= 0.f && screenPointX <= 1.f && screenPointY >= 0.f && screenPointY <= 1.f)
1029+
return osg::Vec2f(screenPointX, screenPointY);
1030+
}
10411031
}
10421032

1043-
return osg::Vec4f(min_x, min_y, max_x, max_y);
1033+
return osg::Vec2f(0.5f, 0.f);
10441034
}
10451035

10461036
RenderingManager::RayResult getIntersectionResult(osgUtil::LineSegmentIntersector* intersector,

apps/openmw/mwrender/renderingmanager.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ namespace MWRender
185185
RayResult castCameraToViewportRay(
186186
const float nX, const float nY, float maxDistance, bool ignorePlayer, bool ignoreActors = false);
187187

188-
/// Get the bounding box of the given object in screen coordinates as (minX, minY, maxX, maxY), with (0,0) being
189-
/// the top left corner.
190-
osg::Vec4f getScreenBounds(const osg::BoundingBox& worldbb);
188+
/// Get normalized screen coordinates of the bounding box's summit, where (0,0) is the top left corner
189+
osg::Vec2f getScreenCoords(const osg::BoundingBox& bb);
191190

192191
void setSkyEnabled(bool enabled);
193192

apps/openmw/mwworld/worldimp.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ namespace MWWorld
17841784
// inform the GUI about focused object
17851785
MWWorld::Ptr object = getFacedObject();
17861786

1787-
// retrieve object dimensions so we know where to place the floating label
1787+
// retrieve the object's top point's screen position so we know where to place the floating label
17881788
if (!object.isEmpty())
17891789
{
17901790
osg::BoundingBox bb = mPhysics->getBoundingBox(object);
@@ -1795,9 +1795,8 @@ namespace MWWorld
17951795
object.getRefData().getBaseNode()->accept(computeBoundsVisitor);
17961796
bb = computeBoundsVisitor.getBoundingBox();
17971797
}
1798-
osg::Vec4f screenBounds = mRendering->getScreenBounds(bb);
1799-
MWBase::Environment::get().getWindowManager()->setFocusObjectScreenCoords(
1800-
screenBounds.x(), screenBounds.y(), screenBounds.z(), screenBounds.w());
1798+
const osg::Vec2f pos = mRendering->getScreenCoords(bb);
1799+
MWBase::Environment::get().getWindowManager()->setFocusObjectScreenCoords(pos.x(), pos.y());
18011800
}
18021801

18031802
MWBase::Environment::get().getWindowManager()->setFocusObject(object);

0 commit comments

Comments
 (0)