@ -67,158 +67,193 @@ void ToolTips::onFrame(float frameDuration)
if ( ! mGameMode )
if ( ! mGameMode )
{
{
const MyGUI : : IntPoint & mousePos = InputManager : : getInstance ( ) . getMousePosition ( ) ;
const MyGUI : : IntPoint & mousePos = InputManager : : getInstance ( ) . getMousePosition ( ) ;
const MyGUI : : IntPoint & lastPressed = InputManager : : getInstance ( ) . getLastPressedPosition ( MyGUI : : MouseButton : : Left ) ;
if ( mousePos = = lastPressed ) // mouseclick makes tooltip disappear
if ( mWindowManager - > getWorldMouseOver ( ) & & ( ( mWindowManager - > getMode ( ) = = GM_Console )
return ;
| | ( mWindowManager - > getMode ( ) = = GM_Container )
| | ( mWindowManager - > getMode ( ) = = GM_Inventory ) ) )
if ( mousePos . left = = mLastMouseX & & mousePos . top = = mLastMouseY )
{
{
mRemainingDelay - = frameDuration ;
std : : string handle = MWBase : : Environment : : get ( ) . getWorld ( ) - > getFacedHandle ( ) ;
try
{
mFocusObject = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPtrViaHandle ( handle ) ;
}
catch ( std : : exception & e )
{
return ;
}
MyGUI : : IntSize tooltipSize = getToolTipViaPtr ( true ) ;
IntPoint tooltipPosition = InputManager : : getInstance ( ) . getMousePosition ( ) + IntPoint ( 0 , 24 ) ;
// make the tooltip stay completely in the viewport
if ( ( tooltipPosition . left + tooltipSize . width ) > viewSize . width )
{
tooltipPosition . left = viewSize . width - tooltipSize . width ;
}
if ( ( tooltipPosition . top + tooltipSize . height ) > viewSize . height )
{
tooltipPosition . top = viewSize . height - tooltipSize . height ;
}
setCoord ( tooltipPosition . left , tooltipPosition . top , tooltipSize . width , tooltipSize . height ) ;
}
}
else
else
{
{
mRemainingDelay = mDelay ;
const MyGUI : : IntPoint & lastPressed = InputManager : : getInstance ( ) . getLastPressedPosition ( MyGUI : : MouseButton : : Left ) ;
}
mLastMouseX = mousePos . left ;
mLastMouseY = mousePos . top ;
if ( mRemainingDelay > 0 )
if ( mousePos = = lastPressed ) // mouseclick makes tooltip disappear
return ;
return ;
Widget * focus = InputManager : : getInstance ( ) . getMouseFocusWidget ( ) ;
if ( mousePos . left = = mLastMouseX & & mousePos . top = = mLastMouseY )
if ( focus = = 0 )
{
{
mRemainingDelay - = frameDuration ;
return ;
}
}
else
{
mRemainingDelay = mDelay ;
}
mLastMouseX = mousePos . left ;
mLastMouseY = mousePos . top ;
IntSize tooltipSize ;
if ( mRemainingDelay > 0 )
return ;
// try to go 1 level up until there is a widget that has tooltip
Widget * focus = InputManager : : getInstance ( ) . getMouseFocusWidget ( ) ;
// this is necessary because some skin elements are actually separate widgets
if ( focus = = 0 )
int i = 0 ;
{
while ( ! focus - > isUserString ( " ToolTipType " ) )
{
focus = focus - > getParent ( ) ;
if ( ! focus )
return ;
return ;
+ + i ;
}
}
std : : string type = focus - > getUserString ( " ToolTipType " ) ;
IntSize tooltipSize ;
std : : string text = focus - > getUserString ( " ToolTipText " ) ;
ToolTipInfo info ;
// try to go 1 level up until there is a widget that has tooltip
if ( type = = " " )
// this is necessary because some skin elements are actually separate widgets
{
int i = 0 ;
return ;
while ( ! focus - > isUserString ( " ToolTipType " ) )
}
else if ( type = = " ItemPtr " )
{
mFocusObject = * focus - > getUserData < MWWorld : : Ptr > ( ) ;
tooltipSize = getToolTipViaPtr ( false ) ;
}
else if ( type = = " Spell " )
{
ToolTipInfo info ;
const ESM : : Spell * spell = MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . spells . find ( focus - > getUserString ( " Spell " ) ) ;
info . caption = spell - > name ;
Widgets : : SpellEffectList effects ;
std : : vector < ESM : : ENAMstruct > : : const_iterator end = spell - > effects . list . end ( ) ;
for ( std : : vector < ESM : : ENAMstruct > : : const_iterator it = spell - > effects . list . begin ( ) ; it ! = end ; + + it )
{
{
Widgets : : SpellEffectParams params ;
focus = focus - > getParent ( ) ;
params . mEffectID = it - > effectID ;
if ( ! focus )
params . mSkill = it - > skill ;
return ;
params . mAttribute = it - > attribute ;
+ + i ;
params . mDuration = it - > duration ;
params . mMagnMin = it - > magnMin ;
params . mMagnMax = it - > magnMax ;
params . mRange = it - > range ;
params . mIsConstant = ( spell - > data . type = = ESM : : Spell : : ST_Ability ) ;
effects . push_back ( params ) ;
}
}
info . effects = effects ;
tooltipSize = createToolTip ( info ) ;
}
else if ( type = = " Layout " )
{
// tooltip defined in the layout
MyGUI : : Widget * tooltip ;
getWidget ( tooltip , focus - > getUserString ( " ToolTipLayout " ) ) ;
tooltip - > setVisible ( true ) ;
std : : string type = focus - > getUserString ( " ToolTipType " ) ;
if ( ! tooltip - > isUserString ( " DontResize " ) )
std : : string text = focus - > getUserString ( " ToolTipText " ) ;
{
tooltip - > setCoord ( 0 , 0 , 450 , 300 ) ; // this is the maximum width of the tooltip before it starts word-wrapping
tooltipSize = MyGUI : : IntSize ( 0 , tooltip - > getSize ( ) . height ) ;
ToolTipInfo info ;
if ( type = = " " )
{
return ;
}
}
else
else if ( type = = " ItemPtr " )
tooltipSize = tooltip - > getSize ( ) ;
{
mFocusObject = * focus - > getUserData < MWWorld : : Ptr > ( ) ;
std : : map < std : : string , std : : string > userStrings = focus - > getUserStrings ( ) ;
tooltipSize = getToolTipViaPtr ( false ) ;
for ( std : : map < std : : string , std : : string > : : iterator it = userStrings . begin ( ) ;
}
it ! = userStrings . end ( ) ; + + it )
else if ( type = = " Spell " )
{
ToolTipInfo info ;
const ESM : : Spell * spell = MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . spells . find ( focus - > getUserString ( " Spell " ) ) ;
info . caption = spell - > name ;
Widgets : : SpellEffectList effects ;
std : : vector < ESM : : ENAMstruct > : : const_iterator end = spell - > effects . list . end ( ) ;
for ( std : : vector < ESM : : ENAMstruct > : : const_iterator it = spell - > effects . list . begin ( ) ; it ! = end ; + + it )
{
Widgets : : SpellEffectParams params ;
params . mEffectID = it - > effectID ;
params . mSkill = it - > skill ;
params . mAttribute = it - > attribute ;
params . mDuration = it - > duration ;
params . mMagnMin = it - > magnMin ;
params . mMagnMax = it - > magnMax ;
params . mRange = it - > range ;
params . mIsConstant = ( spell - > data . type = = ESM : : Spell : : ST_Ability ) ;
effects . push_back ( params ) ;
}
info . effects = effects ;
tooltipSize = createToolTip ( info ) ;
}
else if ( type = = " Layout " )
{
{
if ( it - > first = = " ToolTipType "
// tooltip defined in the layout
| | it - > first = = " ToolTipLayout " )
MyGUI : : Widget * tooltip ;
continue ;
getWidget ( tooltip , focus - > getUserString ( " ToolTipLayout " ) ) ;
tooltip - > setVisible ( true ) ;
if ( ! tooltip - > isUserString ( " DontResize " ) )
{
tooltip - > setCoord ( 0 , 0 , 450 , 300 ) ; // this is the maximum width of the tooltip before it starts word-wrapping
size_t underscorePos = it - > first . find ( " _ " ) ;
tooltipSize = MyGUI : : IntSize ( 0 , tooltip - > getSize ( ) . height ) ;
std : : string propertyKey = it - > first . substr ( 0 , underscorePos ) ;
}
std : : string widgetName = it - > first . substr ( underscorePos + 1 , it - > first . size ( ) - ( underscorePos + 1 ) ) ;
else
tooltipSize = tooltip - > getSize ( ) ;
MyGUI : : Widget * w ;
std : : map < std : : string , std : : string > userStrings = focus - > getUserStrings ( ) ;
getWidget ( w , widgetName ) ;
for ( std : : map < std : : string , std : : string > : : iterator it = userStrings . begin ( ) ;
w - > setProperty ( propertyKey , it - > second ) ;
it ! = userStrings . end ( ) ; + + it )
}
{
if ( it - > first = = " ToolTipType "
| | it - > first = = " ToolTipLayout " )
continue ;
for ( unsigned int i = 0 ; i < tooltip - > getChildCount ( ) ; + + i )
{
MyGUI : : Widget * w = tooltip - > getChildAt ( i ) ;
if ( w - > isUserString ( " AutoResizeHorizontal " ) )
size_t underscorePos = it - > first . find ( " _ " ) ;
{
std : : string propertyKey = it - > first . substr ( 0 , underscorePos ) ;
MyGUI : : TextBox * text = w - > castType < MyGUI : : TextBox > ( ) ;
std : : string widgetName = it - > first . substr ( underscorePos + 1 , it - > first . size ( ) - ( underscorePos + 1 ) ) ;
tooltipSize . width = std : : max ( tooltipSize . width , w - > getLeft ( ) + text - > getTextSize ( ) . width + 8 ) ;
MyGUI : : Widget * w ;
getWidget ( w , widgetName ) ;
w - > setProperty ( propertyKey , it - > second ) ;
}
}
else if ( ! tooltip - > isUserString ( " DontResize " ) )
tooltipSize . width = std : : max ( tooltipSize . width , w - > getLeft ( ) + w - > getWidth ( ) + 8 ) ;
if ( w - > isUserString ( " AutoResizeVertical " ) )
for ( unsigned int i = 0 ; i < tooltip - > getChildCount ( ) ; + + i )
{
{
MyGUI : : TextBox* text = w - > castType < MyGUI : : TextBox > ( ) ;
MyGUI : : Widget* w = tooltip - > getChildAt ( i ) ;
int height = text - > getTextSize ( ) . height ;
if ( height > w - > getHeight ( ) )
if ( w- > isUserString ( " AutoResizeHorizontal " ) )
{
{
tooltipSize + = MyGUI : : IntSize ( 0 , height - w - > getHeight ( ) ) ;
MyGUI : : TextBox * text = w - > castType < MyGUI : : TextBox > ( ) ;
tooltipSize . width = std : : max ( tooltipSize . width , w - > getLeft ( ) + text - > getTextSize ( ) . width + 8 ) ;
}
}
if ( height < w - > getHeight ( ) )
else if ( ! tooltip - > isUserString ( " DontResize " ) )
tooltipSize . width = std : : max ( tooltipSize . width , w - > getLeft ( ) + w - > getWidth ( ) + 8 ) ;
if ( w - > isUserString ( " AutoResizeVertical " ) )
{
{
tooltipSize - = MyGUI : : IntSize ( 0 , w - > getHeight ( ) - height ) ;
MyGUI : : TextBox * text = w - > castType < MyGUI : : TextBox > ( ) ;
int height = text - > getTextSize ( ) . height ;
if ( height > w - > getHeight ( ) )
{
tooltipSize + = MyGUI : : IntSize ( 0 , height - w - > getHeight ( ) ) ;
}
if ( height < w - > getHeight ( ) )
{
tooltipSize - = MyGUI : : IntSize ( 0 , w - > getHeight ( ) - height ) ;
}
}
}
}
}
tooltip - > setCoord ( 0 , 0 , tooltipSize . width , tooltipSize . height ) ;
}
}
tooltip - > setCoord ( 0 , 0 , tooltipSize . width , tooltipSize . height ) ;
else
}
throw std : : runtime_error ( " unknown tooltip type " ) ;
else
throw std : : runtime_error ( " unknown tooltip type " ) ;
IntPoint tooltipPosition = InputManager : : getInstance ( ) . getMousePosition ( ) + IntPoint ( 0 , 24 ) ;
IntPoint tooltipPosition = InputManager : : getInstance ( ) . getMousePosition ( ) + IntPoint ( 0 , 24 ) ;
// make the tooltip stay completely in the viewport
// make the tooltip stay completely in the viewport
if ( ( tooltipPosition . left + tooltipSize . width ) > viewSize . width )
if ( ( tooltipPosition . left + tooltipSize . width ) > viewSize . width )
{
{
tooltipPosition . left = viewSize . width - tooltipSize . width ;
tooltipPosition . left = viewSize . width - tooltipSize . width ;
}
}
if ( ( tooltipPosition . top + tooltipSize . height ) > viewSize . height )
if ( ( tooltipPosition . top + tooltipSize . height ) > viewSize . height )
{
{
tooltipPosition . top = viewSize . height - tooltipSize . height ;
tooltipPosition . top = viewSize . height - tooltipSize . height ;
}
}
setCoord ( tooltipPosition . left , tooltipPosition . top , tooltipSize . width , tooltipSize . height ) ;
setCoord ( tooltipPosition . left , tooltipPosition . top , tooltipSize . width , tooltipSize . height ) ;
}
}
}
else
else
{
{