-
Notifications
You must be signed in to change notification settings - Fork 3
/
Tooltip.as
executable file
·102 lines (86 loc) · 2.26 KB
/
Tooltip.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package
{
import org.flixel.FlxSprite;
import org.flixel.FlxText;
import org.flixel.FlxG;
import Buttons.Button;
/**
* ...
* @author Nicholas 'A' Feinberg
*/
public class Tooltip extends FlxText {
protected var _moused:Button;
protected var hoverTime:Number;
protected var backdrop:FlxSprite;
public static var tracker:Tooltip;
public function Tooltip() {
super( -1, -1, 120);
_moused = null;
hoverTime = 0;
backdrop = new FlxSprite( -10, -10);
tracker = this;
}
override public function update():void {
super.update();
if (moused) {
if (hoverTime < SHORT_TIME) {
hoverTime += FlxG.elapsed / FlxG.timeScale// ? FlxG.timeScale : 1);
if (hoverTime >= SHORT_TIME)
display();
} else if (hoverTime < LONG_TIME) {
hoverTime += FlxG.elapsed / FlxG.timeScale //? FlxG.timeScale : 1);
if (hoverTime >= LONG_TIME)
elongate();
}
}
}
override public function render():void {
if (text) {
backdrop.render();
super.render();
}
}
public function display():void {
x = FlxG.mouse.x+5;
y = FlxG.mouse.y+5;
text = moused.getDescription(false);
if (!text) {
trace("tooltip error: " + String(moused));
text = '';
}
format();
}
protected function elongate():void {
text = moused.getDescription(true);
format();
}
protected function format():void {
var max:Number = _tf.getLineMetrics(0).width;
for (var i:int = 1; i < _tf.numLines; i++)
if (max < _tf.getLineMetrics(i).width) max = _tf.getLineMetrics(i).width
backdrop.createGraphic(max + 2, height -2, 0xff808080);
if (x + backdrop.width > 320)
x = 320 - backdrop.width;
backdrop.x = x;
if (y + backdrop.height > 240) {
y = 239 - backdrop.height;
}
backdrop.y = y + 1;
}
public function resetTime():void {
hoverTime = 0;
}
public function get moused():Button {
return _moused;
}
public function set moused(mousedButton:Button):void {
_moused = mousedButton;
if (!_moused) {
text = '';
}
hoverTime = 0;
}
private static const SHORT_TIME:Number = .75;
private static const LONG_TIME:Number = 2.5;
}
}