text.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. local text = require "item":extend()
  2. text.align = "center"
  3. text.text_color = { 1, 1, 1, 1 }
  4. text.selectable = true
  5. text.fade = true
  6. function text.color_fn(self, menu, dt)
  7. local internal = menu.internal
  8. if not internal.fade_time then
  9. internal.fade_time = 0
  10. end
  11. internal.fade_time = (internal.fade_time + dt) % (math.pi * 2)
  12. self.color[1] = math.max(0.25, (math.abs(math.cos(menu.internal.fade_time))))
  13. self.color[2] = .75
  14. self.color[3] = math.max(0.25, (math.abs(math.sin(menu.internal.fade_time))))
  15. self.color[4] = 1
  16. end
  17. function text:new(text, params)
  18. if params then
  19. for k,v in pairs(params) do
  20. self[k] = v
  21. end
  22. end
  23. self.text = text
  24. self.selected_color = { 0, 0, 0, 0 }
  25. self.color = self.text_color
  26. end
  27. function text:update(menu, dt)
  28. if menu:current_item() == self then
  29. self.color = self.selected_color
  30. if self.fade then
  31. self:color_fn(menu, dt)
  32. end
  33. else
  34. self.color = self.text_color
  35. end
  36. end
  37. function text:draw(menu, x, y, w, h)
  38. if self.text then
  39. menu.funcs.draw_text(menu, self.text, self.color, x, y, w, self.align)
  40. end
  41. end
  42. function text:__tostring()
  43. return "lynx.text"
  44. end
  45. return text