test_textnode.py 2.8 KB

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