forked from teamnwah/openmw-tes3coop
basic tooltips
parent
0c6862e3e6
commit
cac662ca98
@ -0,0 +1,63 @@
|
||||
#include "tooltips.hpp"
|
||||
|
||||
using namespace MWGui;
|
||||
using namespace MyGUI;
|
||||
|
||||
ToolTips::ToolTips() :
|
||||
Layout("openmw_tooltips.xml")
|
||||
, mGameMode(true)
|
||||
{
|
||||
getWidget(mTextToolTip, "TextToolTip");
|
||||
getWidget(mTextToolTipBox, "TextToolTipBox");
|
||||
getWidget(mDynamicToolTipBox, "DynamicToolTipBox");
|
||||
|
||||
mDynamicToolTipBox->setVisible(false);
|
||||
|
||||
// turn off mouse focus so that getMouseFocusWidget returns the correct widget,
|
||||
// even if the mouse is over the tooltip
|
||||
mDynamicToolTipBox->setNeedMouseFocus(false);
|
||||
mTextToolTipBox->setNeedMouseFocus(false);
|
||||
mTextToolTip->setNeedMouseFocus(false);
|
||||
mMainWidget->setNeedMouseFocus(false);
|
||||
}
|
||||
|
||||
void ToolTips::onFrame(float frameDuration)
|
||||
{
|
||||
/// \todo Store a MWWorld::Ptr in the widget user data, retrieve it here and construct a tooltip dynamically
|
||||
|
||||
const IntSize &viewSize = RenderManager::getInstance().getViewSize();
|
||||
|
||||
Widget* focus = InputManager::getInstance().getMouseFocusWidget();
|
||||
if (focus == 0) return;
|
||||
|
||||
// this the maximum width of the tooltip before it starts word-wrapping
|
||||
setCoord(0, 0, 300, 300);
|
||||
|
||||
mTextToolTip->setCaption("Focused: " + focus->getName() + "\nType: " + focus->getTypeName());
|
||||
const IntSize &textSize = mTextToolTip->getTextSize();
|
||||
|
||||
IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24);
|
||||
|
||||
IntSize size = textSize + IntSize(12, 12);
|
||||
// make the tooltip stay completely in the viewport
|
||||
if ((tooltipPosition.left + size.width) > viewSize.width)
|
||||
{
|
||||
tooltipPosition.left = viewSize.width - size.width;
|
||||
}
|
||||
if ((tooltipPosition.top + size.height) > viewSize.height)
|
||||
{
|
||||
tooltipPosition.top = viewSize.height - size.height;
|
||||
}
|
||||
|
||||
setCoord(tooltipPosition.left, tooltipPosition.top, size.width, size.height);
|
||||
}
|
||||
|
||||
void ToolTips::enterGameMode()
|
||||
{
|
||||
mGameMode = true;
|
||||
}
|
||||
|
||||
void ToolTips::enterGuiMode()
|
||||
{
|
||||
mGameMode = false;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
|
||||
#ifndef MWGUI_TOOLTIPS_H
|
||||
#define MWGUI_TOOLTIPS_H
|
||||
|
||||
#include <openengine/gui/layout.hpp>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class ToolTips : public OEngine::GUI::Layout
|
||||
{
|
||||
public:
|
||||
ToolTips();
|
||||
|
||||
void onFrame(float frameDuration);
|
||||
|
||||
void enterGameMode();
|
||||
void enterGuiMode();
|
||||
|
||||
void adjustScreen(int screenWidth, int screenHeight);
|
||||
|
||||
private:
|
||||
MyGUI::EditBox* mTextToolTip;
|
||||
MyGUI::Widget* mTextToolTipBox;
|
||||
|
||||
MyGUI::Widget* mDynamicToolTipBox;
|
||||
|
||||
bool mGameMode;
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<Widget type="Widget" layer="Popup" position="0 0 300 200" name="_Main">
|
||||
|
||||
<!-- Simple text-only tooltip -->
|
||||
<Widget type="Widget" skin="HUD_Box" position="0 0 300 200" align="Stretch" name="TextToolTipBox">
|
||||
<Widget type="EditBox" skin="MW_TextEdit" position="0 0 300 200" align="Stretch" name="TextToolTip">
|
||||
<Property key="WordWrap" value="true"/>
|
||||
<Property key="Static" value="true"/>
|
||||
<Property key="TextAlign" value="Left Top"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<!-- Dynamically constructed tooltip goes here -->
|
||||
<Widget type="Widget" skin="HUD_Box" position="0 0 300 200" align="Stretch" name="DynamicToolTipBox">
|
||||
</Widget>
|
||||
|
||||
</Widget>
|
||||
</MyGUI>
|
||||
|
Loading…
Reference in New Issue