<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Always show marker tooltips]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=402&amp;type=atom" />
	<updated>2017-02-03T12:46:52Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=402</id>
		<entry>
			<title type="html"><![CDATA[Re: Always show marker tooltips]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1762#p1762" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Example of how to change the position of tooltips:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class ModifyDrawTooltipsAlways:MonoBehaviour
{
    public float offsetY;

    private OnlineMaps map;
    private OnlineMapsControlBase control;
    private bool isTileset;
    private GUIStyle tooltipStyle;

    private void Start()
    {
        map = OnlineMaps.instance;
        control = OnlineMapsControlBase.instance;
        isTileset = control is OnlineMapsTileSetControl;
        OnlineMapsMarkerBase.OnMarkerDrawTooltip += OnMarkerDrawTooltip;

        tooltipStyle = new GUIStyle
        {
            normal =
            {
                background = map.tooltipBackgroundTexture,
                textColor = new Color32(230, 230, 230, 255)
            },
            border = new RectOffset(8, 8, 8, 8),
            margin = new RectOffset(4, 4, 4, 4),
            wordWrap = true,
            richText = true,
            alignment = TextAnchor.MiddleCenter,
            stretchWidth = true,
            padding = new RectOffset(0, 0, 3, 3)
        };
    }

    private void OnGUITooltip(GUIStyle style, string text, Vector2 position)
    {
        GUIContent tip = new GUIContent(text);
        Vector2 size = style.CalcSize(tip);
        GUI.Label(new Rect(position.x - size.x / 2 - 5, Screen.height - position.y - size.y - 20 + offsetY, size.x + 10, size.y + 5), text, style);
    }

    private void OnMarkerDrawTooltip(OnlineMapsMarkerBase markerBase)
    {
        double tlx, tly, brx, bry;
        map.GetCorners(out tlx, out tly, out brx, out bry);
        if (brx &lt; tlx) brx += 360;

        double mx, my;
        markerBase.GetPosition(out mx, out my);

        OnlineMapsMarker marker = markerBase as OnlineMapsMarker;

        GUIStyle style = new GUIStyle(tooltipStyle);

        if (isTileset)
        {
            Vector2 tilesetSize = map.tilesetSize;

            Vector3 p1 = OnlineMapsTileSetControl.instance.GetWorldPositionWithElevation(mx, my, tlx, tly, brx, bry);
            Vector3 p2 = p1 + new Vector3(0, 0, tilesetSize.y / map.tilesetHeight * marker.height * marker.scale);

            Vector2 screenPoint1 = OnlineMapsTileSetControl.instance.activeCamera.WorldToScreenPoint(p1);
            Vector2 screenPoint2 = OnlineMapsTileSetControl.instance.activeCamera.WorldToScreenPoint(p2);

            float yOffset = (screenPoint1.y - screenPoint2.y) * transform.localScale.x - 10;

            OnGUITooltip(style, marker.label, screenPoint1 + new Vector2(0, yOffset));
        }
        else
        {
            Rect rect = marker.screenRect;
            OnGUITooltip(style, marker.label, new Vector2(rect.x + rect.width / 2, rect.y + rect.height + 5));
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-02-03T12:46:52Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1762#p1762</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Always show marker tooltips]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1761#p1761" />
			<content type="html"><![CDATA[<p>I&#039;m trying to always show a tooltip attached to a marker that the user can drag around. I currently have the &quot;Show Marker Tooltip&quot; property set to &quot;On Hover&quot; and the tooltip appears right next to the marker and moves pretty close to the cursor when the marker gets dragged.</p><p>When I change that setting to &quot;Always&quot; the tooltip always stays visible but it&#039;s displaced from the marker by a pretty significant amount. It still moves with the marker but they&#039;re pretty far apart from one another. How can I keep displaying the tool tip always but bring it back so it&#039;s close to the marker?</p>]]></content>
			<author>
				<name><![CDATA[lbrehms]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=365</uri>
			</author>
			<updated>2017-02-02T20:33:34Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1761#p1761</id>
		</entry>
</feed>
