GUI Scripting:Tooltip Macro: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
Geep (talk | contribs)
mNo edit summary
Geep (talk | contribs)
mNo edit summary
Line 8: Line 8:


This macro expands into event handlers and so should be placed after the Property List. Usually, it is placed at the end of the guiDef's body, after any other event handlers.
This macro expands into event handlers and so should be placed after the Property List. Usually, it is placed at the end of the guiDef's body, after any other event handlers.
The TDM convention is to include this as needed with editDefs, choiceDefs, and sliderDefs, not with their windowDef prompts.


==Caution==
==Caution==
This macro expands into OnMouseEnter and OnMouseExit event handlers... so if you have those same handlers elsewhere in your guiDef, you may need check for conflicts and/or merge handler bodies manually, using showTopTip(...) and hideTooltip(). See windowDef SettingsRestartGameAction in mainmenu_settings.gui for an example.
This macro expands into OnMouseEnter and OnMouseExit event handlers... so if you have those same handlers elsewhere in your guiDef, you may need check for conflicts and/or merge handler bodies manually, using showTopTip(...) and hideTooltip(). See windowDef SettingsRestartGameAction in mainmenu_settings.gui for an example.


Also, "noevents 1" should not be set in your guiDef.
Also, "noevents 1" would disable toolTip, so treat them as mutually exclusive. For example, the windowDef that provides the tic-mark background behind sliderDef appropriately has "noevents 1" set, and does not include toolTip.


==Implementation==
==Implementation==

Revision as of 16:52, 7 August 2022

This page is part of a series. See GUI Scripting Language for overview.

Introduction

Specific to TDM's main menu system, a macro offers a simple way to provide an internationalized tooltip, invoked by guiDef mouse-over. The tooltip appears, not over the guiDef, but in a fixed screen location, offset to the left of the current menu. Syntax:

toolTip ("string")

Note the parentheses around the quoted string, and no semicolon at the end. As a specific example:

toolTip("#str_menu_fov_tooltip")

This macro expands into event handlers and so should be placed after the Property List. Usually, it is placed at the end of the guiDef's body, after any other event handlers.

The TDM convention is to include this as needed with editDefs, choiceDefs, and sliderDefs, not with their windowDef prompts.

Caution

This macro expands into OnMouseEnter and OnMouseExit event handlers... so if you have those same handlers elsewhere in your guiDef, you may need check for conflicts and/or merge handler bodies manually, using showTopTip(...) and hideTooltip(). See windowDef SettingsRestartGameAction in mainmenu_settings.gui for an example.

Also, "noevents 1" would disable toolTip, so treat them as mutually exclusive. For example, the windowDef that provides the tic-mark background behind sliderDef appropriately has "noevents 1" set, and does not include toolTip.

Implementation

In mainmenu_utils.gui, which is included with other main menu GUIs:

...
windowDef ToolTip
{
   rect 16, 360 , 288, 120
   visible "gui::tdm_show_menu_tooltips"
   float active;
   windowDef ToolTipText
   {
      rect 00, 10, 280, 80
      MM_TT_FONT
      textscale 0.2
   }
}
#define showToolTip(TTtext)\
set "ToolTipText::text" TTtext

#define hideToolTip\
set "ToolTipText::text" ""

#define toolTip(TTtext)\
onMouseEnter\
{\
   showToolTip(TTtext);\
}\
onMouseExit\
{\
   hideToolTip;\
}

See Also