test_textnode.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from panda3d import core
  2. def test_textnode_write():
  3. out = core.StringStream()
  4. text = core.TextNode("test")
  5. text.write(out, 0)
  6. assert out.data.startswith(b"TextNode test")
  7. def test_textnode_card_as_margin():
  8. text = core.TextNode("test")
  9. text.text = "Test"
  10. l, r, b, t = 0.1, 0.2, 0.3, 0.4
  11. text.set_card_as_margin(l, r, b, t)
  12. assert text.has_card()
  13. assert text.is_card_as_margin()
  14. assert text.get_card_as_set() == (l, r, b, t)
  15. card_actual = text.get_card_actual()
  16. card_expect = core.LVecBase4(
  17. text.get_left() - l,
  18. text.get_right() + r,
  19. text.get_bottom() - b,
  20. text.get_top() + t)
  21. assert card_actual == card_expect
  22. def test_textnode_card_actual():
  23. text = core.TextNode("test")
  24. text.text = "Test"
  25. l, r, b, t = 0.1, 0.2, 0.3, 0.4
  26. text.set_card_actual(l, r, b, t)
  27. assert text.has_card()
  28. assert not text.is_card_as_margin()
  29. assert text.get_card_as_set() == (l, r, b, t)
  30. card_actual = text.get_card_actual()
  31. card_expect = core.LVecBase4(l, r, b, t)
  32. assert card_actual == card_expect
  33. def test_textnode_frame_as_margin():
  34. text = core.TextNode("test")
  35. text.text = "Test"
  36. l, r, b, t = 0.1, 0.2, 0.3, 0.4
  37. text.set_frame_as_margin(l, r, b, t)
  38. assert text.has_frame()
  39. assert text.is_frame_as_margin()
  40. assert text.get_frame_as_set() == (l, r, b, t)
  41. frame_actual = text.get_frame_actual()
  42. frame_expect = core.LVecBase4(
  43. text.get_left() - l,
  44. text.get_right() + r,
  45. text.get_bottom() - b,
  46. text.get_top() + t)
  47. assert frame_actual == frame_expect
  48. def test_textnode_frame_actual():
  49. text = core.TextNode("test")
  50. text.text = "Test"
  51. l, r, b, t = 0.1, 0.2, 0.3, 0.4
  52. text.set_frame_actual(l, r, b, t)
  53. assert text.has_frame()
  54. assert not text.is_frame_as_margin()
  55. assert text.get_frame_as_set() == (l, r, b, t)
  56. frame_actual = text.get_frame_actual()
  57. frame_expect = core.LVecBase4(l, r, b, t)
  58. assert frame_actual == frame_expect
  59. def test_textnode_flatten_color():
  60. text = core.TextNode("test")
  61. text.text_color = (0, 0, 0, 1)
  62. path = core.NodePath(text)
  63. color = core.LColor(1, 0, 0, 1)
  64. path.set_color(color)
  65. path.flatten_strong()
  66. assert text.text_color.almost_equal(color)
  67. assert text.shadow_color.almost_equal(color)
  68. assert text.frame_color.almost_equal(color)
  69. assert text.card_color.almost_equal(color)
  70. def test_textnode_flatten_colorscale():
  71. text = core.TextNode("test")
  72. text.text_color = (1, 0, 0, 0)
  73. text.shadow_color = (0, 1, 0, 0)
  74. text.frame_color = (0, 0, 1, 0)
  75. text.card_color = (0, 0, 0, 1)
  76. path = core.NodePath(text)
  77. color = core.LColor(.5, .5, .5, .5)
  78. path.set_color_scale(color)
  79. path.flatten_strong()
  80. assert text.text_color.almost_equal((.5, 0, 0, 0))
  81. assert text.shadow_color.almost_equal((0, .5, 0, 0))
  82. assert text.frame_color.almost_equal((0, 0, .5, 0))
  83. assert text.card_color.almost_equal((0, 0, 0, .5))