forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_textnode.py
More file actions
113 lines (83 loc) · 2.98 KB
/
test_textnode.py
File metadata and controls
113 lines (83 loc) · 2.98 KB
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
103
104
105
106
107
108
109
110
111
112
113
from panda3d import core
def test_textnode_write():
out = core.StringStream()
text = core.TextNode("test")
text.write(out, 0)
assert out.data.startswith(b"TextNode test")
def test_textnode_card_as_margin():
text = core.TextNode("test")
text.text = "Test"
l, r, b, t = 0.1, 0.2, 0.3, 0.4
text.set_card_as_margin(l, r, b, t)
assert text.has_card()
assert text.is_card_as_margin()
assert text.get_card_as_set() == (l, r, b, t)
card_actual = text.get_card_actual()
card_expect = core.LVecBase4(
text.get_left() - l,
text.get_right() + r,
text.get_bottom() - b,
text.get_top() + t)
assert card_actual == card_expect
def test_textnode_card_actual():
text = core.TextNode("test")
text.text = "Test"
l, r, b, t = 0.1, 0.2, 0.3, 0.4
text.set_card_actual(l, r, b, t)
assert text.has_card()
assert not text.is_card_as_margin()
assert text.get_card_as_set() == (l, r, b, t)
card_actual = text.get_card_actual()
card_expect = core.LVecBase4(l, r, b, t)
assert card_actual == card_expect
def test_textnode_frame_as_margin():
text = core.TextNode("test")
text.text = "Test"
l, r, b, t = 0.1, 0.2, 0.3, 0.4
text.set_frame_as_margin(l, r, b, t)
assert text.has_frame()
assert text.is_frame_as_margin()
assert text.get_frame_as_set() == (l, r, b, t)
frame_actual = text.get_frame_actual()
frame_expect = core.LVecBase4(
text.get_left() - l,
text.get_right() + r,
text.get_bottom() - b,
text.get_top() + t)
assert frame_actual == frame_expect
def test_textnode_frame_actual():
text = core.TextNode("test")
text.text = "Test"
l, r, b, t = 0.1, 0.2, 0.3, 0.4
text.set_frame_actual(l, r, b, t)
assert text.has_frame()
assert not text.is_frame_as_margin()
assert text.get_frame_as_set() == (l, r, b, t)
frame_actual = text.get_frame_actual()
frame_expect = core.LVecBase4(l, r, b, t)
assert frame_actual == frame_expect
def test_textnode_flatten_color():
text = core.TextNode("test")
text.text_color = (0, 0, 0, 1)
path = core.NodePath(text)
color = core.LColor(1, 0, 0, 1)
path.set_color(color)
path.flatten_strong()
assert text.text_color.almost_equal(color)
assert text.shadow_color.almost_equal(color)
assert text.frame_color.almost_equal(color)
assert text.card_color.almost_equal(color)
def test_textnode_flatten_colorscale():
text = core.TextNode("test")
text.text_color = (1, 0, 0, 0)
text.shadow_color = (0, 1, 0, 0)
text.frame_color = (0, 0, 1, 0)
text.card_color = (0, 0, 0, 1)
path = core.NodePath(text)
color = core.LColor(.5, .5, .5, .5)
path.set_color_scale(color)
path.flatten_strong()
assert text.text_color.almost_equal((.5, 0, 0, 0))
assert text.shadow_color.almost_equal((0, .5, 0, 0))
assert text.frame_color.almost_equal((0, 0, .5, 0))
assert text.card_color.almost_equal((0, 0, 0, .5))