Click or drag to resize

HintOverlay Class

A wrapper class to present a simple overlay window with some text.
Inheritance Hierarchy
SystemObject
  KSPDev.GUIUtilsHintOverlay

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.5 (in KSPDev_Utils.2.5.dll) Version: 2.5 for KSP v1
Syntax
C#
public class HintOverlay
Request Example View Source

The HintOverlay type exposes the following members.

Constructors
  NameDescription
Public methodHintOverlay
Constructs an overlay.
Top
Properties
  NameDescription
Public propertytext
The hint overlay text.
Top
Methods
  NameDescription
Public methodShowAtCursor
Shows hint text at the current mouse pointer.
Public methodShowAtPosition
Shows hint at the absolute screen position.
Top
Fields
  NameDescription
Public fieldleftSideMousePadding
Padding when showing hint on the left side of the mouse cursor.
Public fieldrightSideMousePadding
Padding when showing hint on the right side of the mouse cursor.
Top
Remarks

The overlay windows don't have a border or title. The main purpose of such windows is present the "hints". I.e. short a lived piece of information presented for the current context. The hint won't be shown in UI until explicitly requested via a call to the ShowAt* method.

Keep in mind that this window resources will be destroyed when the scene is re-loaded. I.e. the hint window must be re-created on every scene change.

Examples
In a common case, the initialization of the hint window is done on the game object awakening, and it's either shown or hidden in the OnGUI method.
class MyMod : MonoBehaviour {
  HintOverlay hint;

  void Awake() {
    hint = new HintOverlay(() => GUI.skin, () => GUI.skin.label, adjustGuiScale: true);
  }

  void OnGUI() {
    hint.text = string.Format("Current frame is: {0}", Time.frameCount);
    hint.ShowAtCursor();
  }
}

In the example above the text of the hint is set on every frame update since the frame count is updated this frequently. However, if your data is updated less frequently you may save some performance by updating text in the methods different from OnGUI. You still need to call ShowAtCursor in every frame, though.

See Also