from PodSix.Resource import *
from PodSix.Concurrent import Concurrent

class TimedText(Concurrent):
	"""
	Shows some text for an amount of time and then calls TextDone.
	Use it for "game over" and title text.
	position is specified in relative coordinates (e.g. center of screen is [0.5, 0.5])
	"""
	def __init__(self, text, time=4, position={"centerx": 0.5, "centery": 0.5}, color=[0, 0, 0], shadow=False, font="default"):
		Concurrent.__init__(self)
		self.font = font
		self.text = text
		self.pos = position
		self.color = color
		self.time = time
		self.counter = 0
		self.visible = False
		self.Start()
	
	def Reset(self):
		self.counter = self.time
		self.visible = False
	
	def SetText(self, text):
		self.text = text.split("\n")
	
	def Start(self):
		self.counter = self.time
		self.visible = True
	
	def Draw(self):
		if self.visible:
			self.rect = gfx.DrawText(self.text, self.pos, self.color, self.font, shadow=False)
			if self.counter > 0:
				self.counter -= self.Elapsed()
			else:
				self.visible = False
				self.TimeOut()
	
	def TimeOut(self):
		"""
		Override this to provide a specific behaviour when the time is up
		"""
	

