import sys

import PodSix
PodSix.engine = "pygame"

from PodSix.VectorEditor import VectorEditor
from PodSix.EditableVectorShape import EditableVectorShape
from PodSix.EditableVectorSprite import EditableVectorSprite
from PodSix.Game import Game
from PodSix.Resource import *

class MyEditableVectorShape(EditableVectorShape):
	def DrawPolygon(self, points, color):
		gfx.DrawPolygon(points, color)
	
	def DrawLine(self, points, color):
		gfx.DrawLines(points, color, False)
	
	def DrawCircle(self, center, color, radius):
		gfx.DrawCircle(center, color, radius)

class MyEditableVectorSprite(EditableVectorSprite):
	shapeClass = MyEditableVectorShape

class MyVectorEditor(VectorEditor):
	spriteClass = MyEditableVectorSprite

class TestVectorEditor(Game, EventMonitor):
	def __init__(self):
		gfx.Caption('Test Vector Editor')
		gfx.SetSize([640, 480])
		
		self.e = MyVectorEditor()
		self.e.SetSize([640, 480])
		
		EventMonitor.__init__(self)
		Game.__init__(self)
		self.Add(self.e)
		
		if len(sys.argv) == 2:
			self.e.sprite.LoadSVG(sys.argv[1])
	
	def Pump(self):
		Game.Pump(self)
		EventMonitor.Pump(self)
	
	def Run(self):
		gfx.SetBackgroundColor([255, 255, 255])
		Game.Run(self)
		gfx.Flip()
	
	def MouseDown(self, e):
		self.e.PenDown(e.pos)
	
	def MouseMove(self, e):
		self.e.PenTo(e.pos, e.rel)
	
	def MouseUp(self, e):
		self.e.PenUp(e.pos)
	
	def KeyDown_delete(self, e):
		self.e.DeleteSelected()
	
	def KeyDown_escape(self, e):
		self.Quit()

t = TestVectorEditor()
t.Launch()


